avocado-old/packages/entity/packets/entity-create.packet.js

34 lines
634 B
JavaScript
Raw Normal View History

2019-05-13 21:07:51 -05:00
import msgpack from 'msgpack-lite';
import {EntityPacket} from './entity.packet';
export class EntityCreatePacket extends EntityPacket {
constructor(data, entity) {
if ('undefined' !== typeof entity) {
data.layer = entity.layer.index;
}
super(data, entity);
2019-05-13 21:07:51 -05:00
}
static pack(packet) {
return this.builder.encode({
_id: packet.data[0],
data: msgpack.encode(packet.data[1]),
})
}
static get schema() {
return {
...super.schema,
data: 'buffer',
};
}
static unpack(packet) {
const {data} = this.builder.decode(packet);
return msgpack.decode(data);
}
}