Skip to content

Commit

Permalink
fixes #1553
Browse files Browse the repository at this point in the history
  • Loading branch information
aymericdelab committed Sep 16, 2024
1 parent df6a8a3 commit d9f4504
Showing 1 changed file with 22 additions and 36 deletions.
58 changes: 22 additions & 36 deletions client/src/dojo/modelManager/TileManager.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { BUILDINGS_CENTER } from "@/three/scenes/constants";
import { HexPosition } from "@/types";
import { FELT_CENTER } from "@/ui/config";
import { getEntityIdFromKeys } from "@/ui/utils/utils";
import { BuildingType, Direction, getNeighborHexes, ID, StructureType } from "@bibliothecadao/eternum";
import { Has, HasValue, NotValue, getComponentValue, runQuery } from "@dojoengine/recs";
import { getComponentValue, Has, HasValue, NotValue, runQuery } from "@dojoengine/recs";
import { uuid } from "@latticexyz/utils";
import { CairoOption, CairoOptionVariant } from "starknet";
import { SetupResult } from "../setup";
import { BUILDINGS_CENTER } from "@/three/scenes/constants";

export class TileManager {
private col: number;
Expand Down Expand Up @@ -151,49 +151,35 @@ export class TileManager {
const directions = getDirectionsArray(startingPosition, endPosition);

// add optimistic rendering
let overrideId = this._optimisticBuilding(entityId, col, row, buildingType, resourceType);

// const directions = [0, 0];
this._optimisticBuilding(entityId, col, row, buildingType, resourceType);

await this.setup.systemCalls
.create_building({
signer: this.setup.network.burnerManager.account!,
entity_id: entityId,
directions: directions,
building_category: buildingType,
produce_resource_type:
buildingType == BuildingType.Resource && resourceType
? new CairoOption<Number>(CairoOptionVariant.Some, resourceType)
: new CairoOption<Number>(CairoOptionVariant.None, 0),
})
.finally(() => {
setTimeout(() => {
this.setup.components.Building.removeOverride(overrideId);
}, 2000);
});
await this.setup.systemCalls.create_building({
signer: this.setup.network.burnerManager.account!,
entity_id: entityId,
directions: directions,
building_category: buildingType,
produce_resource_type:
buildingType == BuildingType.Resource && resourceType
? new CairoOption<Number>(CairoOptionVariant.Some, resourceType)
: new CairoOption<Number>(CairoOptionVariant.None, 0),
});
};

destroyBuilding = async (col: number, row: number) => {
const entityId = this._getOwnerEntityId();

if (!entityId) throw new Error("TileManager: Not Owner of the Tile");
// add optimistic rendering
let overrideId = this._optimisticDestroy(entityId, col, row);
this._optimisticDestroy(entityId, col, row);

await this.setup.systemCalls
.destroy_building({
signer: this.setup.network.burnerManager.account!,
entity_id: entityId,
building_coord: {
x: col,
y: row,
},
})
.finally(() => {
setTimeout(() => {
this.setup.components.Building.removeOverride(overrideId);
}, 2000);
});
await this.setup.systemCalls.destroy_building({
signer: this.setup.network.burnerManager.account!,
entity_id: entityId,
building_coord: {
x: col,
y: row,
},
});
};

pauseProduction = async (col: number, row: number) => {
Expand Down

0 comments on commit d9f4504

Please sign in to comment.