summaryrefslogtreecommitdiff
path: root/resources/js/classes
diff options
context:
space:
mode:
Diffstat (limited to 'resources/js/classes')
-rw-r--r--resources/js/classes/InventoryItem.js3
-rw-r--r--resources/js/classes/Monster.js4
-rw-r--r--resources/js/classes/State.js5
-rw-r--r--resources/js/classes/Trainer.js36
4 files changed, 37 insertions, 11 deletions
diff --git a/resources/js/classes/InventoryItem.js b/resources/js/classes/InventoryItem.js
index d6eb311..9db42ff 100644
--- a/resources/js/classes/InventoryItem.js
+++ b/resources/js/classes/InventoryItem.js
@@ -12,8 +12,9 @@ class InventoryItem {
/**
* @param {Item} item
*/
- constructor (item) {
+ constructor (item, quantity = 1) {
this.item = item;
+ this.quantity = quantity;
}
/* Item */
diff --git a/resources/js/classes/Monster.js b/resources/js/classes/Monster.js
index 5c930f8..69bb654 100644
--- a/resources/js/classes/Monster.js
+++ b/resources/js/classes/Monster.js
@@ -66,6 +66,10 @@ class Monster {
return DB.monsters[this.slug].types;
}
+ get category () {
+ return DB.monsters[this.slug].category;
+ }
+
get moveset () {
return DB.monsters[this.slug].moveset;
}
diff --git a/resources/js/classes/State.js b/resources/js/classes/State.js
index 5d3cfff..6180c52 100644
--- a/resources/js/classes/State.js
+++ b/resources/js/classes/State.js
@@ -48,4 +48,9 @@ class State {
* @type {Technique}
*/
activeTechnique = null;
+
+ /**
+ * @type {InventoryItem}
+ */
+ activeBall = null;
};
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);
+ }
}
}
}