feat : added proper logic to MJP, JKP, TRE
This commit is contained in:
parent
f7552a8479
commit
61e438f4a6
@ -1,4 +1,3 @@
|
|||||||
// ✅ Final SelectionService.ts with special TAN (three-group) logic
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { BehaviorSubject } from 'rxjs';
|
import { BehaviorSubject } from 'rxjs';
|
||||||
|
|
||||||
@ -81,12 +80,18 @@ export class SelectionService {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'TRE':
|
case 'TRE': // TBP: 3 legs
|
||||||
case 'MJP':
|
case 'MJP': // MJP: 4 legs
|
||||||
case 'JKP': {
|
case 'JKP': { // JPP: 5 legs
|
||||||
const legs = this.splitToLegs(numbers, this.getLegCount(label));
|
const legs = this.splitToLegs(updated.numbers, this.getLegCount(label));
|
||||||
const comb = legs.reduce((acc, leg) => acc * (leg.length || 1), 1);
|
const requiredLegs = this.getLegCount(label);
|
||||||
updated.total = comb * value * 10;
|
// Calculate partial total if at least second-to-last leg has numbers
|
||||||
|
const filledLegs = legs.filter(leg => leg.length > 0).length;
|
||||||
|
if (filledLegs >= requiredLegs - 1) {
|
||||||
|
// Assume remaining legs have at least 1 horse
|
||||||
|
const combinations = legs.reduce((acc, leg) => acc * (leg.length || 1), 1);
|
||||||
|
updated.total = combinations * value * 10; // fUBA = 10
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,20 +129,42 @@ export class SelectionService {
|
|||||||
return n >= 2 ? n * (n - 1) : 0; // nP2
|
return n >= 2 ? n * (n - 1) : 0; // nP2
|
||||||
}
|
}
|
||||||
|
|
||||||
private splitToLegs(numbers: number[], legCount: number): number[][] {
|
private splitToLegs(numbers: (number | string)[], legCount: number): number[][] {
|
||||||
const result: number[][] = [];
|
const result: number[][] = [];
|
||||||
const perLeg = Math.floor(numbers.length / legCount);
|
let currentLeg: number[] = [];
|
||||||
for (let i = 0; i < legCount; i++) {
|
let separatorCount = 0;
|
||||||
result.push(numbers.slice(i * perLeg, (i + 1) * perLeg));
|
|
||||||
|
for (const item of numbers) {
|
||||||
|
if (item === '-') {
|
||||||
|
if (currentLeg.length > 0) {
|
||||||
|
result.push([...currentLeg]);
|
||||||
|
currentLeg = [];
|
||||||
|
separatorCount++;
|
||||||
}
|
}
|
||||||
return result;
|
if (separatorCount >= legCount - 1) break;
|
||||||
|
} else if (typeof item === 'number') {
|
||||||
|
currentLeg.push(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Push the last leg if it has numbers
|
||||||
|
if (currentLeg.length > 0) {
|
||||||
|
result.push([...currentLeg]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fill remaining legs with empty arrays if needed
|
||||||
|
while (result.length < legCount) {
|
||||||
|
result.push([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.slice(0, legCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getLegCount(label: string): number {
|
private getLegCount(label: string): number {
|
||||||
switch (label) {
|
switch (label) {
|
||||||
case 'TRE': return 3;
|
case 'TRE': return 3; // TBP
|
||||||
case 'MJP': return 4;
|
case 'MJP': return 4; // MJP
|
||||||
case 'JKP': return 5;
|
case 'JKP': return 5; // JPP
|
||||||
default: return 3;
|
default: return 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
// ... same imports
|
|
||||||
import { Component, Input, OnInit } from '@angular/core';
|
import { Component, Input, OnInit } from '@angular/core';
|
||||||
import { CommonModule } from '@angular/common';
|
import { CommonModule } from '@angular/common';
|
||||||
import { SelectionService } from '../selection.service/selection.service';
|
import { SelectionService } from '../selection.service/selection.service';
|
||||||
@ -12,7 +11,9 @@ import { SelectionService } from '../selection.service/selection.service';
|
|||||||
})
|
})
|
||||||
export class TouchPadMenuComponent implements OnInit {
|
export class TouchPadMenuComponent implements OnInit {
|
||||||
@Input() ticketingActive: boolean = false;
|
@Input() ticketingActive: boolean = false;
|
||||||
|
|
||||||
public twoGroupLabels = ['FOR', 'QUI'];
|
public twoGroupLabels = ['FOR', 'QUI'];
|
||||||
|
public multiLegLabels = ['TRE', 'MJP', 'JKP'];
|
||||||
|
|
||||||
labels: string[] = [
|
labels: string[] = [
|
||||||
'WIN', 'SHP', 'THP', 'PLC', 'SHW', 'FOR',
|
'WIN', 'SHP', 'THP', 'PLC', 'SHW', 'FOR',
|
||||||
@ -34,15 +35,19 @@ export class TouchPadMenuComponent implements OnInit {
|
|||||||
|
|
||||||
disabledLabels: string[] = ['SHW', 'SJP'];
|
disabledLabels: string[] = ['SHW', 'SJP'];
|
||||||
|
|
||||||
// TAN logic
|
// ✅ Original TAN logic
|
||||||
tanGroupStage = 0;
|
tanGroupStage = 0;
|
||||||
tanGroups: number[][] = [[], [], []];
|
tanGroups: number[][] = [[], [], []];
|
||||||
|
|
||||||
// FOR/QUI logic
|
// ✅ FOR/QUI logic
|
||||||
isFirstGroupComplete = false;
|
isFirstGroupComplete = false;
|
||||||
firstGroup: number[] = [];
|
firstGroup: number[] = [];
|
||||||
secondGroup: number[] = [];
|
secondGroup: number[] = [];
|
||||||
|
|
||||||
|
// ✅ Multi-leg logic (TRE, MJP, JKP)
|
||||||
|
multiLegStage = 0;
|
||||||
|
multiLegGroups: number[][] = [[], [], [], [], []];
|
||||||
|
|
||||||
isBoxed: boolean = false;
|
isBoxed: boolean = false;
|
||||||
|
|
||||||
// FIELD modal
|
// FIELD modal
|
||||||
@ -73,13 +78,16 @@ export class TouchPadMenuComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get showShashEnter(): boolean {
|
get showShashEnter(): boolean {
|
||||||
const specialLabels = ['FOR', 'QUI', 'TAN', 'EXA', 'WSP', 'TRE', 'MJP', 'JKP', 'SJP', '.'];
|
const specialLabels = ['FOR', 'QUI', 'TAN', 'EXA', 'WSP', 'TRE', 'MJP', 'JKP', '.'];
|
||||||
return specialLabels.includes(this.selectedLabel || '');
|
return specialLabels.includes(this.selectedLabel || '');
|
||||||
}
|
}
|
||||||
|
|
||||||
get isShashEnterDisabled(): boolean {
|
get isShashEnterDisabled(): boolean {
|
||||||
if (this.selectedLabel === 'TAN') {
|
if (this.selectedLabel === 'TAN') {
|
||||||
return this.tanGroupStage >= 2 || this.tanGroups[this.tanGroupStage].length === 0;
|
return this.tanGroupStage >= 2 || this.tanGroups[this.tanGroupStage].length === 0;
|
||||||
|
} else if (this.multiLegLabels.includes(this.selectedLabel || '')) {
|
||||||
|
const maxLegs = this.getMaxLegs(this.selectedLabel || '');
|
||||||
|
return this.multiLegStage >= maxLegs - 1 || this.multiLegGroups[this.multiLegStage].length === 0;
|
||||||
} else if (this.twoGroupLabels.includes(this.selectedLabel || '')) {
|
} else if (this.twoGroupLabels.includes(this.selectedLabel || '')) {
|
||||||
return this.isFirstGroupComplete || this.firstGroup.length === 0;
|
return this.isFirstGroupComplete || this.firstGroup.length === 0;
|
||||||
}
|
}
|
||||||
@ -109,15 +117,19 @@ export class TouchPadMenuComponent implements OnInit {
|
|||||||
this.canPrint = false;
|
this.canPrint = false;
|
||||||
this.isBoxed = false;
|
this.isBoxed = false;
|
||||||
|
|
||||||
// Reset TAN state
|
// ✅ Reset TAN
|
||||||
this.tanGroupStage = 0;
|
this.tanGroupStage = 0;
|
||||||
this.tanGroups = [[], [], []];
|
this.tanGroups = [[], [], []];
|
||||||
|
|
||||||
// Reset FOR/QUI state
|
// ✅ Reset FOR/QUI
|
||||||
this.isFirstGroupComplete = false;
|
this.isFirstGroupComplete = false;
|
||||||
this.firstGroup = [];
|
this.firstGroup = [];
|
||||||
this.secondGroup = [];
|
this.secondGroup = [];
|
||||||
|
|
||||||
|
// ✅ Reset Multi-leg
|
||||||
|
this.multiLegStage = 0;
|
||||||
|
this.multiLegGroups = [[], [], [], [], []];
|
||||||
|
|
||||||
this.selectionService.updatePartial({ label });
|
this.selectionService.updatePartial({ label });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,6 +148,14 @@ export class TouchPadMenuComponent implements OnInit {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.multiLegLabels.includes(this.selectedLabel)) {
|
||||||
|
if (!this.multiLegGroups[this.multiLegStage].includes(number)) {
|
||||||
|
this.multiLegGroups[this.multiLegStage].push(number);
|
||||||
|
this.updateMultiLegSelection();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.twoGroupLabels.includes(this.selectedLabel || '')) {
|
if (this.twoGroupLabels.includes(this.selectedLabel || '')) {
|
||||||
if (!this.isFirstGroupComplete) {
|
if (!this.isFirstGroupComplete) {
|
||||||
if (!this.firstGroup.includes(number)) {
|
if (!this.firstGroup.includes(number)) {
|
||||||
@ -158,12 +178,23 @@ export class TouchPadMenuComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private updateMultiLegSelection() {
|
||||||
|
const combined: (number | string)[] = [];
|
||||||
|
for (let i = 0; i <= this.multiLegStage; i++) {
|
||||||
|
if (i > 0) combined.push('-');
|
||||||
|
combined.push(...this.multiLegGroups[i]);
|
||||||
|
}
|
||||||
|
this.selectedNumbers = combined;
|
||||||
|
this.selectionService.updatePartial({ numbers: [...this.selectedNumbers] });
|
||||||
|
}
|
||||||
|
|
||||||
isNumberDisabled(number: number): boolean {
|
isNumberDisabled(number: number): boolean {
|
||||||
if (this.twoGroupLabels.includes(this.selectedLabel || '') || this.selectedLabel === 'TAN') return false;
|
if (this.selectedLabel === 'TAN' || this.multiLegLabels.includes(this.selectedLabel || '') || this.twoGroupLabels.includes(this.selectedLabel || '')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return this.selectedNumbers.includes(number);
|
return this.selectedNumbers.includes(number);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 👉 Changed from padEnter to split into two handlers
|
|
||||||
onPadEnter() {
|
onPadEnter() {
|
||||||
if (this.canPrint) {
|
if (this.canPrint) {
|
||||||
this.print();
|
this.print();
|
||||||
@ -183,13 +214,21 @@ export class TouchPadMenuComponent implements OnInit {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.multiLegLabels.includes(this.selectedLabel || '')) {
|
||||||
|
const maxLegs = this.getMaxLegs(this.selectedLabel || '');
|
||||||
|
if (this.multiLegStage < maxLegs - 1) {
|
||||||
|
this.multiLegStage++;
|
||||||
|
this.updateMultiLegSelection();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.twoGroupLabels.includes(this.selectedLabel || '')) {
|
if (this.twoGroupLabels.includes(this.selectedLabel || '')) {
|
||||||
if (!this.isFirstGroupComplete && this.firstGroup.length > 0) {
|
if (!this.isFirstGroupComplete && this.firstGroup.length > 0) {
|
||||||
this.isFirstGroupComplete = true;
|
this.isFirstGroupComplete = true;
|
||||||
this.secondGroup = [];
|
this.secondGroup = [];
|
||||||
this.selectedNumbers = [...this.firstGroup, '-'];
|
this.selectedNumbers = [...this.firstGroup, '-'];
|
||||||
this.selectionService.updatePartial({ numbers: [...this.selectedNumbers] });
|
this.selectionService.updatePartial({ numbers: [...this.selectedNumbers] });
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -233,16 +272,16 @@ export class TouchPadMenuComponent implements OnInit {
|
|||||||
this.canPrint = false;
|
this.canPrint = false;
|
||||||
this.isBoxed = false;
|
this.isBoxed = false;
|
||||||
|
|
||||||
// Reset FOR/QUI
|
this.tanGroupStage = 0;
|
||||||
|
this.tanGroups = [[], [], []];
|
||||||
|
|
||||||
this.isFirstGroupComplete = false;
|
this.isFirstGroupComplete = false;
|
||||||
this.firstGroup = [];
|
this.firstGroup = [];
|
||||||
this.secondGroup = [];
|
this.secondGroup = [];
|
||||||
|
|
||||||
// Reset TAN
|
this.multiLegStage = 0;
|
||||||
this.tanGroupStage = 0;
|
this.multiLegGroups = [[], [], [], [], []];
|
||||||
this.tanGroups = [[], [], []];
|
|
||||||
|
|
||||||
// Reset field modal
|
|
||||||
this.fieldModalOpen = false;
|
this.fieldModalOpen = false;
|
||||||
this.fieldInput = '';
|
this.fieldInput = '';
|
||||||
this.fieldFEntered = false;
|
this.fieldFEntered = false;
|
||||||
@ -260,22 +299,9 @@ export class TouchPadMenuComponent implements OnInit {
|
|||||||
this.updateCanPrint();
|
this.updateCanPrint();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ✅ New method for BKP logic
|
|
||||||
removeLastNumber() {
|
removeLastNumber() {
|
||||||
if (!this.selectedLabel || this.selectedNumbers.length === 0) return;
|
if (!this.selectedLabel || this.selectedNumbers.length === 0) return;
|
||||||
|
|
||||||
if (this.twoGroupLabels.includes(this.selectedLabel)) {
|
|
||||||
if (!this.isFirstGroupComplete && this.firstGroup.length > 0) {
|
|
||||||
this.firstGroup.pop();
|
|
||||||
this.selectedNumbers = [...this.firstGroup];
|
|
||||||
} else if (this.secondGroup.length > 0) {
|
|
||||||
this.secondGroup.pop();
|
|
||||||
this.selectedNumbers = [...this.firstGroup, '-', ...this.secondGroup];
|
|
||||||
}
|
|
||||||
this.selectionService.updatePartial({ numbers: [...this.selectedNumbers] });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.selectedLabel === 'TAN') {
|
if (this.selectedLabel === 'TAN') {
|
||||||
const currentGroup = this.tanGroups[this.tanGroupStage];
|
const currentGroup = this.tanGroups[this.tanGroupStage];
|
||||||
if (currentGroup.length > 0) {
|
if (currentGroup.length > 0) {
|
||||||
@ -289,11 +315,41 @@ export class TouchPadMenuComponent implements OnInit {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.multiLegLabels.includes(this.selectedLabel)) {
|
||||||
|
const currentGroup = this.multiLegGroups[this.multiLegStage];
|
||||||
|
if (currentGroup.length > 0) {
|
||||||
|
currentGroup.pop();
|
||||||
|
this.updateMultiLegSelection();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.twoGroupLabels.includes(this.selectedLabel)) {
|
||||||
|
if (!this.isFirstGroupComplete && this.firstGroup.length > 0) {
|
||||||
|
this.firstGroup.pop();
|
||||||
|
this.selectedNumbers = [...this.firstGroup];
|
||||||
|
} else if (this.secondGroup.length > 0) {
|
||||||
|
this.secondGroup.pop();
|
||||||
|
this.selectedNumbers = [...this.firstGroup, '-', ...this.secondGroup];
|
||||||
|
}
|
||||||
|
this.selectionService.updatePartial({ numbers: [...this.selectedNumbers] });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.selectedNumbers.pop();
|
this.selectedNumbers.pop();
|
||||||
this.selectionService.updatePartial({ numbers: [...this.selectedNumbers] });
|
this.selectionService.updatePartial({ numbers: [...this.selectedNumbers] });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculator and Field Modal methods (unchanged)...
|
private getMaxLegs(label: string): number {
|
||||||
|
switch (label) {
|
||||||
|
case 'TRE': return 3;
|
||||||
|
case 'MJP': return 4;
|
||||||
|
case 'JKP': return 5;
|
||||||
|
default: return 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculator and Field Modal methods (unchanged)
|
||||||
openCalculator() { this.calculatorOpen = true; this.calcDisplay = ''; }
|
openCalculator() { this.calculatorOpen = true; this.calcDisplay = ''; }
|
||||||
closeCalculator() { this.calculatorOpen = false; }
|
closeCalculator() { this.calculatorOpen = false; }
|
||||||
press(val: string) { if (this.calcDisplay === 'Error') this.calcDisplay = ''; this.calcDisplay += val; }
|
press(val: string) { if (this.calcDisplay === 'Error') this.calcDisplay = ''; this.calcDisplay += val; }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user