52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
import Component from '@/ecs/component.js';
|
|
|
|
const State = {
|
|
CLOSED: 0,
|
|
OPENING: 1,
|
|
OPEN: 2,
|
|
CLOSING: 3,
|
|
};
|
|
|
|
export default class Player extends Component {
|
|
instanceFromSchema() {
|
|
const {ecs} = this;
|
|
return class PlayerInstance extends super.instanceFromSchema() {
|
|
$$openInventory;
|
|
$$openInventoryState = State.CLOSED;
|
|
closeInventory() {
|
|
this.$$openInventoryState = State.CLOSING;
|
|
}
|
|
updateAttachments(update) {
|
|
if (!this.$$openInventory) {
|
|
return;
|
|
}
|
|
if (![State.OPENING, State.CLOSING].includes(this.$$openInventoryState)) {
|
|
return;
|
|
}
|
|
if (!ecs.get(this.$$openInventory.entity)) {
|
|
return;
|
|
}
|
|
if (!update[this.$$openInventory.entity]) {
|
|
update[this.$$openInventory.entity] = {};
|
|
}
|
|
if (this.$$openInventoryState === State.OPENING) {
|
|
update[this.$$openInventory.entity].Inventory = this.$$openInventory.toNet(ecs.get(this.entity))
|
|
this.$$openInventoryState = State.OPEN;
|
|
}
|
|
else {
|
|
update[this.$$openInventory.entity].Inventory = {closed: true};
|
|
this.$$openInventory = undefined;
|
|
this.$$openInventoryState = State.CLOSED;
|
|
}
|
|
}
|
|
get openInventory() {
|
|
return this.$$openInventory;
|
|
}
|
|
set openInventory(Inventory) {
|
|
this.$$openInventoryState = State.OPENING;
|
|
this.$$openInventory = Inventory;
|
|
}
|
|
};
|
|
}
|
|
}
|