refactor: HMR

This commit is contained in:
cha0s 2021-03-26 09:43:15 -05:00
parent 5a7ff04a31
commit ada2e32596
3 changed files with 58 additions and 28 deletions

View File

@ -139,6 +139,13 @@ export default () => class Mobile extends decorate(Trait) {
};
}
hotJSON() {
return {
appliedMovement: this.#appliedMovement,
movement: this.#movement,
};
}
listeners() {
return {
@ -153,6 +160,12 @@ export default () => class Mobile extends decorate(Trait) {
async load(json) {
await super.load(json);
if (json.appliedMovement) {
this.#appliedMovement = json.appliedMovement;
}
if (json.movement) {
this.#movement = json.movement;
}
if (this.params.mobileAnimation) {
this.on('actionMovementChanged', this.updateAnimation, this);
}
@ -161,6 +174,15 @@ export default () => class Mobile extends decorate(Trait) {
methods() {
return {
applyMovement: (vector) => {
this.#appliedMovement = Vector.add(this.#appliedMovement, vector);
},
forceMovement: (movement) => {
this.entity.x += movement[0];
this.entity.y += movement[1];
},
moveFor: (vector, duration) => {
if (duration <= 0) {
return undefined;
@ -201,14 +223,6 @@ export default () => class Mobile extends decorate(Trait) {
},
);
},
applyMovement: (vector) => {
this.#appliedMovement = Vector.add(this.#appliedMovement, vector);
},
forceMovement: (movement) => {
this.entity.x += movement[0];
this.entity.y += movement[1];
},
requestMovement: (vector) => {
if (!this.entity.isMobile) {

View File

@ -39,6 +39,12 @@ export default () => class Followed extends Trait {
return this.#camera;
}
hotJSON() {
return {
camera: this.#camera,
};
}
listeners() {
return {
@ -61,6 +67,9 @@ export default () => class Followed extends Trait {
async load(json) {
await super.load(json);
if (json.camera) {
this.#camera = json.camera;
}
this.#camera.viewSize = this.params.viewSize;
this.updatePosition();
this.onRoomSizeChanged();

View File

@ -31,12 +31,30 @@ export default () => class Layered extends Trait {
layer?.off('tilesetChanged', this.onLayerTilesetChanged);
}
get tile() {
return this.#tile;
hotJson() {
return {
tile: this.#tile,
tileOffset: this.#tileOffset,
};
}
get tileOffset() {
return this.#tileOffset;
listeners() {
return {
addedToLayer: () => {
this.entity.layer.on('tilesetChanged', this.onLayerTilesetChanged, this);
this.setCurrentTileFromLayer();
},
positionChanged: () => {
this.setCurrentTileFromLayer();
},
removedFromLayer: (layer) => {
this.detachFromLayer(layer);
},
};
}
async load(json) {
@ -76,23 +94,12 @@ export default () => class Layered extends Trait {
}
}
listeners() {
return {
get tile() {
return this.#tile;
}
addedToLayer: () => {
this.entity.layer.on('tilesetChanged', this.onLayerTilesetChanged, this);
this.setCurrentTileFromLayer();
},
positionChanged: () => {
this.setCurrentTileFromLayer();
},
removedFromLayer: (layer) => {
this.detachFromLayer(layer);
},
};
get tileOffset() {
return this.#tileOffset;
}
};