From bbeb97b7b4c55ae7d800f7825f5184c3155c5b57 Mon Sep 17 00:00:00 2001 From: karthik Date: Fri, 25 Jul 2025 13:11:51 +0530 Subject: [PATCH] feat : touchpad math logic --- .../selection.service/selection.service.ts | 116 ++++++++++++------ .../touch-pad-menu.component.html | 9 +- .../touch-pad-menu.component.ts | 45 +++++-- 3 files changed, 120 insertions(+), 50 deletions(-) diff --git a/btc-UI/src/app/components/selection.service/selection.service.ts b/btc-UI/src/app/components/selection.service/selection.service.ts index e1fdbc1..a83353b 100644 --- a/btc-UI/src/app/components/selection.service/selection.service.ts +++ b/btc-UI/src/app/components/selection.service/selection.service.ts @@ -1,9 +1,10 @@ +// selection.service.ts import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs'; -// selection.service.ts + export interface SelectionData { label: string; - numbers: number[]; + numbers: (number | string)[]; value: number; total: number; } @@ -25,30 +26,56 @@ export class SelectionService { // ✅ Update only part of the current row (label / numbers / value) updatePartial(update: Partial) { - const current = this.currentRow.value; + const current = this.currentRow.value; + const updated: SelectionData = { ...current, ...update }; - const updated: SelectionData = { - ...current, - ...update - }; + const label = updated.label; + const value = updated.value; + const numbers = (updated.numbers || []).filter(n => typeof n === 'number') as number[]; - - const multiplyByTenLabels = ['WIN', 'SHP', 'THP', 'PLC']; - - if (updated.numbers.length > 0 && updated.value > 0) { - if (multiplyByTenLabels.includes(updated.label)) { - updated.total = updated.numbers.length * updated.value * 10; - } else { - // For other labels, define your logic e.g. no multiply by 10 or another multiplier - updated.total = updated.numbers.length * updated.value; - // Or whatever logic you need here - } - } else { updated.total = 0; - } - this.currentRow.next(updated); -} + if (numbers.length > 0 && value > 0 && label) { + switch (label) { + // SINGLELEG: WIN, SHP, THP, PLC + case 'WIN': + case 'SHP': + case 'THP': + case 'PLC': + updated.total = numbers.length * value * 10; + break; + + // EXOTIC: QUI (2 groups) + case 'QUI': { + const mid = Math.floor(numbers.length / 2); + const group1 = numbers.slice(0, mid); + const group2 = numbers.slice(mid); + const combinations = group1.length * group2.length; + updated.total = combinations * value * 10; + updated.numbers = [...group1, '-', ...group2]; + break; + } + + // MULTILEG: TRE (3 legs), MJP (4), JKP (5) + case 'TRE': + case 'MJP': + case 'JKP': + case 'SJP': { + const legs = this.splitToLegs(numbers, this.getLegCount(label)); + const comb = legs.reduce((acc, leg) => acc * (leg.length || 1), 1); + updated.total = comb * value * 10; + break; + } + + // EXOTIC fallback (e.g., TAN, EXA, FRP, QNP, EXP, etc.) + default: + updated.total = this.calculateCombinations(numbers.length) * value * 10; + break; + } + } + + this.currentRow.next(updated); + } // ✅ Finalize the current row and push it to the finalized list finalizeCurrentRow() { @@ -57,29 +84,38 @@ export class SelectionService { // Validation: must have label, numbers, and valid value if (!completed.label || completed.numbers.length === 0 || completed.value <= 0) return; - const total = completed.numbers.length * completed.value * 10; - const finalRow: SelectionData = { ...completed, total }; + const finalRow: SelectionData = { ...completed }; + this.selections.next([...this.selections.value, finalRow]); - const updatedSelections = [...this.selections.value, finalRow]; - this.selections.next(updatedSelections); - - // Reset current row - this.currentRow.next({ - label: '', - numbers: [], - value: 0, - total: 0 - }); + this.currentRow.next({ label: '', numbers: [], value: 0, total: 0 }); } // ✅ Clear everything (for ERASE) clearSelections() { this.selections.next([]); - this.currentRow.next({ - label: '', - numbers: [], - value: 0, - total: 0 - }); + this.currentRow.next({ label: '', numbers: [], value: 0, total: 0 }); + } + + private calculateCombinations(n: number): number { + return n >= 2 ? (n * (n - 1)) / 2 : 0; + } + + private splitToLegs(numbers: number[], legCount: number): number[][] { + const result: number[][] = []; + const perLeg = Math.floor(numbers.length / legCount); + for (let i = 0; i < legCount; i++) { + result.push(numbers.slice(i * perLeg, (i + 1) * perLeg)); + } + return result; + } + + private getLegCount(label: string): number { + switch (label) { + case 'TRE': return 3; + case 'MJP': return 4; + case 'JKP': return 5; + case 'SJP': return 5; + default: return 3; + } } } diff --git a/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.html b/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.html index 06ab210..0ecbdd3 100755 --- a/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.html +++ b/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.html @@ -14,7 +14,14 @@
- + + diff --git a/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts b/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts index 49c0355..862190e 100755 --- a/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts +++ b/btc-UI/src/app/components/touch-pad-menu/touch-pad-menu.component.ts @@ -37,6 +37,10 @@ export class TouchPadMenuComponent implements OnInit { // ✅ Disabled labels list disabledLabels: string[] = ['SHW', 'SJP']; + isQUIFirstGroupComplete = false; + QUIGroup1: number[] = []; + QUIGroup2: number[] = []; + constructor(private selectionService: SelectionService) {} ngOnInit() { @@ -77,24 +81,43 @@ export class TouchPadMenuComponent implements OnInit { this.selectedNumbers = []; this.padValue = ''; this.canPrint = false; - - // 👇 Update label immediately in table + this.isQUIFirstGroupComplete = false; + this.QUIGroup1 = []; + this.QUIGroup2 = []; this.selectionService.updatePartial({ label }); } selectNumber(number: number) { if (!this.selectedLabel) return; - if (!this.selectedNumbers.includes(number)) { - this.selectedNumbers.push(number); - this.padValue = ''; - this.canPrint = false; - // 👇 Update numbers immediately in table - this.selectionService.updatePartial({ numbers: [...this.selectedNumbers] }); + if (this.selectedLabel === 'QUI') { + if (this.isQUIFirstGroupComplete) { + if (!this.QUIGroup2.includes(number)) { + this.QUIGroup2.push(number); + this.selectedNumbers = [...this.QUIGroup1, ...this.QUIGroup2]; + this.selectionService.updatePartial({ numbers: this.selectedNumbers }); + } + } else { + if (!this.QUIGroup1.includes(number)) { + this.QUIGroup1.push(number); + this.selectedNumbers = [...this.QUIGroup1]; + this.selectionService.updatePartial({ numbers: this.selectedNumbers }); + } + } + } else { + if (!this.selectedNumbers.includes(number)) { + this.selectedNumbers.push(number); + this.selectionService.updatePartial({ numbers: [...this.selectedNumbers] }); + } } + this.padValue = ''; + this.canPrint = false; } isNumberDisabled(number: number) { + if (this.selectedLabel === 'QUI') { + return this.QUIGroup1.includes(number) || this.QUIGroup2.includes(number); + } return this.selectedNumbers.includes(number); } @@ -119,7 +142,11 @@ export class TouchPadMenuComponent implements OnInit { } padEnter() { - if (this.canPrint) { + if (this.selectedLabel === 'QUI') { + if (!this.isQUIFirstGroupComplete && this.QUIGroup1.length > 0) { + this.isQUIFirstGroupComplete = true; + } + } else if (this.canPrint) { this.print(); } }