8-bitsy builds, allow :game.files to override filename
This commit is contained in:
parent
16a6830b20
commit
d5714f14d4
BIN
8Bitsy.dsk
BIN
8Bitsy.dsk
Binary file not shown.
|
@ -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
5
game/init.fnl
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
(local files (require :game.files))
|
||||||
|
(local util (require :lib.util))
|
||||||
|
|
||||||
|
(util.reload (files.module))
|
||||||
|
|
Loading…
Reference in a new issue