diff --git a/client/src/scenes/item.list.js b/client/src/scenes/item.list.js index 2cdd78ae..b58c863e 100644 --- a/client/src/scenes/item.list.js +++ b/client/src/scenes/item.list.js @@ -1,4 +1,5 @@ const Phaser = require('phaser'); +const { countBy } = require('lodash'); const { TEXT, @@ -10,7 +11,7 @@ const X = ITEM_LIST.x(); const Y = ITEM_LIST.y(); const WIDTH = ITEM_LIST.width(); const HEIGHT = ITEM_LIST.height(); -const ITEM_WIDTH = WIDTH * 0.3; +const ITEM_WIDTH = WIDTH * 0.4; const ITEM_HEIGHT = HEIGHT * 0.1; const itemCheckHitbox = (scenePlugin, pointer) => { @@ -32,11 +33,11 @@ const itemCheckHitbox = (scenePlugin, pointer) => { }; class Item extends Phaser.GameObjects.Container { - constructor(scene, item, x, y) { + constructor(scene, action, count, x, y) { super(scene, x, y); this.state = 'deselect'; - this.item = item; + this.action = action; this.scene = scene; this.origX = x; @@ -46,7 +47,7 @@ class Item extends Phaser.GameObjects.Container { .rectangle(0, 0, ITEM_WIDTH, ITEM_HEIGHT, 0x222222); this.text = scene.add - .text(0, 0, item.action, TEXT.HEADER) + .text(0, 0, `${action} x${count}`, TEXT.HEADER) .setOrigin(0.5, 0.5); this.add(this.box); @@ -104,13 +105,18 @@ class ItemList extends Phaser.Scene { this.registry.events.on('setdata', this.updateData, this); if (!itemList) return false; - + this.add.text(WIDTH / 4, HEIGHT / 4, 'Inventory', TEXT.HEADER); - itemList.forEach((item, i) => { + + const actions = countBy(itemList, i => i.action); + + console.log(actions); + + Object.keys(actions).forEach((action, i) => { const ITEM_X = ITEM_WIDTH; const ITEM_Y = ITEM_HEIGHT * 1.2 * i + HEIGHT / 2.5; - const itemBox = new Item(this, item, ITEM_X, ITEM_Y); + const itemBox = new Item(this, action, actions[action], ITEM_X, ITEM_Y); this.input.setDraggable(itemBox); this.add.existing(itemBox); }); @@ -129,7 +135,7 @@ class ItemList extends Phaser.Scene { box.deselect(); const hitBox = itemCheckHitbox(this.scene, pointer); if (hitBox) { - ws.sendItemUse(box.item.id, hitBox.cryp.id); + ws.sendItemUse(itemList.find(li => li.action === box.action).id, hitBox.cryp.id); } box.setPosition(box.origX, box.origY); }); diff --git a/server/WORKLOG.md b/server/WORKLOG.md index b746135e..17ccf8e6 100644 --- a/server/WORKLOG.md +++ b/server/WORKLOG.md @@ -10,7 +10,6 @@ strangle ## NOW -* order cryps based on id * reduce inventory ## SOON