35 lines
588 B
JavaScript
35 lines
588 B
JavaScript
import Packet from '@/net/packet.js';
|
|
|
|
const WIRE_MAP = {
|
|
'moveUp': 0,
|
|
'moveRight': 1,
|
|
'moveDown': 2,
|
|
'moveLeft': 3,
|
|
'use': 4,
|
|
'changeSlot': 5,
|
|
'interact': 6,
|
|
};
|
|
Object.entries(WIRE_MAP)
|
|
.forEach(([k, v]) => {
|
|
WIRE_MAP[v] = k;
|
|
});
|
|
|
|
export default class Action extends Packet {
|
|
|
|
static pack(payload) {
|
|
return super.pack({
|
|
type: WIRE_MAP[payload.type],
|
|
value: payload.value,
|
|
});
|
|
}
|
|
|
|
static unpack(packed) {
|
|
const unpacked = super.unpack(packed);
|
|
return {
|
|
type: WIRE_MAP[unpacked.type],
|
|
value: unpacked.value,
|
|
};
|
|
}
|
|
|
|
}
|