@wildshard/shard-format 0.5.10 → 0.7.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.
@@ -11,39 +11,28 @@
11
11
  * `attackSpan` is the attack duration the export sampled the attack clip with (seconds).
12
12
  */
13
13
  import * as v from 'valibot';
14
- import { parseSkinBindings, parseSkinRows, validateCreatureBones, type SkinBinding, type SkinRow } from './skinData.ts';
15
- import type { ShardRows } from './rows.ts';
14
+ import { validateCreatureBones } from './skinData.ts';
15
+ import type { SkinRow } from './skinData.ts';
16
16
  import type { Shardfile } from './shardSchema.ts';
17
17
  import { parseGlbData as parseGlb } from './glbCost.ts';
18
18
  import { skinLayerDecoded } from './skinLayers.ts';
19
19
  import { MaterialsSchema } from './materials.ts';
20
20
  import { SkinGlbMaterialsSchema, SkinPrimitiveSchema, skinMaterialsFault, skinPartsFault, skinPrimitiveCount } from './skin-materials.ts';
21
21
 
22
- import { SKIN_LOOK_RECIPE, SKIN_CLIPS_RECIPE, SkinLookParametersSchema, SkinClipParametersSchema, ShardSkinFileSchema, type SkinLookParameters } from './skins.ts';
22
+ import { SKIN_LOOK_RECIPE, SKIN_CLIPS_RECIPE } from './skins.ts';
23
+ import type { SkinLookParameters } from './skins.ts';
24
+ import { resolveSkinLookFiles } from './skin-variants.ts';
25
+ import { skinLookParameters } from './skin-file.ts';
23
26
 
24
- /** Parse a `platform.skin` look row's parameters (throws on anything else). */
25
- export function skinLookParameters(row: ShardRows['looks'][number]): SkinLookParameters {
26
- if (row.recipe !== SKIN_LOOK_RECIPE) throw new Error(`look ${row.id}: not a skin look`);
27
- if (row.animation.recipe !== SKIN_CLIPS_RECIPE) throw new Error(`look ${row.id}: a skin look animates with ${SKIN_CLIPS_RECIPE}`);
28
- const look = v.safeParse(SkinLookParametersSchema, row.parameters), clips = v.safeParse(SkinClipParametersSchema, row.animation.parameters);
29
- if (!look.success || !clips.success) throw new Error(`look ${row.id}: invalid skin parameters`);
30
- return { skin: look.output.skin, attackSpan: clips.output.attackSpan };
31
- }
32
- /** Decode and validate one skin file's bytes: its rig row and binding, the binding for that row. */
33
- export function parseSkinFile(bytes: Uint8Array): { row: SkinRow; binding: SkinBinding } {
34
- const file = v.parse(ShardSkinFileSchema, JSON.parse(new TextDecoder().decode(bytes)));
35
- const [row] = parseSkinRows([file.row]); if (row === undefined) throw new Error('skin file: no row');
36
- const [binding] = parseSkinBindings([file.binding], [row]); if (binding === undefined) throw new Error('skin file: no binding');
37
- return { row, binding };
38
- }
39
27
  /** Shardfile reference rules for skin looks: a library `json` file whose dependencies are exactly its row's `glb`. */
