item list cleanup
This commit is contained in:
parent
400d972aa5
commit
139cf58e5b
3
client/src/scenes/elements/item.js
Normal file → Executable file
3
client/src/scenes/elements/item.js
Normal file → Executable file
@ -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();
|
||||
}
|
||||
|
||||
|
||||
44
client/src/scenes/item.list.js
Normal file → Executable file
44
client/src/scenes/item.list.js
Normal file → Executable file
@ -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() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user