item list cleanup

This commit is contained in:
Mashy 2019-02-13 13:30:41 +10:00
parent 400d972aa5
commit 139cf58e5b
2 changed files with 19 additions and 28 deletions

3
client/src/scenes/elements/item.js Normal file → Executable file
View File

@ -5,7 +5,6 @@ const {
COLOURS, COLOURS,
} = require('../constants'); } = require('../constants');
class Item extends Phaser.GameObjects.Container { class Item extends Phaser.GameObjects.Container {
constructor(scene, action, count, x, y, width, height) { constructor(scene, action, count, x, y, width, height) {
super(scene, x, y); super(scene, x, y);
@ -34,6 +33,8 @@ class Item extends Phaser.GameObjects.Container {
clickHandler() { clickHandler() {
this.scene.activeItem = this; this.scene.activeItem = this;
// Set the main context to display the item info
this.scene.registry.set('itemInfo', this.action);
this.select(); this.select();
} }

44
client/src/scenes/item.list.js Normal file → Executable file
View File

@ -52,18 +52,11 @@ class CombinerHitBox extends Phaser.GameObjects.Rectangle {
super(scene, x, y, ITEM_WIDTH, ITEM_HEIGHT, 0x000000); super(scene, x, y, ITEM_WIDTH, ITEM_HEIGHT, 0x000000);
this.setOrigin(0); this.setOrigin(0);
this.slot = i; this.slot = i;
} this.itemSelect = () => this.setFillStyle(0x222222);
this.itemDeselect = () => this.setFillStyle(0x000000);
itemSelect() {
this.setFillStyle(0x222222);
}
itemDeselect() {
this.setFillStyle(0x000000);
} }
} }
const itemCheckHitbox = (scene, pointer) => { const itemCheckHitbox = (scene, pointer) => {
const { list } = scene.scene.get('MenuCrypList').children; const { list } = scene.scene.get('MenuCrypList').children;
const hitboxes = list.filter(c => c.cryp) const hitboxes = list.filter(c => c.cryp)
@ -95,22 +88,25 @@ class ItemList extends Phaser.Scene {
} }
create(itemList) { 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(); const graphics = this.add.graphics();
graphics.lineStyle(5, 0x808080, 1.0); graphics.lineStyle(5, 0x808080, 1.0);
drawCombiner(graphics); drawCombiner(graphics);
drawInventory(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 / 4, Y + HEIGHT / 8, 'Inventory', TEXT.HEADER);
this.add.text(X + WIDTH * 3 / 4, Y + HEIGHT / 8, 'Combiner', TEXT.HEADER); this.add.text(X + WIDTH * 3 / 4, Y + HEIGHT / 8, 'Combiner', TEXT.HEADER);
}
addItems(itemList) {
const actions = countBy(itemList, i => i.action); const actions = countBy(itemList, i => i.action);
for (let i = 0; i < 4; i += 1) { for (let i = 0; i < 4; i += 1) {
@ -126,14 +122,10 @@ class ItemList extends Phaser.Scene {
this.input.setDraggable(itemBox); this.input.setDraggable(itemBox);
this.add.existing(itemBox); this.add.existing(itemBox);
}); });
}
this.input.on('pointerdown', (pointer, box) => { addClickHandlers(itemList) {
if (!(box[0] instanceof Item)) return false; const ws = this.registry.get('ws');
this.registry.set('itemInfo', box[0].action);
return true;
});
this.input.on('dragstart', (pointer, box) => { this.input.on('dragstart', (pointer, box) => {
if (!(box instanceof Item)) return false; if (!(box instanceof Item)) return false;
box.clickHandler(); box.clickHandler();
@ -159,8 +151,6 @@ class ItemList extends Phaser.Scene {
hitBox.itemDeselect(); hitBox.itemDeselect();
return true; return true;
}); });
return this;
} }
cleanUp() { cleanUp() {