fix: plant growth packet

This commit is contained in:
cha0s 2019-09-30 21:21:09 -05:00
parent 1daa3ecd72
commit d23c0a2d1d
3 changed files with 22 additions and 16 deletions

View File

@ -1,11 +0,0 @@
import {Packet} from '@avocado/net';
export class TraitPlantPacket extends Packet {
static get schema() {
const schema = super.schema;
schema.data.growthStage = 'uint8';
return schema;
}
}

View File

@ -0,0 +1,14 @@
import {Packet} from '@avocado/net';
export class TraitUpdatePlantPacket extends Packet {
static get schema() {
return {
...super.schema,
data: {
growthStage: 'uint8',
},
};
}
}

View File

@ -2,7 +2,7 @@ import {behaviorItemFromJSON, Context} from '@avocado/behavior';
import {compose, Property} from '@avocado/core';
import {StateProperty, Trait} from '@avocado/entity';
import {TraitPlantPacket} from '../packets/trait-plant.packet';
import {TraitUpdatePlantPacket} from '../packets/trait-update-plant.packet';
const decorate = compose(
StateProperty('growthStage', {
@ -43,14 +43,17 @@ export class Plant extends decorate(Trait) {
}
acceptPacket(packet) {
if (packet instanceof TraitPlantPacket) {
if (packet instanceof TraitUpdatePlantPacket) {
this.entity.growthStage = packet.data.growthStage;
}
}
// packetsForUpdate() {
// return this.createTraitPacketUpdates(TraitPlantPacket);
// }
packets(informed) {
const {growthStage} = this.stateDifferences();
if (growthStage) {
return new TraitUpdatePlantPacket(this.state);
}
}
listeners() {
return {