Skip to content

Commit

Permalink
Merge pull request #436 from softwaremagico/430-changing-score-direct…
Browse files Browse the repository at this point in the history
…ion-where-to-put-hansoku

430 changing score direction where to put hansoku
  • Loading branch information
softwaremagico authored May 16, 2024
2 parents 6fc5369 + 7f5fcf8 commit 4cb2b05
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {Component, Input, OnChanges, OnInit, SimpleChanges, ViewEncapsulation} f
import {Duel} from "../../../../../models/duel";
import {DuelService} from "../../../../../services/duel.service";
import {MessageService} from "../../../../../services/message.service";
import {Score} from "../../../../../models/score";
import {ScoreUpdatedService} from "../../../../../services/notifications/score-updated.service";
import {TranslateService} from "@ngx-translate/core";
import {RbacService} from "../../../../../services/rbac/rbac.service";
Expand Down Expand Up @@ -64,9 +63,7 @@ export class FaultComponent implements OnInit, OnChanges {
} else {
this.duel.competitor1Fault = false;
this.duel.competitor1FaultTime = undefined;
if (this.duel.competitor2Score.length < 2) {
this.duel.competitor2Score.push(Score.HANSOKU);
this.duel.competitor2ScoreTime.push(this.duel.duration!);
if (Duel.addHansoku(this.duel, false)) {
this.scoreUpdatedService.isScoreUpdated.next(this.duel);
} else {
this.messageService.warningMessage("scoreNotAdded");
Expand All @@ -85,9 +82,7 @@ export class FaultComponent implements OnInit, OnChanges {
} else {
this.duel.competitor2Fault = false;
this.duel.competitor2FaultTime = undefined;
if (this.duel.competitor1Score.length < 2) {
this.duel.competitor1Score.push(Score.HANSOKU);
this.duel.competitor1ScoreTime.push(this.duel.duration!);
if (Duel.addHansoku(this.duel, true)) {
this.scoreUpdatedService.isScoreUpdated.next(this.duel);
} else {
this.messageService.warningMessage("scoreNotAdded");
Expand Down
24 changes: 24 additions & 0 deletions frontend/src/app/models/duel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,28 @@ export class Duel extends Element {
this.copy(data, instance);
return instance;
}

public static addHansoku(duel: Duel, competitor1: boolean): boolean {
if (competitor1) {
if (duel.competitor1Score[0] == undefined) {
duel.competitor1Score[0] = Score.HANSOKU;
duel.competitor1ScoreTime[0] = duel.duration!;
} else if (duel.competitor1Score[1] == undefined) {
duel.competitor1Score[1] = Score.HANSOKU;
duel.competitor1ScoreTime[1] = duel.duration!;
return false;
}
} else {
if (duel.competitor2Score[0] == undefined) {
duel.competitor2Score[0] = Score.HANSOKU;
duel.competitor2ScoreTime[0] = duel.duration!;
} else if (duel.competitor2Score[1] == undefined) {
duel.competitor2Score[1] = Score.HANSOKU;
duel.competitor2ScoreTime[1] = duel.duration!;
} else {
return false;
}
}
return true;
}
}

0 comments on commit 4cb2b05

Please sign in to comment.