Skip to content

Commit

Permalink
#113 - no ER on TIE
Browse files Browse the repository at this point in the history
  • Loading branch information
AloisSeckar committed Jul 28, 2023
1 parent 3bbfb6c commit 131bbfd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions assets/lang/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
"noER1" : "Je vybrán umožněný doběh (R1), ale to není možné, pokud nastal decessive error.",
"noER2" : "Je vybrán umožněný doběh (R2), ale to není možné, pokud nastal decessive error.",
"noER3" : "Je vybrán umožněný doběh (R3), ale to není možné, pokud nastal decessive error.",
"noTieER" : "Doběh běžce, který byl umístěn na metu jako TIE, musí být unearned.",
"missingOAdv" : "Je vybrán další postup na 'FC - Occupied)', ale chybí odpovídající FC situace.",
"window" : {
"title" : "Neplatný vstup",
Expand Down
1 change: 1 addition & 0 deletions assets/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@
"noER1" : "Earned run is selected (Runner at 1st), \nbut this is not possible with a decisive error.",
"noER2" : "Earned run is selected (Runner at 2nd), \nbut this is not possible with a decisive error.",
"noER3" : "Earned run is selected (Runner at 3rd), \nbut this is not possible with a decisive error.",
"noTieER" : "If a run is scored with a runner placed as TIE, it must be an unearned run.",
"missingOAdv" : "Advance after 'FC - Occupied' is selected, \nbut no corresponding FC play was given.",
"window" : {
"title" : "Invalid input",
Expand Down
26 changes: 26 additions & 0 deletions utils/wbsc-validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,18 @@ function checkEarnedRuns (inputs: WBSCInput[]) {
let errR2 = false
let errR3 = false

// only relevant for runners at 1st and 2nd
// run marked as team-unearned
let r1TU = false
let r2TU = false
// it was a TIE runner
let tieR1 = false
let tieR2 = false

inputs.forEach((input) => {
const err = isError(input, decisiveErrorActions)
const earned = isEarnedRun(input)
const teamUnearned = isTeamUnearnedRun(input)

switch (input.group) {
case inputB:
Expand All @@ -599,6 +608,8 @@ function checkEarnedRuns (inputs: WBSCInput[]) {
}
break
case inputR1:
tieR1 = input.tie
// falls through
case inputR1a:
case inputR1b:
if (err) {
Expand All @@ -607,15 +618,23 @@ function checkEarnedRuns (inputs: WBSCInput[]) {
if (earned) {
r1ER = true
}
if (teamUnearned) {
r1TU = true
}
break
case inputR2:
tieR2 = input.tie
// falls through
case inputR2a:
if (err) {
errR2 = true
}
if (earned) {
r2ER = true
}
if (teamUnearned) {
r2TU = true
}
break
case inputR3:
if (err) {
Expand All @@ -640,6 +659,9 @@ function checkEarnedRuns (inputs: WBSCInput[]) {
if (r3ER && errR3) {
validation = attachValidation(validation, useT('editor.validation.noER3'))
}
if ((tieR1 && (r1ER || r1TU)) || (tieR2 && (r2ER || r2TU))) {
validation = attachValidation(validation, useT('editor.validation.noTieER'))
}

return validation
}
Expand Down Expand Up @@ -683,6 +705,10 @@ function isError (input: WBSCInput, actionList: string[]): boolean {
function isEarnedRun (input: WBSCInput): boolean {
return (input?.output?.base === 4 || input?.output?.errorTarget === 4) && input?.output?.run === 'e'
}
// helper to decide whether there is a team unearned run in current input
function isTeamUnearnedRun (input: WBSCInput): boolean {
return (input?.output?.base === 4 || input?.output?.errorTarget === 4) && input?.output?.run === 'tu'
}

// helper to attach new part of validation message to previous contents
function attachValidation (validation: string, newMessage: string) {
Expand Down

0 comments on commit 131bbfd

Please # to comment.