reduce inventory items

This commit is contained in:
ntr 2019-01-05 17:10:09 +11:00
parent 03e3f45fc8
commit badd7a8aba
2 changed files with 14 additions and 9 deletions

View File

@ -1,4 +1,5 @@
const Phaser = require('phaser'); const Phaser = require('phaser');
const { countBy } = require('lodash');
const { const {
TEXT, TEXT,
@ -10,7 +11,7 @@ const X = ITEM_LIST.x();
const Y = ITEM_LIST.y(); const Y = ITEM_LIST.y();
const WIDTH = ITEM_LIST.width(); const WIDTH = ITEM_LIST.width();
const HEIGHT = ITEM_LIST.height(); const HEIGHT = ITEM_LIST.height();
const ITEM_WIDTH = WIDTH * 0.3; const ITEM_WIDTH = WIDTH * 0.4;
const ITEM_HEIGHT = HEIGHT * 0.1; const ITEM_HEIGHT = HEIGHT * 0.1;
const itemCheckHitbox = (scenePlugin, pointer) => { const itemCheckHitbox = (scenePlugin, pointer) => {
@ -32,11 +33,11 @@ const itemCheckHitbox = (scenePlugin, pointer) => {
}; };
class Item extends Phaser.GameObjects.Container { class Item extends Phaser.GameObjects.Container {
constructor(scene, item, x, y) { constructor(scene, action, count, x, y) {
super(scene, x, y); super(scene, x, y);
this.state = 'deselect'; this.state = 'deselect';
this.item = item; this.action = action;
this.scene = scene; this.scene = scene;
this.origX = x; this.origX = x;
@ -46,7 +47,7 @@ class Item extends Phaser.GameObjects.Container {
.rectangle(0, 0, ITEM_WIDTH, ITEM_HEIGHT, 0x222222); .rectangle(0, 0, ITEM_WIDTH, ITEM_HEIGHT, 0x222222);
this.text = scene.add this.text = scene.add
.text(0, 0, item.action, TEXT.HEADER) .text(0, 0, `${action} x${count}`, TEXT.HEADER)
.setOrigin(0.5, 0.5); .setOrigin(0.5, 0.5);
this.add(this.box); this.add(this.box);
@ -104,13 +105,18 @@ class ItemList extends Phaser.Scene {
this.registry.events.on('setdata', this.updateData, this); this.registry.events.on('setdata', this.updateData, this);
if (!itemList) return false; if (!itemList) return false;
this.add.text(WIDTH / 4, HEIGHT / 4, 'Inventory', TEXT.HEADER); 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_X = ITEM_WIDTH;
const ITEM_Y = ITEM_HEIGHT * 1.2 * i + HEIGHT / 2.5; 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.input.setDraggable(itemBox);
this.add.existing(itemBox); this.add.existing(itemBox);
}); });
@ -129,7 +135,7 @@ class ItemList extends Phaser.Scene {
box.deselect(); box.deselect();
const hitBox = itemCheckHitbox(this.scene, pointer); const hitBox = itemCheckHitbox(this.scene, pointer);
if (hitBox) { 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); box.setPosition(box.origX, box.origY);
}); });

View File

@ -10,7 +10,6 @@ strangle
## NOW ## NOW
* order cryps based on id
* reduce inventory * reduce inventory
## SOON ## SOON