refactor: socket API
This commit is contained in:
parent
86cfe1fb8a
commit
900470ee2c
|
@ -2,11 +2,11 @@ import {packets, Packet} from '@latus/socket';
|
||||||
|
|
||||||
export default (latus) => class EntityListUpdateEntityPacket extends Packet {
|
export default (latus) => class EntityListUpdateEntityPacket extends Packet {
|
||||||
|
|
||||||
static packData(data) {
|
static pack(data) {
|
||||||
const {fromType: {Bundle}} = packets(latus);
|
const {fromType: {Bundle}} = packets(latus);
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
data[i].packets = Bundle.bundle(data[i].packets);
|
data[i].packets = Bundle.encode(data[i].packets);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,11 @@ export default (latus) => class EntityListUpdateEntityPacket extends Packet {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
static unpackData(data) {
|
static unpack(data) {
|
||||||
const {fromType: {Bundle}} = packets(latus);
|
const {fromType: {Bundle}} = packets(latus);
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
data[i].packets = Bundle.unbundle(data[i].packets);
|
data[i].packets = Bundle.decode(data[i].packets);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import {packets} from '@latus/socket';
|
||||||
|
|
||||||
export default (latus) => class EntityUpdateTraitPacket extends SynchronizedUpdatePacket {
|
export default (latus) => class EntityUpdateTraitPacket extends SynchronizedUpdatePacket {
|
||||||
|
|
||||||
static packData(data) {
|
static pack(data) {
|
||||||
const {fromType: {Bundle}} = packets(latus);
|
const {fromType: {Bundle}} = packets(latus);
|
||||||
const {fromType} = traits(latus);
|
const {fromType} = traits(latus);
|
||||||
for (let i = 0; i < data.traits.length; i++) {
|
for (let i = 0; i < data.traits.length; i++) {
|
||||||
|
@ -12,7 +12,7 @@ export default (latus) => class EntityUpdateTraitPacket extends SynchronizedUpda
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
data.traits[i] = {
|
data.traits[i] = {
|
||||||
type: Trait.id,
|
type: Trait.id,
|
||||||
packets: Bundle.bundle(data.traits[i].packets),
|
packets: Bundle.encode(data.traits[i].packets),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
|
@ -29,7 +29,7 @@ export default (latus) => class EntityUpdateTraitPacket extends SynchronizedUpda
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static unpackData(data) {
|
static unpack(data) {
|
||||||
const {fromType: {Bundle}} = packets(latus);
|
const {fromType: {Bundle}} = packets(latus);
|
||||||
const {fromId} = traits(latus);
|
const {fromId} = traits(latus);
|
||||||
for (let i = 0; i < data.traits.length; i++) {
|
for (let i = 0; i < data.traits.length; i++) {
|
||||||
|
@ -37,7 +37,7 @@ export default (latus) => class EntityUpdateTraitPacket extends SynchronizedUpda
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
data.traits[i] = {
|
data.traits[i] = {
|
||||||
type: Trait.type,
|
type: Trait.type,
|
||||||
packets: Bundle.unbundle(data.traits[i].packets),
|
packets: Bundle.decode(data.traits[i].packets),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
|
|
|
@ -2,7 +2,7 @@ import {Packet} from '@latus/socket';
|
||||||
|
|
||||||
export default () => class TraitUpdateVisiblePacket extends Packet {
|
export default () => class TraitUpdateVisiblePacket extends Packet {
|
||||||
|
|
||||||
static packData(data) {
|
static pack(data) {
|
||||||
return {
|
return {
|
||||||
isVisibile: data.isVisible,
|
isVisibile: data.isVisible,
|
||||||
opacity: Math.floor(data.opacity * 255),
|
opacity: Math.floor(data.opacity * 255),
|
||||||
|
@ -16,7 +16,7 @@ export default () => class TraitUpdateVisiblePacket extends Packet {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static unpackData(data) {
|
static unpack(data) {
|
||||||
return {
|
return {
|
||||||
isVisibile: data.isVisible,
|
isVisibile: data.isVisible,
|
||||||
opacity: data.opacity / 255,
|
opacity: data.opacity / 255,
|
||||||
|
|
|
@ -12,7 +12,7 @@ export default class InputPacket extends Packet {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static packData(data) {
|
static pack(data) {
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
const {action, value} = data[i];
|
const {action, value} = data[i];
|
||||||
const actionId = this.actionIds[action];
|
const actionId = this.actionIds[action];
|
||||||
|
@ -26,7 +26,7 @@ export default class InputPacket extends Packet {
|
||||||
return ['uint32'];
|
return ['uint32'];
|
||||||
}
|
}
|
||||||
|
|
||||||
static unpackData(data) {
|
static unpack(data) {
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
// eslint-disable-next-line no-bitwise
|
// eslint-disable-next-line no-bitwise
|
||||||
const [actionId, value] = [data[i] >> 24, data[i] & 0xFFFFFF];
|
const [actionId, value] = [data[i] >> 24, data[i] & 0xFFFFFF];
|
||||||
|
|
|
@ -33,14 +33,14 @@ export default (key) => (Superclass) => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
PackedVectorPacket.packData = key
|
PackedVectorPacket.pack = key
|
||||||
? (data) => {
|
? (data) => {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
data[key] = packToUint32(data[key]);
|
data[key] = packToUint32(data[key]);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
: (data) => packToUint32(data);
|
: (data) => packToUint32(data);
|
||||||
PackedVectorPacket.unpackData = key
|
PackedVectorPacket.unpack = key
|
||||||
? (data) => {
|
? (data) => {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
data[key] = unpackFromUint32(data[key]);
|
data[key] = unpackFromUint32(data[key]);
|
||||||
|
|
|
@ -4,7 +4,7 @@ import SynchronizedPacket from './synchronized';
|
||||||
|
|
||||||
export default class SynchronizedCreatePacket extends SynchronizedPacket {
|
export default class SynchronizedCreatePacket extends SynchronizedPacket {
|
||||||
|
|
||||||
static packData(data) {
|
static pack(data) {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
data.spec = msgpack.encode(data.spec);
|
data.spec = msgpack.encode(data.spec);
|
||||||
return data;
|
return data;
|
||||||
|
@ -20,7 +20,7 @@ export default class SynchronizedCreatePacket extends SynchronizedPacket {
|
||||||
return 'create';
|
return 'create';
|
||||||
}
|
}
|
||||||
|
|
||||||
static unpackData(data) {
|
static unpack(data) {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
data.spec = msgpack.decode(data.spec);
|
data.spec = msgpack.decode(data.spec);
|
||||||
return data;
|
return data;
|
||||||
|
|
|
@ -2,11 +2,11 @@ import {packets, Packet} from '@latus/socket';
|
||||||
|
|
||||||
export default (latus) => class LayersUpdateLayerPacket extends Packet {
|
export default (latus) => class LayersUpdateLayerPacket extends Packet {
|
||||||
|
|
||||||
static packData(data) {
|
static pack(data) {
|
||||||
const {fromType: {Bundle}} = packets(latus);
|
const {fromType: {Bundle}} = packets(latus);
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
data[i].layerPackets = Bundle.bundle(data[i].layerPackets);
|
data[i].layerPackets = Bundle.encode(data[i].layerPackets);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -20,11 +20,11 @@ export default (latus) => class LayersUpdateLayerPacket extends Packet {
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
static unpackData(data) {
|
static unpack(data) {
|
||||||
const {fromType: {Bundle}} = packets(latus);
|
const {fromType: {Bundle}} = packets(latus);
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
data[i].layerPackets = Bundle.unbundle(data[i].layerPackets);
|
data[i].layerPackets = Bundle.decode(data[i].layerPackets);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,10 @@ import {SynchronizedUpdatePacket} from '@avocado/s13n';
|
||||||
|
|
||||||
export default (latus) => class RoomUpdateLayers extends SynchronizedUpdatePacket {
|
export default (latus) => class RoomUpdateLayers extends SynchronizedUpdatePacket {
|
||||||
|
|
||||||
static packData(data) {
|
static pack(data) {
|
||||||
const {fromType: {Bundle}} = packets(latus);
|
const {fromType: {Bundle}} = packets(latus);
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
data.layersPackets = Bundle.bundle(data.layersPackets);
|
data.layersPackets = Bundle.encode(data.layersPackets);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,10 +16,10 @@ export default (latus) => class RoomUpdateLayers extends SynchronizedUpdatePacke
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static unpackData(data) {
|
static unpack(data) {
|
||||||
const {fromType: {Bundle}} = packets(latus);
|
const {fromType: {Bundle}} = packets(latus);
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
data.layersPackets = Bundle.unbundle(data.layersPackets);
|
data.layersPackets = Bundle.decode(data.layersPackets);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user