40
- export function skinLookRules(source: Pick<Shardfile, 'rows' | 'files' | 'library'>): string[] {
28
+ function skinLookRules(source: Pick<Shardfile, 'rows' | 'files' | 'library'>): string[] {
41
29
  const errors: string[] = [], files = new Map(source.files.map((file) => [file.hash, file]));
42
30
  for (const row of source.rows.looks) {
43
- if (row.recipe !== SKIN_LOOK_RECIPE) { if (row.animation.recipe === SKIN_CLIPS_RECIPE) errors.push('skin clips without a skin look'); continue; }
44
- let skin: string; try { skin = skinLookParameters(row).skin; } catch { errors.push('skin look parameters'); continue; }
45
- const file = files.get(skin), glb = file?.dependencies.length === 1 ? files.get(file.dependencies[0] ?? '') : undefined;
46
- if (file?.kind !== 'json' || glb?.kind !== 'glb' || !source.library.includes(skin)) errors.push('skin look file references');
31
+ if (row.recipe !== SKIN_LOOK_RECIPE) { if (row.animation.recipe === SKIN_CLIPS_RECIPE) {errors.push('skin clips without a skin look');} continue; }
32
+ let parameters: SkinLookParameters; try { parameters = skinLookParameters(row); } catch { errors.push('skin look parameters'); continue; }
33
+ const { skin, variants } = parameters, file = files.get(skin), glb = file?.dependencies.length === 1 ? files.get(file.dependencies[0] ?? '') : undefined;
34
+ if (file?.kind !== 'json' || glb?.kind !== 'glb' || !source.library.includes(skin)) {errors.push('skin look file references');}
35
+ if (variants !== undefined && (files.get(variants)?.kind !== 'json' || !source.library.includes(variants))) {errors.push('skin variant table references');}
47
36
  }
48
37
  return errors;
49
38
  }
@@ -58,7 +47,7 @@ const glbRigSchema = v.object({
58
47
 
59
48
  /** Check admitted GLB joint order, sockets and clips before a renderer allocates the creature view. */
60
49
  function validateRigBytes(glb: Uint8Array, row: SkinRow, parts: Readonly<Record<string, string>> | undefined): void {
61
- // parseGlb already bounds and validates the header, JSON chunk and every node/accessor reference.
50
+ // ParseGlb already bounds and validates the header, JSON chunk and every node/accessor reference.
62
51
  const length = new DataView(glb.buffer, glb.byteOffset, glb.byteLength).getUint32(12, true);
63
52
  const rig = v.parse(glbRigSchema, JSON.parse(new TextDecoder().decode(glb.subarray(20, 20 + length))));
64
53
  function fail(reason: string): never { throw new Error(`skin ${row.id}: ${reason}`); }
@@ -66,42 +55,47 @@ function validateRigBytes(glb: Uint8Array, row: SkinRow, parts: Readonly<Record<
66
55
  const meshes = rig.nodes.filter(node => node.skin !== undefined && node.mesh !== undefined);
67
56
  const mesh = meshes[0];
68
57
  if (meshes.length !== 1 || mesh?.mesh === undefined || mesh.skin === undefined
69
- || !skinPrimitiveCount(rig.meshes[mesh.mesh]?.primitives.length)) fail('expected one skinned mesh');
58
+ || !skinPrimitiveCount(rig.meshes[mesh.mesh]?.primitives.length)) {fail('expected one skinned mesh');}
70
59
  const partsFault = skinPartsFault(rig.meshes[mesh.mesh]?.primitives ?? [], rig.materials, parts);
71
60
  if (partsFault !== '') { fail(partsFault); }
72
61
  const joints = rig.skins[mesh.skin]?.joints.map(index => rig.nodes[index]?.name);
73
62
  const expected = row.rig.joints[0];
74
63
  if (joints === undefined || expected === undefined || joints.length !== expected.length
75
- || joints.some((name, index) => name !== expected[index])) fail('skin joint order differs from bake');
64
+ || joints.some((name, index) => name !== expected[index])) {fail('skin joint order differs from bake');}
76
65
  for (const name of row.rig.sockets) {
77
- if (named.filter(actual => actual === name).length !== 1) fail(`missing or ambiguous socket ${name}`);
66
+ if (named.filter(actual => actual === name).length !== 1) {fail(`missing or ambiguous socket ${name}`);}
78
67
  }
79
68
  for (const name of row.rig.clips) {
80
- if (rig.animations.filter(clip => clip.name === name).length !== 1) fail(`missing or ambiguous clip ${name}`);
69
+ if (rig.animations.filter(clip => clip.name === name).length !== 1) {fail(`missing or ambiguous clip ${name}`);}
81
70
  }
82
71
  }
83
72
 
84
73
  /** Admit each rig binding and its exact GLB dependency before allocating a client view. */
85
- export function validateSkinAssets(source: Pick<Shardfile, 'rows' | 'files'> & { readonly look?: Pick<Shardfile['look'], 'materials'> }, assets: ReadonlyMap<string, Uint8Array>): void {
74
+ function validateSkinAssets(source: Pick<Shardfile, 'rows' | 'files'> & { readonly look?: Pick<Shardfile['look'], 'materials'> }, assets: ReadonlyMap<string, Uint8Array>): void {
86
75
  const files = new Map(source.files.map((file) => [file.hash, file]));
87
76
  for (const look of source.rows.looks) {
88
- if (look.recipe !== SKIN_LOOK_RECIPE) continue;
89
- const skinHash = skinLookParameters(look).skin, bytes = assets.get(skinHash);
90
- if (bytes === undefined) throw new Error('skin file missing');
91
- const { row, binding } = parseSkinFile(bytes);
92
- if (files.get(skinHash)?.dependencies[0] !== row.file) throw new Error('skin rig dependency mismatch');
77
+ if (look.recipe !== SKIN_LOOK_RECIPE) {continue;}
78
+ const resolved = resolveSkinLookFiles(source, look, assets);
79
+ const skins = new Map([resolved.skin, ...(resolved.variants?.values() ?? [])].map((skin): [string, typeof resolved.skin] => [skin.hash, skin]));
80
+ for (const { row, binding } of skins.values()) {
81
+
93
82
  validateCreatureBones(look.species, row.rig.sockets);
94
83
  validateCreatureBones(look.species, row.rig.joints[0] ?? []);
95
84
  v.parse(MaterialsSchema, { skin: binding.material });
96
- const glb = assets.get(row.file), declared = files.get(row.file);
97
- if (glb === undefined || declared === undefined) throw new Error('skin GLB missing');
85
+ const glb = assets.get(row.file); const declared = files.get(row.file);
86
+ if (glb === undefined || declared === undefined) {throw new Error('skin GLB missing');}
98
87
  const cost = parseGlb(glb);
99
88
  validateRigBytes(glb, row, binding.materials);
100
89
  const undeclared = skinMaterialsFault(binding.materials, source.look?.materials ?? {});
101
90
  if (undeclared !== '') { throw new Error(undeclared); }
102
91
  cost.decoded += skinLayerDecoded(binding.poseLayers ?? {}, row.rig.joints[0]?.length ?? 0);
103
92
  for (const key of ['decoded', 'gpu', 'triangles', 'draws'] as const) {
104
- if (cost[key] > row.cost[key] || cost[key] > declared[key]) throw new Error('skin cost understated');
93
+ if (cost[key] > row.cost[key] || cost[key] > declared[key]) {throw new Error('skin cost understated');}
94
+ }
105
95
  }
106
96
  }
107
97
  }
98
+
99
+ export { parseSkinFile, skinLookParameters } from './skin-file.ts';
100
+ export { resolveSkinLookFiles } from './skin-variants.ts';
101
+ export { skinLookRules, validateSkinAssets };
@@ -1,37 +1,51 @@
1
1
  import * as v from 'valibot';
2
2
 
3
3
  /** The look recipe for an exported skin, and its animation recipe. */
4
- export const SKIN_LOOK_RECIPE = 'platform.skin';
4
+ const SKIN_LOOK_RECIPE = 'platform.skin';
5
5
  /** The animation recipe that consumes the exported skin clip parameters. */
6
- export const SKIN_CLIPS_RECIPE = 'platform.clips';
6
+ const SKIN_CLIPS_RECIPE = 'platform.clips';
7
7
  const hash = v.pipe(v.string(), v.regex(/^[0-9a-f]{64}$/u));
8
8
  /** The look row's parameters. */
9
- export const SkinLookParametersSchema: v.GenericSchema<SkinLookParametersRowsInput, SkinLookParametersRows> = v.strictObject({ skin: hash });
9
+ const SkinLookParametersSchema: v.GenericSchema<SkinLookParametersRowsInput, SkinLookParametersRows> = v.strictObject({ skin: hash, variants: v.exactOptional(hash) });
10
+ /** Complete variant-to-skin declarations in one ordinary content-addressed JSON file. */
11
+ const VARIANTS_VERSION = 1;
12
+ const MIN_VARIANTS = 1;
13
+ const MAX_VARIANTS = 64;
14
+ const MAX_VARIANT_LENGTH = 128;
15
+ const variantId = v.pipe(v.string(), v.minLength(MIN_VARIANTS), v.maxLength(MAX_VARIANT_LENGTH));
16
+ const variantSkins = v.pipe(v.record(variantId, hash), v.minEntries(MIN_VARIANTS), v.maxEntries(MAX_VARIANTS));
17
+ interface SkinVariantsFields { version: typeof VARIANTS_VERSION; skins: Record<string, string> }
18
+ type SkinVariants = { [Key in keyof SkinVariantsFields]: SkinVariantsFields[Key] };
19
+ const SkinVariantsSchema: v.GenericSchema<SkinVariants> = v.strictObject({ version: v.literal(VARIANTS_VERSION),
20
+ skins: variantSkins });
10
21
  /** The animation recipe's parameters. */
11
- export const SkinClipParametersSchema: v.GenericSchema<SkinClipParametersRowsInput, SkinClipParametersRows> = v.strictObject({ attackSpan: v.optional(v.pipe(v.number(), v.finite(), v.minValue(0.05), v.maxValue(10)), 1) });
22
+ const SkinClipParametersSchema: v.GenericSchema<SkinClipParametersRowsInput, SkinClipParametersRows> = v.strictObject({ attackSpan: v.optional(v.pipe(v.number(), v.finite(), v.minValue(0.05), v.maxValue(10)), 1) });
12
23
  /** The content-addressed skin file: one export row and its binding (validated together by the SF9c parsers). */
13
- export const ShardSkinFileSchema: v.GenericSchema<ShardSkinFileRowsInput, ShardSkinFileRows> = v.strictObject({ row: v.unknown(), binding: v.unknown() });
24
+ const ShardSkinFileSchema: v.GenericSchema<ShardSkinFileRowsInput, ShardSkinFileRows> = v.strictObject({ row: v.unknown(), binding: v.unknown() });
14
25
 
15
26
  /** A parsed skin look: the file it names and the attack span its clip was sampled with. */
16
- export interface SkinLookParameters { skin: string; attackSpan: number }
27
+ interface SkinLookParameters { skin: string; variants?: string; attackSpan: number }
17
28
 
18
29
  /** Admitted data contracts, independent of validator implementation metadata. */
19
- export type SkinLookParametersRowsInput = SkinLookParametersRows;
30
+ type SkinLookParametersRowsInput = SkinLookParametersRows;
20
31
  interface SkinLookParametersRowsFields {
21
32
  skin: string;
33
+ variants?: string;
22
34
  }
23
- export type SkinLookParametersRows = { [Key in keyof SkinLookParametersRowsFields]: SkinLookParametersRowsFields[Key] };
35
+ type SkinLookParametersRows = { [Key in keyof SkinLookParametersRowsFields]: SkinLookParametersRowsFields[Key] };
24
36
  interface SkinClipParametersRowsInputFields {
25
37
  attackSpan?: number | undefined;
26
38
  }
27
- export type SkinClipParametersRowsInput = { [Key in keyof SkinClipParametersRowsInputFields]: SkinClipParametersRowsInputFields[Key] };
39
+ type SkinClipParametersRowsInput = { [Key in keyof SkinClipParametersRowsInputFields]: SkinClipParametersRowsInputFields[Key] };
28
40
  interface SkinClipParametersRowsFields {
29
41
  attackSpan: number;
30
42
  }
31
- export type SkinClipParametersRows = { [Key in keyof SkinClipParametersRowsFields]: SkinClipParametersRowsFields[Key] };
32
- export type ShardSkinFileRowsInput = ShardSkinFileRows;
43
+ type SkinClipParametersRows = { [Key in keyof SkinClipParametersRowsFields]: SkinClipParametersRowsFields[Key] };
44
+ type ShardSkinFileRowsInput = ShardSkinFileRows;
33
45
  interface ShardSkinFileRowsFields {
34
46
  row: unknown;
35
47
  binding: unknown;
36
48
  }
37
- export type ShardSkinFileRows = { [Key in keyof ShardSkinFileRowsFields]: ShardSkinFileRowsFields[Key] };
49
+ type ShardSkinFileRows = { [Key in keyof ShardSkinFileRowsFields]: ShardSkinFileRowsFields[Key] };
50
+
51
+ export { SKIN_LOOK_RECIPE, SKIN_CLIPS_RECIPE, SkinLookParametersSchema, type SkinVariants, SkinVariantsSchema, SkinClipParametersSchema, ShardSkinFileSchema, type SkinLookParameters, type SkinLookParametersRowsInput, type SkinLookParametersRows, type SkinClipParametersRowsInput, type SkinClipParametersRows, type ShardSkinFileRowsInput, type ShardSkinFileRows };
@@ -25,6 +25,8 @@ const tuning = v.strictObject({
25
25
  herdAlertRadius: nonnegative, herdBoltDelayMin: nonnegative, herdBoltDelayMax: nonnegative, impactSpook: nonnegative, impactAlert: nonnegative,
26
26
  stalk: v.exactOptional(stalk),
27
27
  });
28
+ /** Existing hunt numbers shared by the additive species temperament layer. */
29
+ const HuntTuningSchema: v.GenericSchema<NonNullable<SpeciesData['tuning']>> = tuning;
28
30
  const optionalTuning = v.strictObject({
29
31
  hp: v.exactOptional(nonnegative), sightRange: v.exactOptional(nonnegative), sightRangeGraze: v.exactOptional(nonnegative), sightCone: v.exactOptional(nonnegative), hearStill: v.exactOptional(nonnegative),
30
32
  hearCrouch: v.exactOptional(nonnegative), hearWalk: v.exactOptional(nonnegative), hearSprint: v.exactOptional(nonnegative), noticeRate: v.exactOptional(nonnegative), forgetRate: v.exactOptional(nonnegative),
@@ -38,7 +40,7 @@ const flight = v.strictObject({ altitude: finite, above: v.exactOptional(v.pickl
38
40
  climbRate: positive, diveRate: positive, lockRange: v.exactOptional(positive),
39
41
  bank: v.exactOptional(v.pipe(positive, v.check(n => n < Math.PI / 2, 'bank below pi/2'))) });
40
42
  /** Strict species data, with bounded ordered variants and no native callback fields. */
41
- export const SpeciesSchema: v.StrictObjectSchema<{ readonly id: v.GenericSchema<SpeciesDataInput['id'], SpeciesData['id']>; readonly kind: v.GenericSchema<SpeciesDataInput['kind'], SpeciesData['kind']>; readonly label: v.GenericSchema<SpeciesDataInput['label'], SpeciesData['label']>; readonly variants: v.ArraySchema<v.StrictObjectSchema<{ readonly id: v.GenericSchema<SpeciesVariantDataInput['id'], SpeciesVariantData['id']>; readonly label: v.GenericSchema<SpeciesVariantDataInput['label'], SpeciesVariantData['label']>; readonly weight: v.GenericSchema<SpeciesVariantDataInput['weight'], SpeciesVariantData['weight']>; readonly rarity: v.GenericSchema<SpeciesVariantDataInput['rarity'], SpeciesVariantData['rarity']>; readonly scale: v.GenericSchema<SpeciesVariantDataInput['scale'], SpeciesVariantData['scale']>; readonly hp: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesVariantDataInput['hp'], undefined>, Exclude<SpeciesVariantData['hp'], undefined>>, undefined>; readonly mods: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesVariantDataInput['mods'], undefined>, Exclude<SpeciesVariantData['mods'], undefined>>, undefined>; }, undefined>, undefined>; readonly spawnOnly: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['spawnOnly'], undefined>, Exclude<SpeciesData['spawnOnly'], undefined>>, undefined>; readonly aggressive: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['aggressive'], undefined>, Exclude<SpeciesData['aggressive'], undefined>>, undefined>; readonly walkSpeed: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['walkSpeed'], undefined>, Exclude<SpeciesData['walkSpeed'], undefined>>, undefined>; readonly chargeSpeed: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['chargeSpeed'], undefined>, Exclude<SpeciesData['chargeSpeed'], undefined>>, undefined>; readonly chargeDamage: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['chargeDamage'], undefined>, Exclude<SpeciesData['chargeDamage'], undefined>>, undefined>; readonly chargeWindup: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['chargeWindup'], undefined>, Exclude<SpeciesData['chargeWindup'], undefined>>, undefined>; readonly ringRadius: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['ringRadius'], undefined>, Exclude<SpeciesData['ringRadius'], undefined>>, undefined>; readonly trampleRadius: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['trampleRadius'], undefined>, Exclude<SpeciesData['trampleRadius'], undefined>>, undefined>; readonly tuning: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['tuning'], undefined>, Exclude<SpeciesData['tuning'], undefined>>, undefined>; readonly sounds: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['sounds'], undefined>, Exclude<SpeciesData['sounds'], undefined>>, undefined>; readonly tick: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['tick'], undefined>, Exclude<SpeciesData['tick'], undefined>>, undefined>; readonly corpseFade: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['corpseFade'], undefined>, Exclude<SpeciesData['corpseFade'], undefined>>, undefined>; readonly blood: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['blood'], undefined>, Exclude<SpeciesData['blood'], undefined>>, undefined>; readonly flight: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['flight'], undefined>, Exclude<SpeciesData['flight'], undefined>>, undefined>; readonly lockable: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['lockable'], undefined>, Exclude<SpeciesData['lockable'], undefined>>, undefined>; }, undefined> = v.strictObject({
43
+ const SpeciesSchema: v.StrictObjectSchema<{ readonly id: v.GenericSchema<SpeciesDataInput['id'], SpeciesData['id']>; readonly kind: v.GenericSchema<SpeciesDataInput['kind'], SpeciesData['kind']>; readonly label: v.GenericSchema<SpeciesDataInput['label'], SpeciesData['label']>; readonly variants: v.ArraySchema<v.StrictObjectSchema<{ readonly id: v.GenericSchema<SpeciesVariantDataInput['id'], SpeciesVariantData['id']>; readonly label: v.GenericSchema<SpeciesVariantDataInput['label'], SpeciesVariantData['label']>; readonly weight: v.GenericSchema<SpeciesVariantDataInput['weight'], SpeciesVariantData['weight']>; readonly rarity: v.GenericSchema<SpeciesVariantDataInput['rarity'], SpeciesVariantData['rarity']>; readonly scale: v.GenericSchema<SpeciesVariantDataInput['scale'], SpeciesVariantData['scale']>; readonly hp: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesVariantDataInput['hp'], undefined>, Exclude<SpeciesVariantData['hp'], undefined>>, undefined>; readonly mods: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesVariantDataInput['mods'], undefined>, Exclude<SpeciesVariantData['mods'], undefined>>, undefined>; }, undefined>, undefined>; readonly spawnOnly: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['spawnOnly'], undefined>, Exclude<SpeciesData['spawnOnly'], undefined>>, undefined>; readonly aggressive: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['aggressive'], undefined>, Exclude<SpeciesData['aggressive'], undefined>>, undefined>; readonly walkSpeed: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['walkSpeed'], undefined>, Exclude<SpeciesData['walkSpeed'], undefined>>, undefined>; readonly chargeSpeed: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['chargeSpeed'], undefined>, Exclude<SpeciesData['chargeSpeed'], undefined>>, undefined>; readonly chargeDamage: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['chargeDamage'], undefined>, Exclude<SpeciesData['chargeDamage'], undefined>>, undefined>; readonly chargeWindup: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['chargeWindup'], undefined>, Exclude<SpeciesData['chargeWindup'], undefined>>, undefined>; readonly ringRadius: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['ringRadius'], undefined>, Exclude<SpeciesData['ringRadius'], undefined>>, undefined>; readonly trampleRadius: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['trampleRadius'], undefined>, Exclude<SpeciesData['trampleRadius'], undefined>>, undefined>; readonly tuning: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['tuning'], undefined>, Exclude<SpeciesData['tuning'], undefined>>, undefined>; readonly sounds: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['sounds'], undefined>, Exclude<SpeciesData['sounds'], undefined>>, undefined>; readonly tick: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['tick'], undefined>, Exclude<SpeciesData['tick'], undefined>>, undefined>; readonly corpseFade: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['corpseFade'], undefined>, Exclude<SpeciesData['corpseFade'], undefined>>, undefined>; readonly blood: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['blood'], undefined>, Exclude<SpeciesData['blood'], undefined>>, undefined>; readonly flight: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['flight'], undefined>, Exclude<SpeciesData['flight'], undefined>>, undefined>; readonly lockable: v.ExactOptionalSchema<v.GenericSchema<Exclude<SpeciesDataInput['lockable'], undefined>, Exclude<SpeciesData['lockable'], undefined>>, undefined>; }, undefined> = v.strictObject({
42
44
  id, kind: id, label: text, variants: v.pipe(v.array(variant), v.minLength(1), v.maxLength(64)),
43
45
  spawnOnly: v.exactOptional(v.pipe(v.array(variant), v.maxLength(64))), aggressive: v.exactOptional(v.boolean()),
44
46
  walkSpeed: v.exactOptional(nonnegative), chargeSpeed: v.exactOptional(nonnegative), chargeDamage: v.exactOptional(nonnegative),
@@ -51,9 +53,9 @@ export const SpeciesSchema: v.StrictObjectSchema<{ readonly id: v.GenericSchema<
51
53
 
52
54
  /** Callback-free gameplay metadata; rendering and policy ownership are admitted separately. */
53
55
 
54
- export function readSpecies(input: unknown): SpeciesData { return v.parse(SpeciesSchema, input); }
56
+ function readSpecies(input: unknown): SpeciesData { return v.parse(SpeciesSchema, input); }
55
57
  /** One existing SpeciesBrains owner receives these admitted policy/body rows and strike definitions. */
56
- export const SpeciesProgramSchema: v.GenericSchema<SpeciesProgramDataInput, SpeciesProgramData> = v.pipe(v.unknown(), v.check(isJsonData, 'Species program must be plain JSON'), v.strictObject({
58
+ const SpeciesProgramSchema: v.GenericSchema<SpeciesProgramDataInput, SpeciesProgramData> = v.pipe(v.unknown(), v.check(isJsonData, 'Species program must be plain JSON'), v.strictObject({
57
59
  species: v.pipe(v.array(v.strictObject({ ...SpeciesSchema.entries, brain: v.exactOptional(SpeciesBrainSchema),
58
60
  body: v.exactOptional(CreatureBodyRecipeSchema) })), v.maxLength(256)),
59
61
  strikes: v.pipe(v.array(CreatureStrikeSchema), v.maxLength(256)),
@@ -61,12 +63,12 @@ export const SpeciesProgramSchema: v.GenericSchema<SpeciesProgramDataInput, Spec
61
63
  }), v.check(value => new Set(value.species.map(row => row.kind)).size === value.species.length
62
64
  && new Set(value.strikes.map(row => row.id)).size === value.strikes.length, 'Unique program kinds and strikes'));
63
65
 
64
- export function readSpeciesProgram(input: unknown): SpeciesProgramData { return v.parse(SpeciesProgramSchema, input); }
66
+ function readSpeciesProgram(input: unknown): SpeciesProgramData { return v.parse(SpeciesProgramSchema, input); }
65
67
 
66
68
  const names = v.pipe(v.array(id), v.maxLength(64));
67
69
  const tag = v.custom<`${string}.${string}`>(value => typeof value === 'string' && value.length <= 128 && /^[a-z][a-zA-Z0-9.-]*\.[a-zA-Z0-9.-]+$/u.test(value));
68
70
  /** Settings for the existing native hunt and continuation owners; no callbacks or replacement clock. */
69
- export const NativeHuntSchema: v.GenericSchema<NativeHuntRowsInput, NativeHuntRows> = v.strictObject({
71
+ const NativeHuntSchema: v.GenericSchema<NativeHuntRowsInput, NativeHuntRows> = v.strictObject({
70
72
  limit: v.pipe(positive, v.integer(), v.maxValue(1024)), player: v.picklist(['host', 'origin']),
71
73
  fight: v.strictObject({ telegraphed: v.exactOptional(v.boolean()), attackers: v.exactOptional(v.pipe(positive, v.integer(), v.maxValue(1024))),
72
74
  maxHitDamage: v.exactOptional(nonnegative), capExempt: v.exactOptional(names),
@@ -77,21 +79,24 @@ export const NativeHuntSchema: v.GenericSchema<NativeHuntRowsInput, NativeHuntRo
77
79
  });
78
80
 
79
81
  /** Page and native registration order is authored explicitly; empty sides install no rows. */
80
- export const SpeciesProgramsSchema: v.GenericSchema<SpeciesProgramsInput, SpeciesPrograms> = v.pipe(v.unknown(), v.check(isJsonData, 'Species programs must be plain JSON'),
82
+ const SpeciesProgramsSchema: v.GenericSchema<SpeciesProgramsInput, SpeciesPrograms> = v.pipe(v.unknown(), v.check(isJsonData, 'Species programs must be plain JSON'),
81
83
  v.strictObject({ page: v.pipe(v.array(SpeciesSchema), v.maxLength(256)), native: v.pipe(v.array(SpeciesSchema), v.maxLength(256)), program: v.exactOptional(SpeciesProgramSchema),
82
84
  spawns: v.exactOptional(SpawnTablesSchema), hunt: v.exactOptional(NativeHuntSchema) }),
83
85
  v.check(value => [value.page, value.native].every(rows => new Set(rows.map(row => row.kind)).size === rows.length), 'Unique species kinds per owner'));
84
86
 
85
- export function readSpeciesPrograms(input: unknown): SpeciesPrograms { return v.parse(SpeciesProgramsSchema, input); }
87
+ function readSpeciesPrograms(input: unknown): SpeciesPrograms { return v.parse(SpeciesProgramsSchema, input); }
86
88
 
87
89
  /** Validated species metadata independent of validator implementation types. */
88
- export type SpeciesVariantDataInput = SpeciesVariantData;
89
- export interface SpeciesVariantData { id: string; label: string; weight: number; rarity: 'common' | 'uncommon' | 'rare' | 'legendary'; scale: [number, number]; hp?: number; mods?: { speed?: number; chargeDist?: number; damageTaken?: number; chargeDamage?: number; relentless?: boolean; }; }
90
- export interface SpeciesDataInput { id: string; kind: string; label: string; variants: (SpeciesVariantDataInput)[]; spawnOnly?: (SpeciesVariantDataInput)[]; aggressive?: boolean; walkSpeed?: number; chargeSpeed?: number; chargeDamage?: number; chargeWindup?: number; ringRadius?: number; trampleRadius?: number; tuning?: { hp: number; sightRange: number; sightRangeGraze: number; sightCone: number; hearStill: number; hearCrouch: number; hearWalk: number; hearSprint: number; noticeRate: number; forgetRate: number; alertAt: number; boltAt: number; freezeMin: number; freezeMax: number; relaxAfter: number; panicDist: number; runSpeed: number; trotSpeed: number; fleeMinTime: number; fleeUntil: number; fleeUntilMax: number; fleeMaxTime: number; lookBack: number; waryTime: number; waryBoost: number; herdAlertRadius: number; herdBoltDelayMin: number; herdBoltDelayMax: number; impactSpook: number; impactAlert: number; stalk?: { detect: number; speed: number; giveUp: number; rechargeCd: number; huffMin: number; huffMax: number; roar: string; fleeBelowHp: number; fleeChance: number; }; }; sounds?: { call: string; hurt: string; callVariants?: (string)[]; callEvery?: [number, number]; }; tick?: 'ai' | 'always'; corpseFade?: number; blood?: boolean; flight?: { altitude: number; above?: 'ground' | 'world'; climbRate: number; diveRate: number; lockRange?: number; bank?: number; }; lockable?: boolean; }
91
- export interface SpeciesData { id: string; kind: string; label: string; variants: (SpeciesVariantData)[]; spawnOnly?: (SpeciesVariantData)[]; aggressive?: boolean; walkSpeed?: number; chargeSpeed?: number; chargeDamage?: number; chargeWindup?: number; ringRadius?: number; trampleRadius?: number; tuning?: { hp: number; sightRange: number; sightRangeGraze: number; sightCone: number; hearStill: number; hearCrouch: number; hearWalk: number; hearSprint: number; noticeRate: number; forgetRate: number; alertAt: number; boltAt: number; freezeMin: number; freezeMax: number; relaxAfter: number; panicDist: number; runSpeed: number; trotSpeed: number; fleeMinTime: number; fleeUntil: number; fleeUntilMax: number; fleeMaxTime: number; lookBack: number; waryTime: number; waryBoost: number; herdAlertRadius: number; herdBoltDelayMin: number; herdBoltDelayMax: number; impactSpook: number; impactAlert: number; stalk?: { detect: number; speed: number; giveUp: number; rechargeCd: number; huffMin: number; huffMax: number; roar: string; fleeBelowHp: number; fleeChance: number; }; }; sounds?: { call: string; hurt: string; callVariants?: (string)[]; callEvery?: [number, number]; }; tick?: 'ai' | 'always'; corpseFade?: number; blood?: boolean; flight?: { altitude: number; above?: 'ground' | 'world'; climbRate: number; diveRate: number; lockRange?: number; bank?: number; }; lockable?: boolean; }
92
- export type SpeciesProgramDataInput = unknown;
93
- export interface SpeciesProgramData { species: ({ brain?: v.InferOutput<typeof SpeciesBrainSchema>; body?: v.InferOutput<typeof CreatureBodyRecipeSchema>; } & SpeciesData)[]; strikes: (v.InferOutput<typeof CreatureStrikeSchema>)[]; modules?: Record<string, string>; }
94
- export type NativeHuntRowsInput = NativeHuntRows;
95
- export interface NativeHuntRows { limit: number; player: 'host' | 'origin'; fight: { telegraphed?: boolean; attackers?: number; maxHitDamage?: number; capExempt?: (string)[]; input?: { bufferMs: number; coyoteMs: number; }; }; tuning?: Record<string, { hp?: number; sightRange?: number; sightRangeGraze?: number; sightCone?: number; hearStill?: number; hearCrouch?: number; hearWalk?: number; hearSprint?: number; noticeRate?: number; forgetRate?: number; alertAt?: number; boltAt?: number; freezeMin?: number; freezeMax?: number; relaxAfter?: number; panicDist?: number; runSpeed?: number; trotSpeed?: number; fleeMinTime?: number; fleeUntil?: number; fleeUntilMax?: number; fleeMaxTime?: number; lookBack?: number; waryTime?: number; waryBoost?: number; herdAlertRadius?: number; herdBoltDelayMin?: number; herdBoltDelayMax?: number; impactSpook?: number; impactAlert?: number; stalk?: { detect: number; speed: number; giveUp: number; rechargeCd: number; huffMin: number; huffMax: number; roar: string; fleeBelowHp: number; fleeChance: number; }; }>; bands: { states: (string)[]; scripted?: boolean; legacyKinds: (string)[]; }; hit: { namespace: string; tags: (`${string}.${string}`)[]; }; memoryFields?: (string)[]; }
96
- export type SpeciesProgramsInput = unknown;
97
- export interface SpeciesPrograms { page: (SpeciesData)[]; native: (SpeciesData)[]; program?: SpeciesProgramData; spawns?: v.InferOutput<typeof SpawnTablesSchema>; hunt?: NativeHuntRows; }
90
+ type SpeciesVariantDataInput = SpeciesVariantData;
91
+ interface SpeciesVariantData { id: string; label: string; weight: number; rarity: 'common' | 'uncommon' | 'rare' | 'legendary'; scale: [number, number]; hp?: number; mods?: { speed?: number; chargeDist?: number; damageTaken?: number; chargeDamage?: number; relentless?: boolean; }; }
92
+ interface SpeciesDataInput { id: string; kind: string; label: string; variants: (SpeciesVariantDataInput)[]; spawnOnly?: (SpeciesVariantDataInput)[]; aggressive?: boolean; walkSpeed?: number; chargeSpeed?: number; chargeDamage?: number; chargeWindup?: number; ringRadius?: number; trampleRadius?: number; tuning?: { hp: number; sightRange: number; sightRangeGraze: number; sightCone: number; hearStill: number; hearCrouch: number; hearWalk: number; hearSprint: number; noticeRate: number; forgetRate: number; alertAt: number; boltAt: number; freezeMin: number; freezeMax: number; relaxAfter: number; panicDist: number; runSpeed: number; trotSpeed: number; fleeMinTime: number; fleeUntil: number; fleeUntilMax: number; fleeMaxTime: number; lookBack: number; waryTime: number; waryBoost: number; herdAlertRadius: number; herdBoltDelayMin: number; herdBoltDelayMax: number; impactSpook: number; impactAlert: number; stalk?: { detect: number; speed: number; giveUp: number; rechargeCd: number; huffMin: number; huffMax: number; roar: string; fleeBelowHp: number; fleeChance: number; }; }; sounds?: { call: string; hurt: string; callVariants?: (string)[]; callEvery?: [number, number]; }; tick?: 'ai' | 'always'; corpseFade?: number; blood?: boolean; flight?: { altitude: number; above?: 'ground' | 'world'; climbRate: number; diveRate: number; lockRange?: number; bank?: number; }; lockable?: boolean; }
93
+ interface SpeciesData { id: string; kind: string; label: string; variants: (SpeciesVariantData)[]; spawnOnly?: (SpeciesVariantData)[]; aggressive?: boolean; walkSpeed?: number; chargeSpeed?: number; chargeDamage?: number; chargeWindup?: number; ringRadius?: number; trampleRadius?: number; tuning?: { hp: number; sightRange: number; sightRangeGraze: number; sightCone: number; hearStill: number; hearCrouch: number; hearWalk: number; hearSprint: number; noticeRate: number; forgetRate: number; alertAt: number; boltAt: number; freezeMin: number; freezeMax: number; relaxAfter: number; panicDist: number; runSpeed: number; trotSpeed: number; fleeMinTime: number; fleeUntil: number; fleeUntilMax: number; fleeMaxTime: number; lookBack: number; waryTime: number; waryBoost: number; herdAlertRadius: number; herdBoltDelayMin: number; herdBoltDelayMax: number; impactSpook: number; impactAlert: number; stalk?: { detect: number; speed: number; giveUp: number; rechargeCd: number; huffMin: number; huffMax: number; roar: string; fleeBelowHp: number; fleeChance: number; }; }; sounds?: { call: string; hurt: string; callVariants?: (string)[]; callEvery?: [number, number]; }; tick?: 'ai' | 'always'; corpseFade?: number; blood?: boolean; flight?: { altitude: number; above?: 'ground' | 'world'; climbRate: number; diveRate: number; lockRange?: number; bank?: number; }; lockable?: boolean; }
94
+ type SpeciesProgramDataInput = unknown;
95
+ interface SpeciesProgramData { species: ({ brain?: v.InferOutput<typeof SpeciesBrainSchema>; body?: v.InferOutput<typeof CreatureBodyRecipeSchema>; } & SpeciesData)[]; strikes: (v.InferOutput<typeof CreatureStrikeSchema>)[]; modules?: Record<string, string>; }
96
+ type NativeHuntRowsInput = NativeHuntRows;
97
+ interface NativeHuntRows { limit: number; player: 'host' | 'origin'; fight: { telegraphed?: boolean; attackers?: number; maxHitDamage?: number; capExempt?: (string)[]; input?: { bufferMs: number; coyoteMs: number; }; }; tuning?: Record<string, { hp?: number; sightRange?: number; sightRangeGraze?: number; sightCone?: number; hearStill?: number; hearCrouch?: number; hearWalk?: number; hearSprint?: number; noticeRate?: number; forgetRate?: number; alertAt?: number; boltAt?: number; freezeMin?: number; freezeMax?: number; relaxAfter?: number; panicDist?: number; runSpeed?: number; trotSpeed?: number; fleeMinTime?: number; fleeUntil?: number; fleeUntilMax?: number; fleeMaxTime?: number; lookBack?: number; waryTime?: number; waryBoost?: number; herdAlertRadius?: number; herdBoltDelayMin?: number; herdBoltDelayMax?: number; impactSpook?: number; impactAlert?: number; stalk?: { detect: number; speed: number; giveUp: number; rechargeCd: number; huffMin: number; huffMax: number; roar: string; fleeBelowHp: number; fleeChance: number; }; }>; bands: { states: (string)[]; scripted?: boolean; legacyKinds: (string)[]; }; hit: { namespace: string; tags: (`${string}.${string}`)[]; }; memoryFields?: (string)[]; }
98
+ type SpeciesProgramsInput = unknown;
99
+ interface SpeciesPrograms { page: (SpeciesData)[]; native: (SpeciesData)[]; program?: SpeciesProgramData; spawns?: v.InferOutput<typeof SpawnTablesSchema>; hunt?: NativeHuntRows; }
100
+
101
+ export { HuntTuningSchema, SpeciesSchema, readSpecies, SpeciesProgramSchema, readSpeciesProgram, NativeHuntSchema, SpeciesProgramsSchema, readSpeciesPrograms };
102
+ export type { SpeciesVariantDataInput, SpeciesVariantData, SpeciesDataInput, SpeciesData, SpeciesProgramDataInput, SpeciesProgramData, NativeHuntRowsInput, NativeHuntRows, SpeciesProgramsInput, SpeciesPrograms };
@@ -30,6 +30,20 @@ interface ViewTile {
30
30
  const VIEW_DRAWS: { readonly phone: number; readonly desktop: number } =
31
31
  Object.freeze({ desktop: DESKTOP_VIEW, phone: PHONE_VIEW })
32
32
 
33
+ /** Desktop's fine-tile triangles: Mossgate's fullest tile (364,625) holds the 60 fps cap on desktop. */
34
+ const DESKTOP_TILE_TRIANGLES = 400_000
35
+
36
+ /**
37
+ * SHARD-SOURCE AP9b: one fine (L0) tile's triangles per tier. The phone's is
38
+ * `CONTENT_CAPS.l0.triangles`; desktop's is raised under J338 (look first).
39
+ * Both are reported, not enforced: the sdk's budget table reads them.
40
+ */
41
+ const TILE_TRIANGLES: { readonly phone: number; readonly desktop: number } =
42
+ Object.freeze({
43
+ desktop: DESKTOP_TILE_TRIANGLES,
44
+ phone: CONTENT_CAPS.l0.triangles,
45
+ })
46
+
33
47
  function centre(tile: ViewTile, axis: number): number {
34
48
  const box = tile.drawBounds ?? tile.bounds
35
49
  return ((box.min[axis] ?? NONE) + (box.max[axis] ?? NONE)) / HALF
@@ -70,4 +84,4 @@ function viewDraws(tiles: readonly ViewTile[], from: ViewTile): number {
70
84
  }
71
85
 
72
86
  export type { ViewTile }
73
- export { VIEW_DRAWS, viewDraws }
87
+ export { TILE_TRIANGLES, VIEW_DRAWS, viewDraws }