@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.
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.
package/README.md CHANGED
@@ -1,3 +1,121 @@
1
- # Temporary Holding Version
1
+ # @adatechnology/game-contracts
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The contracts every game module depends on, and nothing else. Types plus a few tiny pure checkers, **no runtime dependencies**, MIT.
4
+
5
+ The idea: a vehicle, a chair, a pistol or a house is a *module*. It does not need the default destruction world, a renderer or the test room.
6
+ It only needs to agree on a few shapes, and these are they. The destruction package, the weapons package, the fluids package and the test room all
7
+ depend on this one and re-export what they used to define, so `import { Hit } from '@adatechnology/game-destruction'` keeps working.
8
+
9
+ ```text
10
+ your module ──▶ game-contracts ◀── game-destruction / game-weapons / game-fluids / game-test-room
11
+ ```
12
+
13
+ ## Install
14
+
15
+ ```sh
16
+ pnpm add @adatechnology/game-contracts
17
+ ```
18
+
19
+ Browser without a bundler (the global is `GameContracts`):
20
+
21
+ ```html
22
+ <script src="https://unpkg.com/@adatechnology/game-contracts/dist/index.global.js"></script>
23
+ <script>
24
+ const problems = GameContracts.checkHit({ type: 'blunt', point: [0, 1, 0] })
25
+ </script>
26
+ ```
27
+
28
+ ## What is in it
29
+
30
+ | Contract | Exports | Used for |
31
+ |---|---|---|
32
+ | Destruction | `DestructibleSpec`, `PartSpec`, `Hit`, `DestructionEvent`, `ObjectState`, `PartState`, `JointSpec`... | the vocabulary of parts, joints, hits, events and state |
33
+ | Impact | `IMPACT_CONTRACT`, `checkHit(hit)` | the fields a weapon or hazard must put in a `Hit`, per damage type |
34
+ | Own destruction | `DestructibleImpl`, `checkDestructible(impl, { materials })` | a module that owns its destruction (a car with its own panel rule) |
35
+ | Weapons | `Shot`, `Use`, `shotToHit(shot, point, normal?)` | what a weapon produces, and the `Hit` a shot makes at a point |
36
+ | Fluids | `ContainerSpec`, `LiquidId`, `ItemUseDef` | what an item says about the liquid it holds and how it is used |
37
+ | Animation | `AnimationClipSpec`, `ItemAnimationContract`, `checkAnimation(clip, partIds)` | use animations an item brings (a door `open`, a pistol `reload`) |
38
+ | Module | `TestableModule`, `TestableItem`, `ModuleScenario` | what a module hands the test room |
39
+
40
+ ### Destruction: a module owns its object
41
+
42
+ ```ts
43
+ import type { DestructibleImpl } from '@adatechnology/game-contracts'
44
+ import { checkDestructible } from '@adatechnology/game-contracts'
45
+
46
+ const impl: DestructibleImpl = {
47
+ id: 'rental_car_1',
48
+ describe: () => ({ parts: [/* body, door_l, wheel_fl... in the impl's local space */] }),
49
+ hit: (hit) => [/* events: every one has object === id and names a part listed by describe() */],
50
+ state: () => ({ /* ObjectState */ }),
51
+ }
52
+
53
+ checkDestructible(impl, { materials: world.materials.keys() }) // { ok, problems }
54
+ ```
55
+
56
+ Hits arrive in world space and events go out in world space. `checkDestructible` needs no world: it validates `describe()`, hits the impl with a
57
+ 500 J ballistic hit, and checks that `state()` matches `describe()`, hit points never go negative, `update(0.016)` returns an array and every event is
58
+ well-formed and JSON-serializable. The contracts package does not know your materials: pass their ids (the world's `world.materials.keys()`) or
59
+ leave `materials` out to skip that check.
60
+
61
+ ### Weapons
62
+
63
+ ```ts
64
+ const hit = shotToHit(shot, point) // { type: 'ballistic', energy: shot.energyAt(distance), caliber, direction, ... }
65
+ checkHit(hit) // [] when valid
66
+ ```
67
+
68
+ ### Animations
69
+
70
+ A clip is plain data: keys with poses (offsets from the rest pose, Euler XYZ) for the item root and for named parts, plus events.
71
+ `checkAnimation(clip, partIds)` verifies a snake_case id, a positive duration, ordered times inside the clip, finite vectors, that every moved part
72
+ is one of `partIds`, and well-formed events.
73
+
74
+ ```ts
75
+ const open: AnimationClipSpec = {
76
+ id: 'open',
77
+ duration: 1.2,
78
+ keys: [{ t: 0 }, { t: 1.2, parts: { door_l: { rotation: [0, 1.1, 0] } } }],
79
+ events: [{ t: 0.15, type: 'sound', data: { key: 'door_latch' } }],
80
+ }
81
+ checkAnimation(open, ['body', 'door_l']) // { ok: true, problems: [] }
82
+ ```
83
+
84
+ ### A module for the test room
85
+
86
+ ```ts
87
+ import type { TestableModule } from '@adatechnology/game-contracts'
88
+
89
+ export const RENTAL_CARS: TestableModule = {
90
+ id: 'rental_cars',
91
+ name: 'Rental cars',
92
+ group: 'Rental cars',
93
+ items: (locale) => [{ id: 'rental_car', name: 'Rental car', build: (THREE) => buildCar(THREE), impl: (root, id) => createCarImpl(root, id), animations: [open] }],
94
+ scenarios: (locale) => [/* { id, name, run(ctx) } */],
95
+ }
96
+
97
+ room.loadModule(RENTAL_CARS) // items join the catalogue, scenarios become buttons, contract checks write ✓ / ✗ lines to the log
98
+ ```
99
+
100
+ `build` receives the host's three.js namespace and returns its `Object3D` (both are `unknown` here: this package has no dependency on three.js).
101
+ `impl` receives the object id the host gives the item and `DestructibleImpl.id` must equal it.
102
+
103
+ ## API
104
+
105
+ Everything is exported from the package root; see `src/*.ts` for the doc comments. Units: metres, seconds, joules, millimetres (calibre), degrees Celsius.
106
+
107
+ ## Português
108
+
109
+ Os contratos de que todo módulo de jogo depende, e só isso: tipos mais alguns verificadores pequenos e puros, **sem dependências em tempo de
110
+ execução**. Um carro, uma cadeira, uma pistola ou uma casa é um *módulo*; ele não precisa do mundo de destruição padrão, de um renderizador nem da
111
+ sala de testes, só concordar com estas formas. Os pacotes de destruição, armas, fluidos e a sala de testes dependem deste e reexportam os tipos que
112
+ antes definiam, então `import { Hit } from '@adatechnology/game-destruction'` continua funcionando.
113
+
114
+ - **Destruição própria**: `DestructibleImpl` (o módulo manda no seu objeto) e `checkDestructible(impl, { materiais })`, que valida `describe()`,
115
+ aplica um golpe de 500 J e confere eventos e estado sem precisar de mundo.
116
+ - **Impacto**: `IMPACT_CONTRACT` e `checkHit(hit)` dizem quais campos cada tipo de dano exige.
117
+ - **Armas**: `Shot`, `Use` e `shotToHit(shot, ponto)`.
118
+ - **Fluidos**: `ContainerSpec`, `LiquidId` e `ItemUseDef`.
119
+ - **Animações**: `AnimationClipSpec` e `checkAnimation(clipe, idsDasPeças)` (uma porta `open`, uma pistola `reload`).
120
+ - **Módulo**: `TestableModule` entrega itens, animações e cenários à sala de testes; `room.loadModule(modulo)` roda as verificações e escreve linhas
121
+ ✓ / ✗ no log. Assim o módulo de um carro de aluguel já nasce com as suas animações e o seu jeito de quebrar.