@hytopia.com/server-protocol 1.0.9 → 1.0.11
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/exports.ts +7 -0
- package/index.ts +3 -17
- package/package.json +1 -1
- package/packets/PacketCore.ts +21 -17
- package/packets/PacketDefinitions.ts +34 -0
- package/packets/inbound/Heartbeat.ts +4 -4
- package/packets/inbound/Input.ts +4 -4
- package/packets/outbound/Block.ts +4 -4
- package/packets/outbound/BlockRegistry.ts +4 -4
- package/packets/outbound/BlockType.ts +4 -4
- package/packets/outbound/Chunk.ts +4 -4
- package/packets/outbound/Entity.ts +4 -4
- package/packets/outbound/PhysicsDebugRender.ts +4 -4
- package/schemas/Block.ts +6 -6
- package/schemas/BlockRegistry.ts +5 -5
- package/schemas/BlockType.ts +10 -10
- package/schemas/Chunk.ts +5 -5
- package/schemas/Collider.ts +4 -4
- package/schemas/ColliderDesc.ts +20 -20
- package/schemas/Entity.ts +11 -11
- package/schemas/Heartbeat.ts +2 -2
- package/schemas/Input.ts +2 -2
- package/schemas/PhysicsDebugRender.ts +2 -2
- package/schemas/Quaternion.ts +2 -2
- package/schemas/RigidBody.ts +5 -5
- package/schemas/RigidBodyDesc.ts +20 -20
- package/schemas/Shape.ts +8 -8
- package/schemas/Vector.ts +2 -2
- package/schemas/VectorBoolean.ts +2 -2
package/exports.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as inboundPackets from './packets/inbound';
|
|
2
|
+
import * as outboundPackets from './packets/outbound';
|
|
3
|
+
|
|
4
|
+
export { inboundPackets, outboundPackets };
|
|
5
|
+
export * from './packets/PacketCore';
|
|
6
|
+
export * from './packets/PacketDefinitions';
|
|
7
|
+
export * from './schemas';
|
package/index.ts
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import * as schemas from './schemas';
|
|
5
|
-
|
|
6
|
-
export { inboundPackets, outboundPackets };
|
|
7
|
-
export * from './packets/inbound';
|
|
8
|
-
export * from './packets/outbound';
|
|
9
|
-
export * from './packets/PacketCore';
|
|
10
|
-
export * from './schemas';
|
|
11
|
-
|
|
12
|
-
export default {
|
|
13
|
-
inboundPackets,
|
|
14
|
-
outboundPackets,
|
|
15
|
-
...PacketCore,
|
|
16
|
-
...schemas,
|
|
17
|
-
};
|
|
1
|
+
import * as protocol from './exports';
|
|
2
|
+
export * from './exports';
|
|
3
|
+
export default protocol;
|
package/package.json
CHANGED
package/packets/PacketCore.ts
CHANGED
|
@@ -17,7 +17,7 @@ import type { JSONSchemaType, ValidateFunction } from 'ajv';
|
|
|
17
17
|
* in encoded format.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
export enum
|
|
20
|
+
export enum PacketId {
|
|
21
21
|
// Standard Inbound Packet Types: 0 - 31 range
|
|
22
22
|
HEARTBEAT = 0,
|
|
23
23
|
INPUT = 1,
|
|
@@ -40,37 +40,41 @@ export enum PacketIds {
|
|
|
40
40
|
* Generators for packet definitions and validators.
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
|
-
export interface IPacketDefinition<TId extends
|
|
43
|
+
export interface IPacketDefinition<TId extends PacketId, TSchema> {
|
|
44
44
|
id: TId;
|
|
45
45
|
schema: JSONSchemaType<TSchema>;
|
|
46
46
|
validate: ValidateFunction<TSchema>;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export interface IPacket<TId extends
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
export interface IPacket<TId extends PacketId, TSchema> {
|
|
50
|
+
i: TId; // packet id
|
|
51
|
+
d: TSchema; // packet data
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
export type AnyPacket = IPacket<
|
|
54
|
+
export type AnyPacket = IPacket<PacketId, unknown>;
|
|
55
55
|
|
|
56
56
|
export type AnyPacketDefinition = IPacketDefinition<number, unknown>;
|
|
57
57
|
|
|
58
|
-
export
|
|
58
|
+
export function createPacket<TId extends number, TSchema>(
|
|
59
59
|
packetDef: IPacketDefinition<TId, TSchema>,
|
|
60
|
-
|
|
61
|
-
): IPacket<TId, TSchema>
|
|
62
|
-
if (!packetDef.validate(
|
|
60
|
+
data: TSchema,
|
|
61
|
+
): IPacket<TId, TSchema> {
|
|
62
|
+
if (!packetDef.validate(data)) {
|
|
63
63
|
throw new Error(`createPacket(): Invalid payload for packet with id ${packetDef.id}, error: ${Ajv.instance.errorsText(packetDef.validate.errors)}`);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
return {
|
|
66
|
+
return { i: packetDef.id, d: data };
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
export
|
|
69
|
+
export function definePacket<TId extends PacketId, TSchema>(
|
|
70
70
|
id: TId,
|
|
71
71
|
schema: JSONSchemaType<TSchema>,
|
|
72
|
-
): IPacketDefinition<TId, TSchema>
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
): IPacketDefinition<TId, TSchema> {
|
|
73
|
+
return {
|
|
74
|
+
id,
|
|
75
|
+
schema,
|
|
76
|
+
validate: Ajv.instance.compile(schema),
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as inboundPackets from './inbound';
|
|
2
|
+
import * as outboundPackets from './outbound';
|
|
3
|
+
import type { PacketId, AnyPacket, AnyPacketDefinition } from './PacketCore';
|
|
4
|
+
|
|
5
|
+
export const registeredPackets = new Map<PacketId, AnyPacketDefinition>();
|
|
6
|
+
|
|
7
|
+
const allPackets = { ...inboundPackets, ...outboundPackets };
|
|
8
|
+
|
|
9
|
+
for (const packet of Object.values(allPackets)) {
|
|
10
|
+
if ('id' in packet && 'schema' in packet) {
|
|
11
|
+
const definition = packet as AnyPacketDefinition;
|
|
12
|
+
|
|
13
|
+
if (registeredPackets.has(definition.id)) {
|
|
14
|
+
throw new Error(`Packet with id ${definition.id} is already registered.`);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
registeredPackets.set(definition.id, definition);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function isValidPacket(packet: unknown): packet is AnyPacket {
|
|
22
|
+
if (
|
|
23
|
+
typeof packet !== 'object' ||
|
|
24
|
+
packet === null ||
|
|
25
|
+
!('i' in packet) ||
|
|
26
|
+
!('d' in packet) ||
|
|
27
|
+
typeof packet.i !== 'number'
|
|
28
|
+
) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const packetDef = registeredPackets.get(packet.i);
|
|
33
|
+
return !!packetDef && packetDef.validate(packet.d);
|
|
34
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { definePacket,
|
|
1
|
+
import { definePacket, PacketId } from '../PacketCore';
|
|
2
2
|
import type { IPacket } from '../PacketCore';
|
|
3
3
|
import { heartbeatSchema } from '../../schemas/Heartbeat';
|
|
4
|
-
import type {
|
|
4
|
+
import type { HeartbeatSchema } from '../../schemas/Heartbeat';
|
|
5
5
|
|
|
6
|
-
export type HeartbeatPacket = IPacket<typeof
|
|
6
|
+
export type HeartbeatPacket = IPacket<typeof PacketId.HEARTBEAT, HeartbeatSchema>;
|
|
7
7
|
|
|
8
8
|
export const heartbeatPacketDefinition = definePacket(
|
|
9
|
-
|
|
9
|
+
PacketId.HEARTBEAT,
|
|
10
10
|
heartbeatSchema
|
|
11
11
|
);
|
package/packets/inbound/Input.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { definePacket,
|
|
1
|
+
import { definePacket, PacketId } from '../PacketCore';
|
|
2
2
|
import type { IPacket } from '../PacketCore';
|
|
3
3
|
import { inputSchema } from '../../schemas/Input';
|
|
4
|
-
import type {
|
|
4
|
+
import type { InputSchema } from '../../schemas/Input';
|
|
5
5
|
|
|
6
|
-
export type InputPacket = IPacket<typeof
|
|
6
|
+
export type InputPacket = IPacket<typeof PacketId.INPUT, InputSchema>;
|
|
7
7
|
|
|
8
8
|
export const inputPacketDefinition = definePacket(
|
|
9
|
-
|
|
9
|
+
PacketId.INPUT,
|
|
10
10
|
inputSchema
|
|
11
11
|
);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { definePacket,
|
|
1
|
+
import { definePacket, PacketId } from '../PacketCore';
|
|
2
2
|
import type { IPacket } from '../PacketCore';
|
|
3
3
|
import { blockSchema } from '../../schemas/Block';
|
|
4
|
-
import type {
|
|
4
|
+
import type { BlockSchema } from '../../schemas/Block';
|
|
5
5
|
|
|
6
|
-
export type BlockPacket = IPacket<typeof
|
|
6
|
+
export type BlockPacket = IPacket<typeof PacketId.BLOCK, BlockSchema>;
|
|
7
7
|
|
|
8
8
|
export const blockPacketDefinition = definePacket(
|
|
9
|
-
|
|
9
|
+
PacketId.BLOCK,
|
|
10
10
|
blockSchema,
|
|
11
11
|
);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { definePacket,
|
|
1
|
+
import { definePacket, PacketId } from '../PacketCore';
|
|
2
2
|
import type { IPacket } from '../PacketCore';
|
|
3
3
|
import { blockRegistrySchema } from '../../schemas/BlockRegistry';
|
|
4
|
-
import type {
|
|
4
|
+
import type { BlockRegistrySchema } from '../../schemas/BlockRegistry';
|
|
5
5
|
|
|
6
|
-
export type BlockRegistryPacket = IPacket<typeof
|
|
6
|
+
export type BlockRegistryPacket = IPacket<typeof PacketId.BLOCK_REGISTRY, BlockRegistrySchema>;
|
|
7
7
|
|
|
8
8
|
export const blockRegistryPacketDefinition = definePacket(
|
|
9
|
-
|
|
9
|
+
PacketId.BLOCK_REGISTRY,
|
|
10
10
|
blockRegistrySchema,
|
|
11
11
|
);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { definePacket,
|
|
1
|
+
import { definePacket, PacketId } from '../PacketCore';
|
|
2
2
|
import type { IPacket } from '../PacketCore';
|
|
3
3
|
import { blockTypeSchema } from '../../schemas/BlockType';
|
|
4
|
-
import type {
|
|
4
|
+
import type { BlockTypeSchema } from '../../schemas/BlockType';
|
|
5
5
|
|
|
6
|
-
export type BlockTypePacket = IPacket<typeof
|
|
6
|
+
export type BlockTypePacket = IPacket<typeof PacketId.BLOCK_TYPE, BlockTypeSchema>;
|
|
7
7
|
|
|
8
8
|
export const blockTypePacketDefinition = definePacket(
|
|
9
|
-
|
|
9
|
+
PacketId.BLOCK_TYPE,
|
|
10
10
|
blockTypeSchema,
|
|
11
11
|
);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { definePacket,
|
|
1
|
+
import { definePacket, PacketId } from '../PacketCore';
|
|
2
2
|
import type { IPacket } from '../PacketCore';
|
|
3
3
|
import { chunkSchema } from '../../schemas/Chunk';
|
|
4
|
-
import type {
|
|
4
|
+
import type { ChunkSchema } from '../../schemas/Chunk';
|
|
5
5
|
|
|
6
|
-
export type ChunkPacket = IPacket<typeof
|
|
6
|
+
export type ChunkPacket = IPacket<typeof PacketId.CHUNK, ChunkSchema>;
|
|
7
7
|
|
|
8
8
|
export const chunkPacketDefinition = definePacket(
|
|
9
|
-
|
|
9
|
+
PacketId.CHUNK,
|
|
10
10
|
chunkSchema,
|
|
11
11
|
);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { definePacket,
|
|
1
|
+
import { definePacket, PacketId } from '../PacketCore';
|
|
2
2
|
import type { IPacket } from '../PacketCore';
|
|
3
3
|
import { entitySchema } from '../../schemas/Entity';
|
|
4
|
-
import type {
|
|
4
|
+
import type { EntitySchema } from '../../schemas/Entity';
|
|
5
5
|
|
|
6
|
-
export type EntityPacket = IPacket<typeof
|
|
6
|
+
export type EntityPacket = IPacket<typeof PacketId.ENTITY, EntitySchema>;
|
|
7
7
|
|
|
8
8
|
export const entityPacketDefinition = definePacket(
|
|
9
|
-
|
|
9
|
+
PacketId.ENTITY,
|
|
10
10
|
entitySchema,
|
|
11
11
|
);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { definePacket,
|
|
1
|
+
import { definePacket, PacketId } from '../PacketCore';
|
|
2
2
|
import type { IPacket } from '../PacketCore';
|
|
3
3
|
import { physicsDebugRenderSchema } from '../../schemas/PhysicsDebugRender';
|
|
4
|
-
import type {
|
|
4
|
+
import type { PhysicsDebugRenderSchema } from '../../schemas/PhysicsDebugRender';
|
|
5
5
|
|
|
6
|
-
export type PhysicsDebugRenderPacket = IPacket<typeof
|
|
6
|
+
export type PhysicsDebugRenderPacket = IPacket<typeof PacketId.PHYSICS_DEBUG_RENDER, PhysicsDebugRenderSchema>;
|
|
7
7
|
|
|
8
8
|
export const physicsDebugRenderPacketDefinition = definePacket(
|
|
9
|
-
|
|
9
|
+
PacketId.PHYSICS_DEBUG_RENDER,
|
|
10
10
|
physicsDebugRenderSchema,
|
|
11
11
|
);
|
package/schemas/Block.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { vectorSchema } from './Vector';
|
|
2
2
|
import type { JSONSchemaType } from 'ajv';
|
|
3
|
-
import type {
|
|
3
|
+
import type { VectorSchema } from './Vector';
|
|
4
4
|
|
|
5
|
-
export type
|
|
6
|
-
wi: string;
|
|
7
|
-
i: number;
|
|
8
|
-
c:
|
|
5
|
+
export type BlockSchema = {
|
|
6
|
+
wi: string; // world id
|
|
7
|
+
i: number; // block id
|
|
8
|
+
c: VectorSchema; // coordinate
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export const blockSchema: JSONSchemaType<
|
|
11
|
+
export const blockSchema: JSONSchemaType<BlockSchema> = {
|
|
12
12
|
type: 'object',
|
|
13
13
|
properties: {
|
|
14
14
|
wi: { type: 'string' },
|
package/schemas/BlockRegistry.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { blockTypeSchema } from './BlockType';
|
|
2
2
|
import type { JSONSchemaType } from 'ajv';
|
|
3
|
-
import type {
|
|
3
|
+
import type { BlockTypeSchema } from './BlockType';
|
|
4
4
|
|
|
5
|
-
export type
|
|
6
|
-
wi: string;
|
|
7
|
-
b:
|
|
5
|
+
export type BlockRegistrySchema = {
|
|
6
|
+
wi: string; // world id
|
|
7
|
+
b: BlockTypeSchema[]; // block types
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export const blockRegistrySchema: JSONSchemaType<
|
|
10
|
+
export const blockRegistrySchema: JSONSchemaType<BlockRegistrySchema> = {
|
|
11
11
|
type: 'object',
|
|
12
12
|
properties: {
|
|
13
13
|
wi: { type: 'string' },
|
package/schemas/BlockType.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { colliderDescSchema } from './ColliderDesc';
|
|
2
2
|
import type { JSONSchemaType } from 'ajv';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ColliderDescSchema } from './ColliderDesc';
|
|
4
4
|
|
|
5
|
-
export type
|
|
6
|
-
wi: string;
|
|
7
|
-
i: number;
|
|
8
|
-
d: boolean;
|
|
9
|
-
t?: string;
|
|
10
|
-
n?: string;
|
|
11
|
-
c?:
|
|
12
|
-
s?: boolean;
|
|
5
|
+
export type BlockTypeSchema = {
|
|
6
|
+
wi: string; // world id
|
|
7
|
+
i: number; // block type id
|
|
8
|
+
d: boolean; // delta
|
|
9
|
+
t?: string; // textureUri
|
|
10
|
+
n?: string; // name
|
|
11
|
+
c?: ColliderDescSchema; // collider desc
|
|
12
|
+
s?: boolean; // is solid
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export const blockTypeSchema: JSONSchemaType<
|
|
15
|
+
export const blockTypeSchema: JSONSchemaType<BlockTypeSchema> = {
|
|
16
16
|
type: 'object',
|
|
17
17
|
properties: {
|
|
18
18
|
wi: { type: 'string' },
|
package/schemas/Chunk.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { vectorSchema } from './Vector';
|
|
2
2
|
import type { JSONSchemaType } from 'ajv';
|
|
3
|
-
import type {
|
|
3
|
+
import type { VectorSchema } from './Vector';
|
|
4
4
|
|
|
5
|
-
export type
|
|
6
|
-
wi: string;
|
|
7
|
-
c:
|
|
5
|
+
export type ChunkSchema = {
|
|
6
|
+
wi: string; // world id
|
|
7
|
+
c: VectorSchema; // chunk coordinate [ 16n, 16n, 16n ]
|
|
8
8
|
b: Uint8Array | number[]; // block ids in chunk, 16^3 entries, registry block ids 1-255, 0 = none
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export const chunkSchema: JSONSchemaType<
|
|
11
|
+
export const chunkSchema: JSONSchemaType<ChunkSchema> = {
|
|
12
12
|
type: 'object',
|
|
13
13
|
properties: {
|
|
14
14
|
wi: { type: 'string' },
|
package/schemas/Collider.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { colliderDescSchema } from './ColliderDesc';
|
|
2
2
|
import type { JSONSchemaType } from 'ajv';
|
|
3
|
-
import type {
|
|
3
|
+
import type { ColliderDescSchema } from './ColliderDesc';
|
|
4
4
|
|
|
5
|
-
export type
|
|
5
|
+
export type ColliderSchema = {
|
|
6
6
|
h?: number; // collider handle for rapier
|
|
7
|
-
} &
|
|
7
|
+
} & ColliderDescSchema;
|
|
8
8
|
|
|
9
|
-
export const colliderSchema: JSONSchemaType<
|
|
9
|
+
export const colliderSchema: JSONSchemaType<ColliderSchema> = {
|
|
10
10
|
type: 'object',
|
|
11
11
|
properties: {
|
|
12
12
|
h: { type: 'number', nullable: true },
|
package/schemas/ColliderDesc.ts
CHANGED
|
@@ -2,29 +2,29 @@ import { shapeSchema } from './Shape';
|
|
|
2
2
|
import { quaternionSchema } from './Quaternion';
|
|
3
3
|
import { vectorSchema } from './Vector';
|
|
4
4
|
import type { JSONSchemaType } from 'ajv';
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
5
|
+
import type { ShapeSchema } from './Shape';
|
|
6
|
+
import type { QuaternionSchema } from './Quaternion';
|
|
7
|
+
import type { VectorSchema } from './Vector';
|
|
8
8
|
|
|
9
|
-
export type
|
|
10
|
-
at?: number;
|
|
11
|
-
cg?: number;
|
|
12
|
-
cs?: number;
|
|
13
|
-
d?: number;
|
|
14
|
-
f?: number;
|
|
15
|
-
fr?: number;
|
|
16
|
-
en?: boolean;
|
|
17
|
-
sn?: boolean;
|
|
18
|
-
m?: number;
|
|
19
|
-
re?: number;
|
|
20
|
-
rer?: number;
|
|
21
|
-
r?:
|
|
22
|
-
s?:
|
|
23
|
-
sg?: number;
|
|
24
|
-
t?:
|
|
9
|
+
export type ColliderDescSchema = {
|
|
10
|
+
at?: number; // active collision types
|
|
11
|
+
cg?: number; // collision groups
|
|
12
|
+
cs?: number; // contact skin
|
|
13
|
+
d?: number; // density
|
|
14
|
+
f?: number; // friction
|
|
15
|
+
fr?: number; // friction combine rule
|
|
16
|
+
en?: boolean; // enabled
|
|
17
|
+
sn?: boolean; // sensor
|
|
18
|
+
m?: number; // mass
|
|
19
|
+
re?: number; // restitution
|
|
20
|
+
rer?: number; // restitution combine rule
|
|
21
|
+
r?: QuaternionSchema; // rotation
|
|
22
|
+
s?: ShapeSchema; // shape
|
|
23
|
+
sg?: number; // solver groups
|
|
24
|
+
t?: VectorSchema; // translation
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export const colliderDescSchema: JSONSchemaType<
|
|
27
|
+
export const colliderDescSchema: JSONSchemaType<ColliderDescSchema> = {
|
|
28
28
|
type: 'object',
|
|
29
29
|
properties: {
|
|
30
30
|
at: { type: 'number', nullable: true },
|
package/schemas/Entity.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { rigidBodySchema } from './RigidBody';
|
|
2
2
|
import type { JSONSchemaType } from 'ajv';
|
|
3
|
-
import type {
|
|
3
|
+
import type { RigidBodySchema } from './RigidBody';
|
|
4
4
|
|
|
5
|
-
export type
|
|
6
|
-
wi: string;
|
|
7
|
-
i: number;
|
|
8
|
-
d: boolean;
|
|
9
|
-
f?: boolean;
|
|
10
|
-
n?: string;
|
|
11
|
-
m?: string;
|
|
12
|
-
t?: string;
|
|
13
|
-
r?:
|
|
5
|
+
export type EntitySchema = {
|
|
6
|
+
wi: string; // world id
|
|
7
|
+
i: number; // entity id
|
|
8
|
+
d: boolean; // delta
|
|
9
|
+
f?: boolean; // focused
|
|
10
|
+
n?: string; // name
|
|
11
|
+
m?: string; // model uri
|
|
12
|
+
t?: string; // texture uri
|
|
13
|
+
r?: RigidBodySchema; // rigid body
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export const entitySchema: JSONSchemaType<
|
|
16
|
+
export const entitySchema: JSONSchemaType<EntitySchema> = {
|
|
17
17
|
type: 'object',
|
|
18
18
|
properties: {
|
|
19
19
|
wi: { type: 'string' },
|
package/schemas/Heartbeat.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { JSONSchemaType } from 'ajv';
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type HeartbeatSchema = null;
|
|
4
4
|
|
|
5
|
-
export const heartbeatSchema: JSONSchemaType<
|
|
5
|
+
export const heartbeatSchema: JSONSchemaType<HeartbeatSchema> = {
|
|
6
6
|
type: 'null',
|
|
7
7
|
nullable: true,
|
|
8
8
|
}
|
package/schemas/Input.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { JSONSchemaType } from 'ajv';
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type InputSchema = {
|
|
4
4
|
w?: boolean; // w key pressed
|
|
5
5
|
a?: boolean; // a key pressed
|
|
6
6
|
s?: boolean; // s key pressed
|
|
@@ -15,7 +15,7 @@ export type Input = {
|
|
|
15
15
|
cy?: number; // camera yaw radians
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export const inputSchema: JSONSchemaType<
|
|
18
|
+
export const inputSchema: JSONSchemaType<InputSchema> = {
|
|
19
19
|
type: 'object',
|
|
20
20
|
properties: {
|
|
21
21
|
w: { type: 'boolean', nullable: true },
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { JSONSchemaType } from 'ajv';
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type PhysicsDebugRenderSchema = {
|
|
4
4
|
wi: string; // world id
|
|
5
5
|
v: number[]; // rapier debug render vertices
|
|
6
6
|
c: number[]; // rapier debug render colors
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export const physicsDebugRenderSchema: JSONSchemaType<
|
|
9
|
+
export const physicsDebugRenderSchema: JSONSchemaType<PhysicsDebugRenderSchema> = {
|
|
10
10
|
type: 'object',
|
|
11
11
|
properties: {
|
|
12
12
|
wi: { type: 'string' },
|
package/schemas/Quaternion.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { JSONSchemaType } from 'ajv';
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type QuaternionSchema = [
|
|
4
4
|
number, // x
|
|
5
5
|
number, // y
|
|
6
6
|
number, // z
|
|
7
7
|
number, // w
|
|
8
8
|
];
|
|
9
9
|
|
|
10
|
-
export const quaternionSchema: JSONSchemaType<
|
|
10
|
+
export const quaternionSchema: JSONSchemaType<QuaternionSchema> = {
|
|
11
11
|
type: 'array',
|
|
12
12
|
items: [
|
|
13
13
|
{ type: 'number' },
|
package/schemas/RigidBody.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { rigidBodyDescSchema } from './RigidBodyDesc';
|
|
2
2
|
import type { JSONSchemaType } from 'ajv';
|
|
3
|
-
import {
|
|
3
|
+
import { RigidBodyDescSchema } from './RigidBodyDesc';
|
|
4
4
|
|
|
5
|
-
export type
|
|
5
|
+
export type RigidBodySchema = {
|
|
6
6
|
h?: number; // rigid body handle for rapier
|
|
7
|
-
} &
|
|
7
|
+
} & RigidBodyDescSchema;
|
|
8
8
|
|
|
9
|
-
export const rigidBodySchema: JSONSchemaType<
|
|
9
|
+
export const rigidBodySchema: JSONSchemaType<RigidBodySchema> = {
|
|
10
10
|
type: 'object',
|
|
11
11
|
properties: {
|
|
12
|
-
|
|
12
|
+
h: { type: 'number', nullable: true },
|
|
13
13
|
...rigidBodyDescSchema.properties,
|
|
14
14
|
},
|
|
15
15
|
additionalProperties: false,
|
package/schemas/RigidBodyDesc.ts
CHANGED
|
@@ -2,29 +2,29 @@ import { colliderSchema } from './Collider';
|
|
|
2
2
|
import { vectorSchema } from './Vector';
|
|
3
3
|
import { vectorBooleanSchema } from './VectorBoolean'
|
|
4
4
|
import type { JSONSchemaType } from 'ajv';
|
|
5
|
-
import type {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
5
|
+
import type { ColliderSchema } from './Collider';
|
|
6
|
+
import type { VectorSchema } from './Vector';
|
|
7
|
+
import type { VectorBooleanSchema } from './VectorBoolean';
|
|
8
8
|
|
|
9
|
-
export type
|
|
10
|
-
ad?: number;
|
|
11
|
-
av?:
|
|
12
|
-
b?: number;
|
|
13
|
-
c?:
|
|
14
|
-
d?: number;
|
|
15
|
-
ce?: boolean;
|
|
16
|
-
en?: boolean;
|
|
17
|
-
er?:
|
|
18
|
-
et?:
|
|
19
|
-
g?: number;
|
|
20
|
-
ld?: number;
|
|
21
|
-
lv?:
|
|
22
|
-
sl?: boolean;
|
|
23
|
-
scp?: number;
|
|
24
|
-
t?:
|
|
9
|
+
export type RigidBodyDescSchema = {
|
|
10
|
+
ad?: number; // angular dampening
|
|
11
|
+
av?: VectorSchema; // angular velocity
|
|
12
|
+
b?: number; // body type
|
|
13
|
+
c?: ColliderSchema[]; // colliders
|
|
14
|
+
d?: number; // dominance group
|
|
15
|
+
ce?: boolean; // ccd enabled
|
|
16
|
+
en?: boolean; // enabled
|
|
17
|
+
er?: VectorBooleanSchema; // enabled rotations
|
|
18
|
+
et?: VectorBooleanSchema; // enabled translations
|
|
19
|
+
g?: number; // gravity scaling
|
|
20
|
+
ld?: number; // linear damping
|
|
21
|
+
lv?: VectorSchema; // linear velocity
|
|
22
|
+
sl?: boolean; // sleeping
|
|
23
|
+
scp?: number; // soft ccd prediction
|
|
24
|
+
t?: VectorSchema; // translation
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export const rigidBodyDescSchema: JSONSchemaType<
|
|
27
|
+
export const rigidBodyDescSchema: JSONSchemaType<RigidBodyDescSchema> = {
|
|
28
28
|
type: 'object',
|
|
29
29
|
properties: {
|
|
30
30
|
ad: { type: 'number', nullable: true },
|
package/schemas/Shape.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { JSONSchemaType } from 'ajv';
|
|
2
2
|
import { vectorSchema } from './Vector';
|
|
3
|
-
import type {
|
|
3
|
+
import type { VectorSchema } from './Vector';
|
|
4
4
|
|
|
5
|
-
export type
|
|
6
|
-
t?: number;
|
|
7
|
-
b?: number;
|
|
8
|
-
r?: number;
|
|
9
|
-
hx?:
|
|
10
|
-
hh?: number;
|
|
5
|
+
export type ShapeSchema = {
|
|
6
|
+
t?: number; // type
|
|
7
|
+
b?: number; // border radius
|
|
8
|
+
r?: number; // radius
|
|
9
|
+
hx?: VectorSchema; // half extends
|
|
10
|
+
hh?: number; // half height
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export const shapeSchema: JSONSchemaType<
|
|
13
|
+
export const shapeSchema: JSONSchemaType<ShapeSchema> = {
|
|
14
14
|
type: 'object',
|
|
15
15
|
properties: {
|
|
16
16
|
t: { type: 'number', nullable: true },
|
package/schemas/Vector.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { JSONSchemaType } from 'ajv';
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type VectorSchema = [
|
|
4
4
|
number, // x
|
|
5
5
|
number, // y
|
|
6
6
|
number, // z
|
|
7
7
|
];
|
|
8
8
|
|
|
9
|
-
export const vectorSchema: JSONSchemaType<
|
|
9
|
+
export const vectorSchema: JSONSchemaType<VectorSchema> = {
|
|
10
10
|
type: 'array',
|
|
11
11
|
items: [
|
|
12
12
|
{ type: 'number' },
|
package/schemas/VectorBoolean.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { JSONSchemaType } from 'ajv';
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type VectorBooleanSchema = [
|
|
4
4
|
boolean, // x
|
|
5
5
|
boolean, // y
|
|
6
6
|
boolean, // z
|
|
7
7
|
];
|
|
8
8
|
|
|
9
|
-
export const vectorBooleanSchema: JSONSchemaType<
|
|
9
|
+
export const vectorBooleanSchema: JSONSchemaType<VectorBooleanSchema> = {
|
|
10
10
|
type: 'array',
|
|
11
11
|
items: [
|
|
12
12
|
{ type: 'boolean' },
|