From 900470ee2c5e1026202381aee118dcc9098b0eed Mon Sep 17 00:00:00 2001 From: cha0s Date: Mon, 18 Jan 2021 15:49:24 -0600 Subject: [PATCH] refactor: socket API --- packages/entity/src/packets/entity-list-update-entity.js | 8 ++++---- packages/entity/src/packets/entity-update-trait.js | 8 ++++---- packages/graphics/src/packets/trait-update-visible.js | 4 ++-- packages/input/src/packets/input.js | 4 ++-- packages/math/src/vector/packer.js | 4 ++-- packages/s13n/src/packets/synchronized-create.js | 4 ++-- packages/topdown/src/packets/layers-update-layer.js | 8 ++++---- packages/topdown/src/packets/room-update-layers.js | 8 ++++---- 8 files changed, 24 insertions(+), 24 deletions(-) diff --git a/packages/entity/src/packets/entity-list-update-entity.js b/packages/entity/src/packets/entity-list-update-entity.js index d6abee9..474fa5d 100644 --- a/packages/entity/src/packets/entity-list-update-entity.js +++ b/packages/entity/src/packets/entity-list-update-entity.js @@ -2,11 +2,11 @@ import {packets, Packet} from '@latus/socket'; export default (latus) => class EntityListUpdateEntityPacket extends Packet { - static packData(data) { + static pack(data) { const {fromType: {Bundle}} = packets(latus); for (let i = 0; i < data.length; i++) { // 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; } @@ -20,11 +20,11 @@ export default (latus) => class EntityListUpdateEntityPacket extends Packet { ]; } - static unpackData(data) { + static unpack(data) { const {fromType: {Bundle}} = packets(latus); for (let i = 0; i < data.length; i++) { // 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; } diff --git a/packages/entity/src/packets/entity-update-trait.js b/packages/entity/src/packets/entity-update-trait.js index c9c72cf..1cc538f 100644 --- a/packages/entity/src/packets/entity-update-trait.js +++ b/packages/entity/src/packets/entity-update-trait.js @@ -4,7 +4,7 @@ import {packets} from '@latus/socket'; export default (latus) => class EntityUpdateTraitPacket extends SynchronizedUpdatePacket { - static packData(data) { + static pack(data) { const {fromType: {Bundle}} = packets(latus); const {fromType} = traits(latus); 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 data.traits[i] = { type: Trait.id, - packets: Bundle.bundle(data.traits[i].packets), + packets: Bundle.encode(data.traits[i].packets), }; } 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 {fromId} = traits(latus); 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 data.traits[i] = { type: Trait.type, - packets: Bundle.unbundle(data.traits[i].packets), + packets: Bundle.decode(data.traits[i].packets), }; } return data; diff --git a/packages/graphics/src/packets/trait-update-visible.js b/packages/graphics/src/packets/trait-update-visible.js index 02bb010..5469157 100644 --- a/packages/graphics/src/packets/trait-update-visible.js +++ b/packages/graphics/src/packets/trait-update-visible.js @@ -2,7 +2,7 @@ import {Packet} from '@latus/socket'; export default () => class TraitUpdateVisiblePacket extends Packet { - static packData(data) { + static pack(data) { return { isVisibile: data.isVisible, opacity: Math.floor(data.opacity * 255), @@ -16,7 +16,7 @@ export default () => class TraitUpdateVisiblePacket extends Packet { }; } - static unpackData(data) { + static unpack(data) { return { isVisibile: data.isVisible, opacity: data.opacity / 255, diff --git a/packages/input/src/packets/input.js b/packages/input/src/packets/input.js index 3ec94d1..17ed446 100644 --- a/packages/input/src/packets/input.js +++ b/packages/input/src/packets/input.js @@ -12,7 +12,7 @@ export default class InputPacket extends Packet { } } - static packData(data) { + static pack(data) { for (let i = 0; i < data.length; i++) { const {action, value} = data[i]; const actionId = this.actionIds[action]; @@ -26,7 +26,7 @@ export default class InputPacket extends Packet { return ['uint32']; } - static unpackData(data) { + static unpack(data) { for (let i = 0; i < data.length; i++) { // eslint-disable-next-line no-bitwise const [actionId, value] = [data[i] >> 24, data[i] & 0xFFFFFF]; diff --git a/packages/math/src/vector/packer.js b/packages/math/src/vector/packer.js index 7921da3..7089514 100644 --- a/packages/math/src/vector/packer.js +++ b/packages/math/src/vector/packer.js @@ -33,14 +33,14 @@ export default (key) => (Superclass) => { }, }, ); - PackedVectorPacket.packData = key + PackedVectorPacket.pack = key ? (data) => { // eslint-disable-next-line no-param-reassign data[key] = packToUint32(data[key]); return data; } : (data) => packToUint32(data); - PackedVectorPacket.unpackData = key + PackedVectorPacket.unpack = key ? (data) => { // eslint-disable-next-line no-param-reassign data[key] = unpackFromUint32(data[key]); diff --git a/packages/s13n/src/packets/synchronized-create.js b/packages/s13n/src/packets/synchronized-create.js index f882abd..3776436 100644 --- a/packages/s13n/src/packets/synchronized-create.js +++ b/packages/s13n/src/packets/synchronized-create.js @@ -4,7 +4,7 @@ import SynchronizedPacket from './synchronized'; export default class SynchronizedCreatePacket extends SynchronizedPacket { - static packData(data) { + static pack(data) { // eslint-disable-next-line no-param-reassign data.spec = msgpack.encode(data.spec); return data; @@ -20,7 +20,7 @@ export default class SynchronizedCreatePacket extends SynchronizedPacket { return 'create'; } - static unpackData(data) { + static unpack(data) { // eslint-disable-next-line no-param-reassign data.spec = msgpack.decode(data.spec); return data; diff --git a/packages/topdown/src/packets/layers-update-layer.js b/packages/topdown/src/packets/layers-update-layer.js index a167626..e41e891 100644 --- a/packages/topdown/src/packets/layers-update-layer.js +++ b/packages/topdown/src/packets/layers-update-layer.js @@ -2,11 +2,11 @@ import {packets, Packet} from '@latus/socket'; export default (latus) => class LayersUpdateLayerPacket extends Packet { - static packData(data) { + static pack(data) { const {fromType: {Bundle}} = packets(latus); for (let i = 0; i < data.length; i++) { // 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; } @@ -20,11 +20,11 @@ export default (latus) => class LayersUpdateLayerPacket extends Packet { ]; } - static unpackData(data) { + static unpack(data) { const {fromType: {Bundle}} = packets(latus); for (let i = 0; i < data.length; i++) { // 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; } diff --git a/packages/topdown/src/packets/room-update-layers.js b/packages/topdown/src/packets/room-update-layers.js index 2a3dd4a..11061e2 100644 --- a/packages/topdown/src/packets/room-update-layers.js +++ b/packages/topdown/src/packets/room-update-layers.js @@ -3,10 +3,10 @@ import {SynchronizedUpdatePacket} from '@avocado/s13n'; export default (latus) => class RoomUpdateLayers extends SynchronizedUpdatePacket { - static packData(data) { + static pack(data) { const {fromType: {Bundle}} = packets(latus); // eslint-disable-next-line no-param-reassign - data.layersPackets = Bundle.bundle(data.layersPackets); + data.layersPackets = Bundle.encode(data.layersPackets); return data; } @@ -16,10 +16,10 @@ export default (latus) => class RoomUpdateLayers extends SynchronizedUpdatePacke }; } - static unpackData(data) { + static unpack(data) { const {fromType: {Bundle}} = packets(latus); // eslint-disable-next-line no-param-reassign - data.layersPackets = Bundle.unbundle(data.layersPackets); + data.layersPackets = Bundle.decode(data.layersPackets); return data; }