8-bitsy builds, allow :game.files to override filename

This commit is contained in:
Jeremy Penner 2021-06-21 22:59:34 -04:00
parent 16a6830b20
commit d5714f14d4
4 changed files with 17 additions and 7 deletions

Binary file not shown.

View file

@ -4,8 +4,7 @@
(local files (util.hot-table ...)) (local files (util.hot-table ...))
(local filename "game/game.json") (local default-filename "bitsy/game.json")
(local encoded-tile-fields [:gfx :mask]) (local encoded-tile-fields [:gfx :mask])
(fn convert [tile field method] (fn convert [tile field method]
@ -42,21 +41,24 @@
:table (lume.clone v) :table (lume.clone v)
_ v)) _ v))
(fn files.load [] (fn filename [] (or files.filename default-filename))
(fn files.load [?filename]
(when ?filename (set files.filename ?filename))
(set files.game (set files.game
(if (util.file-exists filename) (if (util.file-exists (filename))
(let [game (util.readjson filename)] (let [game (util.readjson (filename))]
(each [k v (pairs game)] (each [k v (pairs game)]
(tset game k (lume.map v #(deserialize k (clone $1))))) (tset game k (lume.map v #(deserialize k (clone $1)))))
game) game)
{:tiles [] :portraits [] :font [] :levels []})) {:tiles [] :portraits [] :font [] :levels []}))
files.game) files.game)
(fn files.save [] (fn files.save [?filename]
(when ?filename (set files.filename ?filename))
(let [game {}] (let [game {}]
(each [k v (pairs files.game)] (each [k v (pairs files.game)]
(tset game k (lume.map v #(serialize k (clone $1))))) (tset game k (lume.map v #(serialize k (clone $1)))))
(util.writejson filename game))) (util.writejson (filename) game)))
(fn new-cache [game key] (fn new-cache [game key]
(let [spritegen (match key (let [spritegen (match key
@ -77,6 +79,9 @@
(each [key cache (pairs files.tilecaches)] (each [key cache (pairs files.tilecaches)]
(cache:load (. files.game key))))) (cache:load (. files.game key)))))
(fn files.module []
(or files.game.module (: (filename) :match "^[^/]+")))
(when (= files.game nil) (when (= files.game nil)
(files.load)) (files.load))

5
game/init.fnl Normal file
View file

@ -0,0 +1,5 @@
(local files (require :game.files))
(local util (require :lib.util))
(util.reload (files.module))