refactor: HMR
This commit is contained in:
parent
5942272b93
commit
402f8539f5
|
@ -35,60 +35,6 @@ export default (latus) => class Tool extends Trait {
|
|||
this.#targets = [];
|
||||
}
|
||||
|
||||
static behaviorTypes() {
|
||||
return {
|
||||
useTool: {
|
||||
type: 'void',
|
||||
label: 'Use tool.',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
static defaultParams() {
|
||||
return {
|
||||
actions: {
|
||||
type: 'expressions',
|
||||
expressions: [],
|
||||
},
|
||||
condition: {
|
||||
type: 'condition',
|
||||
operator: 'or',
|
||||
operands: [],
|
||||
},
|
||||
setup: {
|
||||
type: 'expressions',
|
||||
expressions: [],
|
||||
},
|
||||
target: {
|
||||
type: 'projection',
|
||||
distance: 1,
|
||||
length: 1,
|
||||
width: 1,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
static describeParams() {
|
||||
return {
|
||||
actions: {
|
||||
type: 'expressions',
|
||||
label: 'Actions',
|
||||
},
|
||||
condition: {
|
||||
type: 'condition',
|
||||
label: 'Condition',
|
||||
},
|
||||
setup: {
|
||||
type: 'expressions',
|
||||
label: 'Setup actions',
|
||||
},
|
||||
target: {
|
||||
type: 'object',
|
||||
label: 'Target',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
calculateTargetStart() {
|
||||
const {wielder} = this.entity;
|
||||
if (!wielder || !wielder.is('Directional') || !wielder.is('Layered')) {
|
||||
|
@ -160,6 +106,54 @@ export default (latus) => class Tool extends Trait {
|
|||
);
|
||||
}
|
||||
|
||||
static defaultParams() {
|
||||
return {
|
||||
actions: {
|
||||
type: 'expressions',
|
||||
expressions: [],
|
||||
},
|
||||
condition: {
|
||||
type: 'condition',
|
||||
operator: 'or',
|
||||
operands: [],
|
||||
},
|
||||
setup: {
|
||||
type: 'expressions',
|
||||
expressions: [],
|
||||
},
|
||||
target: {
|
||||
type: 'projection',
|
||||
distance: 1,
|
||||
length: 1,
|
||||
width: 1,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
destroy() {
|
||||
const {wielder} = this.entity;
|
||||
this.onWielderChanged(wielder);
|
||||
this.#primitives.destroy();
|
||||
this.#throbber = {};
|
||||
}
|
||||
|
||||
hotJSON() {
|
||||
return {
|
||||
targets: this.#targets,
|
||||
targetTotal: this.#targetTotal,
|
||||
};
|
||||
}
|
||||
|
||||
listeners() {
|
||||
return {
|
||||
|
||||
wielderChanged: (oldWielder, newWielder) => {
|
||||
this.onWielderChanged(oldWielder, newWielder);
|
||||
},
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
async load(json) {
|
||||
await super.load(json);
|
||||
if (1 !== this.params.target.length % 2) {
|
||||
|
@ -170,84 +164,16 @@ export default (latus) => class Tool extends Trait {
|
|||
}
|
||||
this.toolCondition = compile(this.params.condition, latus);
|
||||
this.toolSetup = new Actions(compile(this.params.setup, latus));
|
||||
}
|
||||
|
||||
onWielderActiveSlotIndexChanged() {
|
||||
this.calculateTargets();
|
||||
if ('client' === process.env.SIDE) {
|
||||
this.#primitives.visible = false;
|
||||
const {wielder} = this.entity;
|
||||
if (!wielder || !wielder.container || !wielder.is('Receptacle')) {
|
||||
return;
|
||||
}
|
||||
this.#primitives.visible = this.entity === wielder.itemInActiveSlot();
|
||||
if (json.targets) {
|
||||
this.#targets = json.targets;
|
||||
}
|
||||
}
|
||||
|
||||
refreshGuide() {
|
||||
this.calculateTargets();
|
||||
this.calculateTargetTotal();
|
||||
this.repositionPrimitives();
|
||||
}
|
||||
|
||||
repositionPrimitives() {
|
||||
if ('client' === process.env.SIDE) {
|
||||
const {wielder} = this.entity;
|
||||
if (!wielder) {
|
||||
return;
|
||||
}
|
||||
if (!wielder.is('Layered')) {
|
||||
return;
|
||||
}
|
||||
this.#primitives.position = Vector.scale(wielder.tileOffset, -1);
|
||||
if (json.targetTotal) {
|
||||
this.#targetTotal = json.targetTotal;
|
||||
}
|
||||
const {wielder} = this.entity;
|
||||
if (wielder) {
|
||||
this.onWielderChanged(undefined, wielder);
|
||||
}
|
||||
}
|
||||
|
||||
listeners() {
|
||||
return {
|
||||
|
||||
wielderChanged: (oldWielder, newWielder) => {
|
||||
if (oldWielder && oldWielder.is('Visible')) {
|
||||
if ('client' === process.env.SIDE) {
|
||||
oldWielder.container.removeChild(this.#primitives);
|
||||
}
|
||||
oldWielder.off(
|
||||
'activeSlotIndexChanged',
|
||||
this.onWielderActiveSlotIndexChanged,
|
||||
);
|
||||
oldWielder.off(
|
||||
[
|
||||
'addedToLayer',
|
||||
'directionChanged',
|
||||
'tileOffsetChanged',
|
||||
],
|
||||
this.refreshGuide,
|
||||
);
|
||||
}
|
||||
if (newWielder && newWielder.is('Visible')) {
|
||||
if ('client' === process.env.SIDE) {
|
||||
newWielder.container.addChild(this.#primitives);
|
||||
}
|
||||
newWielder.on(
|
||||
'activeSlotIndexChanged',
|
||||
this.onWielderActiveSlotIndexChanged,
|
||||
this,
|
||||
);
|
||||
newWielder.on(
|
||||
[
|
||||
'addedToLayer',
|
||||
'directionChanged',
|
||||
'tileOffsetChanged',
|
||||
],
|
||||
this.refreshGuide,
|
||||
this,
|
||||
);
|
||||
}
|
||||
this.refreshGuide();
|
||||
this.onWielderActiveSlotIndexChanged();
|
||||
},
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
methods() {
|
||||
|
@ -289,6 +215,65 @@ export default (latus) => class Tool extends Trait {
|
|||
};
|
||||
}
|
||||
|
||||
onWielderActiveSlotIndexChanged() {
|
||||
this.calculateTargets();
|
||||
if ('client' === process.env.SIDE) {
|
||||
this.#primitives.visible = false;
|
||||
const {wielder} = this.entity;
|
||||
if (!wielder || !wielder.container || !wielder.is('Receptacle')) {
|
||||
return;
|
||||
}
|
||||
this.#primitives.visible = this.entity === wielder.itemInActiveSlot();
|
||||
}
|
||||
}
|
||||
|
||||
onWielderChanged(oldWielder, newWielder) {
|
||||
if (oldWielder && oldWielder.is('Visible')) {
|
||||
if ('client' === process.env.SIDE) {
|
||||
oldWielder.container.removeChild(this.#primitives);
|
||||
}
|
||||
oldWielder.off(
|
||||
'activeSlotIndexChanged',
|
||||
this.onWielderActiveSlotIndexChanged,
|
||||
);
|
||||
oldWielder.off(
|
||||
[
|
||||
'addedToLayer',
|
||||
'directionChanged',
|
||||
'tileOffsetChanged',
|
||||
],
|
||||
this.refreshGuide,
|
||||
);
|
||||
}
|
||||
if (newWielder && newWielder.is('Visible')) {
|
||||
if ('client' === process.env.SIDE) {
|
||||
newWielder.container.addChild(this.#primitives);
|
||||
}
|
||||
newWielder.on(
|
||||
'activeSlotIndexChanged',
|
||||
this.onWielderActiveSlotIndexChanged,
|
||||
this,
|
||||
);
|
||||
newWielder.on(
|
||||
[
|
||||
'addedToLayer',
|
||||
'directionChanged',
|
||||
'tileOffsetChanged',
|
||||
],
|
||||
this.refreshGuide,
|
||||
this,
|
||||
);
|
||||
}
|
||||
this.refreshGuide();
|
||||
this.onWielderActiveSlotIndexChanged();
|
||||
}
|
||||
|
||||
refreshGuide() {
|
||||
this.calculateTargets();
|
||||
this.calculateTargetTotal();
|
||||
this.repositionPrimitives();
|
||||
}
|
||||
|
||||
renderGuide(rectangle, color, expansion) {
|
||||
const position = Rectangle.position(rectangle);
|
||||
const size = Rectangle.size(rectangle);
|
||||
|
@ -346,4 +331,17 @@ export default (latus) => class Tool extends Trait {
|
|||
);
|
||||
}
|
||||
|
||||
repositionPrimitives() {
|
||||
if ('client' === process.env.SIDE) {
|
||||
const {wielder} = this.entity;
|
||||
if (!wielder) {
|
||||
return;
|
||||
}
|
||||
if (!wielder.is('Layered')) {
|
||||
return;
|
||||
}
|
||||
this.#primitives.position = Vector.scale(wielder.tileOffset, -1);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user