Skip to content

Commit

Permalink
place silo
Browse files Browse the repository at this point in the history
  • Loading branch information
konrad2002 committed Oct 29, 2023
1 parent f6e43fa commit 698c3e6
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tidal-harvest/src/app/core/game/TickMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class TickMachine {
});
this._tick.next(this._matrix);
this._globalCrops.next(this.countCrops()); // probably calls #countCrops way too often (no time to fix)
if (counter % 10 === 0) {
if (counter % 60 === 0) {
this._flood.next(new Flood(this._matrix, this._gameObjects).flood())
}
}, 1000);
Expand Down
4 changes: 4 additions & 0 deletions tidal-harvest/src/app/core/service/ui.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class UiService {
this.game.place(type, x, y);
}

public placeWithCropType(field: FieldType, crop: CropKey, x: number, y: number) {
this.game.placeWithCropType(field, crop, x, y);
}

public selectCropType(type: CropKey, x: number, y: number) {
this.game.selectCrop(type, x, y);
}
Expand Down
7 changes: 7 additions & 0 deletions tidal-harvest/src/app/ui/core/model/placing.model.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {FieldType} from "../../../core/model/field/FieldType";
import {CropKey} from "../../../core/model/field/farm/crop/CropKey";

export interface PlacingModel {
fieldType: FieldType;
crop?: CropKey
}
3 changes: 2 additions & 1 deletion tidal-harvest/src/app/ui/grid/grid.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Matrix} from "../../core/model/Matrix";
import {Coordinates} from "../../core/model/Coordinates";
import {FieldType} from "../../core/model/field/FieldType";
import {UiService} from "../../core/service/ui.service";
import {PlacingModel} from "../core/model/placing.model";

