|
1 | 1 | import Konva from 'konva';
|
2 | 2 | import {TABLE} from '../../../constants/constants';
|
3 |
| -import { |
4 |
| - GameStatus, |
5 |
| - GradinBrut, GradinBrutId, |
6 |
| - Team, |
7 |
| -} from '../../../models/showMustGoOn/GameStatus'; |
| 3 | +import {GameStatus, GradinBrut, GradinBrutId, Team,} from '../../../models/showMustGoOn/GameStatus'; |
| 4 | +import {start} from "@popperjs/core"; |
8 | 5 |
|
9 | 6 | export class GameStatusManager {
|
10 | 7 | gradinsBruts: Konva.Group;
|
| 8 | + airesConstruction: Konva.Group; |
11 | 9 |
|
12 | 10 | constructor(private mainLayer: Konva.Layer) {
|
13 | 11 | this.gradinsBruts = new Konva.Group();
|
14 | 12 | this.mainLayer.add(this.gradinsBruts);
|
15 | 13 | this.gradinsBruts.moveToBottom();
|
| 14 | + |
| 15 | + this.airesConstruction = new Konva.Group(); |
| 16 | + this.mainLayer.add(this.airesConstruction); |
| 17 | + this.airesConstruction.moveToBottom(); |
16 | 18 | }
|
17 | 19 |
|
18 | 20 | destroy() {
|
19 | 21 | this.gradinsBruts.destroy()
|
| 22 | + this.airesConstruction.destroy() |
20 | 23 | }
|
21 | 24 |
|
22 | 25 | update(status: Partial<GameStatus>, team: Team) {
|
23 | 26 | this.gradinsBruts.destroyChildren()
|
| 27 | + this.airesConstruction.destroyChildren() |
24 | 28 |
|
25 | 29 | status.gradinBrutStock?.forEach((gradinBrut) => {
|
26 | 30 | this.addGradinBrut(gradinBrut);
|
27 | 31 | });
|
| 32 | + |
| 33 | + this.addAireConstruction(status.airesConstruction?.petitEquipe, team === Team.JAUNE ? 550 : 2000) |
| 34 | + this.addAireConstruction(status.airesConstruction?.grandEquipe, team === Team.JAUNE ? 1000 : 1550) |
| 35 | + this.addAireConstruction(status.airesConstruction?.petitAdverse, team === Team.JAUNE ? 2000 : 550) |
| 36 | + this.addAireConstruction(status.airesConstruction?.grandAdverse, team === Team.JAUNE ? 1550 : 1000) |
28 | 37 | }
|
29 | 38 |
|
30 | 39 | private addGradinBrut(gradinBrut: GradinBrut) {
|
@@ -75,6 +84,53 @@ export class GameStatusManager {
|
75 | 84 | this.gradinsBruts.add(plancheGroup)
|
76 | 85 | }
|
77 | 86 |
|
| 87 | + private addAireConstruction(aireConstruction: boolean[][], startX: number) { |
| 88 | + aireConstruction.forEach((gradinConstruit, index) => this.addGradinConstruit(gradinConstruit, startX, index)) |
| 89 | + } |
| 90 | + |
| 91 | + private addGradinConstruit(gradinConstruit: boolean[], startX: number, index: number) { |
| 92 | + if (!gradinConstruit[0]) return; |
| 93 | + |
| 94 | + const gradinGroup = new Konva.Group({ |
| 95 | + x: (startX + 25) * TABLE.imageRatio, |
| 96 | + y: (TABLE.height - 150 - index * 125) * TABLE.imageRatio, |
| 97 | + width: 400, |
| 98 | + height: 100, |
| 99 | + scaleX: TABLE.imageRatio, |
| 100 | + scaleY: TABLE.imageRatio, |
| 101 | + }) |
| 102 | + |
| 103 | + const gradin = new Konva.Rect({ |
| 104 | + x: 0, |
| 105 | + y: 0, |
| 106 | + width: 400, |
| 107 | + height: 100, |
| 108 | + fill: '#a97a57', |
| 109 | + }) |
| 110 | + gradinGroup.add(gradin) |
| 111 | + gradin.moveToBottom() |
| 112 | + |
| 113 | + const gradinText = new Konva.Text({ |
| 114 | + text: (gradinConstruit.lastIndexOf(true) + 1).toString(), |
| 115 | + x: 0, |
| 116 | + y: 0, |
| 117 | + width: 400, |
| 118 | + height: 100, |
| 119 | + align: 'center', |
| 120 | + verticalAlign: 'middle', |
| 121 | + fontSize: 65, |
| 122 | + fontStyle: 'bold', |
| 123 | + fill: 'black', |
| 124 | + stroke: 'white', |
| 125 | + strokeWidth: 5, |
| 126 | + fillAfterStrokeEnabled: true, |
| 127 | + }) |
| 128 | + gradinGroup.add(gradinText) |
| 129 | + gradinText.moveToTop() |
| 130 | + |
| 131 | + this.gradinsBruts.add(gradinGroup) |
| 132 | + } |
| 133 | + |
78 | 134 | private isGradinVertical = (id: GradinBrutId): boolean => ([
|
79 | 135 | GradinBrutId.JAUNE_HAUT_GAUCHE,
|
80 | 136 | GradinBrutId.JAUNE_BAS_GAUCHE,
|
|
0 commit comments