honeylisp/game/tiles.fnl

27 lines
828 B
Plaintext
Raw Normal View History

2020-10-12 15:48:14 +00:00
(local util (require :lib.util))
(local lume (require :lib.lume))
(local flags [:walkable :neutable :debris])
2020-10-12 15:48:14 +00:00
(fn deserialize [tile]
(match (type tile)
:string {:gfx (tile:fromhex) :flags {}}
:table (doto tile (tset :gfx (tile.gfx:fromhex)))))
(fn serialize [tile] (doto (lume.clone tile) (tset :gfx (tile.gfx:tohex))))
(fn loadtiles [] (lume.map (util.readjson "game/tiles.json") deserialize))
(fn savetiles [tiles] (util.writejson "game/tiles.json" (lume.map tiles serialize)))
2020-10-12 15:48:14 +00:00
(fn appendtiles [tiles org]
(each [_ tile (ipairs tiles)]
(when tile.label (org:append tile.label))
(org:append [:bytes tile.gfx])))
2020-10-12 15:48:14 +00:00
2020-10-19 00:13:26 +00:00
(fn appendmaps [org]
2020-10-29 17:10:57 +00:00
(local map (util.readjson "game/map00001.json"))
(org:append :map [:bytes (map.map:fromhex)]))
2020-10-19 00:13:26 +00:00
{: loadtiles : savetiles : appendtiles : appendmaps : flags}
2020-10-12 15:48:14 +00:00