diff options
author | Daniel Weipert <code@drogueronin.de> | 2023-08-20 14:32:40 +0200 |
---|---|---|
committer | Daniel Weipert <code@drogueronin.de> | 2023-08-20 14:32:40 +0200 |
commit | b227fc9c2ef361f8aa5ee2f24aa1ade6bc972a73 (patch) | |
tree | 8fdd7e980107bfd8fcd58ffe21f2299b37d310c8 /resources/js/classes | |
parent | 2c7890e90e1aad371854cfe60ad63eaa88e64fec (diff) |
area progress
Diffstat (limited to 'resources/js/classes')
-rw-r--r-- | resources/js/classes/Area.js | 37 | ||||
-rw-r--r-- | resources/js/classes/State.js | 15 | ||||
-rw-r--r-- | resources/js/classes/Trainer.js | 33 |
3 files changed, 85 insertions, 0 deletions
diff --git a/resources/js/classes/Area.js b/resources/js/classes/Area.js new file mode 100644 index 0000000..3451757 --- /dev/null +++ b/resources/js/classes/Area.js @@ -0,0 +1,37 @@ +class Area { + slug = ''; + + monsterProgress = 0; + trainerProgress = 0; + isCompleted = false; + + constructor (slug) { + this.slug = slug; + } + + async initialize () {} + + get encounters () { + return DB.areas[this.slug].encounters; + } + + get requiredEncounters () { + return DB.areas[this.slug].requiredEncounters; + } + + get trainers () { + return DB.areas[this.slug].trainers; + } + + get environment () { + return DB.areas[this.slug].environment; + } + + get previousArea () { + return DB.areas[this.slug].previousArea; + } + + get nextArea () { + return DB.areas[this.slug].nextArea; + } +} diff --git a/resources/js/classes/State.js b/resources/js/classes/State.js index 4b209e2..5d3cfff 100644 --- a/resources/js/classes/State.js +++ b/resources/js/classes/State.js @@ -5,6 +5,16 @@ class State { language = 'en_US'; /** + * @type {Object.<string, Area>} + */ + areaProgress = {}; + + /** + * @type {Area} + */ + currentArea = null; + + /** * @type {number} */ turn = 0; @@ -30,6 +40,11 @@ class State { opponent = null; /** + * @type {Monster} + */ + rivalMonster = null; + + /** * @type {Technique} */ activeTechnique = null; diff --git a/resources/js/classes/Trainer.js b/resources/js/classes/Trainer.js index 668c92b..f2c2df9 100644 --- a/resources/js/classes/Trainer.js +++ b/resources/js/classes/Trainer.js @@ -1,4 +1,12 @@ class Trainer { + #monsters = []; + #inventory = []; + + /** + * @type {('trainer' | 'monster')} + */ + type = 'trainer'; + /** * @type {Monster[]} */ @@ -13,4 +21,29 @@ class Trainer { * @type {Monster} */ activeMonster = []; + + constructor (monsters, inventory = []) { + this.#monsters = monsters; + this.#inventory = inventory; + } + + async initialize () { + for (const monsterData of this.#monsters) { + const monster = await fetchMonster(monsterData.slug); + + monster.level = monsterData.level || monster.level; + + this.monsters.push(monster); + } + + this.activeMonster = this.monsters[0]; + + for (const itemData of this.#inventory) { + const item = new InventoryItem(await fetchItem(itemData.slug)); + + item.amount = itemData.amount || 1; + + this.inventory.push(item); + } + } } |