Skip to content

Commit

Permalink
Statut aires de dépose et jardinières
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Sep 17, 2023
1 parent d281ee2 commit 0731b28
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 9 deletions.
56 changes: 56 additions & 0 deletions src/app/components/map/info/map-info.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,51 @@ <h5 class="card-header">
<div class="panneau" [class.panneau--BLEU]="panneau.BLEU" [class.panneau--JAUNE]="panneau.JAUNE"></div>
</div>
</div>
<div class="row">
<span class="col">Jardinières</span>
</div>
<div class="row">
<div class="col">
<ng-container
*ngTemplateOutlet="
plantes;
context: { jardiniere: 'LH', plantes: mainPosition?.gameStatus?.jardinieres?.LH }
"
></ng-container>
<ng-container
*ngTemplateOutlet="
plantes;
context: { jardiniere: 'L1', plantes: mainPosition?.gameStatus?.jardinieres?.L1 }
"
></ng-container>
<ng-container
*ngTemplateOutlet="
plantes;
context: { jardiniere: 'L2', plantes: mainPosition?.gameStatus?.jardinieres?.L2 }
"
></ng-container>
</div>
<div class="col">
<ng-container
*ngTemplateOutlet="
plantes;
context: { jardiniere: 'RH', plantes: mainPosition?.gameStatus?.jardinieres?.RH }
"
></ng-container>
<ng-container
*ngTemplateOutlet="
plantes;
context: { jardiniere: 'R1', plantes: mainPosition?.gameStatus?.jardinieres?.R1 }
"
></ng-container>
<ng-container
*ngTemplateOutlet="
plantes;
context: { jardiniere: 'R2', plantes: mainPosition?.gameStatus?.jardinieres?.R2 }
"
></ng-container>
</div>
</div>
<div class="row">
<span class="col">Etats</span>
</div>
Expand All @@ -40,3 +85,14 @@ <h5 class="card-header">
</div>
</div>
</div>

<ng-template #plantes let-jardiniere="jardiniere" let-plantes="plantes">
<div class="d-flex">
<div class="flex-grow-0 mr-1">{{ jardiniere }}</div>
<div
*ngFor="let plante of plantes; trackBy: trackByIndex"
[class]="'plante plante--' + plante.type"
[class.plante--pot]="plante.pot"
></div>
</div>
</ng-template>
20 changes: 20 additions & 0 deletions src/app/components/map/info/map-info.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,23 @@
display: block;
}
}

.plante {
height: 20px;
width: 20px;
margin: 3px;
border-radius: 50%;
border: 3px solid transparent;

&--FRAGILE {
background-color: white;
border-color: #005b32;
}
&--RESISTANTE {
background-color: #9b6aa6;
border-color: #8cce06;
}
&--pot {
box-shadow: 0 0 0 3px #686868;
}
}
33 changes: 29 additions & 4 deletions src/app/components/map/input/game-status.manager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Point } from 'app/models/Point';
import Konva from 'konva';
import { TABLE } from '../../../constants/constants';
import { DistribPot, GameStatus, PlanteEnPot, TypePlante } from '../../../models/farmingMars/GameStatus';
import { AireDepose, DistribPot, GameStatus, PlanteEnPot, TypePlante } from '../../../models/farmingMars/GameStatus';

