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 { 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);
@ -106,11 +107,16 @@ class ItemList extends Phaser.Scene {
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);
});

View File

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