@wildshard/shard-format 0.11.0 → 0.12.0
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 +1 -1
- package/src/format/props.ts +55 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wildshard/shard-format",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "The raw shardfile format: the spec, the validator and a validate CLI. The public, versioned contract every other repo builds on.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
package/src/format/props.ts
CHANGED
|
@@ -27,6 +27,41 @@ function boxWithinCell(b: v.InferOutput<typeof boxData>): boolean {
|
|
|
27
27
|
const box = v.pipe(boxData, v.check(boxWithinCell, 'collider within cell'));
|
|
28
28
|
const treads = v.pipe(v.strictObject({ kind: v.literal('treads'), from: point, to: point, width: extent, count: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(256)), surface }), v.check((t) => Math.hypot(t.to.x - t.from.x, t.to.z - t.from.z) > 0 && t.to.y >= t.from.y && [t.from, t.to].every((p) => Math.abs(p.x) + t.width / 2 <= 250 && Math.abs(p.z) + t.width / 2 <= 250), 'bounded nondegenerate stair'));
|
|
29
29
|
const collider = v.strictObject({ id, panel: v.nullable(id), initialActive: v.boolean(), shapes: v.pipe(v.array(v.variant('kind', [box, treads])), v.minLength(1), v.maxLength(256)) });
|
|
30
|
+
const BODY_EXTENT_MIN = 0.005;
|
|
31
|
+
const BODY_EXTENT_MAX = 8;
|
|
32
|
+
const BODY_DENSITY_MIN = 1;
|
|
33
|
+
const BODY_DENSITY_MAX = 20_000;
|
|
34
|
+
const BODY_FRICTION_MAX = 2;
|
|
35
|
+
const BODY_DAMPING_MAX = 10;
|
|
36
|
+
const BODIES_MAX = 64;
|
|
37
|
+
const BODY_LEAST = 0;
|
|
38
|
+
const BODIES_LEAST = 1;
|
|
39
|
+
const BODY_SHARE_MAX = 1;
|
|
40
|
+
const halfExtent = v.pipe(finite, v.minValue(BODY_EXTENT_MIN), v.maxValue(BODY_EXTENT_MAX));
|
|
41
|
+
const share = v.pipe(finite, v.minValue(BODY_LEAST), v.maxValue(BODY_SHARE_MAX));
|
|
42
|
+
const friction = v.pipe(finite, v.minValue(BODY_LEAST), v.maxValue(BODY_FRICTION_MAX));
|
|
43
|
+
const damping = v.pipe(finite, v.minValue(BODY_LEAST), v.maxValue(BODY_DAMPING_MAX));
|
|
44
|
+
const density = v.pipe(finite, v.minValue(BODY_DENSITY_MIN), v.maxValue(BODY_DENSITY_MAX));
|
|
45
|
+
const ballShape = v.strictObject({ ball: halfExtent });
|
|
46
|
+
const cylinderShape = v.strictObject({ cylinder: v.strictObject({ radius: halfExtent, halfHeight: halfExtent }) });
|
|
47
|
+
const cuboidShape = v.strictObject({ cuboid: v.strictObject({ x: halfExtent, y: halfExtent, z: halfExtent }) });
|
|
48
|
+
const bodyShape = v.union([ballShape, cylinderShape, cuboidShape]);
|
|
49
|
+
const bodyMaterial = v.picklist(['wood', 'stone', 'grass', 'sand', 'rock', 'metal', 'earth', 'felt']);
|
|
50
|
+
/** SHARD-SOURCE SS9a: a touchable panel. The server keeps it as one Rapier dynamic body (its rest pose `at` and `yaw`,
|
|
51
|
+
* the shape's half extents in metres); players push it, and every page draws the panel at the body's pose. */
|
|
52
|
+
const body = v.strictObject({ id, panel: id, at: point, yaw: finite, shape: bodyShape, material: bodyMaterial,
|
|
53
|
+
density: v.exactOptional(density), friction: v.exactOptional(friction), restitution: v.exactOptional(share),
|
|
54
|
+
linearDamping: v.exactOptional(damping), angularDamping: v.exactOptional(damping), keep: v.exactOptional(v.boolean()) });
|
|
55
|
+
const bodies = v.pipe(v.array(body), v.minLength(BODIES_LEAST), v.maxLength(BODIES_MAX));
|
|
56
|
+
/** Each body has its own id and names a declared panel that no other body and no static collider claims. */
|
|
57
|
+
function bodiesAdmitted(section: { readonly bodies?: readonly { readonly id: string; readonly panel: string }[] | undefined; readonly panels: readonly { readonly id: string }[]; readonly colliders: readonly { readonly panel: string | null }[] }): boolean {
|
|
58
|
+
const declared = new Set(section.panels.map((panel): string => panel.id));
|
|
59
|
+
const claimed = new Set(section.colliders.map((solid): string | null => solid.panel));
|
|
60
|
+
const rows = section.bodies ?? [];
|
|
61
|
+
const ids = new Set(rows.map((row): string => row.id));
|
|
62
|
+
const owned = new Set(rows.map((row): string => row.panel));
|
|
63
|
+
return ids.size === rows.length && owned.size === rows.length && rows.every((row): boolean => declared.has(row.panel) && !claimed.has(row.panel));
|
|
64
|
+
}
|
|
30
65
|
/** Declared self-contained GLBs: merged tile meshes, EXT_mesh_gpu_instancing lists, far proxy and script-addressable panels. */
|
|
31
66
|
export const PropsSchema: v.GenericSchema<PropsDataInput, PropsData> = v.pipe(v.unknown(), v.check(isJsonData, 'JSON-only props'), v.strictObject({ version: v.literal(1), family: id,
|
|
32
67
|
materials: v.exactOptional(PropMaterialsSchema),
|
|
@@ -40,7 +75,8 @@ export const PropsSchema: v.GenericSchema<PropsDataInput, PropsData> = v.pipe(v.
|
|
|
40
75
|
panels: v.pipe(v.array(v.strictObject({ id, file: ref, visible: v.optional(v.boolean(), true) })), v.maxLength(64)), models: v.pipe(v.array(named), v.maxLength(64)), far: v.nullable(ref),
|
|
41
76
|
colliders: v.optional(v.pipe(v.array(collider), v.maxLength(1024)), []),
|
|
42
77
|
textures: v.pipe(v.array(v.strictObject({ model: ref, colour: ref })), v.maxLength(256)),
|
|
43
|
-
|
|
78
|
+
bodies: v.exactOptional(bodies),
|
|
79
|
+
}), v.check((s) => new Set(s.tiles.map((tile) => `${tile.lod}/${tile.x}/${tile.z}`)).size === s.tiles.length && s.tiles.every((tile) => tile.x < (tile.lod === 0 ? 8 : 4) && tile.z < (tile.lod === 0 ? 8 : 4)) && new Set([...s.panels, ...s.models].map((entry) => entry.id)).size === s.panels.length + s.models.length && new Set(s.textures.map((texture) => texture.model)).size === s.textures.length && new Set(s.colliders.map((solid) => solid.id)).size === s.colliders.length && s.colliders.reduce((sum, solid) => sum + solid.shapes.reduce((count, shape) => count + (shape.kind === 'treads' ? shape.count : 1), 0), 0) <= 2048 && s.colliders.every((solid) => solid.panel === null || s.panels.some((panel) => panel.id === solid.panel)), 'unique props addresses and ids'), v.check<PropsData, string>(bodiesAdmitted, 'touchable bodies have unique ids and each names its own panel, which no static collider claims'));
|
|
44
80
|
/** Validated data for the props renderer; no callbacks, URLs or generator code enter this section. */
|
|
45
81
|
export type ShardProps = v.InferOutput<typeof PropsSchema>;
|
|
46
82
|
/** Check every render binding against ordinary admitted file, tile and library rows before allocating content. */
|
|
@@ -133,5 +169,23 @@ interface PropsDataFields {
|
|
|
133
169
|
model: string;
|
|
134
170
|
colour: string;
|
|
135
171
|
})[];
|
|
172
|
+
bodies?: PropsBody[];
|
|
173
|
+
}
|
|
174
|
+
/** SS9a: a point, or a cuboid's half extents, in metres. */
|
|
175
|
+
interface PropsBodyVector { x: number; y: number; z: number }
|
|
176
|
+
/** SS9a: one touchable panel's body. */
|
|
177
|
+
interface PropsBody {
|
|
178
|
+
id: string;
|
|
179
|
+
panel: string;
|
|
180
|
+
at: PropsBodyVector;
|
|
181
|
+
yaw: number;
|
|
182
|
+
shape: { ball: number } | { cylinder: { radius: number; halfHeight: number } } | { cuboid: PropsBodyVector };
|
|
183
|
+
material: 'wood' | 'stone' | 'grass' | 'sand' | 'rock' | 'metal' | 'earth' | 'felt';
|
|
184
|
+
density?: number;
|
|
185
|
+
friction?: number;
|
|
186
|
+
restitution?: number;
|
|
187
|
+
linearDamping?: number;
|
|
188
|
+
angularDamping?: number;
|
|
189
|
+
keep?: boolean;
|
|
136
190
|
}
|
|
137
191
|
export type PropsData = { [Key in keyof PropsDataFields]: PropsDataFields[Key] };
|