@Component({
selector: 'th-grid',
Expand All @@ -11,7 +12,7 @@ import {UiService} from "../../core/service/ui.service";
})
export class GridComponent {
@Input() matrix!: Matrix
@Input() placing?: FieldType;
@Input() placing?: PlacingModel;
@Output() fieldClick: EventEmitter<Coordinates> = new EventEmitter<Coordinates>();

floodMatrix?: boolean[][];
Expand Down
5 changes: 3 additions & 2 deletions tidal-harvest/src/app/ui/grid/tile/tile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {GridTile} from "./tile.interface";
import {TileTypes} from "./tile-types.constant";
import {FieldType} from "../../../core/model/field/FieldType";
import {Coordinates} from "../../../core/model/Coordinates";
import {PlacingModel} from "../../core/model/placing.model";

@Component({
selector: 'th-grid-tile',
Expand All @@ -13,7 +14,7 @@ import {Coordinates} from "../../../core/model/Coordinates";
})
export class TileComponent implements OnInit, OnChanges {
@Input() field!: Field
@Input() placing?: FieldType;
@Input() placing?: PlacingModel;

@Output() tileClick: EventEmitter<Coordinates> = new EventEmitter<Coordinates>();

Expand Down Expand Up @@ -43,7 +44,7 @@ export class TileComponent implements OnInit, OnChanges {
}

isPlaceableOn(): boolean {
return this.field.fieldType != this.placing;
return this.field.fieldType != this.placing?.fieldType;
}

isClickable(): boolean {
Expand Down
18 changes: 12 additions & 6 deletions tidal-harvest/src/app/ui/ui.component.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@

<div class="header">
<th-button [buttonType]="placing === FieldType.FARMER ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.FARMER)">{{placing === FieldType.FARMER ? 'abbrechen' : 'Farmer setzen'}}</th-button>
<th-button [buttonType]="placing === FieldType.FARMLAND ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.FARMLAND)">{{placing === FieldType.FARMLAND ? 'abbrechen' : 'Acker setzen'}}</th-button>
<th-button [buttonType]="placing === FieldType.ROCK ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.ROCK)">{{placing === FieldType.ROCK ? 'abbrechen' : 'Stein setzen'}}</th-button>
<th-button [buttonType]="placing === FieldType.WATER_CHANNEL ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.WATER_CHANNEL)">{{placing === FieldType.WATER_CHANNEL ? 'abbrechen' : 'Graben setzen'}}</th-button>
<th-button [buttonType]="placing === FieldType.SILO ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.SILO)">{{placing === FieldType.SILO ? 'abbrechen' : 'Silo setzen'}}</th-button>
<hr>
<th-button [buttonType]="'normal'" (buttonClick)="triggerFlood()">Flut auslösen</th-button>
<th-button [buttonType]="placeMode ? 'fail' : 'normal'" (buttonClick)="togglePlaceMode()">{{placeMode ? 'beenden' : 'Baumodus'}}</th-button>

</div>

<div class="footer">
<div class="place-mode" *ngIf="placeMode">
<th-button [buttonType]="placing?.fieldType === FieldType.FARMER ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.FARMER)">{{placing?.fieldType === FieldType.FARMER ? 'abbrechen' : 'Farmer setzen'}}</th-button>
<th-button [buttonType]="placing?.fieldType === FieldType.FARMLAND ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.FARMLAND)">{{placing?.fieldType === FieldType.FARMLAND ? 'abbrechen' : 'Acker setzen'}}</th-button>
<th-button [buttonType]="placing?.fieldType === FieldType.ROCK ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.ROCK)">{{placing?.fieldType === FieldType.ROCK ? 'abbrechen' : 'Stein setzen'}}</th-button>
<th-button [buttonType]="placing?.fieldType === FieldType.WATER_CHANNEL ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.WATER_CHANNEL)">{{placing?.fieldType === FieldType.WATER_CHANNEL ? 'abbrechen' : 'Graben setzen'}}</th-button>

<th-button [buttonType]="placing?.fieldType === FieldType.SILO && placing?.crop === CropKey.WHEAT ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.SILO, CropKey.WHEAT)">{{placing?.fieldType === FieldType.SILO && placing?.crop === CropKey.WHEAT ? 'abbrechen' : 'Weizen Silo'}}</th-button>
<th-button [buttonType]="placing?.fieldType === FieldType.SILO && placing?.crop === CropKey.BARLEY ? 'fail' : 'normal'" (buttonClick)="setPlacing(FieldType.SILO, CropKey.BARLEY)">{{placing?.fieldType === FieldType.SILO && placing?.crop === CropKey.BARLEY ? 'abbrechen' : 'Hirse Silo'}}</th-button>

</div>
&copy; Carmen, Entjic (V) und Konrad
</div>

Expand Down
30 changes: 24 additions & 6 deletions tidal-harvest/src/app/ui/ui.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {UiService} from "../core/service/ui.service";
import {Matrix} from "../core/model/Matrix";
import {Coordinates} from "../core/model/Coordinates";
import {FieldType} from "../core/model/field/FieldType";
import {PlacingModel} from "./core/model/placing.model";
import {CropKey} from "../core/model/field/farm/crop/CropKey";

@Component({
selector: 'th-ui',
Expand All @@ -13,7 +15,8 @@ export class UiComponent {

matrix?: Matrix;

placing?: FieldType;
placing?: PlacingModel;
placeMode: boolean = false;

constructor(
private service: UiService
Expand All @@ -26,15 +29,23 @@ export class UiComponent {
onFieldClick($event: Coordinates) {
if (this.placing !== undefined) {
console.log("placing: " + this.placing + "on: " + $event.x + ";" + $event.y);
this.service.place(this.placing, $event.x, $event.y);
if (this.placing.crop) {
this.service.placeWithCropType(this.placing.fieldType, this.placing.crop, $event.x, $event.y)
} else {
this.service.place(this.placing.fieldType, $event.x, $event.y);
}
}
}

setPlacing(type: FieldType) {
if (this.placing == type) {
setPlacing(type: FieldType, crop?: CropKey) {
if (this.placing && this.placing.fieldType === type && this.placing.crop === crop) {
this.placing = undefined;
} else {
this.placing = type;
return;
}

this.placing = {
fieldType: type,
crop: crop
}
}

Expand All @@ -43,4 +54,11 @@ export class UiComponent {
triggerFlood() {
this.service.triggerFlood();
}

protected readonly CropKey = CropKey;

togglePlaceMode() {
this.placeMode = !this.placeMode;
this.placing = undefined;
}
}

0 comments on commit 698c3e6

Please sign in to comment.