@adatechnology/game-contracts 0.0.0-stage → 0.1.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.
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+ var GameContracts = (() => {
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ IMPACT_CONTRACT: () => IMPACT_CONTRACT,
25
+ checkAnimation: () => checkAnimation,
26
+ checkDestructible: () => checkDestructible,
27
+ checkHit: () => checkHit,
28
+ shotToHit: () => shotToHit
29
+ });
30
+
31
+ // src/impact.ts
32
+ var IMPACT_CONTRACT = {
33
+ ballistic: { required: ["type", "point", "direction", "energy", "caliber"], optional: ["space", "source"], note: "bullets and pellets: joules and diameter in millimetres" },
34
+ blunt: { required: ["type", "point", "energy"], optional: ["direction", "radius", "space", "source"], note: "contact radius in metres (default 3 cm)" },
35
+ slash: { required: ["type", "point", "energy"], optional: ["direction", "radius", "space", "source"], note: "axes, knives, machetes" },
36
+ explosive: { required: ["type", "point", "energy", "radius"], optional: ["space", "source"], note: "point is the centre of the blast, radius the range in metres" },
37
+ fire: { required: ["type", "point", "temperature", "radius"], optional: ["duration", "space", "source"], note: "flame temperature in \xB0C; duration in seconds (call every frame with `dt`)" },
38
+ heat: { required: ["type", "point", "temperature", "radius"], optional: ["duration", "space", "source"], note: "heat without flame (cutting torch, hot plate)" }
39
+ };
40
+ var checkHit = (hit) => {
41
+ const c = IMPACT_CONTRACT[hit.type];
42
+ if (!c) return [`unknown damage type "${String(hit.type)}"`];
43
+ const out = [];
44
+ for (const f of c.required) {
45
+ const v = hit[f];
46
+ if (v === void 0 || (Array.isArray(v) ? v.some((n) => !Number.isFinite(n)) : typeof v === "number" && !Number.isFinite(v))) out.push(`${hit.type} hit needs "${f}"`);
47
+ }
48
+ return out;
49
+ };
50
+ var finiteJson = (v, path, out) => {
51
+ if (typeof v === "number") {
52
+ if (!Number.isFinite(v)) out.push(`${path} is not a finite number`);
53
+ } else if (Array.isArray(v)) v.forEach((x, i) => finiteJson(x, `${path}[${i}]`, out));
54
+ else if (v && typeof v === "object") for (const [k, x] of Object.entries(v)) finiteJson(x, `${path}.${k}`, out);
55
+ else if (typeof v === "function" || typeof v === "symbol" || typeof v === "bigint") out.push(`${path} is not JSON`);
56
+ };
57
+ var checkDestructible = (impl, options = {}) => {
58
+ const problems = [];
59
+ const known = options.materials ? new Set(options.materials) : null;
60
+ let spec;
61
+ try {
62
+ spec = impl.describe();
63
+ } catch (e) {
64
+ return { ok: false, problems: [`describe() threw: ${String(e)}`] };
65
+ }
66
+ if (!spec || !Array.isArray(spec.parts) || spec.parts.length === 0) return { ok: false, problems: ["describe() must return at least one part"] };
67
+ const ids = /* @__PURE__ */ new Set();
68
+ for (const p of spec.parts) {
69
+ if (ids.has(p.id)) problems.push(`duplicate part id "${p.id}"`);
70
+ ids.add(p.id);
71
+ if (known && !known.has(p.material)) problems.push(`part "${p.id}" has unknown material "${p.material}"`);
72
+ if (!p.shape || !["box", "cylinder", "sphere"].includes(p.shape.kind)) problems.push(`part "${p.id}" has no valid shape`);
73
+ if (!Array.isArray(p.position) || p.position.length !== 3) problems.push(`part "${p.id}" has no position`);
74
+ }
75
+ const jointIds = /* @__PURE__ */ new Set();
76
+ for (const j of spec.joints ?? []) {
77
+ if (!ids.has(j.a) || !ids.has(j.b)) problems.push(`joint "${j.id ?? `${j.a}~${j.b}`}" references an unknown part`);
78
+ const jid = j.id ?? `${j.a}~${j.b}`;
79
+ if (jointIds.has(jid)) problems.push(`duplicate joint id "${jid}"`);
80
+ jointIds.add(jid);
81
+ }
82
+ const checkState = (label) => {
83
+ let st;
84
+ try {
85
+ st = impl.state();
86
+ } catch (e) {
87
+ problems.push(`state() threw ${label}: ${String(e)}`);
88
+ return;
89
+ }
90
+ const sids = st.parts.map((p) => p.id).sort().join(",");
91
+ if (sids !== [...ids].sort().join(",")) problems.push(`state() part ids do not match describe() ${label}`);
92
+ for (const p of st.parts) if (!(p.hp >= 0)) problems.push(`part "${p.id}" has negative or invalid hp ${label}`);
93
+ };
94
+ const checkEvents = (events, label) => {
95
+ if (!Array.isArray(events)) {
96
+ problems.push(`${label} must return an array`);
97
+ return;
98
+ }
99
+ const evs = events;
100
+ evs.forEach((e, i) => {
101
+ if (e.object !== impl.id) problems.push(`${label} event ${i} (${e.type}) has object "${String(e.object)}", expected "${impl.id}"`);
102
+ const part = e.part;
103
+ if (part !== void 0 && !ids.has(part)) problems.push(`${label} event ${i} (${e.type}) names unknown part "${part}"`);
104
+ });
105
+ const bad = [];
106
+ finiteJson(evs, "events", bad);
107
+ problems.push(...bad.map((b) => `${label}: ${b}`));
108
+ try {
109
+ const s = JSON.stringify(evs);
110
+ if (JSON.stringify(JSON.parse(s)) !== s) problems.push(`${label} events do not survive a JSON round trip`);
111
+ } catch (e) {
112
+ problems.push(`${label} events are not JSON-serializable: ${String(e)}`);
113
+ }
114
+ };
115
+ checkState("before the hit");
116
+ const target = spec.parts[0];
117
+ try {
118
+ const hit = { type: "ballistic", point: [target.position[0], target.position[1], target.position[2]], direction: [0, 0, -1], energy: 500, caliber: 9 };
119
+ checkEvents(impl.hit(hit), "hit()");
120
+ } catch (e) {
121
+ problems.push(`hit() threw: ${String(e)}`);
122
+ }
123
+ checkState("after the hit");
124
+ if (impl.update) {
125
+ try {
126
+ checkEvents(impl.update(0.016), "update()");
127
+ } catch (e) {
128
+ problems.push(`update() threw: ${String(e)}`);
129
+ }
130
+ checkState("after update");
131
+ }
132
+ try {
133
+ impl.reset?.();
134
+ } catch (e) {
135
+ problems.push(`reset() threw: ${String(e)}`);
136
+ }
137
+ return { ok: problems.length === 0, problems };
138
+ };
139
+
140
+ // src/weapons.ts
141
+ var shotToHit = (shot, point, normal) => {
142
+ void normal;
143
+ const dx = point[0] - shot.origin[0];
144
+ const dy = point[1] - shot.origin[1];
145
+ const dz = point[2] - shot.origin[2];
146
+ const distance = Math.hypot(dx, dy, dz);
147
+ return {
148
+ type: "ballistic",
149
+ point: [point[0], point[1], point[2]],
150
+ direction: [shot.direction[0], shot.direction[1], shot.direction[2]],
151
+ energy: shot.energyAt(distance),
152
+ caliber: shot.caliber,
153
+ source: shot.source ?? shot.weapon
154
+ };
155
+ };
156
+
157
+ // src/animation.ts
158
+ var finite3 = (v) => Array.isArray(v) && v.length === 3 && v.every((n) => typeof n === "number" && Number.isFinite(n));
159
+ var checkAnimation = (clip, partIds) => {
160
+ const problems = [];
161
+ const parts = new Set(partIds);
162
+ const id = String(clip?.id ?? "");
163
+ if (!/^[a-z][a-z0-9_]*$/.test(id)) problems.push(`clip id "${id}" must be snake_case`);
164
+ const label = `clip "${id}"`;
165
+ if (!(typeof clip?.duration === "number" && Number.isFinite(clip.duration) && clip.duration > 0)) problems.push(`${label} needs a positive finite duration`);
166
+ const dur = typeof clip?.duration === "number" && clip.duration > 0 ? clip.duration : Infinity;
167
+ if (!Array.isArray(clip?.keys) || clip.keys.length === 0) {
168
+ problems.push(`${label} needs at least one key`);
169
+ return { ok: false, problems };
170
+ }
171
+ let prev = -Infinity;
172
+ clip.keys.forEach((k, i) => {
173
+ if (!(typeof k.t === "number" && Number.isFinite(k.t)) || k.t < 0 || k.t > dur + 1e-9) problems.push(`${label} key ${i} has t=${String(k.t)} outside 0..${dur}`);
174
+ else if (k.t < prev) problems.push(`${label} key ${i} goes back in time (${k.t} < ${prev})`);
175
+ else prev = k.t;
176
+ for (const f of ["position", "rotation"]) if (k[f] !== void 0 && !finite3(k[f])) problems.push(`${label} key ${i} has an invalid ${f}`);
177
+ for (const [pid, pose] of Object.entries(k.parts ?? {})) {
178
+ if (!parts.has(pid)) problems.push(`${label} key ${i} moves unknown part "${pid}"`);
179
+ for (const f of ["position", "rotation"]) if (pose?.[f] !== void 0 && !finite3(pose[f])) problems.push(`${label} key ${i} part "${pid}" has an invalid ${f}`);
180
+ }
181
+ });
182
+ let prevEv = -Infinity;
183
+ (clip.events ?? []).forEach((e, i) => {
184
+ if (!(typeof e.t === "number" && Number.isFinite(e.t)) || e.t < 0 || e.t > dur + 1e-9) problems.push(`${label} event ${i} has t=${String(e.t)} outside 0..${dur}`);
185
+ else if (e.t < prevEv) problems.push(`${label} event ${i} goes back in time`);
186
+ else prevEv = e.t;
187
+ if (typeof e.type !== "string" || e.type === "") problems.push(`${label} event ${i} needs a type`);
188
+ try {
189
+ JSON.stringify(e.data ?? {});
190
+ } catch {
191
+ problems.push(`${label} event ${i} data is not JSON`);
192
+ }
193
+ });
194
+ return { ok: problems.length === 0, problems };
195
+ };
196
+ return __toCommonJS(index_exports);
197
+ })();
198
+ //# sourceMappingURL=index.global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/impact.ts","../src/weapons.ts","../src/animation.ts"],"sourcesContent":["/**\n * @adatechnology/game-contracts: the contracts every game module (vehicles, furniture, plants, houses, weapons) depends on, and nothing else.\n * Types plus tiny pure checkers, no runtime dependencies. The default destruction world, the renderers and the test room are optional.\n */\nexport type {\n Crack,\n DamageType,\n DebrisKind,\n Dent,\n DestructibleSpec,\n DestructionEvent,\n DestructionEventType,\n FluidKind,\n Fragment,\n FractureStyle,\n Hit,\n HitResult,\n Hole,\n JointKind,\n JointSpec,\n JointState,\n MaterialId,\n ObjectState,\n PartShape,\n PartSpec,\n PartState,\n PartStatus,\n Quat,\n RayHit,\n StructureRole,\n ToolKind,\n Vec3,\n} from './destruction'\nexport { IMPACT_CONTRACT, checkDestructible, checkHit } from './impact'\nexport type { CheckOptions, DestructibleImpl, ImpactContract } from './impact'\nexport { shotToHit } from './weapons'\nexport type { Shot, Use } from './weapons'\nexport type { ContainerSpec, ItemUseDef, LiquidId } from './fluids'\nexport { checkAnimation } from './animation'\nexport type { AnimationClipSpec, AnimationEventSpec, AnimationKey, AnimationPose, ItemAnimationContract } from './animation'\nexport type { ModuleItemFluid, ModuleScenario, TestableItem, TestableModule } from './module'\n","import type { DamageType, DestructibleSpec, DestructionEvent, Hit, JointSpec, ObjectState, ToolKind } from './destruction'\n\n/**\n * What a game module implements for an object whose behaviour it owns (a vehicle with its own panel deformation, a creature, a machine). The\n * world (`DestructionWorld.register`) hosts it next to its own objects: raycast, shoot, explode, hit, disassemble, extinguish, update, state,\n * reset and `on` all route to it.\n *\n * Space: the impl receives hits in WORLD space and returns events in WORLD space (it owns its transform; the transform given to `register` or\n * `setTransform` is only used by the world for raycasts and blast range). Every event must carry `object === id` and name parts listed by\n * `describe()`.\n */\nexport interface DestructibleImpl {\n readonly id: string\n readonly name?: string\n /** Parts, joints and structure in the impl's local space, for raycast, inspector and log. Called often: keep it cheap. */\n describe(): DestructibleSpec\n /** Apply one hit (see `IMPACT_CONTRACT` for the fields per type) and return the events it caused. */\n hit(hit: Hit): DestructionEvent[]\n /** Advance fire, melting, collapse and other timed behaviour. */\n update?(dt: number): DestructionEvent[]\n state(): ObjectState\n reset?(): void\n /** Same contract as `DestructionWorld.disassemble`: progress 0..1, or -1 when the tool cannot undo the joint. */\n disassemble?(jointId: string, tool: ToolKind, dt: number): number\n extinguish?(partId?: string): void\n /** Plain JSON of the impl's own state, stored in `DestructionSnapshot.impls`. */\n serialize?(): unknown\n load?(data: unknown): void\n}\n\n/** The fields a weapon or hazard must put in a `Hit`, per damage type. THE impact contract. */\nexport interface ImpactContract {\n required: string[]\n optional: string[]\n note: string\n}\n\nexport const IMPACT_CONTRACT: Record<DamageType, ImpactContract> = {\n ballistic: { required: ['type', 'point', 'direction', 'energy', 'caliber'], optional: ['space', 'source'], note: 'bullets and pellets: joules and diameter in millimetres' },\n blunt: { required: ['type', 'point', 'energy'], optional: ['direction', 'radius', 'space', 'source'], note: 'contact radius in metres (default 3 cm)' },\n slash: { required: ['type', 'point', 'energy'], optional: ['direction', 'radius', 'space', 'source'], note: 'axes, knives, machetes' },\n explosive: { required: ['type', 'point', 'energy', 'radius'], optional: ['space', 'source'], note: 'point is the centre of the blast, radius the range in metres' },\n fire: { required: ['type', 'point', 'temperature', 'radius'], optional: ['duration', 'space', 'source'], note: 'flame temperature in °C; duration in seconds (call every frame with `dt`)' },\n heat: { required: ['type', 'point', 'temperature', 'radius'], optional: ['duration', 'space', 'source'], note: 'heat without flame (cutting torch, hot plate)' },\n}\n\n/** Problems with a hit according to the impact contract (empty when it is valid). */\nexport const checkHit = (hit: Hit): string[] => {\n const c = IMPACT_CONTRACT[hit.type]\n if (!c) return [`unknown damage type \"${String(hit.type)}\"`]\n const out: string[] = []\n for (const f of c.required) {\n const v = (hit as unknown as Record<string, unknown>)[f]\n if (v === undefined || (Array.isArray(v) ? v.some((n) => !Number.isFinite(n)) : typeof v === 'number' && !Number.isFinite(v))) out.push(`${hit.type} hit needs \"${f}\"`)\n }\n return out\n}\n\nexport interface CheckOptions {\n /**\n * Ids of every material the impl may use (the contracts package does not know the materials of your world: pass the ids of\n * `world.materials`, or the built-in plus your own). When omitted, the material check is skipped.\n */\n materials?: Iterable<string>\n}\n\nconst finiteJson = (v: unknown, path: string, out: string[]) => {\n if (typeof v === 'number') {\n if (!Number.isFinite(v)) out.push(`${path} is not a finite number`)\n } else if (Array.isArray(v)) v.forEach((x, i) => finiteJson(x, `${path}[${i}]`, out))\n else if (v && typeof v === 'object') for (const [k, x] of Object.entries(v)) finiteJson(x, `${path}.${k}`, out)\n else if (typeof v === 'function' || typeof v === 'symbol' || typeof v === 'bigint') out.push(`${path} is not JSON`)\n}\n\n/**\n * Contract checker for the test room (it needs no world): `describe()` is valid, a 500 J ballistic hit at a part centre returns well-formed events of this impl, `state()`\n * matches `describe()`, hit points never go negative, `update(0.016)` returns an array and every event is JSON-serializable. It hits the impl\n * (and calls `reset()` afterwards when there is one).\n */\nexport const checkDestructible = (impl: DestructibleImpl, options: CheckOptions = {}): { ok: boolean; problems: string[] } => {\n const problems: string[] = []\n const known = options.materials ? new Set(options.materials) : null\n let spec: DestructibleSpec | undefined\n try {\n spec = impl.describe()\n } catch (e) {\n return { ok: false, problems: [`describe() threw: ${String(e)}`] }\n }\n if (!spec || !Array.isArray(spec.parts) || spec.parts.length === 0) return { ok: false, problems: ['describe() must return at least one part'] }\n const ids = new Set<string>()\n for (const p of spec.parts) {\n if (ids.has(p.id)) problems.push(`duplicate part id \"${p.id}\"`)\n ids.add(p.id)\n if (known && !known.has(p.material)) problems.push(`part \"${p.id}\" has unknown material \"${p.material}\"`)\n if (!p.shape || !['box', 'cylinder', 'sphere'].includes(p.shape.kind)) problems.push(`part \"${p.id}\" has no valid shape`)\n if (!Array.isArray(p.position) || p.position.length !== 3) problems.push(`part \"${p.id}\" has no position`)\n }\n const jointIds = new Set<string>()\n for (const j of (spec.joints ?? []) as JointSpec[]) {\n if (!ids.has(j.a) || !ids.has(j.b)) problems.push(`joint \"${j.id ?? `${j.a}~${j.b}`}\" references an unknown part`)\n const jid = j.id ?? `${j.a}~${j.b}`\n if (jointIds.has(jid)) problems.push(`duplicate joint id \"${jid}\"`)\n jointIds.add(jid)\n }\n const checkState = (label: string) => {\n let st: ObjectState\n try {\n st = impl.state()\n } catch (e) {\n problems.push(`state() threw ${label}: ${String(e)}`)\n return\n }\n const sids = st.parts.map((p) => p.id).sort().join(',')\n if (sids !== [...ids].sort().join(',')) problems.push(`state() part ids do not match describe() ${label}`)\n for (const p of st.parts) if (!(p.hp >= 0)) problems.push(`part \"${p.id}\" has negative or invalid hp ${label}`)\n }\n const checkEvents = (events: unknown, label: string) => {\n if (!Array.isArray(events)) {\n problems.push(`${label} must return an array`)\n return\n }\n const evs = events as DestructionEvent[]\n evs.forEach((e, i) => {\n if (e.object !== impl.id) problems.push(`${label} event ${i} (${e.type}) has object \"${String(e.object)}\", expected \"${impl.id}\"`)\n const part = (e as { part?: string }).part\n if (part !== undefined && !ids.has(part)) problems.push(`${label} event ${i} (${e.type}) names unknown part \"${part}\"`)\n })\n const bad: string[] = []\n finiteJson(evs, 'events', bad)\n problems.push(...bad.map((b) => `${label}: ${b}`))\n try {\n const s = JSON.stringify(evs)\n if (JSON.stringify(JSON.parse(s)) !== s) problems.push(`${label} events do not survive a JSON round trip`)\n } catch (e) {\n problems.push(`${label} events are not JSON-serializable: ${String(e)}`)\n }\n }\n checkState('before the hit')\n const target = spec.parts[0]\n try {\n const hit: Hit = { type: 'ballistic', point: [target.position[0], target.position[1], target.position[2]], direction: [0, 0, -1], energy: 500, caliber: 9 }\n checkEvents(impl.hit(hit), 'hit()')\n } catch (e) {\n problems.push(`hit() threw: ${String(e)}`)\n }\n checkState('after the hit')\n if (impl.update) {\n try {\n checkEvents(impl.update(0.016), 'update()')\n } catch (e) {\n problems.push(`update() threw: ${String(e)}`)\n }\n checkState('after update')\n }\n try {\n impl.reset?.()\n } catch (e) {\n problems.push(`reset() threw: ${String(e)}`)\n }\n return { ok: problems.length === 0, problems }\n}\n","import type { Hit, Vec3 } from './destruction'\n\n/**\n * A ballistic shot (one per pellet) as a weapon module produces it. Plain data: any damage model can consume it (`shotToHit` makes the `Hit`).\n */\nexport interface Shot {\n origin: Vec3\n /** Unit vector. */\n direction: Vec3\n /** Muzzle energy in joules. */\n energy: number\n /** Bullet diameter in millimetres. */\n caliber: number\n /** snake_case calibre id, e.g. `9x19`. */\n caliberId: string\n /** Muzzle speed in m/s. */\n speed: number\n /** Energy at a distance in metres, with the calibre's drag. */\n energyAt(distance: number): number\n pellet: number\n /** snake_case weapon id. */\n weapon: string\n source?: string\n}\n\n/** One use of a non-firearm (melee swing, flame tick, heat tick, throw, tool tick, extinguisher tick). */\nexport type Use =\n | { kind: 'melee'; damage: 'blunt' | 'slash'; energy: number; radius: number; reach: number; origin: Vec3; direction: Vec3 }\n | { kind: 'flame'; temperature: number; radius: number; range: number; cone: boolean; duration: number; origin: Vec3; direction: Vec3 }\n | { kind: 'heat'; temperature: number; radius: number; range: number; duration: number; origin: Vec3; direction: Vec3 }\n | { kind: 'throw'; energy: number; radius: number; fuse: number; velocity: Vec3; origin: Vec3; fire?: { temperature: number; radius: number; seconds: number } }\n | { kind: 'tool'; tool: string; reach: number; duration: number; origin: Vec3; direction: Vec3 }\n | { kind: 'extinguish'; range: number; coolC: number; duration: number; origin: Vec3; direction: Vec3 }\n | { kind: 'hand'; reach: number; origin: Vec3; direction: Vec3 }\n\n/**\n * The `Hit` a ballistic shot makes at `point` (world space): the energy is what is left of the shot at that distance from its origin\n * (`shot.energyAt`), the direction and calibre come from the shot. `normal` (the surface normal at the point, when the caller knows it) does not\n * change the hit; it is accepted so that callers can pass what their raycast returned and so that a stricter implementation could use it.\n */\nexport const shotToHit = (shot: Shot, point: Vec3, normal?: Vec3): Hit => {\n void normal\n const dx = point[0] - shot.origin[0]\n const dy = point[1] - shot.origin[1]\n const dz = point[2] - shot.origin[2]\n const distance = Math.hypot(dx, dy, dz)\n return {\n type: 'ballistic',\n point: [point[0], point[1], point[2]],\n direction: [shot.direction[0], shot.direction[1], shot.direction[2]],\n energy: shot.energyAt(distance),\n caliber: shot.caliber,\n source: shot.source ?? shot.weapon,\n }\n}\n","import type { Vec3 } from './destruction'\n\n/** Pose of one part (or of the whole item) at a key: position offset in metres and Euler XYZ rotation in radians, both relative to the rest pose. */\nexport interface AnimationPose {\n position?: Vec3\n rotation?: Vec3\n}\n\nexport interface AnimationKey {\n /** Seconds from the start of the clip. */\n t: number\n /** Pose of the item's root. */\n position?: Vec3\n rotation?: Vec3\n /** Poses of named parts: the key is a destruction part id (a pistol `reload` moves `mag`; a car door `open` rotates `door_l`). */\n parts?: Record<string, AnimationPose>\n}\n\nexport interface AnimationEventSpec {\n /** Seconds from the start of the clip. */\n t: number\n /** snake_case type the host maps (`sound`, `eject_casing`, `door_latch`...). */\n type: string\n data?: Record<string, unknown>\n}\n\n/** A use animation a module brings with its item. Poses between keys are interpolated by the player (the test room does it linearly). */\nexport interface AnimationClipSpec {\n /** snake_case: `reload`, `open`, `drink`... Unique within the item. */\n id: string\n /** Seconds. */\n duration: number\n keys: AnimationKey[]\n events?: AnimationEventSpec[]\n}\n\n/** What an item exposes when it brings its own animations. */\nexport interface ItemAnimationContract {\n animations: AnimationClipSpec[]\n}\n\nconst finite3 = (v: unknown): boolean => Array.isArray(v) && v.length === 3 && v.every((n) => typeof n === 'number' && Number.isFinite(n))\n\n/**\n * Problems with a clip (empty when it is valid): a snake_case id, a positive finite duration, at least one key, key and event times inside\n * `[0, duration]` and not going backwards, finite vectors, every named part one of `partIds`, event types that are non-empty strings and\n * JSON-serializable event data.\n */\nexport const checkAnimation = (clip: AnimationClipSpec, partIds: Iterable<string>): { ok: boolean; problems: string[] } => {\n const problems: string[] = []\n const parts = new Set(partIds)\n const id = String(clip?.id ?? '')\n if (!/^[a-z][a-z0-9_]*$/.test(id)) problems.push(`clip id \"${id}\" must be snake_case`)\n const label = `clip \"${id}\"`\n if (!(typeof clip?.duration === 'number' && Number.isFinite(clip.duration) && clip.duration > 0)) problems.push(`${label} needs a positive finite duration`)\n const dur = typeof clip?.duration === 'number' && clip.duration > 0 ? clip.duration : Infinity\n if (!Array.isArray(clip?.keys) || clip.keys.length === 0) {\n problems.push(`${label} needs at least one key`)\n return { ok: false, problems }\n }\n let prev = -Infinity\n clip.keys.forEach((k, i) => {\n if (!(typeof k.t === 'number' && Number.isFinite(k.t)) || k.t < 0 || k.t > dur + 1e-9) problems.push(`${label} key ${i} has t=${String(k.t)} outside 0..${dur}`)\n else if (k.t < prev) problems.push(`${label} key ${i} goes back in time (${k.t} < ${prev})`)\n else prev = k.t\n for (const f of ['position', 'rotation'] as const) if (k[f] !== undefined && !finite3(k[f])) problems.push(`${label} key ${i} has an invalid ${f}`)\n for (const [pid, pose] of Object.entries(k.parts ?? {})) {\n if (!parts.has(pid)) problems.push(`${label} key ${i} moves unknown part \"${pid}\"`)\n for (const f of ['position', 'rotation'] as const) if (pose?.[f] !== undefined && !finite3(pose[f])) problems.push(`${label} key ${i} part \"${pid}\" has an invalid ${f}`)\n }\n })\n let prevEv = -Infinity\n ;(clip.events ?? []).forEach((e, i) => {\n if (!(typeof e.t === 'number' && Number.isFinite(e.t)) || e.t < 0 || e.t > dur + 1e-9) problems.push(`${label} event ${i} has t=${String(e.t)} outside 0..${dur}`)\n else if (e.t < prevEv) problems.push(`${label} event ${i} goes back in time`)\n else prevEv = e.t\n if (typeof e.type !== 'string' || e.type === '') problems.push(`${label} event ${i} needs a type`)\n try {\n JSON.stringify(e.data ?? {})\n } catch {\n problems.push(`${label} event ${i} data is not JSON`)\n }\n })\n return { ok: problems.length === 0, problems }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACqCO,MAAM,kBAAsD;AAAA,IACjE,WAAW,EAAE,UAAU,CAAC,QAAQ,SAAS,aAAa,UAAU,SAAS,GAAG,UAAU,CAAC,SAAS,QAAQ,GAAG,MAAM,0DAA0D;AAAA,IAC3K,OAAO,EAAE,UAAU,CAAC,QAAQ,SAAS,QAAQ,GAAG,UAAU,CAAC,aAAa,UAAU,SAAS,QAAQ,GAAG,MAAM,0CAA0C;AAAA,IACtJ,OAAO,EAAE,UAAU,CAAC,QAAQ,SAAS,QAAQ,GAAG,UAAU,CAAC,aAAa,UAAU,SAAS,QAAQ,GAAG,MAAM,yBAAyB;AAAA,IACrI,WAAW,EAAE,UAAU,CAAC,QAAQ,SAAS,UAAU,QAAQ,GAAG,UAAU,CAAC,SAAS,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AK,UAAU,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC,eAAe,GAAG,EAAE;AAAA,eACxJ,EAAE,IAAI,OAAQ,UAAS,KAAK,GAAG,KAAK,UAAU,CAAC,oBAAoB;AAAA,UACvE,UAAS,EAAE;AAChB,UAAI,OAAO,EAAE,SAAS,YAAY,EAAE,SAAS,GAAI,UAAS,KAAK,GAAG,KAAK,UAAU,CAAC,eAAe;AACjG,UAAI;AACF,aAAK,UAAU,EAAE,QAAQ,CAAC,CAAC;AAAA,MAC7B,QAAQ;AACN,iBAAS,KAAK,GAAG,KAAK,UAAU,CAAC,mBAAmB;AAAA,MACtD;AAAA,IACF,CAAC;AACD,WAAO,EAAE,IAAI,SAAS,WAAW,GAAG,SAAS;AAAA,EAC/C;","names":[]}
package/dist/index.js ADDED
@@ -0,0 +1,173 @@
1
+ // src/impact.ts
2
+ var IMPACT_CONTRACT = {
3
+ ballistic: { required: ["type", "point", "direction", "energy", "caliber"], optional: ["space", "source"], note: "bullets and pellets: joules and diameter in millimetres" },
4
+ blunt: { required: ["type", "point", "energy"], optional: ["direction", "radius", "space", "source"], note: "contact radius in metres (default 3 cm)" },
5
+ slash: { required: ["type", "point", "energy"], optional: ["direction", "radius", "space", "source"], note: "axes, knives, machetes" },
6
+ explosive: { required: ["type", "point", "energy", "radius"], optional: ["space", "source"], note: "point is the centre of the blast, radius the range in metres" },
7
+ fire: { required: ["type", "point", "temperature", "radius"], optional: ["duration", "space", "source"], note: "flame temperature in \xB0C; duration in seconds (call every frame with `dt`)" },
8
+ heat: { required: ["type", "point", "temperature", "radius"], optional: ["duration", "space", "source"], note: "heat without flame (cutting torch, hot plate)" }
9
+ };
10
+ var checkHit = (hit) => {
11
+ const c = IMPACT_CONTRACT[hit.type];
12
+ if (!c) return [`unknown damage type "${String(hit.type)}"`];
13
+ const out = [];
14
+ for (const f of c.required) {
15
+ const v = hit[f];
16
+ if (v === void 0 || (Array.isArray(v) ? v.some((n) => !Number.isFinite(n)) : typeof v === "number" && !Number.isFinite(v))) out.push(`${hit.type} hit needs "${f}"`);
17
+ }
18
+ return out;
19
+ };
20
+ var finiteJson = (v, path, out) => {
21
+ if (typeof v === "number") {
22
+ if (!Number.isFinite(v)) out.push(`${path} is not a finite number`);
23
+ } else if (Array.isArray(v)) v.forEach((x, i) => finiteJson(x, `${path}[${i}]`, out));
24
+ else if (v && typeof v === "object") for (const [k, x] of Object.entries(v)) finiteJson(x, `${path}.${k}`, out);
25
+ else if (typeof v === "function" || typeof v === "symbol" || typeof v === "bigint") out.push(`${path} is not JSON`);
26
+ };
27
+ var checkDestructible = (impl, options = {}) => {
28
+ const problems = [];
29
+ const known = options.materials ? new Set(options.materials) : null;
30
+ let spec;
31
+ try {
32
+ spec = impl.describe();
33
+ } catch (e) {
34
+ return { ok: false, problems: [`describe() threw: ${String(e)}`] };
35
+ }
36
+ if (!spec || !Array.isArray(spec.parts) || spec.parts.length === 0) return { ok: false, problems: ["describe() must return at least one part"] };
37
+ const ids = /* @__PURE__ */ new Set();
38
+ for (const p of spec.parts) {
39
+ if (ids.has(p.id)) problems.push(`duplicate part id "${p.id}"`);
40
+ ids.add(p.id);
41
+ if (known && !known.has(p.material)) problems.push(`part "${p.id}" has unknown material "${p.material}"`);
42
+ if (!p.shape || !["box", "cylinder", "sphere"].includes(p.shape.kind)) problems.push(`part "${p.id}" has no valid shape`);
43
+ if (!Array.isArray(p.position) || p.position.length !== 3) problems.push(`part "${p.id}" has no position`);
44
+ }
45
+ const jointIds = /* @__PURE__ */ new Set();
46
+ for (const j of spec.joints ?? []) {
47
+ if (!ids.has(j.a) || !ids.has(j.b)) problems.push(`joint "${j.id ?? `${j.a}~${j.b}`}" references an unknown part`);
48
+ const jid = j.id ?? `${j.a}~${j.b}`;
49
+ if (jointIds.has(jid)) problems.push(`duplicate joint id "${jid}"`);
50
+ jointIds.add(jid);
51
+ }
52
+ const checkState = (label) => {
53
+ let st;
54
+ try {
55
+ st = impl.state();
56
+ } catch (e) {
57
+ problems.push(`state() threw ${label}: ${String(e)}`);
58
+ return;
59
+ }
60
+ const sids = st.parts.map((p) => p.id).sort().join(",");
61
+ if (sids !== [...ids].sort().join(",")) problems.push(`state() part ids do not match describe() ${label}`);
62
+ for (const p of st.parts) if (!(p.hp >= 0)) problems.push(`part "${p.id}" has negative or invalid hp ${label}`);
63
+ };
64
+ const checkEvents = (events, label) => {
65
+ if (!Array.isArray(events)) {
66
+ problems.push(`${label} must return an array`);
67
+ return;
68
+ }
69
+ const evs = events;
70
+ evs.forEach((e, i) => {
71
+ if (e.object !== impl.id) problems.push(`${label} event ${i} (${e.type}) has object "${String(e.object)}", expected "${impl.id}"`);
72
+ const part = e.part;
73
+ if (part !== void 0 && !ids.has(part)) problems.push(`${label} event ${i} (${e.type}) names unknown part "${part}"`);
74
+ });
75
+ const bad = [];
76
+ finiteJson(evs, "events", bad);
77
+ problems.push(...bad.map((b) => `${label}: ${b}`));
78
+ try {
79
+ const s = JSON.stringify(evs);
80
+ if (JSON.stringify(JSON.parse(s)) !== s) problems.push(`${label} events do not survive a JSON round trip`);
81
+ } catch (e) {
82
+ problems.push(`${label} events are not JSON-serializable: ${String(e)}`);
83
+ }
84
+ };
85
+ checkState("before the hit");
86
+ const target = spec.parts[0];
87
+ try {
88
+ const hit = { type: "ballistic", point: [target.position[0], target.position[1], target.position[2]], direction: [0, 0, -1], energy: 500, caliber: 9 };
89
+ checkEvents(impl.hit(hit), "hit()");
90
+ } catch (e) {
91
+ problems.push(`hit() threw: ${String(e)}`);
92
+ }
93
+ checkState("after the hit");
94
+ if (impl.update) {
95
+ try {
96
+ checkEvents(impl.update(0.016), "update()");
97
+ } catch (e) {
98
+ problems.push(`update() threw: ${String(e)}`);
99
+ }
100
+ checkState("after update");
101
+ }
102
+ try {
103
+ impl.reset?.();
104
+ } catch (e) {
105
+ problems.push(`reset() threw: ${String(e)}`);
106
+ }
107
+ return { ok: problems.length === 0, problems };
108
+ };
109
+
110
+ // src/weapons.ts
111
+ var shotToHit = (shot, point, normal) => {
112
+ void normal;
113
+ const dx = point[0] - shot.origin[0];
114
+ const dy = point[1] - shot.origin[1];
115
+ const dz = point[2] - shot.origin[2];
116
+ const distance = Math.hypot(dx, dy, dz);
117
+ return {
118
+ type: "ballistic",
119
+ point: [point[0], point[1], point[2]],
120
+ direction: [shot.direction[0], shot.direction[1], shot.direction[2]],
121
+ energy: shot.energyAt(distance),
122
+ caliber: shot.caliber,
123
+ source: shot.source ?? shot.weapon
124
+ };
125
+ };
126
+
127
+ // src/animation.ts
128
+ var finite3 = (v) => Array.isArray(v) && v.length === 3 && v.every((n) => typeof n === "number" && Number.isFinite(n));
129
+ var checkAnimation = (clip, partIds) => {
130
+ const problems = [];
131
+ const parts = new Set(partIds);
132
+ const id = String(clip?.id ?? "");
133
+ if (!/^[a-z][a-z0-9_]*$/.test(id)) problems.push(`clip id "${id}" must be snake_case`);
134
+ const label = `clip "${id}"`;
135
+ if (!(typeof clip?.duration === "number" && Number.isFinite(clip.duration) && clip.duration > 0)) problems.push(`${label} needs a positive finite duration`);
136
+ const dur = typeof clip?.duration === "number" && clip.duration > 0 ? clip.duration : Infinity;
137
+ if (!Array.isArray(clip?.keys) || clip.keys.length === 0) {
138
+ problems.push(`${label} needs at least one key`);
139
+ return { ok: false, problems };
140
+ }
141
+ let prev = -Infinity;
142
+ clip.keys.forEach((k, i) => {
143
+ if (!(typeof k.t === "number" && Number.isFinite(k.t)) || k.t < 0 || k.t > dur + 1e-9) problems.push(`${label} key ${i} has t=${String(k.t)} outside 0..${dur}`);
144
+ else if (k.t < prev) problems.push(`${label} key ${i} goes back in time (${k.t} < ${prev})`);
145
+ else prev = k.t;
146
+ for (const f of ["position", "rotation"]) if (k[f] !== void 0 && !finite3(k[f])) problems.push(`${label} key ${i} has an invalid ${f}`);
147
+ for (const [pid, pose] of Object.entries(k.parts ?? {})) {
148
+ if (!parts.has(pid)) problems.push(`${label} key ${i} moves unknown part "${pid}"`);
149
+ for (const f of ["position", "rotation"]) if (pose?.[f] !== void 0 && !finite3(pose[f])) problems.push(`${label} key ${i} part "${pid}" has an invalid ${f}`);
150
+ }
151
+ });
152
+ let prevEv = -Infinity;
153
+ (clip.events ?? []).forEach((e, i) => {
154
+ if (!(typeof e.t === "number" && Number.isFinite(e.t)) || e.t < 0 || e.t > dur + 1e-9) problems.push(`${label} event ${i} has t=${String(e.t)} outside 0..${dur}`);
155
+ else if (e.t < prevEv) problems.push(`${label} event ${i} goes back in time`);
156
+ else prevEv = e.t;
157
+ if (typeof e.type !== "string" || e.type === "") problems.push(`${label} event ${i} needs a type`);
158
+ try {
159
+ JSON.stringify(e.data ?? {});
160
+ } catch {
161
+ problems.push(`${label} event ${i} data is not JSON`);
162
+ }
163
+ });
164
+ return { ok: problems.length === 0, problems };
165
+ };
166
+ export {
167
+ IMPACT_CONTRACT,
168
+ checkAnimation,
169
+ checkDestructible,
170
+ checkHit,
171
+ shotToHit
172
+ };
173
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/impact.ts","../src/weapons.ts","../src/animation.ts"],"sourcesContent":["import type { DamageType, DestructibleSpec, DestructionEvent, Hit, JointSpec, ObjectState, ToolKind } from './destruction'\n\n/**\n * What a game module implements for an object whose behaviour it owns (a vehicle with its own panel deformation, a creature, a machine). The\n * world (`DestructionWorld.register`) hosts it next to its own objects: raycast, shoot, explode, hit, disassemble, extinguish, update, state,\n * reset and `on` all route to it.\n *\n * Space: the impl receives hits in WORLD space and returns events in WORLD space (it owns its transform; the transform given to `register` or\n * `setTransform` is only used by the world for raycasts and blast range). Every event must carry `object === id` and name parts listed by\n * `describe()`.\n */\nexport interface DestructibleImpl {\n readonly id: string\n readonly name?: string\n /** Parts, joints and structure in the impl's local space, for raycast, inspector and log. Called often: keep it cheap. */\n describe(): DestructibleSpec\n /** Apply one hit (see `IMPACT_CONTRACT` for the fields per type) and return the events it caused. */\n hit(hit: Hit): DestructionEvent[]\n /** Advance fire, melting, collapse and other timed behaviour. */\n update?(dt: number): DestructionEvent[]\n state(): ObjectState\n reset?(): void\n /** Same contract as `DestructionWorld.disassemble`: progress 0..1, or -1 when the tool cannot undo the joint. */\n disassemble?(jointId: string, tool: ToolKind, dt: number): number\n extinguish?(partId?: string): void\n /** Plain JSON of the impl's own state, stored in `DestructionSnapshot.impls`. */\n serialize?(): unknown\n load?(data: unknown): void\n}\n\n/** The fields a weapon or hazard must put in a `Hit`, per damage type. THE impact contract. */\nexport interface ImpactContract {\n required: string[]\n optional: string[]\n note: string\n}\n\nexport const IMPACT_CONTRACT: Record<DamageType, ImpactContract> = {\n ballistic: { required: ['type', 'point', 'direction', 'energy', 'caliber'], optional: ['space', 'source'], note: 'bullets and pellets: joules and diameter in millimetres' },\n blunt: { required: ['type', 'point', 'energy'], optional: ['direction', 'radius', 'space', 'source'], note: 'contact radius in metres (default 3 cm)' },\n slash: { required: ['type', 'point', 'energy'], optional: ['direction', 'radius', 'space', 'source'], note: 'axes, knives, machetes' },\n explosive: { required: ['type', 'point', 'energy', 'radius'], optional: ['space', 'source'], note: 'point is the centre of the blast, radius the range in metres' },\n fire: { required: ['type', 'point', 'temperature', 'radius'], optional: ['duration', 'space', 'source'], note: 'flame temperature in °C; duration in seconds (call every frame with `dt`)' },\n heat: { required: ['type', 'point', 'temperature', 'radius'], optional: ['duration', 'space', 'source'], note: 'heat without flame (cutting torch, hot plate)' },\n}\n\n/** Problems with a hit according to the impact contract (empty when it is valid). */\nexport const checkHit = (hit: Hit): string[] => {\n const c = IMPACT_CONTRACT[hit.type]\n if (!c) return [`unknown damage type \"${String(hit.type)}\"`]\n const out: string[] = []\n for (const f of c.required) {\n const v = (hit as unknown as Record<string, unknown>)[f]\n if (v === undefined || (Array.isArray(v) ? v.some((n) => !Number.isFinite(n)) : typeof v === 'number' && !Number.isFinite(v))) out.push(`${hit.type} hit needs \"${f}\"`)\n }\n return out\n}\n\nexport interface CheckOptions {\n /**\n * Ids of every material the impl may use (the contracts package does not know the materials of your world: pass the ids of\n * `world.materials`, or the built-in plus your own). When omitted, the material check is skipped.\n */\n materials?: Iterable<string>\n}\n\nconst finiteJson = (v: unknown, path: string, out: string[]) => {\n if (typeof v === 'number') {\n if (!Number.isFinite(v)) out.push(`${path} is not a finite number`)\n } else if (Array.isArray(v)) v.forEach((x, i) => finiteJson(x, `${path}[${i}]`, out))\n else if (v && typeof v === 'object') for (const [k, x] of Object.entries(v)) finiteJson(x, `${path}.${k}`, out)\n else if (typeof v === 'function' || typeof v === 'symbol' || typeof v === 'bigint') out.push(`${path} is not JSON`)\n}\n\n/**\n * Contract checker for the test room (it needs no world): `describe()` is valid, a 500 J ballistic hit at a part centre returns well-formed events of this impl, `state()`\n * matches `describe()`, hit points never go negative, `update(0.016)` returns an array and every event is JSON-serializable. It hits the impl\n * (and calls `reset()` afterwards when there is one).\n */\nexport const checkDestructible = (impl: DestructibleImpl, options: CheckOptions = {}): { ok: boolean; problems: string[] } => {\n const problems: string[] = []\n const known = options.materials ? new Set(options.materials) : null\n let spec: DestructibleSpec | undefined\n try {\n spec = impl.describe()\n } catch (e) {\n return { ok: false, problems: [`describe() threw: ${String(e)}`] }\n }\n if (!spec || !Array.isArray(spec.parts) || spec.parts.length === 0) return { ok: false, problems: ['describe() must return at least one part'] }\n const ids = new Set<string>()\n for (const p of spec.parts) {\n if (ids.has(p.id)) problems.push(`duplicate part id \"${p.id}\"`)\n ids.add(p.id)\n if (known && !known.has(p.material)) problems.push(`part \"${p.id}\" has unknown material \"${p.material}\"`)\n if (!p.shape || !['box', 'cylinder', 'sphere'].includes(p.shape.kind)) problems.push(`part \"${p.id}\" has no valid shape`)\n if (!Array.isArray(p.position) || p.position.length !== 3) problems.push(`part \"${p.id}\" has no position`)\n }\n const jointIds = new Set<string>()\n for (const j of (spec.joints ?? []) as JointSpec[]) {\n if (!ids.has(j.a) || !ids.has(j.b)) problems.push(`joint \"${j.id ?? `${j.a}~${j.b}`}\" references an unknown part`)\n const jid = j.id ?? `${j.a}~${j.b}`\n if (jointIds.has(jid)) problems.push(`duplicate joint id \"${jid}\"`)\n jointIds.add(jid)\n }\n const checkState = (label: string) => {\n let st: ObjectState\n try {\n st = impl.state()\n } catch (e) {\n problems.push(`state() threw ${label}: ${String(e)}`)\n return\n }\n const sids = st.parts.map((p) => p.id).sort().join(',')\n if (sids !== [...ids].sort().join(',')) problems.push(`state() part ids do not match describe() ${label}`)\n for (const p of st.parts) if (!(p.hp >= 0)) problems.push(`part \"${p.id}\" has negative or invalid hp ${label}`)\n }\n const checkEvents = (events: unknown, label: string) => {\n if (!Array.isArray(events)) {\n problems.push(`${label} must return an array`)\n return\n }\n const evs = events as DestructionEvent[]\n evs.forEach((e, i) => {\n if (e.object !== impl.id) problems.push(`${label} event ${i} (${e.type}) has object \"${String(e.object)}\", expected \"${impl.id}\"`)\n const part = (e as { part?: string }).part\n if (part !== undefined && !ids.has(part)) problems.push(`${label} event ${i} (${e.type}) names unknown part \"${part}\"`)\n })\n const bad: string[] = []\n finiteJson(evs, 'events', bad)\n problems.push(...bad.map((b) => `${label}: ${b}`))\n try {\n const s = JSON.stringify(evs)\n if (JSON.stringify(JSON.parse(s)) !== s) problems.push(`${label} events do not survive a JSON round trip`)\n } catch (e) {\n problems.push(`${label} events are not JSON-serializable: ${String(e)}`)\n }\n }\n checkState('before the hit')\n const target = spec.parts[0]\n try {\n const hit: Hit = { type: 'ballistic', point: [target.position[0], target.position[1], target.position[2]], direction: [0, 0, -1], energy: 500, caliber: 9 }\n checkEvents(impl.hit(hit), 'hit()')\n } catch (e) {\n problems.push(`hit() threw: ${String(e)}`)\n }\n checkState('after the hit')\n if (impl.update) {\n try {\n checkEvents(impl.update(0.016), 'update()')\n } catch (e) {\n problems.push(`update() threw: ${String(e)}`)\n }\n checkState('after update')\n }\n try {\n impl.reset?.()\n } catch (e) {\n problems.push(`reset() threw: ${String(e)}`)\n }\n return { ok: problems.length === 0, problems }\n}\n","import type { Hit, Vec3 } from './destruction'\n\n/**\n * A ballistic shot (one per pellet) as a weapon module produces it. Plain data: any damage model can consume it (`shotToHit` makes the `Hit`).\n */\nexport interface Shot {\n origin: Vec3\n /** Unit vector. */\n direction: Vec3\n /** Muzzle energy in joules. */\n energy: number\n /** Bullet diameter in millimetres. */\n caliber: number\n /** snake_case calibre id, e.g. `9x19`. */\n caliberId: string\n /** Muzzle speed in m/s. */\n speed: number\n /** Energy at a distance in metres, with the calibre's drag. */\n energyAt(distance: number): number\n pellet: number\n /** snake_case weapon id. */\n weapon: string\n source?: string\n}\n\n/** One use of a non-firearm (melee swing, flame tick, heat tick, throw, tool tick, extinguisher tick). */\nexport type Use =\n | { kind: 'melee'; damage: 'blunt' | 'slash'; energy: number; radius: number; reach: number; origin: Vec3; direction: Vec3 }\n | { kind: 'flame'; temperature: number; radius: number; range: number; cone: boolean; duration: number; origin: Vec3; direction: Vec3 }\n | { kind: 'heat'; temperature: number; radius: number; range: number; duration: number; origin: Vec3; direction: Vec3 }\n | { kind: 'throw'; energy: number; radius: number; fuse: number; velocity: Vec3; origin: Vec3; fire?: { temperature: number; radius: number; seconds: number } }\n | { kind: 'tool'; tool: string; reach: number; duration: number; origin: Vec3; direction: Vec3 }\n | { kind: 'extinguish'; range: number; coolC: number; duration: number; origin: Vec3; direction: Vec3 }\n | { kind: 'hand'; reach: number; origin: Vec3; direction: Vec3 }\n\n/**\n * The `Hit` a ballistic shot makes at `point` (world space): the energy is what is left of the shot at that distance from its origin\n * (`shot.energyAt`), the direction and calibre come from the shot. `normal` (the surface normal at the point, when the caller knows it) does not\n * change the hit; it is accepted so that callers can pass what their raycast returned and so that a stricter implementation could use it.\n */\nexport const shotToHit = (shot: Shot, point: Vec3, normal?: Vec3): Hit => {\n void normal\n const dx = point[0] - shot.origin[0]\n const dy = point[1] - shot.origin[1]\n const dz = point[2] - shot.origin[2]\n const distance = Math.hypot(dx, dy, dz)\n return {\n type: 'ballistic',\n point: [point[0], point[1], point[2]],\n direction: [shot.direction[0], shot.direction[1], shot.direction[2]],\n energy: shot.energyAt(distance),\n caliber: shot.caliber,\n source: shot.source ?? shot.weapon,\n }\n}\n","import type { Vec3 } from './destruction'\n\n/** Pose of one part (or of the whole item) at a key: position offset in metres and Euler XYZ rotation in radians, both relative to the rest pose. */\nexport interface AnimationPose {\n position?: Vec3\n rotation?: Vec3\n}\n\nexport interface AnimationKey {\n /** Seconds from the start of the clip. */\n t: number\n /** Pose of the item's root. */\n position?: Vec3\n rotation?: Vec3\n /** Poses of named parts: the key is a destruction part id (a pistol `reload` moves `mag`; a car door `open` rotates `door_l`). */\n parts?: Record<string, AnimationPose>\n}\n\nexport interface AnimationEventSpec {\n /** Seconds from the start of the clip. */\n t: number\n /** snake_case type the host maps (`sound`, `eject_casing`, `door_latch`...). */\n type: string\n data?: Record<string, unknown>\n}\n\n/** A use animation a module brings with its item. Poses between keys are interpolated by the player (the test room does it linearly). */\nexport interface AnimationClipSpec {\n /** snake_case: `reload`, `open`, `drink`... Unique within the item. */\n id: string\n /** Seconds. */\n duration: number\n keys: AnimationKey[]\n events?: AnimationEventSpec[]\n}\n\n/** What an item exposes when it brings its own animations. */\nexport interface ItemAnimationContract {\n animations: AnimationClipSpec[]\n}\n\nconst finite3 = (v: unknown): boolean => Array.isArray(v) && v.length === 3 && v.every((n) => typeof n === 'number' && Number.isFinite(n))\n\n/**\n * Problems with a clip (empty when it is valid): a snake_case id, a positive finite duration, at least one key, key and event times inside\n * `[0, duration]` and not going backwards, finite vectors, every named part one of `partIds`, event types that are non-empty strings and\n * JSON-serializable event data.\n */\nexport const checkAnimation = (clip: AnimationClipSpec, partIds: Iterable<string>): { ok: boolean; problems: string[] } => {\n const problems: string[] = []\n const parts = new Set(partIds)\n const id = String(clip?.id ?? '')\n if (!/^[a-z][a-z0-9_]*$/.test(id)) problems.push(`clip id \"${id}\" must be snake_case`)\n const label = `clip \"${id}\"`\n if (!(typeof clip?.duration === 'number' && Number.isFinite(clip.duration) && clip.duration > 0)) problems.push(`${label} needs a positive finite duration`)\n const dur = typeof clip?.duration === 'number' && clip.duration > 0 ? clip.duration : Infinity\n if (!Array.isArray(clip?.keys) || clip.keys.length === 0) {\n problems.push(`${label} needs at least one key`)\n return { ok: false, problems }\n }\n let prev = -Infinity\n clip.keys.forEach((k, i) => {\n if (!(typeof k.t === 'number' && Number.isFinite(k.t)) || k.t < 0 || k.t > dur + 1e-9) problems.push(`${label} key ${i} has t=${String(k.t)} outside 0..${dur}`)\n else if (k.t < prev) problems.push(`${label} key ${i} goes back in time (${k.t} < ${prev})`)\n else prev = k.t\n for (const f of ['position', 'rotation'] as const) if (k[f] !== undefined && !finite3(k[f])) problems.push(`${label} key ${i} has an invalid ${f}`)\n for (const [pid, pose] of Object.entries(k.parts ?? {})) {\n if (!parts.has(pid)) problems.push(`${label} key ${i} moves unknown part \"${pid}\"`)\n for (const f of ['position', 'rotation'] as const) if (pose?.[f] !== undefined && !finite3(pose[f])) problems.push(`${label} key ${i} part \"${pid}\" has an invalid ${f}`)\n }\n })\n let prevEv = -Infinity\n ;(clip.events ?? []).forEach((e, i) => {\n if (!(typeof e.t === 'number' && Number.isFinite(e.t)) || e.t < 0 || e.t > dur + 1e-9) problems.push(`${label} event ${i} has t=${String(e.t)} outside 0..${dur}`)\n else if (e.t < prevEv) problems.push(`${label} event ${i} goes back in time`)\n else prevEv = e.t\n if (typeof e.type !== 'string' || e.type === '') problems.push(`${label} event ${i} needs a type`)\n try {\n JSON.stringify(e.data ?? {})\n } catch {\n problems.push(`${label} event ${i} data is not JSON`)\n }\n })\n return { ok: problems.length === 0, problems }\n}\n"],"mappings":";AAqCO,IAAM,kBAAsD;AAAA,EACjE,WAAW,EAAE,UAAU,CAAC,QAAQ,SAAS,aAAa,UAAU,SAAS,GAAG,UAAU,CAAC,SAAS,QAAQ,GAAG,MAAM,0DAA0D;AAAA,EAC3K,OAAO,EAAE,UAAU,CAAC,QAAQ,SAAS,QAAQ,GAAG,UAAU,CAAC,aAAa,UAAU,SAAS,QAAQ,GAAG,MAAM,0CAA0C;AAAA,EACtJ,OAAO,EAAE,UA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AAM;AACrC,QAAI,EAAE,OAAO,EAAE,MAAM,YAAY,OAAO,SAAS,EAAE,CAAC,MAAM,EAAE,IAAI,KAAK,EAAE,IAAI,MAAM,KAAM,UAAS,KAAK,GAAG,KAAK,UAAU,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC,eAAe,GAAG,EAAE;AAAA,aACxJ,EAAE,IAAI,OAAQ,UAAS,KAAK,GAAG,KAAK,UAAU,CAAC,oBAAoB;AAAA,QACvE,UAAS,EAAE;AAChB,QAAI,OAAO,EAAE,SAAS,YAAY,EAAE,SAAS,GAAI,UAAS,KAAK,GAAG,KAAK,UAAU,CAAC,eAAe;AACjG,QAAI;AACF,WAAK,UAAU,EAAE,QAAQ,CAAC,CAAC;AAAA,IAC7B,QAAQ;AACN,eAAS,KAAK,GAAG,KAAK,UAAU,CAAC,mBAAmB;AAAA,IACtD;AAAA,EACF,CAAC;AACD,SAAO,EAAE,IAAI,SAAS,WAAW,GAAG,SAAS;AAC/C;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,52 @@
1
1
  {
2
2
  "name": "@adatechnology/game-contracts",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "description": "The contracts every game module depends on, and nothing else: destruction (parts, hits, events, DestructibleImpl), weapons (shots), fluids (containers, item uses), item animations and the TestableModule a module hands the test room. Types plus tiny checkers, no runtime dependencies.",
6
+ "keywords": [
7
+ "game",
8
+ "contracts",
9
+ "types",
10
+ "destruction",
11
+ "weapons",
12
+ "fluids",
13
+ "animation",
14
+ "modules"
15
+ ],
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/Andersonfrfilho/adatechnology-game-kit.git",
19
+ "directory": "packages/game-contracts"
20
+ },
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "type": "module",
25
+ "main": "dist/index.js",
26
+ "module": "dist/index.js",
27
+ "types": "dist/index.d.ts",
28
+ "unpkg": "dist/index.global.js",
29
+ "jsdelivr": "dist/index.global.js",
30
+ "sideEffects": false,
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/index.d.ts",
34
+ "import": "./dist/index.js"
35
+ },
36
+ "./global": "./dist/index.global.js"
37
+ },
38
+ "files": [
39
+ "dist"
40
+ ],
41
+ "devDependencies": {
42
+ "@types/node": "^22.10.7",
43
+ "tsup": "^8.5.1",
44
+ "typescript": "^5.7.3",
45
+ "vitest": "^3.2.4"
46
+ },
47
+ "scripts": {
48
+ "build": "tsup",
49
+ "typecheck": "tsc -p tsconfig.json --noEmit",
50
+ "test": "vitest run"
51
+ }
6
52
  }