@hytopia.com/server-protocol 1.0.15 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hytopia.com/server-protocol",
3
- "version": "1.0.15",
3
+ "version": "1.0.17",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -48,10 +48,10 @@ export interface IPacketDefinition<TId extends PacketId, TSchema> {
48
48
  validate: ValidateFunction<TSchema>;
49
49
  }
50
50
 
51
- export interface IPacket<TId extends PacketId, TSchema> {
52
- i: TId; // packet id
53
- d: TSchema; // packet data
54
- }
51
+ export type IPacket<TId extends PacketId, TSchema> = [
52
+ TId, // packet id
53
+ TSchema // packet data
54
+ ];
55
55
 
56
56
  export type AnyPacket = IPacket<PacketId, unknown>;
57
57
 
@@ -65,7 +65,7 @@ export function createPacket<TId extends number, TSchema>(
65
65
  throw new Error(`createPacket(): Invalid payload for packet with id ${packetDef.id}, error: ${Ajv.instance.errorsText(packetDef.validate.errors)}`);
66
66
  }
67
67
 
68
- return { i: packetDef.id, d: data };
68
+ return [ packetDef.id, data ];
69
69
  }
70
70
 
71
71
  export function definePacket<TId extends PacketId, TSchema>(
@@ -24,13 +24,13 @@ export function isValidPacket(packet: unknown): packet is AnyPacket {
24
24
  if (
25
25
  typeof packet !== 'object' ||
26
26
  packet === null ||
27
- !('i' in packet) ||
28
- !('d' in packet) ||
29
- typeof packet.i !== 'number'
27
+ !packet[0] ||
28
+ !packet[1] ||
29
+ typeof packet[0] !== 'number'
30
30
  ) {
31
31
  return false;
32
32
  }
33
33
 
34
- const packetDef = registeredPackets.get(packet.i);
35
- return !!packetDef && packetDef.validate(packet.d);
34
+ const packetDef = registeredPackets.get(packet[0]);
35
+ return !!packetDef && packetDef.validate(packet[1]);
36
36
  }
@@ -5,7 +5,6 @@ import type { ColliderDescSchema } from './ColliderDesc';
5
5
  export type BlockTypeSchema = {
6
6
  wi: number; // world id
7
7
  i: number; // block type id
8
- d: boolean; // delta
9
8
  t?: string; // textureUri
10
9
  n?: string; // name
11
10
  c?: ColliderDescSchema; // collider desc
@@ -17,12 +16,11 @@ export const blockTypeSchema: JSONSchemaType<BlockTypeSchema> = {
17
16
  properties: {
18
17
  wi: { type: 'number' },
19
18
  i: { type: 'number' },
20
- d: { type: 'boolean' },
21
19
  t: { type: 'string', nullable: true },
22
20
  n: { type: 'string', nullable: true },
23
21
  c: { ...colliderDescSchema, nullable: true },
24
22
  s: { type: 'boolean', nullable: true },
25
23
  },
26
- required: [ 'wi', 'i', 'd' ],
24
+ required: [ 'wi', 'i' ],
27
25
  additionalProperties: false,
28
26
  }
package/schemas/Entity.ts CHANGED
@@ -5,7 +5,6 @@ import type { RigidBodySchema } from './RigidBody';
5
5
  export type EntitySchema = {
6
6
  wi: number; // world id
7
7
  i: number; // entity id
8
- d: boolean; // delta
9
8
  f?: boolean; // focused
10
9
  rm?: boolean; // removed
11
10
  n?: string; // name
@@ -19,7 +18,6 @@ export const entitySchema: JSONSchemaType<EntitySchema> = {
19
18
  properties: {
20
19
  wi: { type: 'number' },
21
20
  i: { type: 'number' },
22
- d: { type: 'boolean' },
23
21
  f: { type: 'boolean', nullable: true },
24
22
  rm: { type: 'boolean', nullable: true },
25
23
  n: { type: 'string', nullable: true },
@@ -27,6 +25,6 @@ export const entitySchema: JSONSchemaType<EntitySchema> = {
27
25
  t: { type: 'string', nullable: true },
28
26
  r: { ...rigidBodySchema, nullable: true },
29
27
  },
30
- required: [ 'wi', 'i', 'd' ],
28
+ required: [ 'wi', 'i' ],
31
29
  additionalProperties: false,
32
30
  }