@adatechnology/game-vfx 0.0.0-stage → 0.1.1
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 +21 -0
- package/README.md +85 -2
- package/dist/index.d.ts +1703 -0
- package/dist/index.global.js +7985 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +7962 -0
- package/dist/index.js.map +1 -0
- package/package.json +51 -3
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,86 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @adatechnology/game-vfx
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Visual effects with no renderer, deterministic and testable in Node. It knows nothing about any game: the host gives it a camera position and a clock,
|
|
4
|
+
calls `update(dt)`, and reads plain pools (`puffs`, `sparks`, `glows`, `chunks`, `shocks`, `rings`, lights, marks) that a renderer draws (see
|
|
5
|
+
[`@adatechnology/game-vfx-three`](../game-vfx-three)).
|
|
6
|
+
|
|
7
|
+
It is a literal port of the Explosion Lab of the effects team: the layer compositor (`blast`) and the simulation loops, with the same draws from the
|
|
8
|
+
same seeded stream in the same order, so the same seed gives the same explosion.
|
|
9
|
+
|
|
10
|
+
- **Layers of an explosion**, in the Lab's order: flash and light, fireball that cools into smoke, the explosion's own smoke, shock wave (it pushes the
|
|
11
|
+
smoke it meets), low dust, shrapnel and embers, glowing debris, then marks on the ground (scorch, crater with a dented ground field and rim rocks),
|
|
12
|
+
mushroom cloud, lingering fires. Six layers can be turned off one by one (`flash`, `fire`, `shock`, `smoke`, `shrapnel`, `mark`).
|
|
13
|
+
- **Pools** (`OrderedPool`): live records in the order they were added, reused instead of allocated, compacted in place. A full pool drops the oldest
|
|
14
|
+
record (chunks drop a resting one first).
|
|
15
|
+
- **Random** (`lehmer`, `lcg`, `streamFor`): `randomMode: 'per_event'` (default) gives each explosion a stream of its own seed, so a LAN client repeats the
|
|
16
|
+
visual from a few bytes whatever else is playing; `'shared'` uses one stream for everything, like the Lab page (the goldens).
|
|
17
|
+
- **LOD and cap**: `LOD_GAME` (15 / 40 / 80 m, scales 1 / .5 / .2 / .1, default) and `LOD_LAB`; the game's area cap (the 7th explosion within 40 m in 4 s
|
|
18
|
+
is made at 0.3, `AREA_CAP_GAME`).
|
|
19
|
+
- **Screen** (`screen()`): shake, flash (the flash grenade blinds only who is near), and the Workshop's white, red, sides, chroma, desaturation, gas and beat,
|
|
20
|
+
with the same decays.
|
|
21
|
+
- **Budgets**: `PROFILES` (`high` bench and goldens, `medium` game default, `low`), `EVENT_BUDGET` (400 particles, 40 debris, 4 + 2 lights) and
|
|
22
|
+
`estimateCost(def)` (the number of the Lab's effect sheet).
|
|
23
|
+
- **Side requests** (`onRequest`): what an effect cannot do alone. `crater` (dig a ground you own), `blast_front` (glass, characters, with `speed` 340 m/s so
|
|
24
|
+
the host delays by distance) and `ignite` (characters inside the radius catch fire).
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { createGroundField, createVfx, LOD_LAB } from '@adatechnology/game-vfx'
|
|
28
|
+
|
|
29
|
+
const vfx = createVfx({
|
|
30
|
+
seed: 42,
|
|
31
|
+
profile: 'high',
|
|
32
|
+
lod: LOD_LAB,
|
|
33
|
+
ground: createGroundField(), // optional: craters dig it, bouncing things read it
|
|
34
|
+
explosions: myExplosions, // Record<string, ExplosionDef>; the 16 of the Lab arrive with the catalogue
|
|
35
|
+
onRequest: (request) => host.handle(request),
|
|
36
|
+
})
|
|
37
|
+
vfx.setCamera([10, 6.5, 14])
|
|
38
|
+
vfx.explosion('m67', [0, 0.1, 0], { seed: 7 }) // or { direction: [1, 0, 0], scale: 2, delay: 0.5 }
|
|
39
|
+
vfx.fire({ point: [2, 0, 0], radius: 1.4, life: 7 })
|
|
40
|
+
|
|
41
|
+
// every frame
|
|
42
|
+
vfx.update(dt)
|
|
43
|
+
render(vfx.pools(), vfx.screen())
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`explosion` answers a handle (or `null` for an unknown id), `stop(handle)` ends a fire, `clear()` takes everything away and restarts the clock, `stats()`
|
|
47
|
+
reports what is alive, what the last explosion made, the scale it was made at and the seconds since.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## Workshop recipes, sprites and event effects
|
|
51
|
+
|
|
52
|
+
`vfx.play(id, point, { direction?, normal?, seed?, param? })` plays one of the **36 recipes of the Workshop of VFX** (blood by infection age, headshot,
|
|
53
|
+
dismemberment, bloater cloud, scream, muzzle flashes by weapon, impact by material, glass, doors, collapses, fires, cars, the screen effects) into the
|
|
54
|
+
Workshop pools (`vfx.workshop()`: additive and normal sprites, streaks, physics debris, decals, rings, flash and fire lights, screen state). The recipes
|
|
55
|
+
are **data** (`WORKSHOP_EFFECTS`, `EffectDef`: a small language of expressions and steps) that a runner executes in the page's own order of random draws,
|
|
56
|
+
so the goldens (`tests/workshop-golden.test.ts`, 162 assertions over 54 runs) replay the recording of the page. `param` picks the variant of a recipe by
|
|
57
|
+
index or id (`'fresh'`, `'ak'`, `'concrete'`); `anchor` and `heading` of the recipe place and turn it at `point` and `direction`; `seed` makes it
|
|
58
|
+
repeatable on a LAN client. `patchEffects(base, changes)` tunes, adds or removes recipes like `patchExplosions` does.
|
|
59
|
+
|
|
60
|
+
`vfx.burst(kind, point, normal, count, speed?)` and `vfx.spawn(kind, point, velocity)` are the **sprite kinds** that destruction, fluids and weapons share
|
|
61
|
+
(debris, sparks, ash, steam, drips, leaks...: `data/sprite-kinds.json`, `patchSpriteKinds`), with `onLand(owner, ...)` to hear where a drop touched the ground.
|
|
62
|
+
|
|
63
|
+
`effectForEvent(event)` maps the destruction events to effects (`data/event-effects.json`): `spall` plays `impact_<material>`, the stages `stage_crack`,
|
|
64
|
+
`breach_dust` and `collapse_dust`, `expose` `rebar_expose`, a fracture of glass `glass_burst`; `muzzle_*` and `casing_*` are the weapon slices. `GAME_EFFECTS`
|
|
65
|
+
is the recipes plus these, what a world plays by default. Texts of every recipe (name, cost, when, look, budget, network) are in `locales` (`en`, `pt-BR`).
|
|
66
|
+
|
|
67
|
+
## Install
|
|
68
|
+
|
|
69
|
+
```sh
|
|
70
|
+
pnpm add @adatechnology/game-vfx
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Browser without a bundler (the global is `GameVfx`):
|
|
74
|
+
|
|
75
|
+
```html
|
|
76
|
+
<script src="https://unpkg.com/@adatechnology/game-vfx/dist/index.global.js"></script>
|
|
77
|
+
<script>
|
|
78
|
+
const vfx = GameVfx.createVfx({ seed: 1 })
|
|
79
|
+
</script>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Port invariants
|
|
83
|
+
|
|
84
|
+
Each one has a test: pools iterate in insertion order and compact in place; every puff draws its seed even when the caller gives one; chunks draw
|
|
85
|
+
rotation and spin first and a hot one adds a halo drawn after; due timers run from the last added to the first; colours are converted once, at spawn;
|
|
86
|
+
no pool grows past its profile. The goldens (`tests/team-golden.test.ts`) replay the Lab's 16 scenes against a recording of the page.
|