wobblyhead hg > minor_monsters
comparison doc/architecture.md @ 17:fe680946164b
reorganised repo
| author | ark |
|---|---|
| date | 2026-10-20 00:12 +0200 |
| parents | 7fda634d15ad |
| children | fa04481563b7 |
comparison
equal
deleted
inserted
replaced
| 16:30bd10284fd8 | 17:fe680946164b |
|---|---|
| 1 architecture | 1 architecture |
| 2 ------------ | 2 ------------ |
| 3 | 3 |
| 4 the game is a static html page with plain javascript, drawn on a 2d canvas. it | 4 the game is a static html page with plain javascript, drawn on a 2d canvas. it |
| 5 uses no javascript libraries and needs no build step to run. a python build | 5 uses no javascript libraries. a python build script prepares everything that |
| 6 script prepares everything that can be calculated in advance: processed | 6 can be calculated in advance: processed images, map data, route data and the |
| 7 images, map data, route data and the config. its output is committed, so the | 7 config. it writes them to www/, together with a copy of the hand-written game |
| 8 game runs straight from the source tree. | 8 files from game/. www/ is the runnable game. it is not kept in the repository, |
| 9 so the game has to be built before it can be run. | |
| 9 | 10 |
| 10 this is a plan; nothing is implemented yet. | 11 this is a plan; nothing is implemented yet. |
| 11 | 12 |
| 12 | 13 |
| 13 directory layout | 14 directory layout |
| 20 sounds/ sounds cut from the recordings (tools/cut_sounds.py) | 21 sounds/ sounds cut from the recordings (tools/cut_sounds.py) |
| 21 config/ hand-edited game settings (toml) | 22 config/ hand-edited game settings (toml) |
| 22 game.toml numbers from balance.md, waves, debug switches | 23 game.toml numbers from balance.md, waves, debug switches |
| 23 routes.toml manual corrections to the extracted routes | 24 routes.toml manual corrections to the extracted routes |
| 24 tools/ python build scripts | 25 tools/ python build scripts |
| 25 game/ the runnable game, opened as game/index.html | 26 game/ hand-written game files |
| 26 index.html | 27 index.html |
| 27 style.css | 28 style.css |
| 28 js/ game code, hand-written | 29 js/ game code |
| 29 assets/ processed images (generated, committed) | |
| 30 data/ maps.js, sounds.js, config.js (generated, committed) | |
| 31 doc/ design and technical notes | 30 doc/ design and technical notes |
| 32 www/ copy of game/ prepared for publishing (ignored) | 31 www/ the built game, opened as www/index.html (generated, ignored) |
| 32 index.html copied from game/, as are style.css and js/ | |
| 33 assets/ processed images | |
| 34 data/ maps.js, sounds.js, config.js | |
| 33 dist/ zip archives for distribution (ignored) | 35 dist/ zip archives for distribution (ignored) |
| 34 temp/ scratch files, build previews (ignored) | 36 temp/ scratch files, build previews (ignored) |
| 35 | 37 |
| 36 generated files carry a header line saying so and naming the script that made | 38 generated files carry a header line saying so and naming the script that made |
| 37 them. | 39 them. |
| 38 | 40 |
| 39 | 41 |
| 40 running the game | 42 running the game |
| 41 ---------------- | 43 ---------------- |
| 42 | 44 |
| 43 - desktop: open game/index.html directly from disk, or serve the directory | 45 - desktop: open www/index.html directly from disk, or serve the directory |
| 44 with any static web server | 46 with any static web server |
| 45 - tablet: tablets cannot easily open local html files, so the game is served | 47 - tablet: tablets cannot easily open local html files, so the game is served |
| 46 over http, from a computer on the home network or from a web host. www/ is | 48 over http, from a computer on the home network or from a web host. the zip |
| 47 the copy meant for that | 49 in dist/ is meant for that |
| 48 - an optional later step makes it installable to the home screen (web app | 50 - an optional later step makes it installable to the home screen (web app |
| 49 manifest, offline cache). that requires https | 51 manifest, offline cache). that requires https |
| 50 | 52 |
| 51 opening the page from disk (file://) limits what the browser allows. chrome | 53 opening the page from disk (file://) limits what the browser allows. chrome |
| 52 blocks javascript modules, fetch() and reading pixels back from a canvas | 54 blocks javascript modules, fetch() and reading pixels back from a canvas |
| 67 firefox's own --screenshot captures at the load event. the game loads its | 69 firefox's own --screenshot captures at the load event. the game loads its |
| 68 images and draws its first frame after that, so the capture shows an empty | 70 images and draws its first frame after that, so the capture shows an empty |
| 69 page. the ff_screenshot script (in $PATH, ~/bin/ff_screenshot) drives | 71 page. the ff_screenshot script (in $PATH, ~/bin/ff_screenshot) drives |
| 70 headless firefox over marionette and waits before capturing: | 72 headless firefox over marionette and waits before capturing: |
| 71 | 73 |
| 72 ff_screenshot -w 1024,768 -s 2 file://$PWD/game/index.html temp/splash.png | 74 ff_screenshot -w 1024,768 -s 2 file://$PWD/www/index.html temp/splash.png |
| 73 | 75 |
| 74 -w sets the viewport, -s the wait after loading. the game state is not | 76 -w sets the viewport, -s the wait after loading. the game state is not |
| 75 reachable from outside, so other screens are reached by tapping: -J runs | 77 reachable from outside, so other screens are reached by tapping: -J runs |
| 76 javascript after the wait, and -S waits again before capturing. a pointer | 78 javascript after the wait, and -S waits again before capturing. a pointer |
| 77 event sent to the canvas counts as a tap at that position in css pixels. | 79 event sent to the canvas counts as a tap at that position in css pixels. |
| 78 this taps the play button on the splash screen at 1024 x 768: | 80 this taps the play button on the splash screen at 1024 x 768: |
| 79 | 81 |
| 80 ff_screenshot -w 1024,768 -s 2 -S 3 -J 'document.getElementById("game") | 82 ff_screenshot -w 1024,768 -s 2 -S 3 -J 'document.getElementById("game") |
| 81 .dispatchEvent(new PointerEvent("pointerdown", | 83 .dispatchEvent(new PointerEvent("pointerdown", |
| 82 {clientX: 497, clientY: 560, bubbles: true}))' \ | 84 {clientX: 497, clientY: 560, bubbles: true}))' \ |
| 83 file://$PWD/game/index.html temp/play.png | 85 file://$PWD/www/index.html temp/play.png |
| 84 | 86 |
| 85 `ff_screenshot -h` lists the other options. | 87 `ff_screenshot -h` lists the other options. |
| 86 | 88 |
| 87 | 89 |
| 88 build | 90 build |
| 98 cut_sounds.py also needs ffmpeg with mp3 support, so the build itself does not | 100 cut_sounds.py also needs ffmpeg with mp3 support, so the build itself does not |
| 99 depend on it. see sound.md. | 101 depend on it. see sound.md. |
| 100 | 102 |
| 101 steps: | 103 steps: |
| 102 | 104 |
| 103 1. sprites: trim transparent edges, write to game/assets/. this covers the | 105 1. sprites: trim transparent edges, write to www/assets/. this covers the |
| 104 icons, buttons and screens, and the digits from art/digits/ as | 106 icons, buttons and screens, and the digits from art/digits/ as |
| 105 digit_NAME_N. make the hp bar variants: the empty part, and the blue bars | 107 digit_NAME_N. make the hp bar variants: the empty part, and the blue bars |
| 106 for slowed monsters (art.md) | 108 for slowed monsters (art.md) |
| 107 2. tower levels: t0-t3 are level 1. split each t*p strip into four images, | 109 2. tower levels: t0-t3 are level 1. split each t*p strip into four images, |
| 108 levels 2-5. fill the inside of the outline with white (flood fill from | 110 levels 2-5. fill the inside of the outline with white (flood fill from |
| 115 nor opaque pure red, blue or green stops the build (art.md) | 117 nor opaque pure red, blue or green stops the build (art.md) |
| 116 - extract routes, see below | 118 - extract routes, see below |
| 117 - write a placement grid: cells where a tower footprint fits next to the | 119 - write a placement grid: cells where a tower footprint fits next to the |
| 118 road, within the limits in balance.md. the red path in the mask is the | 120 road, within the limits in balance.md. the red path in the mask is the |
| 119 centre line of the road; the road's half width is set per map | 121 centre line of the road; the road's half width is set per map |
| 120 5. sounds: embed art/sounds/*.mp3 as base64 in game/data/sounds.js, | 122 5. sounds: embed art/sounds/*.mp3 as base64 in www/data/sounds.js, |
| 121 grouped by event | 123 grouped by event |
| 122 6. config: read config/game.toml, check it, write game/data/config.js | 124 6. config: read config/game.toml, check it, write www/data/config.js |
| 123 7. checks: print a summary per map (routes with length and turning, monster | 125 7. checks: print a summary per map (routes with length and turning, monster |
| 124 counts, coins and hp per map against the target) and warn on problems | 126 counts, coins and hp per map against the target) and warn on problems |
| 125 8. previews: draw each map with its routes, entrances, exits and placement | 127 8. previews: draw each map with its routes, entrances, exits and placement |
| 126 grid into temp/preview/, for checking without starting the game | 128 grid into temp/preview/, for checking without starting the game |
| 129 9. game files: copy the files in game/ to www/. a file is copied when its | |
| 130 time or size differs from the copy. files no longer in game/ are removed | |
| 131 from www/, apart from www/assets/ and www/data/ | |
| 127 | 132 |
| 128 a watch mode (`tools/build.py --watch`) reruns the build when a file in | 133 a watch mode (`tools/build.py --watch`) reruns the build when a file in |
| 129 config/, art/ or art/sounds/ changes. tuning then means: edit the toml, save, reload the | 134 config/, art/, art/sounds/ or game/ changes. tuning then means: edit the toml, |
| 130 browser. | 135 save, reload the browser. the same goes for changes to the game code: they |
| 131 | 136 show in www/ only after the build has copied them. |
| 132 `tools/publish.py` copies game/ to www/ with debug switches off, and writes a | 137 |
| 133 zip into dist/. | 138 `tools/publish.py` writes a zip of www/ into dist/, with debug switches off. |
| 134 | 139 |
| 135 | 140 |
| 136 routes | 141 routes |
| 137 ------ | 142 ------ |
| 138 | 143 |
| 167 | 172 |
| 168 config | 173 config |
| 169 ------ | 174 ------ |
| 170 | 175 |
| 171 config/game.toml holds every number in balance.md, the wave lists, and debug | 176 config/game.toml holds every number in balance.md, the wave lists, and debug |
| 172 switches. the build converts it into game/data/config.js. toml allows comments, | 177 switches. the build converts it into www/data/config.js. toml allows comments, |
| 173 so each value can carry its source note (guess, decided). | 178 so each value can carry its source note (guess, decided). |
| 174 | 179 |
| 175 wave format: | 180 wave format: |
| 176 | 181 |
| 177 [[map.0.wave]] | 182 [[map.0.wave]] |
