fix: animated packet
This commit is contained in:
parent
e1ac271b8b
commit
147b8d1556
|
@ -1,12 +0,0 @@
|
|||
import {Packet} from '@avocado/net';
|
||||
|
||||
export class TraitAnimatedPacket extends Packet {
|
||||
|
||||
static get schema() {
|
||||
const schema = super.schema;
|
||||
schema.data.currentAnimation = 'string';
|
||||
schema.data.isAnimating = 'bool';
|
||||
return schema;
|
||||
}
|
||||
|
||||
}
|
15
packages/timing/packets/trait-update-animated.packet.js
Normal file
15
packages/timing/packets/trait-update-animated.packet.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import {Packet} from '@avocado/net';
|
||||
|
||||
export class TraitUpdateAnimatedPacket extends Packet {
|
||||
|
||||
static get schema() {
|
||||
return {
|
||||
...super.schema,
|
||||
data: {
|
||||
currentAnimation: 'string',
|
||||
isAnimating: 'bool',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -4,7 +4,7 @@ import {Rectangle, Vector} from '@avocado/math';
|
|||
|
||||
import {Animation} from '../animation';
|
||||
import {AnimationView} from '../animation-view';
|
||||
import {TraitAnimatedPacket} from '../packets/trait-animated.packet';
|
||||
import {TraitUpdateAnimatedPacket} from '../packets/trait-update-animated.packet';
|
||||
|
||||
const decorate = compose(
|
||||
StateProperty('currentAnimation', {
|
||||
|
@ -63,7 +63,7 @@ export class Animated extends decorate(Trait) {
|
|||
}
|
||||
|
||||
acceptPacket(packet) {
|
||||
if (packet instanceof TraitAnimatedPacket) {
|
||||
if (packet instanceof TraitUpdateAnimatedPacket) {
|
||||
this.entity.currentAnimation = packet.data.currentAnimation;
|
||||
this.entity.isAnimating = packet.data.isAnimating;
|
||||
}
|
||||
|
@ -144,8 +144,14 @@ export class Animated extends decorate(Trait) {
|
|||
return this._animations[key].offset;
|
||||
}
|
||||
|
||||
packetsForUpdate() {
|
||||
return this.createTraitPacketUpdates(TraitAnimatedPacket);
|
||||
packets(informed) {
|
||||
const {currentAnimation, isAnimating} = this.stateDifferences();
|
||||
if (currentAnimation || isAnimating) {
|
||||
return new TraitUpdateAnimatedPacket({
|
||||
currentAnimation: this.state.currentAnimation,
|
||||
isAnimating: this.state.isAnimating,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
promiseAnimations() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user