assetFS
This commit is contained in:
@@ -52,7 +52,7 @@ Game content lives in `lib/` as package-level `var`s — one struct value
|
||||
per file, no constructor functions. `main.go` only calls `lib.Run()`.
|
||||
|
||||
```
|
||||
main.go func main() { lib.Run() }
|
||||
main.go embeds assets/ (go:embed) and calls lib.Run()
|
||||
lib/
|
||||
setup.go Run() and Build(); the only wiring code
|
||||
assets.go var Assets []pncdsl.Asset
|
||||
@@ -74,6 +74,13 @@ Adding new content means creating one file with one `var`, and adding
|
||||
one `Register(...)` line in `lib/setup.go`. No registrar functions, no
|
||||
indirection.
|
||||
|
||||
The `assets/` tree is compiled into the binary via `go:embed` and
|
||||
handed to the framework through `pncdsl.AssetFS`, so the js/wasm build
|
||||
(`make wasm`) ships with working art. Native builds read from the same
|
||||
embedded copy — changing a PNG requires a rebuild. Files listed in
|
||||
`lib/assets.go` but missing from `assets/` still fall back to the
|
||||
framework's colored placeholders.
|
||||
|
||||
## Custom theme and chat widget
|
||||
|
||||
The demo ships with a game-specific theme (`morning-coffee`, warm coffee
|
||||
|
||||
@@ -1,7 +1,19 @@
|
||||
package main
|
||||
|
||||
import "git.teletypegames.org/games/pncdsl-demo/lib"
|
||||
import (
|
||||
"embed"
|
||||
|
||||
p "git.teletypegames.org/games/pncdsl"
|
||||
"git.teletypegames.org/games/pncdsl-demo/lib"
|
||||
)
|
||||
|
||||
// The asset tree is compiled into the binary so the js/wasm build can
|
||||
// load it too — in the browser there is no OS filesystem to read from.
|
||||
//
|
||||
//go:embed assets
|
||||
var assetsFS embed.FS
|
||||
|
||||
func main() {
|
||||
p.AssetFS = assetsFS
|
||||
lib.Run()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user