From 139cf58e5bb83d8f74999ee74ed5f744f1c39139 Mon Sep 17 00:00:00 2001 From: Mashy Date: Wed, 13 Feb 2019 13:30:41 +1000 Subject: [PATCH] item list cleanup --- client/src/scenes/elements/item.js | 3 +- client/src/scenes/item.list.js | 44 ++++++++++++------------------ 2 files changed, 19 insertions(+), 28 deletions(-) mode change 100644 => 100755 client/src/scenes/elements/item.js mode change 100644 => 100755 client/src/scenes/item.list.js diff --git a/client/src/scenes/elements/item.js b/client/src/scenes/elements/item.js old mode 100644 new mode 100755 index 8f4b5750..9febb941 --- a/client/src/scenes/elements/item.js +++ b/client/src/scenes/elements/item.js @@ -5,7 +5,6 @@ const { COLOURS, } = require('../constants'); - class Item extends Phaser.GameObjects.Container { constructor(scene, action, count, x, y, width, height) { super(scene, x, y); @@ -34,6 +33,8 @@ class Item extends Phaser.GameObjects.Container { clickHandler() { this.scene.activeItem = this; + // Set the main context to display the item info + this.scene.registry.set('itemInfo', this.action); this.select(); } diff --git a/client/src/scenes/item.list.js b/client/src/scenes/item.list.js old mode 100644 new mode 100755 index 1fb890de..5d404b07 --- a/client/src/scenes/item.list.js +++ b/client/src/scenes/item.list.js @@ -52,18 +52,11 @@ class CombinerHitBox extends Phaser.GameObjects.Rectangle { super(scene, x, y, ITEM_WIDTH, ITEM_HEIGHT, 0x000000); this.setOrigin(0); this.slot = i; - } - - itemSelect() { - this.setFillStyle(0x222222); - } - - itemDeselect() { - this.setFillStyle(0x000000); + this.itemSelect = () => this.setFillStyle(0x222222); + this.itemDeselect = () => this.setFillStyle(0x000000); } } - const itemCheckHitbox = (scene, pointer) => { const { list } = scene.scene.get('MenuCrypList').children; const hitboxes = list.filter(c => c.cryp) @@ -95,22 +88,25 @@ class ItemList extends Phaser.Scene { } create(itemList) { + if (!itemList) return false; + this.registry.events.on('changedata', this.updateData, this); + this.registry.events.on('setdata', this.updateData, this); + this.addStatic(); + this.addItems(itemList); + this.addClickHandlers(itemList); + return this; + } + + addStatic() { const graphics = this.add.graphics(); graphics.lineStyle(5, 0x808080, 1.0); drawCombiner(graphics); drawInventory(graphics); - - if (!itemList) return false; - const ws = this.registry.get('ws'); - - this.registry.events.on('changedata', this.updateData, this); - this.registry.events.on('setdata', this.updateData, this); - - if (!itemList) return false; - this.add.text(X + WIDTH / 4, Y + HEIGHT / 8, 'Inventory', TEXT.HEADER); this.add.text(X + WIDTH * 3 / 4, Y + HEIGHT / 8, 'Combiner', TEXT.HEADER); + } + addItems(itemList) { const actions = countBy(itemList, i => i.action); for (let i = 0; i < 4; i += 1) { @@ -126,14 +122,10 @@ class ItemList extends Phaser.Scene { this.input.setDraggable(itemBox); this.add.existing(itemBox); }); + } - this.input.on('pointerdown', (pointer, box) => { - if (!(box[0] instanceof Item)) return false; - this.registry.set('itemInfo', box[0].action); - return true; - }); - - + addClickHandlers(itemList) { + const ws = this.registry.get('ws'); this.input.on('dragstart', (pointer, box) => { if (!(box instanceof Item)) return false; box.clickHandler(); @@ -159,8 +151,6 @@ class ItemList extends Phaser.Scene { hitBox.itemDeselect(); return true; }); - - return this; } cleanUp() {