interface Globals {
objects: GameObjectProperties[]
+ inventory: object
}
class GameState {
events: Map<ID, GameEvent>;
objects: Map<ID, GameObject>;
agents: Map<ID, GameAgent>;
+ playerInventory: Map<ID, number>;
textView: TextView;
cellEditor: CellEditor;
this.objects = new Map();
this.agents = new Map();
this.map = new GameMap();
+ this.playerInventory = new Map();
document.body.classList.toggle('edit-mode', this.editMode);
}
}
+ addInventory(o: ID, count=1) {
+ if (this.playerInventory.has(o)) {
+ const currentCount = this.playerInventory.get(o);
+ this.playerInventory.set(o, currentCount + count);
+ } else {
+ this.playerInventory.set(o, count);
+ }
+ }
+
storeGlobals(): Globals {
const objects: GameObjectProperties[] = [];
for (let [k, o] of this.objects) {
objects.push(o.store());
}
- return { objects };
+ const inventory = Object.fromEntries(this.playerInventory);
+
+ return { objects, inventory };
}
loadGlobals(globals: Globals) {
this.addObject(obj);
}
}
+
+ if (globals.inventory) {
+ this.playerInventory = new Map(Object.entries(globals.inventory));
+ }
}
}