56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
export class GlobalState {
|
|
constructor() {
|
|
this.playerData = {
|
|
hearts: 3,
|
|
maxHearts: 3,
|
|
score: 0,
|
|
inventory: [],
|
|
upgrades: []
|
|
};
|
|
}
|
|
|
|
get hearts() {
|
|
return this.playerData.hearts;
|
|
}
|
|
|
|
set hearts(value) {
|
|
if (value < 0) throw new Error("Hearts cannot be less than 0");
|
|
this.playerData.hearts = value;
|
|
}
|
|
|
|
get maxHearts() {
|
|
return this.playerData.maxHearts;
|
|
}
|
|
|
|
set maxHearts(value) {
|
|
if (value < 0) throw new Error("Max hearts cannot be less than 0");
|
|
this.playerData.maxHearts = value;
|
|
}
|
|
|
|
get score() {
|
|
return this.playerData.score;
|
|
}
|
|
|
|
set score(value) {
|
|
if (value < 0) throw new Error("Score cannot be less than 0");
|
|
this.playerData.score = value;
|
|
}
|
|
|
|
get inventory() {
|
|
return [...this.playerData.inventory]; // Return a copy
|
|
}
|
|
|
|
set inventory(value) {
|
|
if (!Array.isArray(value)) throw new Error("Inventory must be an array");
|
|
this.playerData.inventory = value;
|
|
}
|
|
|
|
get upgrades() {
|
|
return [...this.playerData.upgrades]; // Return a copy
|
|
}
|
|
|
|
set upgrades(value) {
|
|
if (!Array.isArray(value)) throw new Error("Upgrades must be an array");
|
|
this.playerData.upgrades = value;
|
|
}
|
|
} |