summaryrefslogtreecommitdiff
path: root/resources/js/classes/Trainer.js
diff options
context:
space:
mode:
authorDaniel Weipert <code@drogueronin.de>2023-08-20 20:48:29 +0200
committerDaniel Weipert <code@drogueronin.de>2023-08-20 20:48:29 +0200
commit43a28ad77190f2e55e2e6ba65a9a7b5b1f5dea6c (patch)
tree759b4f27a68e729df313b9f8370117d4a6fbae37 /resources/js/classes/Trainer.js
parentb227fc9c2ef361f8aa5ee2f24aa1ade6bc972a73 (diff)
area progression, item usage
Diffstat (limited to 'resources/js/classes/Trainer.js')
-rw-r--r--resources/js/classes/Trainer.js36
1 files changed, 26 insertions, 10 deletions
diff --git a/resources/js/classes/Trainer.js b/resources/js/classes/Trainer.js
index f2c2df9..d63e52d 100644
--- a/resources/js/classes/Trainer.js
+++ b/resources/js/classes/Trainer.js
@@ -7,6 +7,9 @@ class Trainer {
*/
type = 'trainer';
+ name = '';
+ sprite = '';
+
/**
* @type {Monster[]}
*/
@@ -22,28 +25,41 @@ class Trainer {
*/
activeMonster = [];
- constructor (monsters, inventory = []) {
- this.#monsters = monsters;
- this.#inventory = inventory;
+ /**
+ * @param {(Monster[]|Object[])} monsters
+ * @param {(InventoryItem[]|Object[])} inventory
+ */
+ constructor (trainerData) {
+ this.#monsters = trainerData.monsters;
+ this.#inventory = trainerData.inventory || [];
+ this.name = trainerData.name;
+ this.sprite = trainerData.sprite;
}
async initialize () {
for (const monsterData of this.#monsters) {
- const monster = await fetchMonster(monsterData.slug);
+ if (monsterData instanceof Monster) {
+ this.monsters.push(monsterData);
+ } else {
+ const monster = await fetchMonster(monsterData.slug);
- monster.level = monsterData.level || monster.level;
+ monster.level = monsterData.level || monster.level;
- this.monsters.push(monster);
+ 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;
+ if (itemData instanceof InventoryItem) {
+ this.inventory.push(itemData);
+ } else {
+ const item = new InventoryItem(await fetchItem(itemData.slug));
- this.inventory.push(item);
+ item.quantity = itemData.quantity || 1;
+ this.inventory.push(item);
+ }
}
}
}