avocado-old/packages/entity/packets/entity-create.packet.js
2019-05-13 21:07:51 -05:00

36 lines
691 B
JavaScript

import msgpack from 'msgpack-lite';
import {EntityPacket} from './entity.packet';
export class EntityCreatePacket extends EntityPacket {
constructor(data, entity) {
if ('undefined' !== typeof entity) {
data.uuid = entity.instanceUuid;
data.layer = entity.layer.index;
}
super(data);
this.entity = entity;
}
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);
}
}