From 4a2a0d130b643c5813339fe25d6c474a0b83267b Mon Sep 17 00:00:00 2001 From: Zsolt Tasnadi Date: Thu, 30 Jul 2026 07:19:20 +0200 Subject: [PATCH] assetFS --- README.md | 9 ++++++++- main.go | 14 +++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 94bf2f0..2267c1d 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/main.go b/main.go index 06b9317..3e39a66 100644 --- a/main.go +++ b/main.go @@ -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() }