@datamoc/mw_games 0.2.1 → 0.3.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/README.md +395 -352
- package/dist/assets/Streaming.d.ts +10 -4
- package/dist/assets/Streaming.d.ts.map +1 -1
- package/dist/assets/Streaming.js +17 -6
- package/dist/assets/Streaming.js.map +1 -1
- package/dist/assets/index.d.ts +10 -2
- package/dist/assets/index.d.ts.map +1 -1
- package/dist/assets/index.js +8 -4
- package/dist/assets/index.js.map +1 -1
- package/dist/audio/Music.d.ts +10 -0
- package/dist/audio/Music.d.ts.map +1 -1
- package/dist/audio/Music.js +36 -1
- package/dist/audio/Music.js.map +1 -1
- package/dist/audio/Playable.d.ts +3 -0
- package/dist/audio/Playable.d.ts.map +1 -1
- package/dist/audio/Playable.js.map +1 -1
- package/dist/core/Feedback.d.ts +3 -9
- package/dist/core/Feedback.d.ts.map +1 -1
- package/dist/core/Feedback.js +6 -18
- package/dist/core/Feedback.js.map +1 -1
- package/dist/core/HttpTransport.d.ts +22 -0
- package/dist/core/HttpTransport.d.ts.map +1 -0
- package/dist/core/HttpTransport.js +33 -0
- package/dist/core/HttpTransport.js.map +1 -0
- package/dist/core/Multiplayer.d.ts +63 -0
- package/dist/core/Multiplayer.d.ts.map +1 -0
- package/dist/core/Multiplayer.js +73 -0
- package/dist/core/Multiplayer.js.map +1 -0
- package/dist/core/SaveSync.d.ts +17 -14
- package/dist/core/SaveSync.d.ts.map +1 -1
- package/dist/core/SaveSync.js +35 -31
- package/dist/core/SaveSync.js.map +1 -1
- package/dist/core/Stats.d.ts +33 -0
- package/dist/core/Stats.d.ts.map +1 -0
- package/dist/core/Stats.js +34 -0
- package/dist/core/Stats.js.map +1 -0
- package/dist/core/Telemetry.d.ts +34 -0
- package/dist/core/Telemetry.d.ts.map +1 -0
- package/dist/core/Telemetry.js +47 -0
- package/dist/core/Telemetry.js.map +1 -0
- package/dist/core/index.d.ts +6 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/mw_games.global.js +10 -9
- package/dist/render/StatusVisuals.d.ts +46 -0
- package/dist/render/StatusVisuals.d.ts.map +1 -0
- package/dist/render/StatusVisuals.js +48 -0
- package/dist/render/StatusVisuals.js.map +1 -0
- package/dist/render/index.d.ts +2 -0
- package/dist/render/index.d.ts.map +1 -1
- package/dist/render/index.js +1 -0
- package/dist/render/index.js.map +1 -1
- package/dist/simulation/Scenario.d.ts +29 -0
- package/dist/simulation/Scenario.d.ts.map +1 -0
- package/dist/simulation/Scenario.js +25 -0
- package/dist/simulation/Scenario.js.map +1 -0
- package/dist/simulation/Turns.d.ts +29 -0
- package/dist/simulation/Turns.d.ts.map +1 -0
- package/dist/simulation/Turns.js +30 -0
- package/dist/simulation/Turns.js.map +1 -0
- package/dist/simulation/index.d.ts +5 -0
- package/dist/simulation/index.d.ts.map +1 -0
- package/dist/simulation/index.js +3 -0
- package/dist/simulation/index.js.map +1 -0
- package/dist/ui/Button.d.ts +18 -1
- package/dist/ui/Button.d.ts.map +1 -1
- package/dist/ui/Button.js +15 -5
- package/dist/ui/Button.js.map +1 -1
- package/dist/ui/Label.d.ts +8 -0
- package/dist/ui/Label.d.ts.map +1 -1
- package/dist/ui/Label.js +3 -0
- package/dist/ui/Label.js.map +1 -1
- package/dist/ui/StatsScreen.d.ts +25 -0
- package/dist/ui/StatsScreen.d.ts.map +1 -0
- package/dist/ui/StatsScreen.js +27 -0
- package/dist/ui/StatsScreen.js.map +1 -0
- package/dist/ui/index.d.ts +3 -1
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +1 -0
- package/dist/ui/index.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +147 -112
package/README.md
CHANGED
|
@@ -1,352 +1,395 @@
|
|
|
1
|
-
# mwg
|
|
2
|
-
|
|
3
|
-
A framework for building primarily 2D top-down games that run **from a local file**: no
|
|
4
|
-
server, no install, no runtime to download. An optional Babylon.js module supports 3D maps.
|
|
5
|
-
|
|
6
|
-
Licensed under the [MPL-2.0](LICENSE): games built with `mwg` carry no licence obligation
|
|
7
|
-
of their own; improvements to `mwg`'s own files are shared back.
|
|
8
|
-
|
|
9
|
-
**[Live examples and API docs](https://datamoc.github.io/mwg/)**: every example below,
|
|
10
|
-
playable in the browser with no download, plus the generated API reference.
|
|
11
|
-
|
|
12
|
-
> **Status: early release (v0.
|
|
13
|
-
> 3D, mobile (Capacitor) and desktop (WebView2) packaging, is built and tested - see
|
|
14
|
-
> [ROADMAP.md](ROADMAP.md) for the full, numbered history. Still `0.y.z`: the "public API"
|
|
15
|
-
> can still change between minor versions, and the wider genre-specific modules keep growing.
|
|
16
|
-
|
|
17
|
-
## What it is for
|
|
18
|
-
|
|
19
|
-
Tile-based games with a camera over a grid. Nine existing games mark out the corners of
|
|
20
|
-
what that has to cover:
|
|
21
|
-
|
|
22
|
-
| reference | what it demands that the others do not |
|
|
23
|
-
| --- | --- |
|
|
24
|
-
| **[Shattered Pixel Dungeon](https://shatteredpixel.com/shatteredpd/)** | generated dungeons, field of view, energy-cost turn scheduling, permadeath, dense inventory UI |
|
|
25
|
-
| **[ADOM](https://www.adom.de/)** | many persistent maps joined by a world map, hunger and long-running effects, skills and attributes, quests inside a roguelike |
|
|
26
|
-
| **[RPG Maker](https://www.rpgmakerweb.com/) projects** | hand-authored maps, events on tiles, dialogue and cutscenes, a party, menu combat, save slots |
|
|
27
|
-
| **[Pokémon](https://www.pokemon.com/), in its traditional form** | encounter tables by terrain, a roster of creatures with derived stats, an effectiveness matrix, speed-ordered battles, capture and storage |
|
|
28
|
-
| **[Ren'Py](https://www.renpy.org/), and the conversation scenes every RPG borrows from it** | a backdrop with characters standing in front of it, expressions, whoever speaks picked out from the rest, branching written as data |
|
|
29
|
-
| **[The Battle for Wesnoth](https://www.wesnoth.org/)** | hexagonal tactical maps, movement cost and defense by terrain, zone of control, turn-based unit combat with recruiting and upkeep |
|
|
30
|
-
| **[Flare](https://flarerpg.org/)'s Empyrean Campaign** | isometric tile maps, loaded straight from Tiled's own isometric export |
|
|
31
|
-
| **[Dungeon Crawl Stone Soup](https://crawl.develz.org/) (Tiles)** | a branching dungeon of many interconnected levels, and autoexplore pathing to the nearest unseen tile |
|
|
32
|
-
| **[Twine](https://twinery.org/)** | a story as named passages, not one linear list - a choice jumps to another passage by name, which can loop back or braid together, entirely on state and no visual stage at all |
|
|
33
|
-
|
|
34
|
-
Underneath they share almost everything: a grid, a camera following someone across it,
|
|
35
|
-
sprites that need tinting, turn-taking, characters with stats and equipment, an inventory,
|
|
36
|
-
and a great many windows. The differences are narrower than the genre labels suggest: one
|
|
37
|
-
generates its maps and another authors them; one schedules monsters and another schedules
|
|
38
|
-
events; one rolls encounters from the terrain and another places them by hand; one puts its
|
|
39
|
-
conversations in a corner of the map and another gives them the whole screen; one moves in
|
|
40
|
-
four directions on a square grid and another in six on a hex grid.
|
|
41
|
-
|
|
42
|
-
`mwg` provides that shared floor plus each specialism, on top of
|
|
43
|
-
[PixiJS](https://pixijs.com) for rendering and [rot.js](https://ondras.github.io/rot.js/)
|
|
44
|
-
for the classic roguelike algorithms. Optional 3D scenes use Babylon.js. See
|
|
45
|
-
[Capability spec](#capability-spec).
|
|
46
|
-
|
|
47
|
-
These are references for *what a finished game of each kind has to do*, and nothing more.
|
|
48
|
-
No code, asset, data table or file format is taken from any of them: see
|
|
49
|
-
[Licence and provenance](#licence-and-provenance).
|
|
50
|
-
|
|
51
|
-
### On being "like RPG Maker"
|
|
52
|
-
|
|
53
|
-
Worth being precise, because RPG Maker is two things and `mwg` is only aiming at one of
|
|
54
|
-
them for now.
|
|
55
|
-
|
|
56
|
-
It is a **runtime**: a tile engine, an event interpreter, a battle system, a message box.
|
|
57
|
-
That is what the capability spec below commits to.
|
|
58
|
-
|
|
59
|
-
It is also an **editor**, and that is what most people actually mean by RPG Maker: drawing
|
|
60
|
-
maps and wiring events without writing code. `mwg` does not have one. What it does instead
|
|
61
|
-
is keep maps, events and dialogue as **plain data** rather than code, so an editor can be
|
|
62
|
-
built against that data later without reworking the runtime, and so that in the meantime
|
|
63
|
-
the data can be written by hand, generated by a script, or exported from
|
|
64
|
-
[Tiled](https://www.mapeditor.org/), which is free and already good at this.
|
|
65
|
-
|
|
66
|
-
That data is loaded exactly like any other asset, which means the `file://` story covers it
|
|
67
|
-
for free: a finished game is still a folder you double-click.
|
|
68
|
-
|
|
69
|
-
## Two ways to use it
|
|
70
|
-
|
|
71
|
-
**With a toolchain**, if you already use a bundler:
|
|
72
|
-
|
|
73
|
-
```
|
|
74
|
-
npm install @datamoc/mw_games
|
|
75
|
-
```
|
|
76
|
-
```ts
|
|
77
|
-
import { Game, Scene } from '@datamoc/mw_games/core';
|
|
78
|
-
import { Sprite } from '@datamoc/mw_games/render';
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
No npm registry access (an offline machine, a pinned artifact for reproducible builds)?
|
|
82
|
-
`npm pack @datamoc/mw_games` downloads the exact published tarball; install it by path
|
|
83
|
-
instead of by name:
|
|
84
|
-
|
|
85
|
-
```
|
|
86
|
-
npm install ./datamoc-mw_games-0.1.1.tgz
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
**Without either.** Drop one file next to your page and open it: this path exists because
|
|
90
|
-
the framework's own target is a game you can run by double-clicking it. Download
|
|
91
|
-
`mw_games.global.js` from a [release](https://github.com/datamoc/mwg/releases) (no `npm`,
|
|
92
|
-
no `node_modules`, nothing to install):
|
|
93
|
-
|
|
94
|
-
```html
|
|
95
|
-
<script src="mw_games.global.js"></script>
|
|
96
|
-
<script>
|
|
97
|
-
const game = new mw_games.Game(document.getElementById('game'));
|
|
98
|
-
</script>
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
Node and npm are developer tools here, in the same sense that a compiler is. Nothing from
|
|
102
|
-
them is present when the game runs: the output is HTML, JavaScript and assets.
|
|
103
|
-
|
|
104
|
-
## Running from `file://`
|
|
105
|
-
|
|
106
|
-
Opening a page from disk takes three capabilities away, and the framework is shaped around
|
|
107
|
-
them rather than pretending otherwise:
|
|
108
|
-
|
|
109
|
-
| what is blocked | consequence | how `mwg` handles it |
|
|
110
|
-
| --- | --- | --- |
|
|
111
|
-
| ES modules (CORS) | `<script type="module">` will not run | the standalone build is a classic IIFE |
|
|
112
|
-
| `fetch()` / XHR | no asset can be loaded on demand, no directory can be listed | `tools/compile-resources` turns assets into scripts loaded before the game |
|
|
113
|
-
| cross-origin images | an `<img>` from a sibling file taints a WebGL texture in Chrome | assets travel as `data:` URIs inside those scripts |
|
|
114
|
-
|
|
115
|
-
The practical effect: resources are **compiled at build time**, so at runtime every lookup
|
|
116
|
-
is synchronous. Game code never awaits an asset.
|
|
117
|
-
|
|
118
|
-
## Capability spec
|
|
119
|
-
|
|
120
|
-
The definition of done for 1.0, drawn from what each of the nine references actually
|
|
121
|
-
demands. The shared floor is what all of them need; the sections after it are the parts
|
|
122
|
-
only some do.
|
|
123
|
-
|
|
124
|
-
### Shared floor
|
|
125
|
-
|
|
126
|
-
| area | capability | provided by |
|
|
127
|
-
| --- | --- | --- |
|
|
128
|
-
| **core** | fixed-step game loop, scenes, timing | `mwg/core` |
|
|
129
|
-
| | signals and listeners | `mwg/core` |
|
|
130
|
-
| | deterministic seeded RNG, reproducible across machines | `mwg/core` |
|
|
131
|
-
| | named, versioned save slots with a preview | `mwg/core` |
|
|
132
|
-
| **render** | sprite batching at thousands of tiles | PixiJS |
|
|
133
|
-
| | per-sprite colour transform: multiply **and** add | `mwg/render` |
|
|
134
|
-
| | animated sprites driven by named frame sets | `mwg/render` |
|
|
135
|
-
| | dense tile maps, multi-layer, with per-cell visibility | `mwg/render` |
|
|
136
|
-
| | hexagonal tile maps, alongside square, as a second grid shape | `mwg/render` |
|
|
137
|
-
| | camera with follow, pan, shake and zoom | `mwg/render` |
|
|
138
|
-
| | particle effects | `mwg/render` |
|
|
139
|
-
| | screen transitions: fade, flash, tint | `mwg/render` |
|
|
140
|
-
| **ui** | windows, lists, tooltips | `mwg/ui` |
|
|
141
|
-
| | text and fonts, including non-latin fallback | PixiJS |
|
|
142
|
-
| | pointer, keyboard and gamepad input with rebinding | `mwg/core` |
|
|
143
|
-
| **text** | message tables per language, compiled at build time | `mwg/i18n` |
|
|
144
|
-
| | plurals, gendered forms and interpolation | `mwg/i18n` |
|
|
145
|
-
| | Fluent-style FTL catalogs with locale-aware fallback and variants | `mwg/i18n` |
|
|
146
|
-
| | left-to-right, right-to-left and vertical writing | `mwg/i18n` |
|
|
147
|
-
| | interface mirrored for right-to-left languages | `mwg/ui` |
|
|
148
|
-
| | a missing translation falls back rather than showing a key | `mwg/i18n` |
|
|
149
|
-
| **audio** | sound effects with pooling, music with crossfade | `mwg/audio` |
|
|
150
|
-
|
|
151
|
-
### World
|
|
152
|
-
|
|
153
|
-
Shared by everything past a single screen, and the thing ADOM needs most.
|
|
154
|
-
|
|
155
|
-
| capability | provided by |
|
|
156
|
-
| --- | --- |
|
|
157
|
-
| many maps in one world, joined by transitions | `mwg/world` |
|
|
158
|
-
| maps that persist when left and returned to | `mwg/world` |
|
|
159
|
-
| an overworld map with locations on it | `mwg/world` |
|
|
160
|
-
| a turn clock driving hunger, poison and other long effects | `mwg/world` |
|
|
161
|
-
|
|
162
|
-
### Roguelike
|
|
163
|
-
|
|
164
|
-
| capability | provided by |
|
|
165
|
-
| --- | --- |
|
|
166
|
-
| field of view and lighting | rot.js + `mwg/roguelike` |
|
|
167
|
-
| pathfinding over a passability map | rot.js + `mwg/roguelike` |
|
|
168
|
-
| turn scheduling by energy cost | `mwg/roguelike` |
|
|
169
|
-
| level generation from composable room builders | `mwg/roguelike` |
|
|
170
|
-
| autoexplore: pathing to the nearest unexplored cell | `mwg/roguelike` |
|
|
171
|
-
|
|
172
|
-
### Tactical maps (hex)
|
|
173
|
-
|
|
174
|
-
The Wesnoth-shaped half: a grid whose shape is a parameter, not a parallel implementation.
|
|
175
|
-
|
|
176
|
-
| capability | provided by |
|
|
177
|
-
| --- | --- |
|
|
178
|
-
| hexagonal tile maps, addressed by axial or offset coordinates | `mwg/render` |
|
|
179
|
-
| movement cost and defense bonus by terrain, hex or square alike | `mwg/roguelike` |
|
|
180
|
-
| field of view and pathfinding over a hex grid, not just square | `mwg/roguelike` |
|
|
181
|
-
| isometric (and staggered) projection, alongside orthogonal and hex | `mwg/render` |
|
|
182
|
-
| zone of control: a hex a unit can only move into, not through, unless already engaged | `mwg/board` |
|
|
183
|
-
| an army economy: recruiting against a currency, recalling from a pool, per-turn upkeep | `mwg/board` |
|
|
184
|
-
|
|
185
|
-
A game picks a grid shape once; the camera, field of view, pathfinding and turn scheduler
|
|
186
|
-
work the same way over either, rather than a hex game needing its own copy of each. Between
|
|
187
|
-
them, orthogonal, isometric and hex cover every map orientation
|
|
188
|
-
[Tiled](https://www.mapeditor.org/) itself supports: a Tiled map loads and renders through
|
|
189
|
-
the same `TileMap`, whichever orientation it was drawn in, rather than mwg reading only the
|
|
190
|
-
one shape it happens to render natively. Flare's Empyrean Campaign is the isometric-shaped
|
|
191
|
-
reference, the same way Wesnoth is the hex-shaped one.
|
|
192
|
-
|
|
193
|
-
### RPG
|
|
194
|
-
|
|
195
|
-
| capability | provided by |
|
|
196
|
-
| --- | --- |
|
|
197
|
-
| maps loaded as data, in any of Tiled's map orientations | `mwg/rpg` |
|
|
198
|
-
| events placed on tiles, with pages selected by conditions | `mwg/rpg` |
|
|
199
|
-
| event triggers: action, touch, autorun, parallel | `mwg/rpg` |
|
|
200
|
-
| a command interpreter for cutscenes: move routes, waits, branches, calls | `mwg/rpg` |
|
|
201
|
-
| global switches and variables, saved with the game | `mwg/rpg` |
|
|
202
|
-
| message box with portraits, choices and typewriter reveal | `mwg/rpg` + `mwg/ui` |
|
|
203
|
-
| grid movement tweened between tiles, with a walk cycle | `mwg/rpg` |
|
|
204
|
-
| a dialogue stage: backdrop, characters, expressions, speaker focus | `mwg/stage` |
|
|
205
|
-
| scenes written as a list of commands, awaited as one call | `mwg/stage` |
|
|
206
|
-
| named passages a choice can jump between, for a story that is a graph, not a line | `mwg/stage` |
|
|
207
|
-
| named save slots with a preview | `mwg/core` |
|
|
208
|
-
|
|
209
|
-
### Characters, equipment and stats
|
|
210
|
-
|
|
211
|
-
All four references have these, and they are what a game changes most, so they are data
|
|
212
|
-
rather than classes.
|
|
213
|
-
|
|
214
|
-
| capability | provided by |
|
|
215
|
-
| --- | --- |
|
|
216
|
-
| a stat block: base attributes, derived values, and the rules that derive them | `mwg/actors` |
|
|
217
|
-
| levels, experience and growth curves, all replaceable | `mwg/actors` |
|
|
218
|
-
| skills and proficiencies, checked against a difficulty | `mwg/actors` |
|
|
219
|
-
| equipment slots defined per game, not fixed by the framework | `mwg/actors` |
|
|
220
|
-
| modifiers from equipment, buffs and states, resolved in a stated order | `mwg/actors` |
|
|
221
|
-
| an inventory with stacking, weight and containers | `mwg/actors` |
|
|
222
|
-
| item identification, and cursed or blessed states | `mwg/actors` |
|
|
223
|
-
| a layered character sprite, so worn equipment is visible | `mwg/render` |
|
|
224
|
-
|
|
225
|
-
That last row is why `tools/make-example-assets.mjs` draws its character in parts. A figure
|
|
226
|
-
assembled from skin, eyes, hair and garments is one palette away from being a second
|
|
227
|
-
character, and one *layer* away from showing the armour it just put on. A single flat
|
|
228
|
-
sprite per character can do neither.
|
|
229
|
-
|
|
230
|
-
### Creatures and battles
|
|
231
|
-
|
|
232
|
-
The Pokémon-shaped half, and the part `mwg` deliberately keeps generic.
|
|
233
|
-
|
|
234
|
-
| capability | provided by |
|
|
235
|
-
| --- | --- |
|
|
236
|
-
| species defined as data, with per-individual stats derived from them | `mwg/battle` |
|
|
237
|
-
| a party with a roster and off-party storage | `mwg/battle` |
|
|
238
|
-
| an effectiveness matrix between arbitrary types | `mwg/battle` |
|
|
239
|
-
| turn order by speed, with move priority overriding it | `mwg/battle` |
|
|
240
|
-
| moves as data: cost, target shape, effects | `mwg/battle` |
|
|
241
|
-
| encounter tables per map region, weighted, with a rate per step | `mwg/world` |
|
|
242
|
-
| capture, experience, levelling and evolution as replaceable rules | `mwg/battle` |
|
|
243
|
-
|
|
244
|
-
`mwg` supplies the *shape*: a stat block, a type matrix, a turn queue. It supplies no
|
|
245
|
-
formulas, no type chart and no species: those are a game's own design, and copying any
|
|
246
|
-
particular game's would be both wrong and useless to anyone else.
|
|
247
|
-
|
|
248
|
-
All of these specialisms share the tile map, the camera, the windows, the turn clock and
|
|
249
|
-
the save system, which is why they sit in one framework rather than four.
|
|
250
|
-
|
|
251
|
-
### Why per-sprite "multiply and add"
|
|
252
|
-
|
|
253
|
-
The single most load-bearing rendering feature in either genre is the colour transform
|
|
254
|
-
`texel × M + A`. Darkness outside the field of view, tinting a poisoned enemy, flashing
|
|
255
|
-
white on a hit, a room lit by a fireplace, a screen-wide tint for a night scene: all of it
|
|
256
|
-
is that one operation.
|
|
257
|
-
|
|
258
|
-
Pixi's built-in `tint` is multiply-only, which can only ever darken. The additive term is
|
|
259
|
-
what `mwg/render` adds, in the batch shader rather than as a per-object filter, so it costs
|
|
260
|
-
nothing per sprite. See `examples/colour-transform`.
|
|
261
|
-
|
|
262
|
-
### Why maps and events are data, not code
|
|
263
|
-
|
|
264
|
-
An RPG's content is enormous and repetitive, and almost none of it deserves to be written
|
|
265
|
-
by hand in TypeScript. Keeping maps, events, dialogue and item tables as data means they
|
|
266
|
-
can be authored in a spreadsheet, generated by a script, exported from Tiled, or eventually
|
|
267
|
-
edited in a proper editor, without any of those options requiring changes to the runtime.
|
|
268
|
-
|
|
269
|
-
It also keeps the content out of the bundle: `tools/compile-resources` treats a map file
|
|
270
|
-
exactly like a sprite sheet, so adding a hundred maps does not touch the build at all.
|
|
271
|
-
|
|
272
|
-
### On writing direction
|
|
273
|
-
|
|
274
|
-
Supporting more than one language is mostly bookkeeping. Supporting more than one writing
|
|
275
|
-
*direction* is not, and the three cases are genuinely different work:
|
|
276
|
-
|
|
277
|
-
- **Left-to-right** is what everything assumes by default.
|
|
278
|
-
- **Right-to-left** (Arabic, Hebrew) is two problems at once. The text itself the browser
|
|
279
|
-
can handle: canvas applies the Unicode bidirectional algorithm and shapes the glyphs, so
|
|
280
|
-
a label mostly comes out right once its direction is declared. The *interface* is the
|
|
281
|
-
harder half, because a right-to-left reader expects it mirrored: lists indent from the
|
|
282
|
-
right, a back arrow points the other way, a progress bar fills the other way. `mwg/ui`
|
|
283
|
-
lays widgets out against a direction rather than against "left" so this can be flipped,
|
|
284
|
-
and a game only has to mark which of its own icons must not be mirrored.
|
|
285
|
-
- **Vertical**, top to bottom (traditional Chinese, Japanese, Mongolian), gets no help at
|
|
286
|
-
all. Canvas has no vertical writing mode, so the text has to be laid out glyph by glyph,
|
|
287
|
-
with its own rules for which characters rotate and which stand upright. This is real work
|
|
288
|
-
and it is scheduled as such, not assumed to fall out of the other two.
|
|
289
|
-
|
|
290
|
-
Message tables are compiled at build time, the same way every other resource is, so adding
|
|
291
|
-
a language costs nothing at runtime and a missing string falls back to the base language
|
|
292
|
-
rather than showing a raw key to the player.
|
|
293
|
-
|
|
294
|
-
## Optional Babylon.js 3D
|
|
295
|
-
|
|
296
|
-
`@babylonjs/core`/`@babylonjs/loaders` are peer dependencies, not installed automatically -
|
|
297
|
-
a game that never imports `mwg/3d` never downloads Babylon.js. Add them yourself
|
|
298
|
-
(`npm install @babylonjs/core @babylonjs/loaders`) once a game imports 3D support:
|
|
299
|
-
|
|
300
|
-
```ts
|
|
301
|
-
import { Engine3D, createTileGrid3D } from '@datamoc/mw_games/3d';
|
|
302
|
-
import { loadModel3D } from '@datamoc/mw_games/3d/models';
|
|
303
|
-
```
|
|
304
|
-
|
|
305
|
-
`Engine3D` owns a WebGL scene, orbit camera, light, resize handling, and render loop.
|
|
306
|
-
`createTileGrid3D` batches square or flat-top hex tiles and elevation columns with thin
|
|
307
|
-
instances; `createHeightmapTerrain3D` builds continuous terrain from decoded RGBA heightmap
|
|
308
|
-
pixels. `Character3D` moves imported meshes or camera-facing sprites continuously, and can
|
|
309
|
-
play imported animation clips. `parseVox` and `createVoxModel3D` load one MagicaVoxel model;
|
|
310
|
-
`loadModel3D` handles glTF/GLB.
|
|
311
|
-
Run `npm run example:3d` for the live example or `npm run benchmark:3d` for its FPS gate.
|
|
312
|
-
|
|
313
|
-
##
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
`
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
1
|
+
# mwg
|
|
2
|
+
|
|
3
|
+
A framework for building primarily 2D top-down games that run **from a local file**: no
|
|
4
|
+
server, no install, no runtime to download. An optional Babylon.js module supports 3D maps.
|
|
5
|
+
|
|
6
|
+
Licensed under the [MPL-2.0](LICENSE): games built with `mwg` carry no licence obligation
|
|
7
|
+
of their own; improvements to `mwg`'s own files are shared back.
|
|
8
|
+
|
|
9
|
+
**[Live examples and API docs](https://datamoc.github.io/mwg/)**: every example below,
|
|
10
|
+
playable in the browser with no download, plus the generated API reference.
|
|
11
|
+
|
|
12
|
+
> **Status: early release (v0.3.1).** Every module in the shared floor below, plus optional
|
|
13
|
+
> 3D, mobile (Capacitor) and desktop (WebView2) packaging, is built and tested - see
|
|
14
|
+
> [ROADMAP.md](ROADMAP.md) for the full, numbered history. Still `0.y.z`: the "public API"
|
|
15
|
+
> can still change between minor versions, and the wider genre-specific modules keep growing.
|
|
16
|
+
|
|
17
|
+
## What it is for
|
|
18
|
+
|
|
19
|
+
Tile-based games with a camera over a grid. Nine existing games mark out the corners of
|
|
20
|
+
what that has to cover:
|
|
21
|
+
|
|
22
|
+
| reference | what it demands that the others do not |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| **[Shattered Pixel Dungeon](https://shatteredpixel.com/shatteredpd/)** | generated dungeons, field of view, energy-cost turn scheduling, permadeath, dense inventory UI |
|
|
25
|
+
| **[ADOM](https://www.adom.de/)** | many persistent maps joined by a world map, hunger and long-running effects, skills and attributes, quests inside a roguelike |
|
|
26
|
+
| **[RPG Maker](https://www.rpgmakerweb.com/) projects** | hand-authored maps, events on tiles, dialogue and cutscenes, a party, menu combat, save slots |
|
|
27
|
+
| **[Pokémon](https://www.pokemon.com/), in its traditional form** | encounter tables by terrain, a roster of creatures with derived stats, an effectiveness matrix, speed-ordered battles, capture and storage |
|
|
28
|
+
| **[Ren'Py](https://www.renpy.org/), and the conversation scenes every RPG borrows from it** | a backdrop with characters standing in front of it, expressions, whoever speaks picked out from the rest, branching written as data |
|
|
29
|
+
| **[The Battle for Wesnoth](https://www.wesnoth.org/)** | hexagonal tactical maps, movement cost and defense by terrain, zone of control, turn-based unit combat with recruiting and upkeep |
|
|
30
|
+
| **[Flare](https://flarerpg.org/)'s Empyrean Campaign** | isometric tile maps, loaded straight from Tiled's own isometric export |
|
|
31
|
+
| **[Dungeon Crawl Stone Soup](https://crawl.develz.org/) (Tiles)** | a branching dungeon of many interconnected levels, and autoexplore pathing to the nearest unseen tile |
|
|
32
|
+
| **[Twine](https://twinery.org/)** | a story as named passages, not one linear list - a choice jumps to another passage by name, which can loop back or braid together, entirely on state and no visual stage at all |
|
|
33
|
+
|
|
34
|
+
Underneath they share almost everything: a grid, a camera following someone across it,
|
|
35
|
+
sprites that need tinting, turn-taking, characters with stats and equipment, an inventory,
|
|
36
|
+
and a great many windows. The differences are narrower than the genre labels suggest: one
|
|
37
|
+
generates its maps and another authors them; one schedules monsters and another schedules
|
|
38
|
+
events; one rolls encounters from the terrain and another places them by hand; one puts its
|
|
39
|
+
conversations in a corner of the map and another gives them the whole screen; one moves in
|
|
40
|
+
four directions on a square grid and another in six on a hex grid.
|
|
41
|
+
|
|
42
|
+
`mwg` provides that shared floor plus each specialism, on top of
|
|
43
|
+
[PixiJS](https://pixijs.com) for rendering and [rot.js](https://ondras.github.io/rot.js/)
|
|
44
|
+
for the classic roguelike algorithms. Optional 3D scenes use Babylon.js. See
|
|
45
|
+
[Capability spec](#capability-spec).
|
|
46
|
+
|
|
47
|
+
These are references for *what a finished game of each kind has to do*, and nothing more.
|
|
48
|
+
No code, asset, data table or file format is taken from any of them: see
|
|
49
|
+
[Licence and provenance](#licence-and-provenance).
|
|
50
|
+
|
|
51
|
+
### On being "like RPG Maker"
|
|
52
|
+
|
|
53
|
+
Worth being precise, because RPG Maker is two things and `mwg` is only aiming at one of
|
|
54
|
+
them for now.
|
|
55
|
+
|
|
56
|
+
It is a **runtime**: a tile engine, an event interpreter, a battle system, a message box.
|
|
57
|
+
That is what the capability spec below commits to.
|
|
58
|
+
|
|
59
|
+
It is also an **editor**, and that is what most people actually mean by RPG Maker: drawing
|
|
60
|
+
maps and wiring events without writing code. `mwg` does not have one. What it does instead
|
|
61
|
+
is keep maps, events and dialogue as **plain data** rather than code, so an editor can be
|
|
62
|
+
built against that data later without reworking the runtime, and so that in the meantime
|
|
63
|
+
the data can be written by hand, generated by a script, or exported from
|
|
64
|
+
[Tiled](https://www.mapeditor.org/), which is free and already good at this.
|
|
65
|
+
|
|
66
|
+
That data is loaded exactly like any other asset, which means the `file://` story covers it
|
|
67
|
+
for free: a finished game is still a folder you double-click.
|
|
68
|
+
|
|
69
|
+
## Two ways to use it
|
|
70
|
+
|
|
71
|
+
**With a toolchain**, if you already use a bundler:
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
npm install @datamoc/mw_games
|
|
75
|
+
```
|
|
76
|
+
```ts
|
|
77
|
+
import { Game, Scene } from '@datamoc/mw_games/core';
|
|
78
|
+
import { Sprite } from '@datamoc/mw_games/render';
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
No npm registry access (an offline machine, a pinned artifact for reproducible builds)?
|
|
82
|
+
`npm pack @datamoc/mw_games` downloads the exact published tarball; install it by path
|
|
83
|
+
instead of by name:
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
npm install ./datamoc-mw_games-0.1.1.tgz
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
**Without either.** Drop one file next to your page and open it: this path exists because
|
|
90
|
+
the framework's own target is a game you can run by double-clicking it. Download
|
|
91
|
+
`mw_games.global.js` from a [release](https://github.com/datamoc/mwg/releases) (no `npm`,
|
|
92
|
+
no `node_modules`, nothing to install):
|
|
93
|
+
|
|
94
|
+
```html
|
|
95
|
+
<script src="mw_games.global.js"></script>
|
|
96
|
+
<script>
|
|
97
|
+
const game = new mw_games.Game(document.getElementById('game'));
|
|
98
|
+
</script>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Node and npm are developer tools here, in the same sense that a compiler is. Nothing from
|
|
102
|
+
them is present when the game runs: the output is HTML, JavaScript and assets.
|
|
103
|
+
|
|
104
|
+
## Running from `file://`
|
|
105
|
+
|
|
106
|
+
Opening a page from disk takes three capabilities away, and the framework is shaped around
|
|
107
|
+
them rather than pretending otherwise:
|
|
108
|
+
|
|
109
|
+
| what is blocked | consequence | how `mwg` handles it |
|
|
110
|
+
| --- | --- | --- |
|
|
111
|
+
| ES modules (CORS) | `<script type="module">` will not run | the standalone build is a classic IIFE |
|
|
112
|
+
| `fetch()` / XHR | no asset can be loaded on demand, no directory can be listed | `tools/compile-resources` turns assets into scripts loaded before the game |
|
|
113
|
+
| cross-origin images | an `<img>` from a sibling file taints a WebGL texture in Chrome | assets travel as `data:` URIs inside those scripts |
|
|
114
|
+
|
|
115
|
+
The practical effect: resources are **compiled at build time**, so at runtime every lookup
|
|
116
|
+
is synchronous. Game code never awaits an asset.
|
|
117
|
+
|
|
118
|
+
## Capability spec
|
|
119
|
+
|
|
120
|
+
The definition of done for 1.0, drawn from what each of the nine references actually
|
|
121
|
+
demands. The shared floor is what all of them need; the sections after it are the parts
|
|
122
|
+
only some do.
|
|
123
|
+
|
|
124
|
+
### Shared floor
|
|
125
|
+
|
|
126
|
+
| area | capability | provided by |
|
|
127
|
+
| --- | --- | --- |
|
|
128
|
+
| **core** | fixed-step game loop, scenes, timing | `mwg/core` |
|
|
129
|
+
| | signals and listeners | `mwg/core` |
|
|
130
|
+
| | deterministic seeded RNG, reproducible across machines | `mwg/core` |
|
|
131
|
+
| | named, versioned save slots with a preview | `mwg/core` |
|
|
132
|
+
| **render** | sprite batching at thousands of tiles | PixiJS |
|
|
133
|
+
| | per-sprite colour transform: multiply **and** add | `mwg/render` |
|
|
134
|
+
| | animated sprites driven by named frame sets | `mwg/render` |
|
|
135
|
+
| | dense tile maps, multi-layer, with per-cell visibility | `mwg/render` |
|
|
136
|
+
| | hexagonal tile maps, alongside square, as a second grid shape | `mwg/render` |
|
|
137
|
+
| | camera with follow, pan, shake and zoom | `mwg/render` |
|
|
138
|
+
| | particle effects | `mwg/render` |
|
|
139
|
+
| | screen transitions: fade, flash, tint | `mwg/render` |
|
|
140
|
+
| **ui** | windows, lists, tooltips | `mwg/ui` |
|
|
141
|
+
| | text and fonts, including non-latin fallback | PixiJS |
|
|
142
|
+
| | pointer, keyboard and gamepad input with rebinding | `mwg/core` |
|
|
143
|
+
| **text** | message tables per language, compiled at build time | `mwg/i18n` |
|
|
144
|
+
| | plurals, gendered forms and interpolation | `mwg/i18n` |
|
|
145
|
+
| | Fluent-style FTL catalogs with locale-aware fallback and variants | `mwg/i18n` |
|
|
146
|
+
| | left-to-right, right-to-left and vertical writing | `mwg/i18n` |
|
|
147
|
+
| | interface mirrored for right-to-left languages | `mwg/ui` |
|
|
148
|
+
| | a missing translation falls back rather than showing a key | `mwg/i18n` |
|
|
149
|
+
| **audio** | sound effects with pooling, music with crossfade | `mwg/audio` |
|
|
150
|
+
|
|
151
|
+
### World
|
|
152
|
+
|
|
153
|
+
Shared by everything past a single screen, and the thing ADOM needs most.
|
|
154
|
+
|
|
155
|
+
| capability | provided by |
|
|
156
|
+
| --- | --- |
|
|
157
|
+
| many maps in one world, joined by transitions | `mwg/world` |
|
|
158
|
+
| maps that persist when left and returned to | `mwg/world` |
|
|
159
|
+
| an overworld map with locations on it | `mwg/world` |
|
|
160
|
+
| a turn clock driving hunger, poison and other long effects | `mwg/world` |
|
|
161
|
+
|
|
162
|
+
### Roguelike
|
|
163
|
+
|
|
164
|
+
| capability | provided by |
|
|
165
|
+
| --- | --- |
|
|
166
|
+
| field of view and lighting | rot.js + `mwg/roguelike` |
|
|
167
|
+
| pathfinding over a passability map | rot.js + `mwg/roguelike` |
|
|
168
|
+
| turn scheduling by energy cost | `mwg/roguelike` |
|
|
169
|
+
| level generation from composable room builders | `mwg/roguelike` |
|
|
170
|
+
| autoexplore: pathing to the nearest unexplored cell | `mwg/roguelike` |
|
|
171
|
+
|
|
172
|
+
### Tactical maps (hex)
|
|
173
|
+
|
|
174
|
+
The Wesnoth-shaped half: a grid whose shape is a parameter, not a parallel implementation.
|
|
175
|
+
|
|
176
|
+
| capability | provided by |
|
|
177
|
+
| --- | --- |
|
|
178
|
+
| hexagonal tile maps, addressed by axial or offset coordinates | `mwg/render` |
|
|
179
|
+
| movement cost and defense bonus by terrain, hex or square alike | `mwg/roguelike` |
|
|
180
|
+
| field of view and pathfinding over a hex grid, not just square | `mwg/roguelike` |
|
|
181
|
+
| isometric (and staggered) projection, alongside orthogonal and hex | `mwg/render` |
|
|
182
|
+
| zone of control: a hex a unit can only move into, not through, unless already engaged | `mwg/board` |
|
|
183
|
+
| an army economy: recruiting against a currency, recalling from a pool, per-turn upkeep | `mwg/board` |
|
|
184
|
+
|
|
185
|
+
A game picks a grid shape once; the camera, field of view, pathfinding and turn scheduler
|
|
186
|
+
work the same way over either, rather than a hex game needing its own copy of each. Between
|
|
187
|
+
them, orthogonal, isometric and hex cover every map orientation
|
|
188
|
+
[Tiled](https://www.mapeditor.org/) itself supports: a Tiled map loads and renders through
|
|
189
|
+
the same `TileMap`, whichever orientation it was drawn in, rather than mwg reading only the
|
|
190
|
+
one shape it happens to render natively. Flare's Empyrean Campaign is the isometric-shaped
|
|
191
|
+
reference, the same way Wesnoth is the hex-shaped one.
|
|
192
|
+
|
|
193
|
+
### RPG
|
|
194
|
+
|
|
195
|
+
| capability | provided by |
|
|
196
|
+
| --- | --- |
|
|
197
|
+
| maps loaded as data, in any of Tiled's map orientations | `mwg/rpg` |
|
|
198
|
+
| events placed on tiles, with pages selected by conditions | `mwg/rpg` |
|
|
199
|
+
| event triggers: action, touch, autorun, parallel | `mwg/rpg` |
|
|
200
|
+
| a command interpreter for cutscenes: move routes, waits, branches, calls | `mwg/rpg` |
|
|
201
|
+
| global switches and variables, saved with the game | `mwg/rpg` |
|
|
202
|
+
| message box with portraits, choices and typewriter reveal | `mwg/rpg` + `mwg/ui` |
|
|
203
|
+
| grid movement tweened between tiles, with a walk cycle | `mwg/rpg` |
|
|
204
|
+
| a dialogue stage: backdrop, characters, expressions, speaker focus | `mwg/stage` |
|
|
205
|
+
| scenes written as a list of commands, awaited as one call | `mwg/stage` |
|
|
206
|
+
| named passages a choice can jump between, for a story that is a graph, not a line | `mwg/stage` |
|
|
207
|
+
| named save slots with a preview | `mwg/core` |
|
|
208
|
+
|
|
209
|
+
### Characters, equipment and stats
|
|
210
|
+
|
|
211
|
+
All four references have these, and they are what a game changes most, so they are data
|
|
212
|
+
rather than classes.
|
|
213
|
+
|
|
214
|
+
| capability | provided by |
|
|
215
|
+
| --- | --- |
|
|
216
|
+
| a stat block: base attributes, derived values, and the rules that derive them | `mwg/actors` |
|
|
217
|
+
| levels, experience and growth curves, all replaceable | `mwg/actors` |
|
|
218
|
+
| skills and proficiencies, checked against a difficulty | `mwg/actors` |
|
|
219
|
+
| equipment slots defined per game, not fixed by the framework | `mwg/actors` |
|
|
220
|
+
| modifiers from equipment, buffs and states, resolved in a stated order | `mwg/actors` |
|
|
221
|
+
| an inventory with stacking, weight and containers | `mwg/actors` |
|
|
222
|
+
| item identification, and cursed or blessed states | `mwg/actors` |
|
|
223
|
+
| a layered character sprite, so worn equipment is visible | `mwg/render` |
|
|
224
|
+
|
|
225
|
+
That last row is why `tools/make-example-assets.mjs` draws its character in parts. A figure
|
|
226
|
+
assembled from skin, eyes, hair and garments is one palette away from being a second
|
|
227
|
+
character, and one *layer* away from showing the armour it just put on. A single flat
|
|
228
|
+
sprite per character can do neither.
|
|
229
|
+
|
|
230
|
+
### Creatures and battles
|
|
231
|
+
|
|
232
|
+
The Pokémon-shaped half, and the part `mwg` deliberately keeps generic.
|
|
233
|
+
|
|
234
|
+
| capability | provided by |
|
|
235
|
+
| --- | --- |
|
|
236
|
+
| species defined as data, with per-individual stats derived from them | `mwg/battle` |
|
|
237
|
+
| a party with a roster and off-party storage | `mwg/battle` |
|
|
238
|
+
| an effectiveness matrix between arbitrary types | `mwg/battle` |
|
|
239
|
+
| turn order by speed, with move priority overriding it | `mwg/battle` |
|
|
240
|
+
| moves as data: cost, target shape, effects | `mwg/battle` |
|
|
241
|
+
| encounter tables per map region, weighted, with a rate per step | `mwg/world` |
|
|
242
|
+
| capture, experience, levelling and evolution as replaceable rules | `mwg/battle` |
|
|
243
|
+
|
|
244
|
+
`mwg` supplies the *shape*: a stat block, a type matrix, a turn queue. It supplies no
|
|
245
|
+
formulas, no type chart and no species: those are a game's own design, and copying any
|
|
246
|
+
particular game's would be both wrong and useless to anyone else.
|
|
247
|
+
|
|
248
|
+
All of these specialisms share the tile map, the camera, the windows, the turn clock and
|
|
249
|
+
the save system, which is why they sit in one framework rather than four.
|
|
250
|
+
|
|
251
|
+
### Why per-sprite "multiply and add"
|
|
252
|
+
|
|
253
|
+
The single most load-bearing rendering feature in either genre is the colour transform
|
|
254
|
+
`texel × M + A`. Darkness outside the field of view, tinting a poisoned enemy, flashing
|
|
255
|
+
white on a hit, a room lit by a fireplace, a screen-wide tint for a night scene: all of it
|
|
256
|
+
is that one operation.
|
|
257
|
+
|
|
258
|
+
Pixi's built-in `tint` is multiply-only, which can only ever darken. The additive term is
|
|
259
|
+
what `mwg/render` adds, in the batch shader rather than as a per-object filter, so it costs
|
|
260
|
+
nothing per sprite. See `examples/colour-transform`.
|
|
261
|
+
|
|
262
|
+
### Why maps and events are data, not code
|
|
263
|
+
|
|
264
|
+
An RPG's content is enormous and repetitive, and almost none of it deserves to be written
|
|
265
|
+
by hand in TypeScript. Keeping maps, events, dialogue and item tables as data means they
|
|
266
|
+
can be authored in a spreadsheet, generated by a script, exported from Tiled, or eventually
|
|
267
|
+
edited in a proper editor, without any of those options requiring changes to the runtime.
|
|
268
|
+
|
|
269
|
+
It also keeps the content out of the bundle: `tools/compile-resources` treats a map file
|
|
270
|
+
exactly like a sprite sheet, so adding a hundred maps does not touch the build at all.
|
|
271
|
+
|
|
272
|
+
### On writing direction
|
|
273
|
+
|
|
274
|
+
Supporting more than one language is mostly bookkeeping. Supporting more than one writing
|
|
275
|
+
*direction* is not, and the three cases are genuinely different work:
|
|
276
|
+
|
|
277
|
+
- **Left-to-right** is what everything assumes by default.
|
|
278
|
+
- **Right-to-left** (Arabic, Hebrew) is two problems at once. The text itself the browser
|
|
279
|
+
can handle: canvas applies the Unicode bidirectional algorithm and shapes the glyphs, so
|
|
280
|
+
a label mostly comes out right once its direction is declared. The *interface* is the
|
|
281
|
+
harder half, because a right-to-left reader expects it mirrored: lists indent from the
|
|
282
|
+
right, a back arrow points the other way, a progress bar fills the other way. `mwg/ui`
|
|
283
|
+
lays widgets out against a direction rather than against "left" so this can be flipped,
|
|
284
|
+
and a game only has to mark which of its own icons must not be mirrored.
|
|
285
|
+
- **Vertical**, top to bottom (traditional Chinese, Japanese, Mongolian), gets no help at
|
|
286
|
+
all. Canvas has no vertical writing mode, so the text has to be laid out glyph by glyph,
|
|
287
|
+
with its own rules for which characters rotate and which stand upright. This is real work
|
|
288
|
+
and it is scheduled as such, not assumed to fall out of the other two.
|
|
289
|
+
|
|
290
|
+
Message tables are compiled at build time, the same way every other resource is, so adding
|
|
291
|
+
a language costs nothing at runtime and a missing string falls back to the base language
|
|
292
|
+
rather than showing a raw key to the player.
|
|
293
|
+
|
|
294
|
+
## Optional Babylon.js 3D
|
|
295
|
+
|
|
296
|
+
`@babylonjs/core`/`@babylonjs/loaders` are peer dependencies, not installed automatically -
|
|
297
|
+
a game that never imports `mwg/3d` never downloads Babylon.js. Add them yourself
|
|
298
|
+
(`npm install @babylonjs/core @babylonjs/loaders`) once a game imports 3D support:
|
|
299
|
+
|
|
300
|
+
```ts
|
|
301
|
+
import { Engine3D, createTileGrid3D } from '@datamoc/mw_games/3d';
|
|
302
|
+
import { loadModel3D } from '@datamoc/mw_games/3d/models';
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
`Engine3D` owns a WebGL scene, orbit camera, light, resize handling, and render loop.
|
|
306
|
+
`createTileGrid3D` batches square or flat-top hex tiles and elevation columns with thin
|
|
307
|
+
instances; `createHeightmapTerrain3D` builds continuous terrain from decoded RGBA heightmap
|
|
308
|
+
pixels. `Character3D` moves imported meshes or camera-facing sprites continuously, and can
|
|
309
|
+
play imported animation clips. `parseVox` and `createVoxModel3D` load one MagicaVoxel model;
|
|
310
|
+
`loadModel3D` handles glTF/GLB.
|
|
311
|
+
Run `npm run example:3d` for the live example or `npm run benchmark:3d` for its FPS gate.
|
|
312
|
+
|
|
313
|
+
## Headless simulation
|
|
314
|
+
|
|
315
|
+
`@datamoc/mw_games/simulation` has no rendering or browser imports. It provides two
|
|
316
|
+
small runners while games keep their state, commands, rules, and event types:
|
|
317
|
+
|
|
318
|
+
- `advanceToInput(rules, budget)` runs automatic scheduled actions until an actor needs
|
|
319
|
+
input, the game finishes, the queue is empty, or the action budget is reached. Rules
|
|
320
|
+
supply `scheduler`, `finished`, `needsInput`, and `act`. `act` returns the cost to
|
|
321
|
+
charge to the current queue entry after the action, or `null` when it handled its own
|
|
322
|
+
scheduling. A `limit` result does not grant input; the caller chooses how to resume.
|
|
323
|
+
- `runScenario({ state, commands, random, step, status? })` applies a finite command
|
|
324
|
+
sequence, preserving event order and stopping when a rule returns `finished`. Each
|
|
325
|
+
rule returns `{ state, events, status: 'ready' | 'finished' }`. Results also report
|
|
326
|
+
`processedCommands`; a command need not consume a game turn.
|
|
327
|
+
|
|
328
|
+
```ts
|
|
329
|
+
import { runScenario } from '@datamoc/mw_games/simulation';
|
|
330
|
+
|
|
331
|
+
const result = runScenario({
|
|
332
|
+
state: { position: 0 },
|
|
333
|
+
commands: [1, 2, -1],
|
|
334
|
+
random: null, // This example has no randomness; supply a generator when needed.
|
|
335
|
+
step: (state, distance, _random) => ({
|
|
336
|
+
state: { position: state.position + distance },
|
|
337
|
+
events: [{ moved: distance }],
|
|
338
|
+
status: 'ready',
|
|
339
|
+
}),
|
|
340
|
+
});
|
|
341
|
+
// result.state.position === 2; result.processedCommands === 3
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
The root/standalone build also exposes these as `Simulation`. The dungeon example uses
|
|
345
|
+
the scheduled runner and shares its own damage rule between the scene and headless
|
|
346
|
+
scenario tests. Neither runner implements a game's combat, inventory, or movement rules.
|
|
347
|
+
|
|
348
|
+
For reproducibility, supply the same initial state, commands, and random state, and keep
|
|
349
|
+
rules independent of wall-clock time and ambient randomness. Existing `Generator`
|
|
350
|
+
instances expose `getState()`/`setState()`; store that state alongside a game's snapshot.
|
|
351
|
+
The runners do not clone state, serialize arbitrary graphs, or roll back a throwing rule.
|
|
352
|
+
Frame-based `core.Recorder`/`Player` remains available for UI replay; command scenarios do
|
|
353
|
+
not need a frame loop. Callers must bound automatic work inside each rule, for example
|
|
354
|
+
with `advanceToInput`.
|
|
355
|
+
|
|
356
|
+
## Roadmap
|
|
357
|
+
|
|
358
|
+
See [ROADMAP.md](ROADMAP.md) for the full, numbered build order and implementation notes.
|
|
359
|
+
The optional 3D group is now implemented without changing the existing 2D entry point.
|
|
360
|
+
|
|
361
|
+
## Licence and provenance
|
|
362
|
+
|
|
363
|
+
`mwg` is MPL-2.0. Its dependencies are permissive and compatible: PixiJS and Babylon.js are
|
|
364
|
+
MIT, and rot.js is BSD-3-Clause.
|
|
365
|
+
|
|
366
|
+
`tools/vendored/rgssad-wasm` is a build of the `rgssad-wasm` crate from
|
|
367
|
+
<https://github.com/nathaniel-daniel/rgssad-rs>, used under its MIT licence
|
|
368
|
+
option (© 2022 Nathaniel Daniel); see `tools/vendored/rgssad-wasm/README.md`.
|
|
369
|
+
It is a developer-side archive tool only, not part of the framework or any game.
|
|
370
|
+
|
|
371
|
+
Shattered Pixel Dungeon (GPL-3, © Oleg Dolya and Evan Debenham), The Battle for Wesnoth
|
|
372
|
+
(GPL-2.0-or-later, © the Battle for Wesnoth contributors), Flare's Empyrean Campaign
|
|
373
|
+
(GPL-3, © the Flare project), and Dungeon Crawl Stone Soup (GPL-2.0, © the Dungeon Crawl
|
|
374
|
+
Stone Soup development team) are referenced only as design studies: a list of what a
|
|
375
|
+
finished roguelike, a finished hex-based tactical game, a finished isometric one, and a
|
|
376
|
+
finished branching dungeon each have to do. None of their code, assets, maps, unit
|
|
377
|
+
definitions or text is included here, and `mwg` is not a derivative work of any of them.
|
|
378
|
+
|
|
379
|
+
ADOM, RPG Maker, Pokémon, Ren'Py and Twine are likewise references for a *shape of game*, not
|
|
380
|
+
sources of anything. `mwg` includes none of their runtimes, assets, text or data tables: no
|
|
381
|
+
type chart, no species list, no stat formula, no map, no line of dialogue. Those are each
|
|
382
|
+
game's own design work. A loader or writer for one of their file formats is a different
|
|
383
|
+
matter and is not off limits on its own: a format is a container, understood the same way
|
|
384
|
+
any published format is, by reading real files in it to learn its shape; what stays out is
|
|
385
|
+
the media that container holds, someone else's actual assets, text or data tables. Where a
|
|
386
|
+
format already exists and needs no reverse-engineering, `mwg` uses Tiled's, which is open
|
|
387
|
+
and documented.
|
|
388
|
+
|
|
389
|
+
Game mechanics are not themselves protected, which is why a framework may offer "a turn
|
|
390
|
+
queue ordered by speed" or "an effectiveness matrix". Particular numbers, names and
|
|
391
|
+
artwork are another matter, and none appear here.
|
|
392
|
+
|
|
393
|
+
The assets under `examples/assets` are generated by `tools/make-example-assets.mjs` and
|
|
394
|
+
carry the project's own licence. Nothing else in this repository was downloaded from
|
|
395
|
+
anywhere, with the sole exception of `tools/vendored/rgssad-wasm` above.
|