@wildshard/shard-format 0.10.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wildshard/shard-format",
3
- "version": "0.10.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": {
@@ -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
- }), v.check((s) => new Set(s.tiles.map((t) => `${t.lod}/${t.x}/${t.z}`)).size === s.tiles.length && s.tiles.every((t) => t.x < (t.lod === 0 ? 8 : 4) && t.z < (t.lod === 0 ? 8 : 4)) && new Set([...s.panels, ...s.models].map((p) => p.id)).size === s.panels.length + s.models.length && new Set(s.textures.map((t) => t.model)).size === s.textures.length && new Set(s.colliders.map((c) => c.id)).size === s.colliders.length && s.colliders.reduce((n, c) => n + c.shapes.reduce((m, shape) => m + (shape.kind === 'treads' ? shape.count : 1), 0), 0) <= 2048 && s.colliders.every((c) => c.panel === null || s.panels.some((p) => p.id === c.panel)), 'unique props addresses and ids'));
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] };
@@ -26,6 +26,7 @@ import { MeshCollisionSchema, meshCollisionRules } from './meshCollision.ts';
26
26
  import { NativeGroundSchema, nativeGroundRules } from './nativeGround.ts';
27
27
  import { WaterSchema } from './water.ts';
28
28
  import { CreaturesSchema } from './creatures.ts';
29
+ import type { ShardCreatures } from './creatures.ts';
29
30
  import { FlockSchema } from './crowds.ts';
30
31
  import { groupBrainRules } from './groupBrains.ts';
31
32
  import { EncountersSchema, encounterRules } from './encounters.ts';
@@ -363,7 +364,20 @@ export function shardfileRules(s: Shardfile): string[] {
363
364
  errors.push(...encounterRules(s.encounters, s.creatures.spawns.map((spawn) => spawn.id), s.ui.filter((row) => row.kind === 'bossPanel')));
364
365
  const controlled = new Set(s.encounters.map((row) => row.entity));
365
366
  errors.push(...groupBrainRules(s.creatures.groups, s.creatures.spawns, s.creatures.brains.map((row) => row.id), [...controlled]));
366
- if (s.creatures.spawns.some((row) => (row.brain === null) !== controlled.has(row.id))) errors.push('exactly one declared creature controller');
367
+ // Keep every previously admitted named/encounter controller. Only the formerly
368
+ // unowned null-brain case is extended to an actual engine policy or declaration.
369
+ const inlineBrains: Record<ShardCreatures['brains'][number]['kind'] | 'hunt', true> = {
370
+ hunt: true, pursue: true, skirmisher: true, guardian: true, 'perch-hunter': true,
371
+ script: true, 'ram-grazer': true, 'challenge-grazer': true, 'orbit-diver': true,
372
+ 'patrol-diver': true, 'burst-flyer': true, grazer: true, diver: true, stalker: true,
373
+ };
374
+ if (s.creatures.spawns.some((row) => {
375
+ if (controlled.has(row.id)) { return row.brain !== null; }
376
+ if (row.brain !== null) { return false; }
377
+ const brain = species.get(row.species)?.temperament?.brain;
378
+ return brain === undefined || !(Object.hasOwn(inlineBrains, brain)
379
+ || s.creatures.brains.some((declaration: { readonly id: string }): boolean => declaration.id === brain));
380
+ })) errors.push('exactly one declared creature controller');
367
381
  return [...new Set(errors)];
368
382
  }
369
383
  /** Strict schema for the public SDK format; rejects unknown fields and invalid references.
@@ -10,6 +10,7 @@ import {
10
10
  minValue,
11
11
  number,
12
12
  pipe,
13
+ picklist,
13
14
  regex,
14
15
  strictObject,
15
16
  string,
@@ -35,10 +36,7 @@ const MAX_PARTICLES = 64
35
36
  const MAX_OVERRIDES = 64
36
37
  const MAX_ID = 128
37
38
  const EMPTY = 0
38
- const surface = custom<StrikeDebris['surface']>(
39
- (value: unknown): boolean =>
40
- value === 'shell' || value === 'wood' || value === 'sand',
41
- )
39
+ const surface = picklist(['shell', 'wood', 'sand'])
42
40
  const count = pipe(
43
41
  number(),
44
42
  integer(),
@@ -74,8 +72,11 @@ const policy = strictObject({
74
72
  default: effect,
75
73
  overrides: exactOptional(overrides),
76
74
  })
75
+ /** Exact plain-data preflight identity for structural JSON Schema projectors. */
76
+ const StrikeDebrisJsonGuard: GenericSchema<StrikeDebrisPolicy> =
77
+ custom<StrikeDebrisPolicy>(isJsonData, 'plain strike debris')
77
78
  const StrikeDebrisSchema: GenericSchema<StrikeDebrisPolicy> = pipe(
78
- custom<StrikeDebrisPolicy>(isJsonData, 'plain strike debris'),
79
+ StrikeDebrisJsonGuard,
79
80
  policy,
80
81
  )
81
82
 
@@ -104,5 +105,5 @@ function strikeDebrisCatalogueRules(value: StrikeDebrisCatalogue): string[] {
104
105
  }
105
106
  return errors
106
107
  }
107
- export { StrikeDebrisSchema, strikeDebrisCatalogueRules }
108
+ export { StrikeDebrisSchema, StrikeDebrisJsonGuard, strikeDebrisCatalogueRules }
108
109
  export type { StrikeDebris, StrikeDebrisPolicy, StrikeDebrisCatalogue }