function mapLinear(x: number, a1: number, a2: number, b1: number, b2: number): number {
return b1 + ((x - a1) * (b2 - b1)) / (a2 - a1);
Expand Down Expand Up @@ -39,6 +39,15 @@ const DISTRIBS_POTS: Record<DistribPot, Point & { dir: number }> = {
RB: { x: 2000, y: 35, dir: Math.PI / 2 },
};

const AIRES_DEPOSE: Record<AireDepose, Point & { dir: number }> = {
L1: { x: 35, y: 1775, dir: 1 },
L2: { x: 35, y: 1000, dir: 1 },
L3: { x: 35, y: 225, dir: 1 },
R1: { x: 3000 - 35, y: 1775, dir: -1 },
R2: { x: 3000 - 35, y: 1000, dir: -1 },
R3: { x: 3000 - 35, y: 225, dir: -1 },
};

export class GameStatusManager {
panneaux: Konva.Group;
plantes: Konva.Group;
Expand Down Expand Up @@ -99,6 +108,10 @@ export class GameStatusManager {
this.addDistribPots(count, distrib as DistribPot);
});

Object.entries(status.airesDepose).forEach(([aire, plante]) => {
this.addAireDepose(plante, aire as AireDepose);
});

status.panneaux.forEach(({ BLEU, JAUNE }, i) => {
const panneau = this.panneaux.children.at(i);
if (BLEU && JAUNE) {
Expand All @@ -120,7 +133,7 @@ export class GameStatusManager {
y: (TABLE.height - plante.pt.y) * TABLE.imageRatio,
radius: 25 * TABLE.imageRatio - 2,
strokeWidth: 4,
fill: plante.type === TypePlante.FRAGILE ? '#fcfcfa' : '#9b6aa6',
fill: plante.type === TypePlante.FRAGILE ? 'white' : '#9b6aa6',
stroke: plante.type === TypePlante.FRAGILE ? '#005b32' : '#8cce06',
}),
);
Expand All @@ -135,8 +148,8 @@ export class GameStatusManager {
new Konva.Circle({
x: pt.x * TABLE.imageRatio,
y: (TABLE.height - pt.y) * TABLE.imageRatio,
radius: 35 * TABLE.imageRatio - 2.5,
strokeWidth: 5,
radius: 35 * TABLE.imageRatio - 2,
strokeWidth: 4,
fill: '#3d3d3d',
stroke: '#686868',
}),
Expand Down Expand Up @@ -184,4 +197,16 @@ export class GameStatusManager {
});
}
}

private addAireDepose(plantes: PlanteEnPot[], aire: AireDepose) {
plantes.forEach((plante, i) => {
this.addPlante({
...plante,
pt: {
x: AIRES_DEPOSE[aire].x + Math.floor(i / 6) * 70 * AIRES_DEPOSE[aire].dir,
y: AIRES_DEPOSE[aire].y + ((i % 6) - 2.5) * 70,
},
});
});
}
}
46 changes: 41 additions & 5 deletions src/app/services/mock/mouvements.mock-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,54 @@ export class MouvementsMockService extends MouvementsService {
RB: 6,
},
airesDepose: {
L1: [],
L1: [
{ type: TypePlante.FRAGILE, pot: true },
{ type: TypePlante.RESISTANTE, pot: true },
{ type: TypePlante.RESISTANTE, pot: false },
{ type: TypePlante.FRAGILE, pot: false },
{ type: TypePlante.FRAGILE, pot: false },
{ type: TypePlante.FRAGILE, pot: false },
{ type: TypePlante.FRAGILE, pot: true },
{ type: TypePlante.FRAGILE, pot: false },
{ type: TypePlante.FRAGILE, pot: true },
],
L2: [],
L3: [],
R1: [],
R2: [],
R2: [
{ type: TypePlante.FRAGILE, pot: true },
{ type: TypePlante.RESISTANTE, pot: true },
{ type: TypePlante.RESISTANTE, pot: false },
{ type: TypePlante.FRAGILE, pot: false },
{ type: TypePlante.FRAGILE, pot: false },
{ type: TypePlante.FRAGILE, pot: false },
{ type: TypePlante.FRAGILE, pot: true },
{ type: TypePlante.FRAGILE, pot: false },
{ type: TypePlante.FRAGILE, pot: true },
],
R3: [],
},
jardinieres: {
LH: [],
LH: [
{ type: TypePlante.FRAGILE, pot: true },
{ type: TypePlante.RESISTANTE, pot: true },
{ type: TypePlante.RESISTANTE, pot: false },
{ type: TypePlante.FRAGILE, pot: false },
{ type: TypePlante.FRAGILE, pot: false },
],
L1: [],
L2: [],
RH: [],
L2: [
{ type: TypePlante.FRAGILE, pot: false },
{ type: TypePlante.FRAGILE, pot: true },
{ type: TypePlante.FRAGILE, pot: false },
],
RH: [
{ type: TypePlante.FRAGILE, pot: true },
{ type: TypePlante.RESISTANTE, pot: true },
{ type: TypePlante.RESISTANTE, pot: false },
{ type: TypePlante.FRAGILE, pot: false },
{ type: TypePlante.FRAGILE, pot: false },
],
R1: [],
R2: [],
},
Expand Down

0 comments on commit 0731b28

Please sign in to comment.