avocado-old/packages/graphics/packets/trait-update-visible.packet.js
2020-06-28 06:39:19 -05:00

29 lines
559 B
JavaScript

import {Packet} from '@avocado/net';
export default class TraitUpdateVisiblePacket extends Packet {
static pack(packet) {
const data = packet.data[1];
data.opacity = Math.floor(data.opacity * 255);
return super.pack(packet);
}
static get schema() {
return {
...super.schema,
data: {
isVisible: 'bool',
opacity: 'uint8',
},
};
}
static unpack(packet) {
const unpacked = super.unpack(packet);
const {data} = unpacked;
data.opacity = data.opacity / 255;
return unpacked;
}
}