|
1 |
| -import { Point } from 'app/models/Point'; |
2 | 1 | import Konva from 'konva';
|
3 |
| -import { TABLE } from '../../../constants/constants'; |
4 |
| -import {GameStatus, Team, } from '../../../models/showMustGoOn/GameStatus'; |
| 2 | +import {TABLE} from '../../../constants/constants'; |
| 3 | +import { |
| 4 | + GameStatus, |
| 5 | + GradinBrut, GradinBrutId, |
| 6 | + Team, |
| 7 | +} from '../../../models/showMustGoOn/GameStatus'; |
5 | 8 |
|
6 | 9 | export class GameStatusManager {
|
| 10 | + gradinsBruts: Konva.Group; |
7 | 11 |
|
8 | 12 | constructor(private mainLayer: Konva.Layer) {
|
9 |
| - |
| 13 | + this.gradinsBruts = new Konva.Group(); |
| 14 | + this.mainLayer.add(this.gradinsBruts); |
| 15 | + this.gradinsBruts.moveToBottom(); |
10 | 16 | }
|
11 | 17 |
|
12 | 18 | destroy() {
|
13 |
| - |
| 19 | + this.gradinsBruts.destroy() |
14 | 20 | }
|
15 | 21 |
|
16 | 22 | update(status: Partial<GameStatus>, team: Team) {
|
| 23 | + this.gradinsBruts.destroyChildren() |
| 24 | + |
| 25 | + status.gradinBrutStock?.forEach((gradinBrut) => { |
| 26 | + this.addGradinBrut(gradinBrut); |
| 27 | + }); |
| 28 | + } |
| 29 | + |
| 30 | + private addGradinBrut(gradinBrut: GradinBrut) { |
| 31 | + if (!gradinBrut.present) return; |
17 | 32 |
|
| 33 | + const isVertical = !!this.isGradinVertical(gradinBrut.id); |
| 34 | + |
| 35 | + const plancheGroup = new Konva.Group({ |
| 36 | + x: (gradinBrut.x - (isVertical ? 50 : 200)) * TABLE.imageRatio, |
| 37 | + y: (TABLE.height - gradinBrut.y - (isVertical ? -200 : 50)) * TABLE.imageRatio, |
| 38 | + width: 400, |
| 39 | + height: 100, |
| 40 | + scaleX: TABLE.imageRatio, |
| 41 | + scaleY: TABLE.imageRatio, |
| 42 | + rotation: isVertical ? -90 : 0, |
| 43 | + }) |
| 44 | + |
| 45 | + const planche = new Konva.Rect({ |
| 46 | + x: 0, |
| 47 | + y: 0, |
| 48 | + width: 400, |
| 49 | + height: 100, |
| 50 | + strokeWidth: gradinBrut.bloque ? 10 : 0, |
| 51 | + fill: '#a97a57', |
| 52 | + stroke: '#ff0000' |
| 53 | + }) |
| 54 | + plancheGroup.add(planche) |
| 55 | + planche.moveToBottom() |
| 56 | + |
| 57 | + const plancheText = new Konva.Text({ |
| 58 | + text: gradinBrut.id.split('_').slice(1, 3).join(' '), |
| 59 | + x: 0, |
| 60 | + y: 0, |
| 61 | + width: 400, |
| 62 | + height: 100, |
| 63 | + align: 'center', |
| 64 | + verticalAlign: 'middle', |
| 65 | + fontSize: 40, |
| 66 | + fontStyle: 'bold', |
| 67 | + fill: 'black', |
| 68 | + stroke: 'white', |
| 69 | + strokeWidth: 5, |
| 70 | + fillAfterStrokeEnabled: true, |
| 71 | + }) |
| 72 | + plancheGroup.add(plancheText) |
| 73 | + plancheText.moveToTop() |
| 74 | + |
| 75 | + this.gradinsBruts.add(plancheGroup) |
18 | 76 | }
|
| 77 | + |
| 78 | + private isGradinVertical = (id: GradinBrutId): boolean => ([ |
| 79 | + GradinBrutId.JAUNE_HAUT_GAUCHE, |
| 80 | + GradinBrutId.JAUNE_BAS_GAUCHE, |
| 81 | + GradinBrutId.BLEU_HAUT_DROITE, |
| 82 | + GradinBrutId.BLEU_BAS_DROITE, |
| 83 | + ].includes(id)) |
19 | 84 | }
|
0 commit comments