@adatechnology/game-vehicles-proving 0.0.0-stage → 0.1.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Anderson Fernandes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,228 @@
1
+ import { DesignStats, BodyDimensions, SemiSimSpec, SemiState, SemiInput, SurfaceRegistry, SemiDriver } from '@adatechnology/game-vehicles-driving';
2
+
3
+ /** Where a vehicle moves: on the ground, on water or in the air. Each domain has its own rooms. */
4
+ type ProvingDomain = 'land' | 'water' | 'air';
5
+ /** The vehicle under test: what the runner needs to drive it, with no three.js. */
6
+ interface ProvingSubject {
7
+ /** Id in the catalogue (`compact_hatch`). */
8
+ id: string;
9
+ domain: ProvingDomain;
10
+ /** Class the ranges are read for (`cars`, `heavy`, `motorcycles`…). Unknown classes use `default`. */
11
+ category: string;
12
+ /** Design ratings from the vehicle's card: acceleration and handling 0-10, top speed in km/h. */
13
+ stats: DesignStats;
14
+ body: BodyDimensions;
15
+ /** Overrides of the semi-simulation spec built from the stats (a game that has measured its own car). */
16
+ spec?: Partial<SemiSimSpec>;
17
+ }
18
+ /** Accepted band of a measured value; a missing side is open. */
19
+ interface ProvingRange {
20
+ min?: number;
21
+ max?: number;
22
+ }
23
+ /** pass: inside the range or signed off; fail: outside or refused; pending: not run yet, its room is not built, or nobody looked yet. */
24
+ type ProvingVerdict = 'pass' | 'fail' | 'pending';
25
+ interface ProvingResult {
26
+ test: string;
27
+ kind: ProvingTestKind;
28
+ verdict: ProvingVerdict;
29
+ /** The measured number (null for a visual check or a test that did not finish). */
30
+ value: number | null;
31
+ unit: string;
32
+ range: ProvingRange;
33
+ /** Why it is pending or failed, or what the number means for this vehicle (target speed lowered for a slow vehicle). */
34
+ note?: string;
35
+ /** Samples of the run, [seconds, value], for a chart. */
36
+ trace?: Array<[number, number]>;
37
+ /** Who signed a visual check off, and the print that proves it. */
38
+ signedBy?: string;
39
+ evidence?: string;
40
+ }
41
+ /**
42
+ * measured: run on the semi-simulation driver and compared with a range.
43
+ * visual: a person looks at it in the test room and signs it off with a print (animations, cameras, mirrors).
44
+ * room: needs a room of a later phase (terrain, wind tunnel, crash test); pending until that room reports a result.
45
+ */
46
+ type ProvingTestKind = 'measured' | 'visual' | 'room';
47
+ /** What a measured test asks of the driver every step, and what it reads back. */
48
+ interface ProvingProcedure {
49
+ /** Surface under the wheels for the whole run (default `dry_asphalt`). */
50
+ surface?: string;
51
+ /** The run stops here whatever happens. */
52
+ maxSeconds: number;
53
+ /** Speed (km/h) the run aims for, when it has one; `memo.target` holds it during the run. */
54
+ target?(subject: ProvingSubject): number;
55
+ input(state: SemiState, time: number, memo: ProvingMemo): SemiInput;
56
+ /** The number drawn on the chart this step. */
57
+ sample(state: SemiState, time: number, memo: ProvingMemo): number;
58
+ finished(state: SemiState, time: number, memo: ProvingMemo): boolean;
59
+ value(state: SemiState, time: number, memo: ProvingMemo): number | null;
60
+ }
61
+ /** Bookkeeping of one run, shared by the procedure's functions. */
62
+ interface ProvingMemo {
63
+ target: number;
64
+ subject: ProvingSubject;
65
+ [key: string]: unknown;
66
+ }
67
+ interface ProvingTest {
68
+ /** snake_case id. */
69
+ id: string;
70
+ kind: ProvingTestKind;
71
+ /** Domains it applies to. */
72
+ domains: readonly ProvingDomain[];
73
+ unit: string;
74
+ /** Measured tests only. */
75
+ procedure?: ProvingProcedure;
76
+ /** The accepted band for this subject (measured tests). */
77
+ range?(subject: ProvingSubject): ProvingRange;
78
+ /** Room tests: false while the room is not built, so the test stays pending. */
79
+ available?: boolean;
80
+ }
81
+ interface ProvingCertificate {
82
+ vehicle: string;
83
+ domain: ProvingDomain;
84
+ category: string;
85
+ /** approved: every test passed. rejected: at least one failed. pending: none failed, some not done. */
86
+ status: 'approved' | 'rejected' | 'pending';
87
+ results: ProvingResult[];
88
+ }
89
+
90
+ /** The semi-simulation spec the runner drives a subject with: from the card's ratings and the body, with the subject's own overrides. */
91
+ declare const subjectSpec: (subject: ProvingSubject) => SemiSimSpec;
92
+ /** One measured test in progress. A host steps it with the frame's seconds and draws `driver.state`; `runTest` steps it to the end in one go. */
93
+ interface ProvingRun {
94
+ readonly test: ProvingTest;
95
+ readonly subject: ProvingSubject;
96
+ readonly driver: SemiDriver;
97
+ readonly surface: string;
98
+ readonly time: number;
99
+ readonly done: boolean;
100
+ /** [seconds, sample] of the run so far. */
101
+ readonly trace: ReadonlyArray<[number, number]>;
102
+ readonly memo: ProvingMemo;
103
+ step(dt: number): void;
104
+ /** The result so far; pending while the run has not ended. */
105
+ result(): ProvingResult;
106
+ }
107
+ interface RunOptions {
108
+ surfaces?: SurfaceRegistry;
109
+ /** Seconds between two trace samples (default 0.1). */
110
+ sampleEvery?: number;
111
+ /** Fixed step of the simulation (default 1/120 s); `step(dt)` splits the frame into steps this long. */
112
+ fixedStep?: number;
113
+ }
114
+ declare function startRun(test: ProvingTest, subject: ProvingSubject, options?: RunOptions): ProvingRun;
115
+ /** Runs a measured test to its end and returns the result. */
116
+ declare function runTest(test: ProvingTest, subject: ProvingSubject, options?: RunOptions): ProvingResult;
117
+
118
+ /**
119
+ * The numbers the ranges come from. Real-world bands for road vehicles (a family car stops from 100 km/h in 35-45 m, turns in 10-11 m, a hatch reaches 100 km/h in about 10 s); every one can
120
+ * be replaced per class through `createProvingTests({ ranges })`.
121
+ */
122
+ interface RangeTable {
123
+ /** 0-100 km/h seconds by the card's acceleration rating (0-10). */
124
+ accelerationSeconds: ReadonlyArray<readonly [number, number]>;
125
+ /** Accepted spread around the expected 0-100 time (0.35 = ±35 %). */
126
+ accelerationSpread: number;
127
+ /** Accepted spread around the card's top speed. */
128
+ topSpeedSpread: number;
129
+ /** Braking deceleration on dry asphalt, m/s², by class. */
130
+ dryBrake: Readonly<Record<string, readonly [number, number]>>;
131
+ /** Braking deceleration on wet asphalt, m/s², by class. */
132
+ wetBrake: Readonly<Record<string, readonly [number, number]>>;
133
+ /** Turning circle diameter, metres, by class. */
134
+ turnCircle: Readonly<Record<string, readonly [number, number]>>;
135
+ /** Metres a four-wheel-drive vehicle has to cover in the mud test. */
136
+ mudFourWheelDrive: number;
137
+ }
138
+ declare const defaultRangeTable: RangeTable;
139
+ /** Expected 0-100 (or 0-`target`) seconds for a subject. Below 100 km/h the time scales linearly with the target speed. */
140
+ declare const expectedAcceleration: (table: RangeTable, subject: ProvingSubject, target: number) => number;
141
+ declare const accelerationRange: (table: RangeTable, subject: ProvingSubject, target: number) => ProvingRange;
142
+ declare const topSpeedRange: (table: RangeTable, subject: ProvingSubject) => ProvingRange;
143
+ /** Stopping distance band from `kmh` for the class's deceleration band. */
144
+ declare const brakeRange: (decel: readonly [number, number], kmh: number) => ProvingRange;
145
+ declare const dryBrakeRange: (table: RangeTable, subject: ProvingSubject, kmh: number) => ProvingRange;
146
+ declare const wetBrakeRange: (table: RangeTable, subject: ProvingSubject, kmh: number) => ProvingRange;
147
+ declare const turnCircleRange: (table: RangeTable, subject: ProvingSubject) => ProvingRange;
148
+ declare const inRange: (value: number, range: ProvingRange) => boolean;
149
+
150
+ /** The tests of the kit. Every number comes from the range table; a game replaces the table, patches a test or adds its own. */
151
+ declare function defaultProvingTests(ranges?: RangeTable): ProvingTest[];
152
+ interface ProvingTestOptions {
153
+ /** Replaces numbers of the range table (`{ turnCircle: { heavy: [12, 28] } }`). Nested tables are merged by class. */
154
+ ranges?: Partial<RangeTable>;
155
+ /** Tests a game adds (or replaces by id). */
156
+ packs?: ReadonlyArray<{
157
+ tests?: readonly ProvingTest[];
158
+ }>;
159
+ patch?: Readonly<Record<string, Partial<ProvingTest>>>;
160
+ remove?: readonly string[];
161
+ }
162
+ interface ProvingTestRegistry {
163
+ readonly tests: readonly ProvingTest[];
164
+ get(id: string): ProvingTest | undefined;
165
+ /** The tests that apply to a domain, in order. */
166
+ forDomain(domain: ProvingSubject['domain']): ProvingTest[];
167
+ readonly ranges: RangeTable;
168
+ }
169
+ declare function createProvingTests(options?: ProvingTestOptions): ProvingTestRegistry;
170
+
171
+ /** A person's verdict on a visual check (or on a room test run by hand), with the print that shows it. */
172
+ interface SignOff {
173
+ vehicle: string;
174
+ test: string;
175
+ ok: boolean;
176
+ by?: string;
177
+ evidence?: string;
178
+ note?: string;
179
+ }
180
+ interface CertifyOptions extends RunOptions {
181
+ tests?: ProvingTestRegistry;
182
+ /** Visual and room checks already signed off. */
183
+ signOffs?: readonly SignOff[];
184
+ /** Results reported by rooms of later phases (terrain, crash test), by test id. */
185
+ reports?: readonly ProvingResult[];
186
+ }
187
+ /** approved when every result passed, rejected when any failed, pending otherwise. */
188
+ declare const statusOf: (results: readonly ProvingResult[]) => ProvingCertificate["status"];
189
+ /** Runs every measured test of the subject's domain, takes the sign-offs and the room reports, and gives the certificate. */
190
+ declare function certify(subject: ProvingSubject, options?: CertifyOptions): ProvingCertificate;
191
+ /** Replaces (or adds) one result of a certificate and recomputes its status. */
192
+ declare function withResult(certificate: ProvingCertificate, result: ProvingResult): ProvingCertificate;
193
+ interface GateOptions {
194
+ /** Lets pending vehicles in too (a game in development). Rejected vehicles never get in unless listed in `allow`. */
195
+ allowPending?: boolean;
196
+ /** Ids a game lets in whatever their certificate says. */
197
+ allow?: readonly string[];
198
+ /** Ids a game keeps out whatever their certificate says. */
199
+ deny?: readonly string[];
200
+ }
201
+ /** The ids, of `ids`, that a game lets in: approved ones (and pending ones with `allowPending`), with the game's own allow and deny lists. An id without a certificate counts as pending. */
202
+ declare function gateVehicles(ids: readonly string[], certificates: readonly ProvingCertificate[], options?: GateOptions): string[];
203
+
204
+ /** Kilograms per cubic metre of the bounding box, by group: only used when the card has no mass. */
205
+ declare const DEFAULT_DENSITY: Readonly<Record<string, number>>;
206
+ /** What a catalogue knows of a vehicle: its design ratings, its measured size and its group (a content pack fills it; see `fleetProvingSubject` of game-vehicles-fleet). */
207
+ interface VehicleCardData {
208
+ stats: DesignStats;
209
+ dims: {
210
+ length: number;
211
+ width: number;
212
+ height: number;
213
+ };
214
+ /** Group of the catalogue (`cars`, `heavy`, `water`, `air`…): the class the ranges are read for, and the domain (water and air groups are not land). */
215
+ group: string;
216
+ /** Kilograms. Estimated from the size and the group when absent. */
217
+ mass?: number;
218
+ /** Metres between the axles and between the wheels, measured on the built vehicle. Estimated from the size when absent. */
219
+ wheelbase?: number;
220
+ track?: number;
221
+ fourWheelDrive?: boolean;
222
+ /** Groups whose vehicles float or fly (default `water` and `air`). */
223
+ domains?: Readonly<Record<string, ProvingDomain>>;
224
+ }
225
+ /** A proving subject from what a catalogue knows of a vehicle. */
226
+ declare function subjectFromCard(id: string, card: VehicleCardData): ProvingSubject;
227
+
228
+ export { type CertifyOptions, DEFAULT_DENSITY, type GateOptions, type ProvingCertificate, type ProvingDomain, type ProvingMemo, type ProvingProcedure, type ProvingRange, type ProvingResult, type ProvingRun, type ProvingSubject, type ProvingTest, type ProvingTestKind, type ProvingTestOptions, type ProvingTestRegistry, type ProvingVerdict, type RangeTable, type RunOptions, type SignOff, type VehicleCardData, accelerationRange, brakeRange, certify, createProvingTests, defaultProvingTests, defaultRangeTable, dryBrakeRange, expectedAcceleration, gateVehicles, inRange, runTest, startRun, statusOf, subjectFromCard, subjectSpec, topSpeedRange, turnCircleRange, wetBrakeRange, withResult };