@wildshard/shard-format 0.7.0 → 0.8.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.7.0",
3
+ "version": "0.8.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": {
@@ -396,7 +396,9 @@
396
396
  "./worldSceneWeld": "./src/format/worldSceneWeld.ts",
397
397
  "./worldScenes": "./src/format/worldScenes.ts",
398
398
  "./worldTargets": "./src/format/worldTargets.ts",
399
- "./worldUpdates": "./src/format/worldUpdates.ts"
399
+ "./worldUpdates": "./src/format/worldUpdates.ts",
400
+ "./strikeDebris": "./src/format/strike-debris.ts",
401
+ "./harvestRows": "./src/format/harvest-rows.ts"
400
402
  },
401
403
  "engines": {
402
404
  "node": ">=24.18.0"
@@ -1,3 +1,4 @@
1
+ import { sketchReference } from './sketch.ts';
1
2
  import * as v from 'valibot';
2
3
 
3
4
  const key = v.pipe(v.string(), v.minLength(1), v.maxLength(128));
@@ -17,8 +18,11 @@ const entry = v.strictObject({ id: key, kind: entryKind, tab: key, name: text, n
17
18
  const stat = v.strictObject({ label: text, value: v.picklist(['seen', 'taken', 'best', 'rarity', 'status']),
18
19
  fallback: v.exactOptional(text), suffix: v.exactOptional(text), words: v.exactOptional(v.record(key, text)) });
19
20
  const stats = v.pipe(v.array(stat), v.maxLength(8));
20
- const icon = v.strictObject({ entryKind: v.exactOptional(entryKind), matchKind: v.exactOptional(key),
21
- icon: v.picklist(['antlers', 'ghost', 'ironhide', 'deer', 'boar', 'elk', 'bear']) });
21
+ const iconSelectors = { entryKind: v.exactOptional(entryKind), matchKind: v.exactOptional(key) };
22
+ const legacyIcon = v.strictObject({ ...iconSelectors, icon: v.picklist(['antlers', 'ghost', 'ironhide', 'deer', 'boar', 'elk', 'bear']) });
23
+ const iconImage = v.pipe(text, v.check(sketchReference, 'bounded inert SVG data or admitted image hash'));
24
+ const imageIcon = v.strictObject({ ...iconSelectors, image: iconImage, tint: v.exactOptional(v.literal('currentColor')) });
25
+ const icon = v.union([imageIcon, legacyIcon]);
22
26
  const cell = v.strictObject({ x: finite, y: finite, w: positive, h: positive });
23
27
  const trophy = v.strictObject({ entry: key, outline: key, mount: v.exactOptional(v.strictObject({ kind: key, variant: key })), title: text });
24
28
  const wall = v.strictObject({ cabin: natural, at: v.tuple([finite, finite, finite]), yaw: finite, width: positive,
@@ -47,12 +51,14 @@ export function journalRowRules(row: JournalRow): readonly string[] {
47
51
  }
48
52
  /** All raster images must be charged immutable library roots; logical URLs are resolved by the admitted product. */
49
53
  export function journalImageRefs(row: JournalRow): readonly string[] {
54
+ const icons = row.icons.flatMap((value: Readonly<JournalIcon>): string[] => 'image' in value && !value.image.startsWith('data:') ? [value.image] : []);
50
55
  return [...new Set([...row.entries.flatMap(value => [value.plate.sketch, ...value.plate.silhouette === undefined ? [] : [value.plate.silhouette]]),
51
- ...row.chalk === undefined ? [] : [row.chalk.atlas]])];
56
+ ...row.chalk === undefined ? [] : [row.chalk.atlas], ...icons])];
52
57
  }
53
58
 
54
59
  /** Admitted data contracts, independent of validator implementation metadata. */
55
60
  export type JournalRowInput = JournalRow;
61
+ type JournalIcon = { entryKind?: 'species' | 'variant' | 'elite' | 'boss' | 'place'; matchKind?: string } & ({ image: string; tint?: 'currentColor' } | { icon: 'antlers' | 'ghost' | 'ironhide' | 'deer' | 'boar' | 'elk' | 'bear' });
56
62
  interface JournalRowFields {
57
63
  kind: 'journal';
58
64
  id: string;
@@ -68,11 +74,7 @@ interface JournalRowFields {
68
74
  place: string;
69
75
  default: string;
70
76
  };
71
- icons: ({
72
- entryKind?: 'species' | 'variant' | 'elite' | 'boss' | 'place';
73
- matchKind?: string;
74
- icon: 'antlers' | 'ghost' | 'ironhide' | 'deer' | 'boar' | 'elk' | 'bear';
75
- })[];
77
+ icons: JournalIcon[];
76
78
  stats: {
77
79
  place: ({
78
80
  label: string;
@@ -3,14 +3,20 @@ import { parseSketchSvg, sketchReference, type CompendiumSketch } from './sketch
3
3
  import type { ShardRows } from './rows.ts';
4
4
 
5
5
  const prefix = 'data:image/svg+xml,';
6
+ type SketchRow = Readonly<{ kind: 'journal'; icons: readonly Readonly<{ image?: string; icon?: string }>[] }> | Readonly<{ kind?: never; entries: readonly Readonly<{ sketch: string }>[] }>;
7
+ function sketchRefs(row: SketchRow): string[] {
8
+ if (row.kind === 'journal') {
9
+ return row.icons.flatMap((value: Readonly<{ image?: string; icon?: string }>): string[] => value.image?.startsWith(prefix) === true ? [value.image] : []);
10
+ }
11
+ return row.entries.map((entry: Readonly<{ sketch: string }>): string => entry.sketch);
12
+ }
6
13
 
7
14
  /** Resolve each distinct sketch once from already-admitted bytes and derive its extra raster cost. */
8
15
  export function compendiumSketches(rows: Pick<ShardRows, 'compendiums'>, assets: ReadonlyMap<string, Uint8Array>): ReadonlyMap<string, CompendiumSketch> {
9
16
  const result = new Map<string, CompendiumSketch>();
10
- for (const row of rows.compendiums) {
11
- if ('kind' in row) continue;
12
- for (const entry of row.entries) {
13
- const ref = entry.sketch; if (result.has(ref)) continue;
17
+ const refs = rows.compendiums.flatMap(sketchRefs);
18
+ for (const ref of refs) {
19
+ if (result.has(ref)) continue;
14
20
  if (!sketchReference(ref)) throw new Error('Compendium sketch must be bounded inert SVG data or an admitted hash');
15
21
  if (ref.startsWith(prefix)) result.set(ref, parseSketchSvg(decodeURIComponent(ref.slice(prefix.length))));
16
22
  else {
@@ -18,6 +24,5 @@ export function compendiumSketches(rows: Pick<ShardRows, 'compendiums'>, assets:
18
24
  result.set(ref, parseSketchSvg(new TextDecoder('utf-8', { fatal: true }).decode(bytes)));
19
25
  }
20
26
  }
21
- }
22
27
  return result;
23
28
  }
@@ -1,3 +1,5 @@
1
+ import { StrikeDebrisSchema } from './strike-debris.ts';
2
+ import type { StrikeDebrisPolicy } from './strike-debris.ts';
1
3
  import * as v from 'valibot';
2
4
  import { ReturnProgramSchema } from './namedJsonContracts.ts';
3
5
  import { NativeRidingSchema } from './nativeRiding.ts';
@@ -102,8 +104,8 @@ const strikeWeight = v.variant('kind', [
102
104
  ]);
103
105
  const strikeTag = v.custom<`${string}.${string}`>(value => typeof value === 'string' && value.length <= 128 && /^[a-z][a-zA-Z0-9.-]*\.[a-zA-Z0-9.*-]+$/u.test(value));
104
106
  /** Full native strike data, including its finite score program; no author callback is admitted. */
105
- export const CreatureStrikeSchema: v.StrictObjectSchema<{ readonly id: v.GenericSchema<CreatureStrikeRowsInput['id'], CreatureStrikeRows['id']>; readonly shape: v.GenericSchema<CreatureStrikeRowsInput['shape'], CreatureStrikeRows['shape']>; readonly windup: v.GenericSchema<CreatureStrikeRowsInput['windup'], CreatureStrikeRows['windup']>; readonly active: v.GenericSchema<CreatureStrikeRowsInput['active'], CreatureStrikeRows['active']>; readonly recover: v.GenericSchema<CreatureStrikeRowsInput['recover'], CreatureStrikeRows['recover']>; readonly cooldown: v.GenericSchema<CreatureStrikeRowsInput['cooldown'], CreatureStrikeRows['cooldown']>; readonly range: v.GenericSchema<CreatureStrikeRowsInput['range'], CreatureStrikeRows['range']>; readonly damage: v.GenericSchema<CreatureStrikeRowsInput['damage'], CreatureStrikeRows['damage']>; readonly tags: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<CreatureStrikeRowsInput['tags'][number], CreatureStrikeRows['tags'][number]>, undefined>, v.MaxLengthAction<CreatureStrikeRows['tags'], 32, undefined>]>; readonly weight: v.GenericSchema<CreatureStrikeRowsInput['weight'], CreatureStrikeRows['weight']>; readonly units: v.ExactOptionalSchema<v.GenericSchema<Exclude<CreatureStrikeRowsInput['units'], undefined>, Exclude<CreatureStrikeRows['units'], undefined>>, undefined>; readonly alternatives: v.ExactOptionalSchema<v.GenericSchema<Exclude<CreatureStrikeRowsInput['alternatives'], undefined>, Exclude<CreatureStrikeRows['alternatives'], undefined>>, undefined>; readonly motion: v.ExactOptionalSchema<v.GenericSchema<Exclude<CreatureStrikeRowsInput['motion'], undefined>, Exclude<CreatureStrikeRows['motion'], undefined>>, undefined>; readonly eligibility: v.ExactOptionalSchema<v.GenericSchema<Exclude<CreatureStrikeRowsInput['eligibility'], undefined>, Exclude<CreatureStrikeRows['eligibility'], undefined>>, undefined>; }, undefined> = v.strictObject({
106
- id: strikeId, shape: strikeShape, windup: strikeNonnegative, active: strikeNonnegative, recover: strikeNonnegative, cooldown: strikeNonnegative,
107
+ export const CreatureStrikeSchema: v.StrictObjectSchema<{ readonly debris: v.ExactOptionalSchema<v.GenericSchema<StrikeDebrisPolicy>, undefined>; readonly id: v.GenericSchema<CreatureStrikeRowsInput['id'], CreatureStrikeRows['id']>; readonly shape: v.GenericSchema<CreatureStrikeRowsInput['shape'], CreatureStrikeRows['shape']>; readonly windup: v.GenericSchema<CreatureStrikeRowsInput['windup'], CreatureStrikeRows['windup']>; readonly active: v.GenericSchema<CreatureStrikeRowsInput['active'], CreatureStrikeRows['active']>; readonly recover: v.GenericSchema<CreatureStrikeRowsInput['recover'], CreatureStrikeRows['recover']>; readonly cooldown: v.GenericSchema<CreatureStrikeRowsInput['cooldown'], CreatureStrikeRows['cooldown']>; readonly range: v.GenericSchema<CreatureStrikeRowsInput['range'], CreatureStrikeRows['range']>; readonly damage: v.GenericSchema<CreatureStrikeRowsInput['damage'], CreatureStrikeRows['damage']>; readonly tags: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<CreatureStrikeRowsInput['tags'][number], CreatureStrikeRows['tags'][number]>, undefined>, v.MaxLengthAction<CreatureStrikeRows['tags'], 32, undefined>]>; readonly weight: v.GenericSchema<CreatureStrikeRowsInput['weight'], CreatureStrikeRows['weight']>; readonly units: v.ExactOptionalSchema<v.GenericSchema<Exclude<CreatureStrikeRowsInput['units'], undefined>, Exclude<CreatureStrikeRows['units'], undefined>>, undefined>; readonly alternatives: v.ExactOptionalSchema<v.GenericSchema<Exclude<CreatureStrikeRowsInput['alternatives'], undefined>, Exclude<CreatureStrikeRows['alternatives'], undefined>>, undefined>; readonly motion: v.ExactOptionalSchema<v.GenericSchema<Exclude<CreatureStrikeRowsInput['motion'], undefined>, Exclude<CreatureStrikeRows['motion'], undefined>>, undefined>; readonly eligibility: v.ExactOptionalSchema<v.GenericSchema<Exclude<CreatureStrikeRowsInput['eligibility'], undefined>, Exclude<CreatureStrikeRows['eligibility'], undefined>>, undefined>; }, undefined> = v.strictObject({
108
+ debris: v.exactOptional(StrikeDebrisSchema), id: strikeId, shape: strikeShape, windup: strikeNonnegative, active: strikeNonnegative, recover: strikeNonnegative, cooldown: strikeNonnegative,
107
109
  range: v.nullable(strikeNonnegative), damage: strikeNonnegative, tags: v.pipe(v.array(strikeTag), v.maxLength(32)), weight: strikeWeight,
108
110
  units: v.exactOptional(v.picklist(['world', 'actor'])), alternatives: v.exactOptional(v.pipe(v.array(strikeShape), v.maxLength(16))),
109
111
  motion: v.exactOptional(v.strictObject({ speed: v.exactOptional(strikeNonnegative), delay: v.exactOptional(strikeNonnegative),
@@ -165,7 +167,7 @@ export interface CreatureBodyRecipeRows { actions?: CreatureMemoryActionsRows; o
165
167
  export type ShardCreaturesInput = { brains: (({ id: string; kind: 'pursue'; awareRadius: number; leashRadius: number; speed: number; returnSpeed: number; stopDistance: number; turnRate: number; thinkDivisor: number; attackCooldownTicks: number; wanderRadius: number; wanderEveryTicks: number; }) | (v.InferInput<typeof SkirmisherSchema>) | (v.InferInput<typeof GuardianSchema>) | (v.InferInput<typeof PerchHunterSchema>) | (v.InferInput<typeof ScriptBrainSchema>) | (v.InferInput<typeof RamGrazerSchema>) | (v.InferInput<typeof ChallengeGrazerSchema>) | (v.InferInput<typeof OrbitDiverSchema>) | (v.InferInput<typeof PatrolDiverSchema>) | (v.InferInput<typeof BurstFlyerSchema>) | (v.InferInput<typeof GrazerSchema>) | (v.InferInput<typeof DiverSchema>) | (v.InferInput<typeof GuardianPatternsSchema>) | (v.InferInput<typeof StalkerSchema>))[]; groups?: (v.InferInput<typeof GroupBrainSchema>)[] | undefined; spawns: ({ phaseOffset?: number | undefined; respawn?: number | undefined; home?: ShardCreatureHomeInput | undefined; id: string; species: string; variant: string; brain: (string) | null; strike: (string) | null; seed: number; scale: number; at: [number, number, number]; yaw: number; })[]; };
166
168
  export interface ShardCreatures { brains: (({ id: string; kind: 'pursue'; awareRadius: number; leashRadius: number; speed: number; returnSpeed: number; stopDistance: number; turnRate: number; thinkDivisor: number; attackCooldownTicks: number; wanderRadius: number; wanderEveryTicks: number; }) | (v.InferOutput<typeof SkirmisherSchema>) | (v.InferOutput<typeof GuardianSchema>) | (v.InferOutput<typeof PerchHunterSchema>) | (v.InferOutput<typeof ScriptBrainSchema>) | (v.InferOutput<typeof RamGrazerSchema>) | (v.InferOutput<typeof ChallengeGrazerSchema>) | (v.InferOutput<typeof OrbitDiverSchema>) | (v.InferOutput<typeof PatrolDiverSchema>) | (v.InferOutput<typeof BurstFlyerSchema>) | (v.InferOutput<typeof GrazerSchema>) | (v.InferOutput<typeof DiverSchema>) | (v.InferOutput<typeof GuardianPatternsSchema>) | (v.InferOutput<typeof StalkerSchema>))[]; groups: (v.InferOutput<typeof GroupBrainSchema>)[]; spawns: ({ phaseOffset?: number | undefined; respawn?: number | undefined; home?: ShardCreatureHome | undefined; id: string; species: string; variant: string; brain: (string) | null; strike: (string) | null; seed: number; scale: number; at: [number, number, number]; yaw: number; })[]; }
167
169
  export type CreatureStrikeRowsInput = CreatureStrikeRows;
168
- export interface CreatureStrikeRows { id: string; shape: ({ kind: 'arc'; radius: number; halfAngle: number; yawOffset?: number; }) | ({ kind: 'lane'; length: number; width: number; }) | ({ kind: 'ring'; inner: number; outer: number; }) | ({ kind: 'wedge'; length: number; halfAngle: number; }) | ({ kind: 'point'; radius: number; exclusive?: boolean; }) | ({ kind: 'sphere'; radius: number; }); windup: number; active: number; recover: number; cooldown: number; range: (number) | null; damage: number; tags: (`${string}.${string}`)[]; weight: ({ kind: 'constant'; value: number; }) | ({ kind: 'horizontal-distance'; above: number; far: number; near: number; }); units?: 'world' | 'actor'; alternatives?: (({ kind: 'arc'; radius: number; halfAngle: number; yawOffset?: number; }) | ({ kind: 'lane'; length: number; width: number; }) | ({ kind: 'ring'; inner: number; outer: number; }) | ({ kind: 'wedge'; length: number; halfAngle: number; }) | ({ kind: 'point'; radius: number; exclusive?: boolean; }) | ({ kind: 'sphere'; radius: number; }))[]; motion?: { speed?: number; delay?: number; track?: 'none' | 'lead' | 'follow'; overshoot?: number; skid?: number; }; eligibility?: { maxDy?: number; jumpDodges?: boolean; }; }
170
+ export interface CreatureStrikeRows { debris?: StrikeDebrisPolicy; id: string; shape: ({ kind: 'arc'; radius: number; halfAngle: number; yawOffset?: number; }) | ({ kind: 'lane'; length: number; width: number; }) | ({ kind: 'ring'; inner: number; outer: number; }) | ({ kind: 'wedge'; length: number; halfAngle: number; }) | ({ kind: 'point'; radius: number; exclusive?: boolean; }) | ({ kind: 'sphere'; radius: number; }); windup: number; active: number; recover: number; cooldown: number; range: (number) | null; damage: number; tags: (`${string}.${string}`)[]; weight: ({ kind: 'constant'; value: number; }) | ({ kind: 'horizontal-distance'; above: number; far: number; near: number; }); units?: 'world' | 'actor'; alternatives?: (({ kind: 'arc'; radius: number; halfAngle: number; yawOffset?: number; }) | ({ kind: 'lane'; length: number; width: number; }) | ({ kind: 'ring'; inner: number; outer: number; }) | ({ kind: 'wedge'; length: number; halfAngle: number; }) | ({ kind: 'point'; radius: number; exclusive?: boolean; }) | ({ kind: 'sphere'; radius: number; }))[]; motion?: { speed?: number; delay?: number; track?: 'none' | 'lead' | 'follow'; overshoot?: number; skid?: number; }; eligibility?: { maxDy?: number; jumpDodges?: boolean; }; }
169
171
  export type CreatureStrikesInput = unknown;
170
172
  export type CreatureStrikes = (CreatureStrikeRows)[];
171
173
  export interface NativeGroupRowsInput { id: string; herds: string; tokens: string; bounds: [number, number, number, number]; owned: (string)[]; contacts: { pack: CreatureStrikeRowsInput; herd: CreatureStrikeRowsInput; }; steps: (({ kind: 'group'; row: v.InferInput<typeof GroupBrainSchema>; adopt: (string) | null; guest?: { program: v.InferInput<typeof ReturnProgramSchema>; binding: v.InferInput<typeof GuardedHerdGuestSchema>; }; }) | ({ kind: 'delay'; program: v.InferInput<typeof ReturnProgramSchema>; signal: string; channel: string; }))[]; }
@@ -0,0 +1,103 @@
1
+ import {
2
+ array,
3
+ check,
4
+ exactOptional,
5
+ integer,
6
+ maxLength,
7
+ maxValue,
8
+ minLength,
9
+ minValue,
10
+ number,
11
+ pipe,
12
+ regex,
13
+ strictObject,
14
+ string,
15
+ } from 'valibot'
16
+
17
+ import type { GenericSchema } from 'valibot'
18
+
19
+ /** Ordered deterministic drops; an omitted selector matches every admitted variant. */
20
+ interface HarvestDrop {
21
+ item: string
22
+ count: number
23
+ variants?: string[]
24
+ }
25
+
26
+ const MAX_ID_LENGTH = 128
27
+ const MAX_ITEMS = 64
28
+ const MIN_COUNT = 1
29
+ const EMPTY_TOTAL = 0
30
+ const identifier = pipe(
31
+ string(),
32
+ regex(/^[a-z][a-zA-Z0-9.:-]*$/u),
33
+ maxLength(MAX_ID_LENGTH),
34
+ )
35
+ const variants = pipe(
36
+ array(identifier),
37
+ minLength(MIN_COUNT),
38
+ maxLength(MAX_ITEMS),
39
+ check<string[], 'unique harvest variants'>(
40
+ (rows: readonly string[]): boolean => new Set(rows).size === rows.length,
41
+ 'unique harvest variants',
42
+ ),
43
+ )
44
+ const drop = strictObject({
45
+ item: identifier,
46
+ count: pipe(number(), integer(), minValue(MIN_COUNT), maxValue(MAX_ITEMS)),
47
+ variants: exactOptional(variants),
48
+ })
49
+
50
+ /** At most 64 item units across a species' entire declaration, even before selectors reduce it. */
51
+ const HarvestDropsSchema: GenericSchema<HarvestDrop[], HarvestDrop[]> = pipe(
52
+ array(drop),
53
+ maxLength(MAX_ITEMS),
54
+ check<HarvestDrop[], 'harvest item budget'>(
55
+ (rows: readonly Readonly<{ count: number }>[]): boolean =>
56
+ rows.reduce(
57
+ (total: number, row: Readonly<{ count: number }>): number =>
58
+ total + row.count,
59
+ EMPTY_TOTAL,
60
+ ) <= MAX_ITEMS,
61
+ 'harvest item budget',
62
+ ),
63
+ )
64
+
65
+ interface HarvestSpecies {
66
+ readonly id: string
67
+ readonly variants: readonly Readonly<{ id: string }>[]
68
+ readonly spawnOnly?: readonly Readonly<{ id: string }>[]
69
+ readonly harvest?: readonly Readonly<{
70
+ item: string
71
+ count: number
72
+ variants?: readonly string[]
73
+ }>[]
74
+ }
75
+
76
+ /** Row admission checks variants; full shard admission additionally checks the pack catalogue. */
77
+ function harvestSpeciesRules(
78
+ species: readonly HarvestSpecies[],
79
+ items?: ReadonlySet<string>,
80
+ ): string[] {
81
+ const errors: string[] = []
82
+ for (const row of species) {
83
+ const known = new Set(
84
+ [...row.variants, ...(row.spawnOnly ?? [])].map(
85
+ (variant: Readonly<{ id: string }>): string => variant.id,
86
+ ),
87
+ )
88
+ for (const entry of row.harvest ?? []) {
89
+ if (items !== undefined && !items.has(entry.item)) {
90
+ errors.push(`species ${row.id}: unknown harvest item ${entry.item}`)
91
+ }
92
+ for (const variant of entry.variants ?? []) {
93
+ if (!known.has(variant)) {
94
+ errors.push(`species ${row.id}: unknown harvest variant ${variant}`)
95
+ }
96
+ }
97
+ }
98
+ }
99
+ return errors
100
+ }
101
+
102
+ export { HarvestDropsSchema, harvestSpeciesRules }
103
+ export type { HarvestDrop, HarvestSpecies }
@@ -1,3 +1,7 @@
1
+ import { StrikeDebrisSchema, strikeDebrisCatalogueRules } from './strike-debris.ts';
2
+ import type { StrikeDebrisPolicy } from './strike-debris.ts';
3
+ import type { HarvestDrop } from './harvest-rows.ts';
4
+ import { HarvestDropsSchema, harvestSpeciesRules } from './harvest-rows.ts';
1
5
  import { LootEconomySchema, BarterEconomySchema, lootEconomyRules } from './lootEconomy.ts';
2
6
  import * as v from 'valibot';
3
7
  import { isJsonData } from './json.ts';
@@ -22,7 +26,7 @@ const shape = v.variant('kind', [
22
26
  v.strictObject({ kind: v.literal('wedge'), length: dimension, halfAngle: v.pipe(positive, v.maxValue(Math.PI)) }),
23
27
  v.pipe(v.strictObject({ kind: v.literal('ring'), inner: nonnegative, outer: dimension }), v.check((r) => r.inner <= r.outer, 'ordered ring')),
24
28
  ]);
25
- const strike: v.StrictObjectSchema<{ readonly id: v.GenericSchema<StrikeRowsInput['id'], StrikeRows['id']>; readonly shape: v.GenericSchema<StrikeRowsInput['shape'], StrikeRows['shape']>; readonly windup: v.GenericSchema<StrikeRowsInput['windup'], StrikeRows['windup']>; readonly active: v.GenericSchema<StrikeRowsInput['active'], StrikeRows['active']>; readonly recover: v.GenericSchema<StrikeRowsInput['recover'], StrikeRows['recover']>; readonly cooldown: v.GenericSchema<StrikeRowsInput['cooldown'], StrikeRows['cooldown']>; readonly range: v.GenericSchema<StrikeRowsInput['range'], StrikeRows['range']>; readonly damage: v.GenericSchema<StrikeRowsInput['damage'], StrikeRows['damage']>; readonly tags: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<`${string}.${string}`>, undefined>, v.MaxLengthAction<StrikeRows['tags'], 32, undefined>]>; readonly weight: v.GenericSchema<StrikeRowsInput['weight'], StrikeRows['weight']>; readonly speed: v.GenericSchema<StrikeRowsInput['speed'], StrikeRows['speed']>; }, undefined> = v.strictObject({ id, shape, windup: nonnegative, active: nonnegative, recover: nonnegative, cooldown: nonnegative, range: dimension, damage: nonnegative,
29
+ const strike: v.StrictObjectSchema<{ readonly debris: v.ExactOptionalSchema<v.GenericSchema<StrikeDebrisPolicy>, undefined>; readonly id: v.GenericSchema<StrikeRowsInput['id'], StrikeRows['id']>; readonly shape: v.GenericSchema<StrikeRowsInput['shape'], StrikeRows['shape']>; readonly windup: v.GenericSchema<StrikeRowsInput['windup'], StrikeRows['windup']>; readonly active: v.GenericSchema<StrikeRowsInput['active'], StrikeRows['active']>; readonly recover: v.GenericSchema<StrikeRowsInput['recover'], StrikeRows['recover']>; readonly cooldown: v.GenericSchema<StrikeRowsInput['cooldown'], StrikeRows['cooldown']>; readonly range: v.GenericSchema<StrikeRowsInput['range'], StrikeRows['range']>; readonly damage: v.GenericSchema<StrikeRowsInput['damage'], StrikeRows['damage']>; readonly tags: v.SchemaWithPipe<readonly [v.ArraySchema<v.GenericSchema<`${string}.${string}`>, undefined>, v.MaxLengthAction<StrikeRows['tags'], 32, undefined>]>; readonly weight: v.GenericSchema<StrikeRowsInput['weight'], StrikeRows['weight']>; readonly speed: v.GenericSchema<StrikeRowsInput['speed'], StrikeRows['speed']>; }, undefined> = v.strictObject({ debris: v.exactOptional(StrikeDebrisSchema), id, shape, windup: nonnegative, active: nonnegative, recover: nonnegative, cooldown: nonnegative, range: dimension, damage: nonnegative,
26
30
  tags: v.pipe(v.array(v.custom<`${string}.${string}`>((value) => typeof value === 'string' && value.length <= 128 && /^[a-z][a-zA-Z0-9.-]*\.[a-zA-Z0-9.-]+$/u.test(value))), v.maxLength(32)), weight: nonnegative, speed: v.pipe(nonnegative, v.maxValue(15)) });
27
31
  const numbers = v.strictObject({ overcast: unit, rain: unit, wet: unit, wind: unit, fog: unit });
28
32
  const weather = v.strictObject({ id, states: v.pipe(v.array(v.strictObject({ id, next: id, length: ordered, numbers })), v.minLength(1), v.maxLength(64)), initial: numbers, soak: unit, dry: unit,
@@ -41,7 +45,7 @@ const flight = v.strictObject({ altitude: v.pipe(finite, v.minValue(-250), v.max
41
45
  lockRange: v.exactOptional(v.pipe(positive, v.maxValue(600))), bank: v.exactOptional(v.pipe(finite, v.check(n => n > 0 && n < Math.PI / 2, 'flight bank between 0 and pi/2'))) });
42
46
  const MAX_ABILITIES = 32;
43
47
  const abilities = v.pipe(v.array(CreatureAbilitySchema), v.maxLength(MAX_ABILITIES));
44
- const species = v.strictObject({ id, kind: id, label: text, aggressive: v.boolean(), lockable: v.boolean(), dims, flight: v.exactOptional(flight),
48
+ const species = v.strictObject({ id, kind: id, label: text, capExempt: v.exactOptional(v.boolean()), harvest: v.exactOptional(HarvestDropsSchema), aggressive: v.boolean(), lockable: v.boolean(), dims, flight: v.exactOptional(flight),
45
49
  variants: v.pipe(v.array(variant), v.minLength(1), v.maxLength(64)),
46
50
  type: v.exactOptional(CreatureTypeSchema), body: v.exactOptional(CreatureBodySchema),
47
51
  temperament: v.exactOptional(CreatureTemperamentSchema), senses: v.exactOptional(CreatureSensesSchema),
@@ -62,7 +66,7 @@ const raw: v.StrictObjectSchema<{ readonly strikes: v.SchemaWithPipe<readonly [v
62
66
 
63
67
  /** Reference, uniqueness and complete clock/weather transition rules for data rows. */
64
68
  function rowRules(rows: ShardRows): string[] {
65
- const errors: string[] = [];
69
+ const errors: string[] = harvestSpeciesRules(rows.species);
66
70
  for (const list of Object.values(rows)) if (new Set(list.map((r) => r.id)).size !== list.length) errors.push('unique row ids');
67
71
  for (const row of rows.loot) if (row.economy !== undefined && !('kind' in row.economy)) errors.push(...lootEconomyRules(row.economy));
68
72
  for (const w of rows.weather) {
@@ -71,6 +75,7 @@ function rowRules(rows: ShardRows): string[] {
71
75
  }
72
76
  for (const d of rows.days) if (d.schedule[0]?.from !== 0 || d.schedule.at(-1)?.to !== 24 || d.schedule.some((s, i) => s.from >= s.to || (i > 0 && d.schedule[i - 1]?.to !== s.from))) errors.push('complete ordered day schedule');
73
77
  const speciesIds = new Set(rows.species.map((s) => s.id));
78
+ errors.push(...strikeDebrisCatalogueRules(rows));
74
79
  for (const s of rows.species) if (new Set(s.variants.map((r) => r.id)).size !== s.variants.length || s.variants.some((r) => r.scale[1] > 10)) errors.push('species variants');
75
80
  const strikeIds = new Set<string>();
76
81
  for (const strikeRow of rows.strikes) { strikeIds.add(strikeRow.id); }
@@ -102,13 +107,13 @@ function parseRows(input: unknown): ShardRows { return v.parse(RowsSchema, input
102
107
 
103
108
  /** Admitted author data independent of validator implementation metadata. */
104
109
  type StrikeRowsInput = StrikeRows;
105
- interface StrikeRows { id: string; shape: ({ kind: 'point'; radius: number; }) | ({ kind: 'sphere'; radius: number; }) | ({ kind: 'lane'; length: number; width: number; }) | ({ kind: 'arc'; radius: number; halfAngle: number; }) | ({ kind: 'wedge'; length: number; halfAngle: number; }) | ({ kind: 'ring'; inner: number; outer: number; }); windup: number; active: number; recover: number; cooldown: number; range: number; damage: number; tags: (`${string}.${string}`)[]; weight: number; speed: number; }
110
+ interface StrikeRows { debris?: StrikeDebrisPolicy; id: string; shape: ({ kind: 'point'; radius: number; }) | ({ kind: 'sphere'; radius: number; }) | ({ kind: 'lane'; length: number; width: number; }) | ({ kind: 'arc'; radius: number; halfAngle: number; }) | ({ kind: 'wedge'; length: number; halfAngle: number; }) | ({ kind: 'ring'; inner: number; outer: number; }); windup: number; active: number; recover: number; cooldown: number; range: number; damage: number; tags: (`${string}.${string}`)[]; weight: number; speed: number; }
106
111
  interface ShardRowsInput { strikes: (StrikeRowsInput)[]; weather: ({ id: string; states: ({ id: string; next: string; length: [number, number]; numbers: { overcast: number; rain: number; wet: number; wind: number; fog: number; }; })[]; initial: { overcast: number; rain: number; wet: number; wind: number; fog: number; }; soak: number; dry: number; modes: ({ id: string; hold: (string) | null; at: number; dry: boolean; })[]; })[]; days: ({ id: string; units: 'hour'; start: number; schedule: ({ phase: 'dawn' | 'day' | 'golden' | 'dusk' | 'night'; from: number; to: number; minutes: number; })[]; sun: { maxElevation: number; azimuthOffset: number; }; fixed: { midday: number; golden: number; sunset: number; night: number; }; presets: { dawn: number; noon: number; dusk: number; night: number; }; })[]; species: SpeciesRow[]; looks: ({ id: string; species: string; recipe: string; material?: (string) | null | undefined; parameters: Record<string, (number) | (boolean) | (string) | ((number)[])>; animation: { recipe: string; parameters: Record<string, (number) | (boolean) | (string) | ((number)[])>; }; })[]; compendiums: (({ id: string; className: string; title: string; tabs: ({ id: string; label: string; })[]; stamp: string; stats: ({ label: string; value: string; })[]; entries: ({ id: string; kind: 'species'; tab: string; name: string; notes: string; sketch: string; species: string; })[]; }) | (v.InferInput<typeof JournalRowSchema>))[]; loot: (({ id: string; gear: 'purse.coins'; finds: null; marks: null; charted: boolean; chime: string; economy?: v.InferInput<typeof LootEconomySchema>; }) | ({ id: string; economy: v.InferInput<typeof BarterEconomySchema>; }))[]; }
107
112
  // oxlint-disable-next-line typescript/consistent-type-definitions -- Object.values needs the original implicit dictionary contract for row validation.
108
113
  type ShardRows = { strikes: (StrikeRows)[]; weather: ({ id: string; states: ({ id: string; next: string; length: [number, number]; numbers: { overcast: number; rain: number; wet: number; wind: number; fog: number; }; })[]; initial: { overcast: number; rain: number; wet: number; wind: number; fog: number; }; soak: number; dry: number; modes: ({ id: string; hold: (string) | null; at: number; dry: boolean; })[]; })[]; days: ({ id: string; units: 'hour'; start: number; schedule: ({ phase: 'dawn' | 'day' | 'golden' | 'dusk' | 'night'; from: number; to: number; minutes: number; })[]; sun: { maxElevation: number; azimuthOffset: number; }; fixed: { midday: number; golden: number; sunset: number; night: number; }; presets: { dawn: number; noon: number; dusk: number; night: number; }; })[]; species: SpeciesRow[]; looks: ({ id: string; species: string; recipe: string; material: (string) | null; parameters: Record<string, (number) | (boolean) | (string) | ((number)[])>; animation: { recipe: string; parameters: Record<string, (number) | (boolean) | (string) | ((number)[])>; }; })[]; compendiums: (({ id: string; className: string; title: string; tabs: ({ id: string; label: string; })[]; stamp: string; stats: ({ label: string; value: string; })[]; entries: ({ id: string; kind: 'species'; tab: string; name: string; notes: string; sketch: string; species: string; })[]; }) | (v.InferOutput<typeof JournalRowSchema>))[]; loot: (({ id: string; gear: 'purse.coins'; finds: null; marks: null; charted: boolean; chime: string; economy?: v.InferOutput<typeof LootEconomySchema>; }) | ({ id: string; economy: v.InferOutput<typeof BarterEconomySchema>; }))[]; };
109
114
 
110
115
  /** A species keeps its old fields, with optional explicit creature layers. */
111
- interface SpeciesRow extends CreatureLayers { id: string; kind: string; label: string; aggressive: boolean; lockable: boolean; dims: { bodyY: number; bodyHalfLen: number; bodyRadius: number; headRadius: number; legLen: number; feet: ([number, number])[]; halfWidth: number; }; flight?: { altitude: number; above?: 'ground' | 'world'; climbRate: number; diveRate: number; lockRange?: number; bank?: number; }; variants: ({ id: string; label: string; rarity: 'common' | 'uncommon' | 'rare' | 'legendary'; weight: number; scale: [number, number]; hp: number; mods: { speed: number; chargeDist: number; damageTaken: number; chargeDamage: number; relentless: boolean; }; })[]; }
116
+ interface SpeciesRow extends CreatureLayers { capExempt?: boolean; harvest?: HarvestDrop[]; id: string; kind: string; label: string; aggressive: boolean; lockable: boolean; dims: { bodyY: number; bodyHalfLen: number; bodyRadius: number; headRadius: number; legLen: number; feet: ([number, number])[]; halfWidth: number; }; flight?: { altitude: number; above?: 'ground' | 'world'; climbRate: number; diveRate: number; lockRange?: number; bank?: number; }; variants: ({ id: string; label: string; rarity: 'common' | 'uncommon' | 'rare' | 'legendary'; weight: number; scale: [number, number]; hp: number; mods: { speed: number; chargeDist: number; damageTaken: number; chargeDamage: number; relentless: boolean; }; })[]; }
112
117
 
113
118
  export { rowRules, RowsSchema, parseRows };
114
119
  export type { StrikeRowsInput, StrikeRows, ShardRowsInput, ShardRows, SpeciesRow };
@@ -1,3 +1,6 @@
1
+ import type { StrikeDebrisPolicy } from './strike-debris.ts';
2
+ import { strikeDebrisCatalogueRules } from './strike-debris.ts';
3
+ import { harvestSpeciesRules } from './harvest-rows.ts';
1
4
  import { AdmissionLateSchema, lateLibraryRootsValid } from './admissionLate.ts';
2
5
  import { ManifestMetadataSchema } from './minimap.ts';
3
6
  import { hasDeclaredClientPage } from './runtimeBinds.ts';
@@ -296,6 +299,17 @@ export function shardfileRules(s: Shardfile): string[] {
296
299
  errors.push(...nativeGroundRules(s), ...navigationRules(s));
297
300
  errors.push(...targetRules(s.targets, s, { panels: s.props?.panels ?? [], colliders: [...s.props?.colliders ?? [], ...s.meshCollision?.panels ?? []], models: s.props?.models ?? [] }));
298
301
  errors.push(...itemRules(s.items, s.sim.scripts));
302
+ const debrisStrikes: Readonly<{debris?: StrikeDebrisPolicy}>[] = [];
303
+ for (const row of s.items.rows) {
304
+ if (row.kind === 'weapon' && row.profile?.family === 'melee') {
305
+ const { moves } = row.profile;
306
+ debrisStrikes.push(...moves.combo, moves.heavy);
307
+ if (moves.passes !== undefined) { debrisStrikes.push(moves.passes.left, moves.passes.right); }
308
+ }
309
+ }
310
+ errors.push(...strikeDebrisCatalogueRules({ strikes: debrisStrikes, species: s.rows.species }));
311
+ const harvestItems = new Set((s.items.catalogue ?? []).map((row: Readonly<{ id: string }>): string => row.id));
312
+ errors.push(...harvestSpeciesRules(s.rows.species, harvestItems));
299
313
  if (s.migrations.some(step => step.equipmentSlots?.some(rename => !s.items.rows.some(row => row.kind === 'weapon' && row.slot === rename.to)))) errors.push('migration equipment slots resolve declared weapons');
300
314
  if ((s.items.runtimeContexts?.length ?? 0) > 0 && !pageOwner && s.runtime?.binds?.includes('items') !== true) errors.push('native input contexts require their declared page or runtime owner');
301
315
  if (s.items.rows.some((row) => row.kind === 'tool' && row.action === null) && s.runtime?.binds?.includes('items') !== true) errors.push('native tools require runtime.binds items');
@@ -21,6 +21,7 @@ export const CreatureGuestSchema: v.GenericSchema<CreatureGuestRowsInput, Creatu
21
21
  }));
22
22
 
23
23
 
24
+ const bookMetadata=v.omit(SpeciesSchema,['harvest','capExempt']);
24
25
  const text=v.pipe(v.string(),v.minLength(1),v.maxLength(4096)),number=v.pipe(v.number(),v.finite()),rgb=v.tuple([number,number,number]);
25
26
  /** A species borrows its existing arena-room brain; initialization is finite
26
27
  * ordered data, before the same original think/act/damage slots. */
@@ -34,7 +35,7 @@ export const ArenaRoomSpeciesControlSchema: v.GenericSchema<ArenaRoomSpeciesCont
34
35
  /** Build-only species catalogue admission. Native consumers import row types. */
35
36
  /** Packed body keys, rig contracts and painterly material measurements. */
36
37
  const book=v.object({slug:text,body:v.unknown(),poses:v.optional(v.record(text,v.unknown())),program:v.optional(v.unknown()),
37
- rows:v.pipe(v.array(v.object({metadata:SpeciesSchema,id:text,family:text,
38
+ rows:v.pipe(v.array(v.object({metadata:bookMetadata,id:text,family:text,
38
39
  rigContract:v.object({skeleton:text,clips:v.array(SkinClipNameSchema),sockets:v.array(text)}),
39
40
  rig:v.optional(v.picklist(['quadruped','custom'])),pose:v.optional(v.object({grazeNeck:number,gallopTail:number})),gait:v.optional(v.object({trot:number,gallop:number})),
40
41
  eyeGlow:v.optional(rgb),eyeGlowIntensity:v.optional(number),
@@ -75,10 +76,10 @@ export interface CreatureGuestRows { program: unknown; clock: string; playerKeys
75
76
  export type ArenaRoomSpeciesControlRowsInput = ArenaRoomSpeciesControlRows;
76
77
  export interface ArenaRoomSpeciesControlRows { kind: 'arena-room'; initialize: { flag: string; defaults: (({ field: string; source: 'value'; value: number; }) | ({ field: string; source: 'height'; }))[]; }; }
77
78
  export type SpeciesLookBookRowsInput = unknown;
78
- export interface SpeciesLookBookRows { slug: string; body: unknown; poses?: Record<string, unknown> | undefined; program?: unknown; rows: ({ metadata: v.InferOutput<typeof SpeciesSchema>; id: string; family: string; rigContract: { skeleton: string; clips: (v.InferOutput<typeof SkinClipNameSchema>)[]; sockets: (string)[]; }; rig?: 'quadruped' | 'custom' | undefined; pose?: { grazeNeck: number; gallopTail: number; } | undefined; gait?: { trot: number; gallop: number; } | undefined; eyeGlow?: [number, number, number] | undefined; eyeGlowIntensity?: number | undefined; variants: Record<string, { body: string; tint?: Record<string, [number, number, number]> | undefined; traits?: Record<string, (number) | (boolean)> | undefined; }>; projection?: v.InferOutput<typeof ActorProjectionV2Schema>; control?: ArenaRoomSpeciesControlRows; group?: v.InferOutput<typeof SpeciesGroupSchema> | undefined; directed?: v.InferOutput<typeof DirectedSpeciesSchema> | undefined; guard?: true | undefined; elite?: true | undefined; postPose?: { alive: string; dead?: string; envelopes?: v.InferOutput<typeof RidingPresentationSchema>; } | undefined; material: { rim: number; bands: number; }; })[]; }
79
+ export interface SpeciesLookBookRows { slug: string; body: unknown; poses?: Record<string, unknown> | undefined; program?: unknown; rows: ({ metadata: Omit<v.InferOutput<typeof SpeciesSchema>, 'harvest' | 'capExempt'>; id: string; family: string; rigContract: { skeleton: string; clips: (v.InferOutput<typeof SkinClipNameSchema>)[]; sockets: (string)[]; }; rig?: 'quadruped' | 'custom' | undefined; pose?: { grazeNeck: number; gallopTail: number; } | undefined; gait?: { trot: number; gallop: number; } | undefined; eyeGlow?: [number, number, number] | undefined; eyeGlowIntensity?: number | undefined; variants: Record<string, { body: string; tint?: Record<string, [number, number, number]> | undefined; traits?: Record<string, (number) | (boolean)> | undefined; }>; projection?: v.InferOutput<typeof ActorProjectionV2Schema>; control?: ArenaRoomSpeciesControlRows; group?: v.InferOutput<typeof SpeciesGroupSchema> | undefined; directed?: v.InferOutput<typeof DirectedSpeciesSchema> | undefined; guard?: true | undefined; elite?: true | undefined; postPose?: { alive: string; dead?: string; envelopes?: v.InferOutput<typeof RidingPresentationSchema>; } | undefined; material: { rim: number; bands: number; }; })[]; }
79
80
  export type NativeSpeciesLookBookRowsInput = unknown;
80
- export type NativeSpeciesLookBookRows = { body: v.InferOutput<typeof CompactSpeciesBodiesSchema>; } & { slug: string; body: unknown; poses?: Record<string, unknown> | undefined; program?: unknown; rows: ({ metadata: v.InferOutput<typeof SpeciesSchema>; id: string; family: string; rigContract: { skeleton: string; clips: (v.InferOutput<typeof SkinClipNameSchema>)[]; sockets: (string)[]; }; rig?: 'quadruped' | 'custom' | undefined; pose?: { grazeNeck: number; gallopTail: number; } | undefined; gait?: { trot: number; gallop: number; } | undefined; eyeGlow?: [number, number, number] | undefined; eyeGlowIntensity?: number | undefined; variants: Record<string, { body: string; tint?: Record<string, [number, number, number]> | undefined; traits?: Record<string, (number) | (boolean)> | undefined; }>; projection?: v.InferOutput<typeof ActorProjectionV2Schema>; control?: ArenaRoomSpeciesControlRows; group?: v.InferOutput<typeof SpeciesGroupSchema> | undefined; directed?: v.InferOutput<typeof DirectedSpeciesSchema> | undefined; guard?: true | undefined; elite?: true | undefined; postPose?: { alive: string; dead?: string; envelopes?: v.InferOutput<typeof RidingPresentationSchema>; } | undefined; material: { rim: number; bands: number; }; })[]; };
81
- export interface SpeciesPresentationRowsInput { poses: Record<string, { prefix: string; group: string; scalars: (unknown)[]; look?: unknown; alive?: boolean; }>; packedBodies: v.InferInput<typeof CompactSpeciesBodiesSchema>; guest: CreatureGuestRowsInput; lookBook: Pick<{ slug: string; body: unknown; poses?: Record<string, unknown> | undefined; program?: unknown; rows: ({ metadata: v.InferInput<typeof SpeciesSchema>; id: string; family: string; rigContract: { skeleton: string; clips: (v.InferInput<typeof SkinClipNameSchema>)[]; sockets: (string)[]; }; rig?: 'quadruped' | 'custom' | undefined; pose?: { grazeNeck: number; gallopTail: number; } | undefined; gait?: { trot: number; gallop: number; } | undefined; eyeGlow?: [number, number, number] | undefined; eyeGlowIntensity?: number | undefined; variants: Record<string, { body: string; tint?: Record<string, [number, number, number]> | undefined; traits?: Record<string, (number) | (boolean)> | undefined; }>; projection?: v.InferInput<typeof ActorProjectionV2Schema>; control?: ArenaRoomSpeciesControlRowsInput; group?: v.InferInput<typeof SpeciesGroupSchema> | undefined; directed?: v.InferInput<typeof DirectedSpeciesSchema> | undefined; guard?: true | undefined; elite?: true | undefined; postPose?: { alive: string; dead?: string; envelopes?: v.InferInput<typeof RidingPresentationSchema>; } | undefined; material: { rim: number; bands: number; }; })[]; }, 'slug' | 'rows' | 'program'>; }
82
- export interface SpeciesPresentationRows { poses: Record<string, { prefix: string; group: string; scalars: (unknown)[]; look?: unknown; alive?: boolean; }>; packedBodies: v.InferOutput<typeof CompactSpeciesBodiesSchema>; guest: CreatureGuestRows; lookBook: Pick<{ slug: string; body: unknown; poses?: Record<string, unknown> | undefined; program?: unknown; rows: ({ metadata: v.InferOutput<typeof SpeciesSchema>; id: string; family: string; rigContract: { skeleton: string; clips: (v.InferOutput<typeof SkinClipNameSchema>)[]; sockets: (string)[]; }; rig?: 'quadruped' | 'custom' | undefined; pose?: { grazeNeck: number; gallopTail: number; } | undefined; gait?: { trot: number; gallop: number; } | undefined; eyeGlow?: [number, number, number] | undefined; eyeGlowIntensity?: number | undefined; variants: Record<string, { body: string; tint?: Record<string, [number, number, number]> | undefined; traits?: Record<string, (number) | (boolean)> | undefined; }>; projection?: v.InferOutput<typeof ActorProjectionV2Schema>; control?: ArenaRoomSpeciesControlRows; group?: v.InferOutput<typeof SpeciesGroupSchema> | undefined; directed?: v.InferOutput<typeof DirectedSpeciesSchema> | undefined; guard?: true | undefined; elite?: true | undefined; postPose?: { alive: string; dead?: string; envelopes?: v.InferOutput<typeof RidingPresentationSchema>; } | undefined; material: { rim: number; bands: number; }; })[]; }, 'slug' | 'rows' | 'program'>; }
81
+ export type NativeSpeciesLookBookRows = { body: v.InferOutput<typeof CompactSpeciesBodiesSchema>; } & { slug: string; body: unknown; poses?: Record<string, unknown> | undefined; program?: unknown; rows: ({ metadata: Omit<v.InferOutput<typeof SpeciesSchema>, 'harvest' | 'capExempt'>; id: string; family: string; rigContract: { skeleton: string; clips: (v.InferOutput<typeof SkinClipNameSchema>)[]; sockets: (string)[]; }; rig?: 'quadruped' | 'custom' | undefined; pose?: { grazeNeck: number; gallopTail: number; } | undefined; gait?: { trot: number; gallop: number; } | undefined; eyeGlow?: [number, number, number] | undefined; eyeGlowIntensity?: number | undefined; variants: Record<string, { body: string; tint?: Record<string, [number, number, number]> | undefined; traits?: Record<string, (number) | (boolean)> | undefined; }>; projection?: v.InferOutput<typeof ActorProjectionV2Schema>; control?: ArenaRoomSpeciesControlRows; group?: v.InferOutput<typeof SpeciesGroupSchema> | undefined; directed?: v.InferOutput<typeof DirectedSpeciesSchema> | undefined; guard?: true | undefined; elite?: true | undefined; postPose?: { alive: string; dead?: string; envelopes?: v.InferOutput<typeof RidingPresentationSchema>; } | undefined; material: { rim: number; bands: number; }; })[]; };
82
+ export interface SpeciesPresentationRowsInput { poses: Record<string, { prefix: string; group: string; scalars: (unknown)[]; look?: unknown; alive?: boolean; }>; packedBodies: v.InferInput<typeof CompactSpeciesBodiesSchema>; guest: CreatureGuestRowsInput; lookBook: Pick<{ slug: string; body: unknown; poses?: Record<string, unknown> | undefined; program?: unknown; rows: ({ metadata: Omit<v.InferInput<typeof SpeciesSchema>, 'harvest' | 'capExempt'>; id: string; family: string; rigContract: { skeleton: string; clips: (v.InferInput<typeof SkinClipNameSchema>)[]; sockets: (string)[]; }; rig?: 'quadruped' | 'custom' | undefined; pose?: { grazeNeck: number; gallopTail: number; } | undefined; gait?: { trot: number; gallop: number; } | undefined; eyeGlow?: [number, number, number] | undefined; eyeGlowIntensity?: number | undefined; variants: Record<string, { body: string; tint?: Record<string, [number, number, number]> | undefined; traits?: Record<string, (number) | (boolean)> | undefined; }>; projection?: v.InferInput<typeof ActorProjectionV2Schema>; control?: ArenaRoomSpeciesControlRowsInput; group?: v.InferInput<typeof SpeciesGroupSchema> | undefined; directed?: v.InferInput<typeof DirectedSpeciesSchema> | undefined; guard?: true | undefined; elite?: true | undefined; postPose?: { alive: string; dead?: string; envelopes?: v.InferInput<typeof RidingPresentationSchema>; } | undefined; material: { rim: number; bands: number; }; })[]; }, 'slug' | 'rows' | 'program'>; }
83
+ export interface SpeciesPresentationRows { poses: Record<string, { prefix: string; group: string; scalars: (unknown)[]; look?: unknown; alive?: boolean; }>; packedBodies: v.InferOutput<typeof CompactSpeciesBodiesSchema>; guest: CreatureGuestRows; lookBook: Pick<{ slug: string; body: unknown; poses?: Record<string, unknown> | undefined; program?: unknown; rows: ({ metadata: Omit<v.InferOutput<typeof SpeciesSchema>, 'harvest' | 'capExempt'>; id: string; family: string; rigContract: { skeleton: string; clips: (v.InferOutput<typeof SkinClipNameSchema>)[]; sockets: (string)[]; }; rig?: 'quadruped' | 'custom' | undefined; pose?: { grazeNeck: number; gallopTail: number; } | undefined; gait?: { trot: number; gallop: number; } | undefined; eyeGlow?: [number, number, number] | undefined; eyeGlowIntensity?: number | undefined; variants: Record<string, { body: string; tint?: Record<string, [number, number, number]> | undefined; traits?: Record<string, (number) | (boolean)> | undefined; }>; projection?: v.InferOutput<typeof ActorProjectionV2Schema>; control?: ArenaRoomSpeciesControlRows; group?: v.InferOutput<typeof SpeciesGroupSchema> | undefined; directed?: v.InferOutput<typeof DirectedSpeciesSchema> | undefined; guard?: true | undefined; elite?: true | undefined; postPose?: { alive: string; dead?: string; envelopes?: v.InferOutput<typeof RidingPresentationSchema>; } | undefined; material: { rim: number; bands: number; }; })[]; }, 'slug' | 'rows' | 'program'>; }
83
84
  export interface SpeciesActorsFileRowsInput { species: SpeciesPresentationRowsInput; page: { world: unknown; specimen: unknown; }; draws: v.InferInput<typeof FixedDrawRowsSchema>; pivots: ([number, number, number])[]; parts: (string)[]; radius: number; }
84
85
  export interface SpeciesActorsFileRows { species: SpeciesPresentationRows; page: { world: unknown; specimen: unknown; }; draws: v.InferOutput<typeof FixedDrawRowsSchema>; pivots: ([number, number, number])[]; parts: (string)[]; radius: number; }
@@ -5,6 +5,7 @@ import { SkinClipNameSchema } from './skinData.ts';
5
5
  import { ClientChannelsSchema, NumericPoseSchema } from './clientChannels.ts';
6
6
  import { RidingPresentationSchema } from './riding.ts';
7
7
 
8
+ const lookMetadata = v.omit(SpeciesSchema, ['harvest', 'capExempt']);
8
9
  const text=v.pipe(v.string(),v.minLength(1),v.maxLength(4096)),number=v.pipe(v.number(),v.finite()),rgb=v.tuple([number,number,number]);
9
10
  const fur = v.object({ texSeed: number, tex: v.object({ contrast: number, grizzle: number, normalStrength: number,
10
11
  bristle: number, strandLen: number, root: number }), roughness: number, sheen: number, sheenColor: rgb,
@@ -12,7 +13,7 @@ const fur = v.object({ texSeed: number, tex: v.object({ contrast: number, grizzl
12
13
  const variantLook = v.object({ tint: v.exactOptional(v.record(text, rgb)), traits: v.exactOptional(v.record(text, number)),
13
14
  fur: v.exactOptional(v.object({ rim: v.exactOptional(rgb), sheenColor: v.exactOptional(rgb), emissive: v.exactOptional(rgb), emissiveIntensity: v.exactOptional(number) })) });
14
15
  /** Immutable species fields and a hull-only rest body; each spawn receives an independent body. */
15
- export const HullSpeciesSchema: v.GenericSchema<HullSpeciesRowsInput, HullSpeciesRows> = v.object({ ...SpeciesSchema.entries, fur,
16
+ export const HullSpeciesSchema: v.GenericSchema<HullSpeciesRowsInput, HullSpeciesRows> = v.object({ ...lookMetadata.entries, fur,
16
17
  variants: v.array(v.object({ ...SpeciesSchema.entries.variants.item.entries, ...variantLook.entries })),
17
18
  rigContract: v.object({ skeleton: text, clips: v.array(v.never()), sockets: v.array(text) }),
18
19
  pose: v.object({ grazeNeck: number, gallopTail: number }),
@@ -129,7 +130,7 @@ export const DirectedSpeciesSchema: v.GenericSchema<DirectedSpeciesRowsInput, Di
129
130
  });
130
131
 
131
132
  /** Admitted data contracts, independent of validator implementation metadata. */
132
- export type HullSpeciesRowsInput = Omit<v.InferInput<typeof SpeciesSchema>, keyof ({
133
+ export type HullSpeciesRowsInput = Omit<v.InferInput<typeof SpeciesSchema>, 'harvest' | 'capExempt' | keyof ({
133
134
  fur: {
134
135
  texSeed: number;
135
136
  tex: {
@@ -368,7 +369,7 @@ export type HullSpeciesRowsInput = Omit<v.InferInput<typeof SpeciesSchema>, keyo
368
369
  };
369
370
  };
370
371
  };
371
- export type HullSpeciesRows = Omit<v.InferOutput<typeof SpeciesSchema>, keyof ({
372
+ export type HullSpeciesRows = Omit<v.InferOutput<typeof SpeciesSchema>, 'harvest' | 'capExempt' | keyof ({
372
373
  fur: {
373
374
  texSeed: number;
374
375
  tex: {
@@ -1,3 +1,7 @@
1
+ import type { StrikeDebrisCatalogue } from './strike-debris.ts';
2
+ import { strikeDebrisCatalogueRules } from './strike-debris.ts';
3
+ import type { HarvestDrop, HarvestSpecies } from './harvest-rows.ts';
4
+ import { HarvestDropsSchema, harvestSpeciesRules } from './harvest-rows.ts';
1
5
  import * as v from 'valibot';
2
6
  import { SpawnTablesSchema } from './spawnTables.ts';
3
7
  import { isJsonData } from './json.ts';
@@ -40,8 +44,8 @@ const flight = v.strictObject({ altitude: finite, above: v.exactOptional(v.pickl
40
44
  climbRate: positive, diveRate: positive, lockRange: v.exactOptional(positive),
41
45
  bank: v.exactOptional(v.pipe(positive, v.check(n => n < Math.PI / 2, 'bank below pi/2'))) });
42
46
  /** Strict species data, with bounded ordered variants and no native callback fields. */
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({
44
- id, kind: id, label: text, variants: v.pipe(v.array(variant), v.minLength(1), v.maxLength(64)),
47
+ const SpeciesSchema: v.StrictObjectSchema<{ readonly capExempt: v.ExactOptionalSchema<v.BooleanSchema<undefined>, undefined>; readonly harvest: v.ExactOptionalSchema<typeof HarvestDropsSchema, undefined>; 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({
48
+ id, kind: id, label: text, capExempt: v.exactOptional(v.boolean()), harvest: v.exactOptional(HarvestDropsSchema), variants: v.pipe(v.array(variant), v.minLength(1), v.maxLength(64)),
45
49
  spawnOnly: v.exactOptional(v.pipe(v.array(variant), v.maxLength(64))), aggressive: v.exactOptional(v.boolean()),
46
50
  walkSpeed: v.exactOptional(nonnegative), chargeSpeed: v.exactOptional(nonnegative), chargeDamage: v.exactOptional(nonnegative),
47
51
  chargeWindup: v.exactOptional(nonnegative), ringRadius: v.exactOptional(nonnegative), trampleRadius: v.exactOptional(nonnegative),
@@ -53,7 +57,14 @@ const SpeciesSchema: v.StrictObjectSchema<{ readonly id: v.GenericSchema<Species
53
57
 
54
58
  /** Callback-free gameplay metadata; rendering and policy ownership are admitted separately. */
55
59
 
56
- function readSpecies(input: unknown): SpeciesData { return v.parse(SpeciesSchema, input); }
60
+ // SpeciesSchema checks field shapes; readSpecies additionally checks row-local harvest references.
61
+ const NO_HARVEST_ERRORS = 0;
62
+ function readSpecies(input: unknown): SpeciesData {
63
+ const row = v.parse(SpeciesSchema, input);
64
+ const errors = harvestSpeciesRules([row]);
65
+ if (errors.length > NO_HARVEST_ERRORS) { throw new Error(errors.join('; ')); }
66
+ return row;
67
+ }
57
68
  /** One existing SpeciesBrains owner receives these admitted policy/body rows and strike definitions. */
58
69
  const SpeciesProgramSchema: v.GenericSchema<SpeciesProgramDataInput, SpeciesProgramData> = v.pipe(v.unknown(), v.check(isJsonData, 'Species program must be plain JSON'), v.strictObject({
59
70
  species: v.pipe(v.array(v.strictObject({ ...SpeciesSchema.entries, brain: v.exactOptional(SpeciesBrainSchema),
@@ -61,7 +72,7 @@ const SpeciesProgramSchema: v.GenericSchema<SpeciesProgramDataInput, SpeciesProg
61
72
  strikes: v.pipe(v.array(CreatureStrikeSchema), v.maxLength(256)),
62
73
  modules: v.exactOptional(v.record(v.pipe(v.string(), v.minLength(1), v.maxLength(128)), v.pipe(v.string(), v.maxLength(400000)))),
63
74
  }), v.check(value => new Set(value.species.map(row => row.kind)).size === value.species.length
64
- && new Set(value.strikes.map(row => row.id)).size === value.strikes.length, 'Unique program kinds and strikes'));
75
+ && new Set(value.strikes.map(row => row.id)).size === value.strikes.length, 'Unique program kinds and strikes'), v.check<SpeciesProgramData, 'Species harvest references'>((value: Readonly<{ species: readonly HarvestSpecies[] }>): boolean => harvestSpeciesRules(value.species).length === NO_HARVEST_ERRORS, 'Species harvest references'), v.check<SpeciesProgramData, 'Strike debris references'>((value: StrikeDebrisCatalogue): boolean => strikeDebrisCatalogueRules(value).length === NO_HARVEST_ERRORS, 'Strike debris references'));
65
76
 
66
77
  function readSpeciesProgram(input: unknown): SpeciesProgramData { return v.parse(SpeciesProgramSchema, input); }
67
78
 
@@ -82,15 +93,15 @@ const NativeHuntSchema: v.GenericSchema<NativeHuntRowsInput, NativeHuntRows> = v
82
93
  const SpeciesProgramsSchema: v.GenericSchema<SpeciesProgramsInput, SpeciesPrograms> = v.pipe(v.unknown(), v.check(isJsonData, 'Species programs must be plain JSON'),
83
94
  v.strictObject({ page: v.pipe(v.array(SpeciesSchema), v.maxLength(256)), native: v.pipe(v.array(SpeciesSchema), v.maxLength(256)), program: v.exactOptional(SpeciesProgramSchema),
84
95
  spawns: v.exactOptional(SpawnTablesSchema), hunt: v.exactOptional(NativeHuntSchema) }),
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'));
96
+ v.check(value => [value.page, value.native].every(rows => new Set(rows.map(row => row.kind)).size === rows.length), 'Unique species kinds per owner'), v.check<SpeciesPrograms, 'Species harvest references'>((value: Readonly<{ page: readonly HarvestSpecies[]; native: readonly HarvestSpecies[] }>): boolean => harvestSpeciesRules([...value.page, ...value.native]).length === NO_HARVEST_ERRORS, 'Species harvest references'));
86
97
 
87
98
  function readSpeciesPrograms(input: unknown): SpeciesPrograms { return v.parse(SpeciesProgramsSchema, input); }
88
99
 
89
100
  /** Validated species metadata independent of validator implementation types. */
90
101
  type SpeciesVariantDataInput = SpeciesVariantData;
91
102
  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; }
103
+ interface SpeciesDataInput { capExempt?: boolean; harvest?: HarvestDrop[]; 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; }
104
+ interface SpeciesData { capExempt?: boolean; harvest?: HarvestDrop[]; 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
105
  type SpeciesProgramDataInput = unknown;
95
106
  interface SpeciesProgramData { species: ({ brain?: v.InferOutput<typeof SpeciesBrainSchema>; body?: v.InferOutput<typeof CreatureBodyRecipeSchema>; } & SpeciesData)[]; strikes: (v.InferOutput<typeof CreatureStrikeSchema>)[]; modules?: Record<string, string>; }
96
107
  type NativeHuntRowsInput = NativeHuntRows;
@@ -0,0 +1,108 @@
1
+ import {
2
+ array,
3
+ boolean,
4
+ check,
5
+ custom,
6
+ exactOptional,
7
+ integer,
8
+ maxLength,
9
+ maxValue,
10
+ minValue,
11
+ number,
12
+ pipe,
13
+ regex,
14
+ strictObject,
15
+ string,
16
+ } from 'valibot'
17
+
18
+ import { isJsonData } from './json.ts'
19
+
20
+ import type { GenericSchema } from 'valibot'
21
+
22
+ /** A bounded contact effect, using the existing effects owner's material recipes. */
23
+ interface StrikeDebris {
24
+ surface: 'shell' | 'wood' | 'sand'
25
+ count: number
26
+ atFeet: boolean
27
+ sparks: boolean
28
+ }
29
+ /** A strike's default and optional target-species overrides, keyed by row id. */
30
+ interface StrikeDebrisPolicy {
31
+ default: StrikeDebris
32
+ overrides?: { target: string; effect: StrikeDebris }[]
33
+ }
34
+ const MAX_PARTICLES = 64
35
+ const MAX_OVERRIDES = 64
36
+ const MAX_ID = 128
37
+ const EMPTY = 0
38
+ const surface = custom<StrikeDebris['surface']>(
39
+ (value: unknown): boolean =>
40
+ value === 'shell' || value === 'wood' || value === 'sand',
41
+ )
42
+ const count = pipe(
43
+ number(),
44
+ integer(),
45
+ minValue(EMPTY),
46
+ maxValue(MAX_PARTICLES),
47
+ )
48
+ const effect: GenericSchema<StrikeDebris> = strictObject({
49
+ surface,
50
+ count,
51
+ atFeet: boolean(),
52
+ sparks: boolean(),
53
+ })
54
+ const target = pipe(
55
+ string(),
56
+ regex(/^[a-z][a-zA-Z0-9.:-]*$/u),
57
+ maxLength(MAX_ID),
58
+ )
59
+ const override = strictObject({ target, effect })
60
+ const overrides = pipe(
61
+ array(override),
62
+ maxLength(MAX_OVERRIDES),
63
+ check<NonNullable<StrikeDebrisPolicy['overrides']>, 'unique debris targets'>(
64
+ (rows: readonly Readonly<{ target: string }>[]): boolean => {
65
+ const identities = rows.map(
66
+ (row: Readonly<{ target: string }>): string => row.target,
67
+ )
68
+ return new Set(identities).size === rows.length
69
+ },
70
+ 'unique debris targets',
71
+ ),
72
+ )
73
+ const policy = strictObject({
74
+ default: effect,
75
+ overrides: exactOptional(overrides),
76
+ })
77
+ const StrikeDebrisSchema: GenericSchema<StrikeDebrisPolicy> = pipe(
78
+ custom<StrikeDebrisPolicy>(isJsonData, 'plain strike debris'),
79
+ policy,
80
+ )
81
+
82
+ interface DebrisReferences {
83
+ readonly overrides?: readonly Readonly<{ target: string }>[]
84
+ }
85
+ interface DebrisSource {
86
+ readonly debris?: DebrisReferences
87
+ }
88
+ interface StrikeDebrisCatalogue {
89
+ readonly strikes: readonly DebrisSource[]
90
+ readonly species: readonly Readonly<{ id: string }>[]
91
+ }
92
+ function strikeDebrisCatalogueRules(value: StrikeDebrisCatalogue): string[] {
93
+ const identities = value.species.map(
94
+ (row: Readonly<{ id: string }>): string => row.id,
95
+ )
96
+ const errors: string[] = []
97
+ const known = new Set(identities)
98
+ for (const strike of value.strikes) {
99
+ for (const row of strike.debris?.overrides ?? []) {
100
+ if (!known.has(row.target)) {
101
+ errors.push(`Unknown debris target species: ${row.target}`)
102
+ }
103
+ }
104
+ }
105
+ return errors
106
+ }
107
+ export { StrikeDebrisSchema, strikeDebrisCatalogueRules }
108
+ export type { StrikeDebris, StrikeDebrisPolicy, StrikeDebrisCatalogue }
@@ -15,11 +15,15 @@ const prompt = { id, at: v.tuple([coord, coord, coord]), radius: v.pipe(finite,
15
15
  /** A use target: its prompt runs `scene`. `unless` (TE-ENG6) names a `hooks.conditions` row: while it holds, the use is
16
16
  * spent and its prompt is gone (a lit brazier). */
17
17
  const interactionRow = v.strictObject({ ...prompt, scene: id, unless: v.exactOptional(id) });
18
+ const FLAG_NAME_MIN = 1;
19
+ const FLAG_NAME_MAX = 128;
20
+ const questFlag = v.pipe(v.string(), v.minLength(FLAG_NAME_MIN), v.maxLength(FLAG_NAME_MAX));
21
+ const itemActionRow = v.strictObject({ scene: id, item: id, action: v.picklist([3, 4]), setsFlag: v.exactOptional(questFlag) });
18
22
  /** Named panels and colliders follow published state; interactions enqueue a named scene on the existing input path. */
19
23
  export const TargetsSchema: v.GenericSchema<ShardTargetsInput, ShardTargets> = v.strictObject({
20
24
  panels: v.pipe(v.array(v.strictObject({ panel: id, scope: v.picklist(['shared', 'player']), fieldId: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(0x7fffffff)), equals: finite, visibleWhenMatched: v.boolean(), colliders: v.array(id), activeWhenMatched: v.boolean() })), v.maxLength(64)),
21
25
  interactions: v.pipe(v.array(interactionRow), v.maxLength(64)),
22
- itemActions: v.exactOptional(v.pipe(v.array(v.strictObject({ scene: id, item: id, action: v.picklist([3, 4]) })), v.maxLength(64))),
26
+ itemActions: v.exactOptional(v.pipe(v.array(itemActionRow), v.maxLength(64))),
23
27
  itemFields: v.exactOptional(v.pipe(v.array(v.strictObject({ item: id, fieldId: v.pipe(v.number(), v.integer(), v.minValue(1), v.maxValue(0x7fffffff)), property: v.picklist(['fuel', 'lit', 'taken']) })), v.maxLength(64))),
24
28
  /** TE-ENG3: a quest-giver who talks from rows. `at` is its feet; its talk prompt stands over them and reaches `radius`. E
25
29
  * opens its `quests.dialogue` tree on the player's node. `figure` names the props model or panel that draws it; none: a
@@ -40,6 +44,15 @@ function idsOf(rows: readonly Readonly<{ id: string }>[]): Set<string> {
40
44
  }
41
45
  return out;
42
46
  }
47
+ /** An item use writes only a flag declared by this shard's quest contract. */
48
+ function itemActionFlags(actions: readonly Readonly<{ setsFlag?: string }>[], flags: readonly string[]): string[] {
49
+ for (const row of actions) {
50
+ if (row.setsFlag !== undefined && !flags.includes(row.setsFlag)) {
51
+ return ['declared item action quest flags'];
52
+ }
53
+ }
54
+ return [];
55
+ }
43
56
  /** TE-ENG6: an interaction's `unless` names a declared condition a page can read: a shared field, or a player field an
44
57
  * item projects (the page sees no other player field). */
45
58
  function unlessRefused(
@@ -115,7 +128,7 @@ function talksRefused(
115
128
  return false;
116
129
  }
117
130
  /** Refuse dangling identities, private fields and two writers for the same visual or collider. */
118
- export function targetRules(targets: ShardTargets, shard: { state: v.InferOutput<typeof StateSchema>; hooks: ShardHooks; sim: { scripts: readonly string[]; bindings: ShardScriptBindings }; items: ShardItems; quests?: { dialogue: readonly { id: string }[] } }, props: { panels: readonly { id: string }[]; colliders: readonly { id: string }[]; models?: readonly { id: string }[] } | null): string[] {
131
+ export function targetRules(targets: ShardTargets, shard: { state: v.InferOutput<typeof StateSchema>; hooks: ShardHooks; sim: { scripts: readonly string[]; bindings: ShardScriptBindings }; items: ShardItems; quests?: { dialogue: readonly { id: string }[]; flags?: readonly string[] } }, props: { panels: readonly { id: string }[]; colliders: readonly { id: string }[]; models?: readonly { id: string }[] } | null): string[] {
119
132
  const errors = hookRules({ conditions: targets.panels.map((row) => ({ id: row.panel, ...row })), scenes: [] }, shard.state);
120
133
  const panels = new Set(props?.panels.map((row) => row.id)), colliders = new Set(props?.colliders.map((row) => row.id)), scenes = new Set(shard.hooks.scenes.map((row) => row.id));
121
134
  const bound = targets.panels.flatMap((row) => row.colliders);
@@ -125,6 +138,8 @@ export function targetRules(targets: ShardTargets, shard: { state: v.InferOutput
125
138
  if (targets.panels.length > 0 && shard.sim.bindings.length === 0) errors.push('target fields require script bindings');
126
139
  const actions = targets.itemActions ?? [], fields = targets.itemFields ?? [];
127
140
  if (new Set(actions.map((row) => row.scene)).size !== actions.length || actions.some((row) => !scenes.has(row.scene) || !shard.items.rows.some((item) => item.id === row.item && (item.kind === 'tool' || item.family === LEVER_FAMILY || item.family === MELEE_FAMILY && row.action === RACK_TAKE)))) errors.push('declared item action scenes');
141
+ // TC-E7: item uses may raise only a declared quest flag, for the player who uses the scene.
142
+ errors.push(...itemActionFlags(actions, shard.quests?.flags ?? []));
128
143
  if (new Set(fields.map((row) => row.fieldId)).size !== fields.length || fields.some((row) => {
129
144
  const field = shard.state.player.find((entry) => entry.id === row.fieldId);
130
145
  return !projects(shard.items.rows, row) || field === undefined || field.privacy === 'host' || field.type !== (row.property === 'fuel' ? 'f64' : 'bool') || (field.min ?? 0) > 0 || (field.max ?? 1) < 1;
@@ -181,6 +196,8 @@ interface ShardTargetsFields {
181
196
  scene: string;
182
197
  item: string;
183
198
  action: 3 | 4;
199
+ /** Raise this declared quest flag for the player whose item use is accepted. */
200
+ setsFlag?: string;
184
201
  })[];
185
202
  itemFields?: ({
186
203
  item: string;
@@ -1,3 +1,5 @@
1
+ import { StrikeDebrisSchema } from './strike-debris.ts';
2
+ import type { StrikeDebrisPolicy } from './strike-debris.ts';
1
3
  import * as v from 'valibot';
2
4
  import { isJsonData } from './json.ts';
3
5
  import { ClientChannelsSchema, ClientChannelInputsSchema, ClientChannelPropertySchema } from './clientChannels.ts';
@@ -9,9 +11,9 @@ const duration = v.pipe(seconds, v.minValue(0.000001));
9
11
  const count = v.pipe(scalar, v.integer(), v.maxValue(1024));
10
12
  const slots = v.pipe(count, v.minValue(1));
11
13
  const probability = v.pipe(scalar, v.maxValue(1));
12
- const swing = v.pipe(v.strictObject({ windup: seconds, slashEnd: duration, total: duration, damage: scalar,
14
+ const swing: v.GenericSchema<MeleeSwingRows> = v.pipe(v.strictObject({ debris: v.exactOptional(StrikeDebrisSchema), windup: seconds, slashEnd: duration, total: duration, damage: scalar,
13
15
  stagger: v.exactOptional(scalar), sweep: v.exactOptional(v.pipe(v.number(), v.finite(), v.minValue(-10000), v.maxValue(10000))), reach: v.exactOptional(positive) }),
14
- v.check(row => row.windup <= row.slashEnd && row.slashEnd <= row.total, 'Ordered native swing phases'));
16
+ v.check<MeleeSwingRows, 'Ordered native swing phases'>((row: Readonly<Pick<MeleeSwingRows, 'windup' | 'slashEnd' | 'total'>>): boolean => row.windup <= row.slashEnd && row.slashEnd <= row.total, 'Ordered native swing phases'));
15
17
  const flight = v.strictObject({ gravity: scalar, drag: scalar, windCoupling: scalar });
16
18
  const cone = v.strictObject({ degrees: scalar, radius: v.picklist(['linear', 'sqrt']), axisScale: v.picklist([1, 2]) });
17
19
 
@@ -300,6 +302,7 @@ export const HeldBowFileSchema: v.GenericSchema<HeldBowFileRowsInput, HeldBowFil
300
302
 
301
303
 
302
304
  /** Admitted data contracts, independent of validator implementation metadata. */
305
+ interface MeleeSwingRows { windup: number; slashEnd: number; total: number; damage: number; stagger?: number; sweep?: number; reach?: number; debris?: StrikeDebrisPolicy; }
303
306
  export type MeleeWeaponProfileRowsInput = MeleeWeaponProfileRows;
304
307
  interface MeleeWeaponProfileRowsFields {
305
308
  family: 'melee';
@@ -310,46 +313,7 @@ interface MeleeWeaponProfileRowsFields {
310
313
  comboGap: number;
311
314
  chainLag: number;
312
315
  heavyCharge: number;
313
- moves: {
314
- combo: ({
315
- windup: number;
316
- slashEnd: number;
317
- total: number;
318
- damage: number;
319
- stagger?: number;
320
- sweep?: number;
321
- reach?: number;
322
- })[];
323
- heavy: {
324
- windup: number;
325
- slashEnd: number;
326
- total: number;
327
- damage: number;
328
- stagger?: number;
329
- sweep?: number;
330
- reach?: number;
331
- };
332
- passes?: {
333
- left: {
334
- windup: number;
335
- slashEnd: number;
336
- total: number;
337
- damage: number;
338
- stagger?: number;
339
- sweep?: number;
340
- reach?: number;
341
- };
342
- right: {
343
- windup: number;
344
- slashEnd: number;
345
- total: number;
346
- damage: number;
347
- stagger?: number;
348
- sweep?: number;
349
- reach?: number;
350
- };
351
- };
352
- };
316
+ moves: { combo: MeleeSwingRows[]; heavy: MeleeSwingRows; passes?: {left: MeleeSwingRows; right: MeleeSwingRows}; };
353
317
  mounted?: {
354
318
  reach: number;
355
319
  cooldown: number;