fix : TAN , QUI , FOR logic is good (not with box )
This commit is contained in:
parent
244604702a
commit
06bb867dc5
@ -1,4 +1,4 @@
|
||||
// ✅ Updated SelectionService with ComputeAmount logic adapted from C#
|
||||
// ✅ Final SelectionService.ts with special TAN (three-group) logic
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject } from 'rxjs';
|
||||
|
||||
@ -37,32 +37,53 @@ export class SelectionService {
|
||||
|
||||
if (numbers.length > 0 && value > 0 && label) {
|
||||
switch (label) {
|
||||
// 🟢 Single Leg Pools
|
||||
case 'WIN': // WNP
|
||||
case 'WIN':
|
||||
case 'SHP':
|
||||
case 'THP':
|
||||
case 'PLC': // PLP
|
||||
case 'PLC':
|
||||
updated.total = numbers.length * value * 10;
|
||||
break;
|
||||
|
||||
// 🟡 Exotic Pools (e.g., QNP, TNP, EXP)
|
||||
case 'FOR': // FRP
|
||||
case 'TAN': // TNP
|
||||
case 'EXA': // EXP
|
||||
case 'QUI': { // QNP (QUI special case already handled in UI logic)
|
||||
const mid = Math.floor(numbers.length / 2);
|
||||
const group1 = numbers.slice(0, mid);
|
||||
const group2 = numbers.slice(mid);
|
||||
const combinations = group1.length * group2.length;
|
||||
case 'FOR':
|
||||
case 'QUI': {
|
||||
const dashIndex = updated.numbers.indexOf('-');
|
||||
const group1 = updated.numbers.slice(0, dashIndex).filter(n => typeof n === 'number') as number[];
|
||||
const group2 = updated.numbers.slice(dashIndex + 1).filter(n => typeof n === 'number') as number[];
|
||||
|
||||
let combinations = group1.length * group2.length;
|
||||
if (isBoxed) {
|
||||
combinations = this.calculatePermutations(group1.length + group2.length);
|
||||
}
|
||||
|
||||
updated.total = combinations * value * 10;
|
||||
updated.numbers = [...group1, '-', ...group2];
|
||||
break;
|
||||
}
|
||||
|
||||
// 🔵 Multileg Pools (e.g., TBP, MJP, JPP)
|
||||
case 'TRE': // TBP
|
||||
case 'TAN': {
|
||||
const dashIndices = updated.numbers
|
||||
.map((n, idx) => (n === '-' ? idx : -1))
|
||||
.filter(idx => idx !== -1);
|
||||
|
||||
if (dashIndices.length < 2) break; // not ready yet
|
||||
|
||||
const group1 = updated.numbers.slice(0, dashIndices[0]).filter(n => typeof n === 'number') as number[];
|
||||
const group2 = updated.numbers.slice(dashIndices[0] + 1, dashIndices[1]).filter(n => typeof n === 'number') as number[];
|
||||
const group3 = updated.numbers.slice(dashIndices[1] + 1).filter(n => typeof n === 'number') as number[];
|
||||
|
||||
let combinations = group1.length * group2.length * group3.length;
|
||||
if (isBoxed) {
|
||||
combinations = this.calculatePermutations(group1.length + group2.length + group3.length);
|
||||
}
|
||||
|
||||
updated.total = combinations * value * 10;
|
||||
updated.numbers = [...group1, '-', ...group2, '-', ...group3];
|
||||
break;
|
||||
}
|
||||
|
||||
case 'TRE':
|
||||
case 'MJP':
|
||||
case 'JKP': { // JPP
|
||||
case 'JKP': {
|
||||
const legs = this.splitToLegs(numbers, this.getLegCount(label));
|
||||
const comb = legs.reduce((acc, leg) => acc * (leg.length || 1), 1);
|
||||
updated.total = comb * value * 10;
|
||||
@ -86,10 +107,7 @@ export class SelectionService {
|
||||
finalizeCurrentRow() {
|
||||
const completed = this.currentRow.value;
|
||||
if (!completed.label || completed.numbers.length === 0 || completed.value <= 0) return;
|
||||
|
||||
const finalRow: SelectionData = { ...completed };
|
||||
this.selections.next([...this.selections.value, finalRow]);
|
||||
|
||||
this.selections.next([...this.selections.value, { ...completed }]);
|
||||
this.currentRow.next({ label: '', numbers: [], value: 0, total: 0, isBoxed: false });
|
||||
}
|
||||
|
||||
@ -117,9 +135,9 @@ export class SelectionService {
|
||||
|
||||
private getLegCount(label: string): number {
|
||||
switch (label) {
|
||||
case 'TRE': return 3; // TBP
|
||||
case 'TRE': return 3;
|
||||
case 'MJP': return 4;
|
||||
case 'JKP': return 5; // JPP
|
||||
case 'JKP': return 5;
|
||||
default: return 3;
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
<button
|
||||
*ngIf="showShashEnter"
|
||||
class="btn btn-dark"
|
||||
[disabled]="selectedLabel === 'QUI' && isQUIFirstGroupComplete"
|
||||
[disabled]="twoGroupLabels.includes(selectedLabel || '') && isFirstGroupComplete"
|
||||
(click)="padEnter()"
|
||||
>
|
||||
shash ENTER
|
||||
|
||||
@ -11,12 +11,11 @@ import { SelectionService } from '../selection.service/selection.service';
|
||||
})
|
||||
export class TouchPadMenuComponent implements OnInit {
|
||||
@Input() ticketingActive: boolean = false;
|
||||
public twoGroupLabels = ['FOR', 'QUI'];
|
||||
|
||||
labels: string[] = [
|
||||
'WIN', 'SHP', 'THP',
|
||||
'PLC', 'SHW', 'FOR',
|
||||
'QUI', 'TAN', 'EXA',
|
||||
'WSP', 'TRE', 'MJP',
|
||||
'WIN', 'SHP', 'THP', 'PLC', 'SHW', 'FOR',
|
||||
'QUI', 'TAN', 'EXA', 'WSP', 'TRE', 'MJP',
|
||||
'JKP', 'SJP', '.'
|
||||
];
|
||||
|
||||
@ -33,12 +32,19 @@ export class TouchPadMenuComponent implements OnInit {
|
||||
maxRowsReached: boolean = false;
|
||||
|
||||
disabledLabels: string[] = ['SHW', 'SJP'];
|
||||
isQUIFirstGroupComplete = false;
|
||||
QUIGroup1: number[] = [];
|
||||
QUIGroup2: number[] = [];
|
||||
|
||||
// TAN logic
|
||||
tanGroupStage = 0;
|
||||
tanGroups: number[][] = [[], [], []];
|
||||
|
||||
// FOR/QUI logic
|
||||
isFirstGroupComplete = false;
|
||||
firstGroup: number[] = [];
|
||||
secondGroup: number[] = [];
|
||||
|
||||
isBoxed: boolean = false;
|
||||
|
||||
// 🔘 FIELD modal related
|
||||
// FIELD modal
|
||||
fieldModalOpen = false;
|
||||
fieldInput: string = '';
|
||||
fieldFEntered = false;
|
||||
@ -48,7 +54,6 @@ export class TouchPadMenuComponent implements OnInit {
|
||||
ngOnInit() {
|
||||
this.labelRowsFlat = this.labelRows.flat();
|
||||
this.numbersFlat = this.numberRows.flat();
|
||||
|
||||
this.selectionService.selections$.subscribe(selections => {
|
||||
this.maxRowsReached = selections.length >= 5;
|
||||
});
|
||||
@ -67,8 +72,17 @@ export class TouchPadMenuComponent implements OnInit {
|
||||
}
|
||||
|
||||
get showShashEnter(): boolean {
|
||||
const enabledLabels = ['FOR', 'QUI', 'TAN', 'EXA', 'WSP', 'TRE', 'MJP', 'JKP', 'SJP', '.'];
|
||||
return enabledLabels.includes(this.selectedLabel || '');
|
||||
const specialLabels = ['FOR', 'QUI', 'TAN', 'EXA', 'WSP', 'TRE', 'MJP', 'JKP', 'SJP', '.'];
|
||||
return specialLabels.includes(this.selectedLabel || '');
|
||||
}
|
||||
|
||||
get isShashEnterDisabled(): boolean {
|
||||
if (this.selectedLabel === 'TAN') {
|
||||
return this.tanGroupStage >= 2 || this.tanGroups[this.tanGroupStage].length === 0;
|
||||
} else if (this.twoGroupLabels.includes(this.selectedLabel || '')) {
|
||||
return this.isFirstGroupComplete || this.firstGroup.length === 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private chunk<T>(array: T[], size: number): T[][] {
|
||||
@ -86,55 +100,92 @@ export class TouchPadMenuComponent implements OnInit {
|
||||
this.selectedNumbers = [];
|
||||
this.padValue = '';
|
||||
this.canPrint = false;
|
||||
this.isQUIFirstGroupComplete = false;
|
||||
this.QUIGroup1 = [];
|
||||
this.QUIGroup2 = [];
|
||||
this.isBoxed = false;
|
||||
|
||||
// Reset TAN state
|
||||
this.tanGroupStage = 0;
|
||||
this.tanGroups = [[], [], []];
|
||||
|
||||
// Reset FOR/QUI state
|
||||
this.isFirstGroupComplete = false;
|
||||
this.firstGroup = [];
|
||||
this.secondGroup = [];
|
||||
|
||||
this.selectionService.updatePartial({ label });
|
||||
}
|
||||
|
||||
selectNumber(number: number) {
|
||||
if (!this.selectedLabel) return;
|
||||
|
||||
if (this.selectedLabel === 'QUI') {
|
||||
if (this.isQUIFirstGroupComplete) {
|
||||
if (!this.QUIGroup2.includes(number)) {
|
||||
this.QUIGroup2.push(number);
|
||||
this.selectedNumbers = [...this.QUIGroup1, '-', ...this.QUIGroup2];
|
||||
}
|
||||
} else {
|
||||
if (!this.QUIGroup1.includes(number)) {
|
||||
this.QUIGroup1.push(number);
|
||||
this.selectedNumbers = [...this.QUIGroup1];
|
||||
if (this.selectedLabel === 'TAN') {
|
||||
if (!this.tanGroups[this.tanGroupStage].includes(number)) {
|
||||
this.tanGroups[this.tanGroupStage].push(number);
|
||||
const combined: (number | string)[] = [...this.tanGroups[0]];
|
||||
if (this.tanGroupStage > 0) combined.push('-', ...this.tanGroups[1]);
|
||||
if (this.tanGroupStage > 1) combined.push('-', ...this.tanGroups[2]);
|
||||
this.selectedNumbers = combined;
|
||||
this.selectionService.updatePartial({ numbers: [...this.selectedNumbers] });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
this.selectionService.updatePartial({ numbers: this.selectedNumbers });
|
||||
if (this.twoGroupLabels.includes(this.selectedLabel || '')) {
|
||||
if (!this.isFirstGroupComplete) {
|
||||
if (!this.firstGroup.includes(number)) {
|
||||
this.firstGroup.push(number);
|
||||
this.selectedNumbers = [...this.firstGroup];
|
||||
}
|
||||
} else {
|
||||
if (!this.secondGroup.includes(number)) {
|
||||
this.secondGroup.push(number);
|
||||
this.selectedNumbers = [...this.firstGroup, '-', ...this.secondGroup];
|
||||
}
|
||||
}
|
||||
this.selectionService.updatePartial({ numbers: [...this.selectedNumbers] });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.selectedNumbers.includes(number)) {
|
||||
this.selectedNumbers.push(number);
|
||||
this.selectionService.updatePartial({ numbers: [...this.selectedNumbers] });
|
||||
}
|
||||
}
|
||||
|
||||
this.padValue = '';
|
||||
this.canPrint = false;
|
||||
isNumberDisabled(number: number): boolean {
|
||||
if (this.twoGroupLabels.includes(this.selectedLabel || '') || this.selectedLabel === 'TAN') return false;
|
||||
return this.selectedNumbers.includes(number);
|
||||
}
|
||||
|
||||
isNumberDisabled(number: number): boolean {
|
||||
if (this.selectedLabel === 'QUI') {
|
||||
return false; // ✅ Allow reuse in second group
|
||||
padEnter() {
|
||||
if (this.selectedLabel === 'TAN') {
|
||||
if (this.tanGroupStage < 2) {
|
||||
this.tanGroupStage++;
|
||||
const combined: (number | string)[] = [...this.tanGroups[0]];
|
||||
if (this.tanGroupStage > 0) combined.push('-', ...this.tanGroups[1]);
|
||||
if (this.tanGroupStage > 1) combined.push('-', ...this.tanGroups[2]);
|
||||
this.selectedNumbers = combined;
|
||||
this.selectionService.updatePartial({ numbers: [...this.selectedNumbers] });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.twoGroupLabels.includes(this.selectedLabel || '')) {
|
||||
if (!this.isFirstGroupComplete && this.firstGroup.length > 0) {
|
||||
this.isFirstGroupComplete = true;
|
||||
this.secondGroup = [];
|
||||
this.selectedNumbers = [...this.firstGroup, '-'];
|
||||
this.selectionService.updatePartial({ numbers: [...this.selectedNumbers] });
|
||||
return;
|
||||
}
|
||||
} else if (this.canPrint) {
|
||||
this.print();
|
||||
}
|
||||
return this.selectedNumbers.includes(number);
|
||||
}
|
||||
|
||||
enterPadVal(key: string) {
|
||||
if (!this.numericPadEnabled) return;
|
||||
if (/[0-9]/.test(key)) {
|
||||
this.padValue += key;
|
||||
} else if (key === 'X') {
|
||||
this.padValue += 'X';
|
||||
}
|
||||
if (/[0-9]/.test(key)) this.padValue += key;
|
||||
else if (key === 'X') this.padValue += 'X';
|
||||
|
||||
this.updateCanPrint();
|
||||
|
||||
@ -153,24 +204,6 @@ export class TouchPadMenuComponent implements OnInit {
|
||||
this.canPrint = this.padValue.trim().length > 0 && /^[0-9]+$/.test(this.padValue);
|
||||
}
|
||||
|
||||
padEnter() {
|
||||
if (this.selectedLabel === 'QUI') {
|
||||
if (!this.isQUIFirstGroupComplete && this.QUIGroup1.length > 0) {
|
||||
this.isQUIFirstGroupComplete = true;
|
||||
|
||||
// ✅ Add dash to represent separator
|
||||
this.selectedNumbers = [...this.QUIGroup1, '-'];
|
||||
this.QUIGroup2 = [];
|
||||
|
||||
// Update to prepare for second group
|
||||
this.selectionService.updatePartial({ numbers: [...this.selectedNumbers] });
|
||||
return;
|
||||
}
|
||||
} else if (this.canPrint) {
|
||||
this.print();
|
||||
}
|
||||
}
|
||||
|
||||
print() {
|
||||
this.selectionService.finalizeCurrentRow();
|
||||
this.resetSelections();
|
||||
@ -187,14 +220,35 @@ export class TouchPadMenuComponent implements OnInit {
|
||||
this.padValue = '';
|
||||
this.canPrint = false;
|
||||
this.isBoxed = false;
|
||||
this.isQUIFirstGroupComplete = false;
|
||||
this.QUIGroup1 = [];
|
||||
this.QUIGroup2 = [];
|
||||
|
||||
// Reset FOR/QUI
|
||||
this.isFirstGroupComplete = false;
|
||||
this.firstGroup = [];
|
||||
this.secondGroup = [];
|
||||
|
||||
// Reset TAN
|
||||
this.tanGroupStage = 0;
|
||||
this.tanGroups = [[], [], []];
|
||||
|
||||
// Reset field modal
|
||||
this.fieldModalOpen = false;
|
||||
this.fieldInput = '';
|
||||
this.fieldFEntered = false;
|
||||
this.fieldModalOpen = false;
|
||||
}
|
||||
|
||||
toggleBoxMode() {
|
||||
this.isBoxed = !this.isBoxed;
|
||||
const value = parseFloat(this.padValue) || 0;
|
||||
this.selectionService.updatePartial({
|
||||
isBoxed: this.isBoxed,
|
||||
label: this.selectedLabel || '',
|
||||
numbers: [...this.selectedNumbers],
|
||||
value
|
||||
});
|
||||
this.updateCanPrint();
|
||||
}
|
||||
|
||||
// Calculator methods
|
||||
openCalculator() {
|
||||
this.calculatorOpen = true;
|
||||
this.calcDisplay = '';
|
||||
@ -214,9 +268,7 @@ export class TouchPadMenuComponent implements OnInit {
|
||||
}
|
||||
|
||||
backspace() {
|
||||
this.calcDisplay = this.calcDisplay === 'Error'
|
||||
? ''
|
||||
: this.calcDisplay.slice(0, -1);
|
||||
this.calcDisplay = this.calcDisplay === 'Error' ? '' : this.calcDisplay.slice(0, -1);
|
||||
}
|
||||
|
||||
calculate() {
|
||||
@ -227,30 +279,10 @@ export class TouchPadMenuComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
toggleBoxMode() {
|
||||
this.isBoxed = !this.isBoxed;
|
||||
|
||||
// 🔁 Re-calculate with current selections and value
|
||||
const value = parseFloat(this.padValue) || 0;
|
||||
this.selectionService.updatePartial({
|
||||
isBoxed: this.isBoxed,
|
||||
label: this.selectedLabel || '',
|
||||
numbers: [...this.selectedNumbers],
|
||||
value: value
|
||||
});
|
||||
|
||||
// Optional: force canPrint update
|
||||
this.updateCanPrint();
|
||||
}
|
||||
|
||||
// 🔘 FIELD Modal Logic
|
||||
// FIELD modal methods
|
||||
canUseField(): boolean {
|
||||
const allowedLabels = ['WIN', 'SHP', 'THP', 'PLC', 'SHW'];
|
||||
return (
|
||||
this.selectedLabel !== null &&
|
||||
allowedLabels.includes(this.selectedLabel) &&
|
||||
this.selectedNumbers.length === 0
|
||||
);
|
||||
return this.selectedLabel !== null && allowedLabels.includes(this.selectedLabel) && this.selectedNumbers.length === 0;
|
||||
}
|
||||
|
||||
openFieldModal() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user