45 lines
1.4 KiB
Fennel
45 lines
1.4 KiB
Fennel
(local util (require :lib.util))
|
|
(local lume (require :lib.lume))
|
|
|
|
(local flags [:walkable :neutable :debris])
|
|
(local flag-to-bit {})
|
|
(each [iflag flag (ipairs flags)]
|
|
(tset flag-to-bit flag (bit.lshift 1 (- iflag 1))))
|
|
|
|
(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))))
|
|
|
|
(local fn-tiles "game/tiles.json")
|
|
(local fn-portraits "game/portraits.json")
|
|
(local fn-font "game/font.json")
|
|
|
|
(fn loadgfx [filename] (lume.map (util.readjson filename) deserialize))
|
|
(fn savegfx [filename gfx] (util.writejson filename (lume.map gfx serialize)))
|
|
|
|
(fn appendgfx [org gfx]
|
|
(each [_ g (ipairs gfx)]
|
|
(when g.label (org:append g.label))
|
|
(org:append [:bytes g.gfx])))
|
|
|
|
(fn appendtiles [org]
|
|
(local tiles (loadgfx fn-tiles))
|
|
(appendgfx org tiles)
|
|
(appendgfx org (loadgfx fn-portraits))
|
|
(org:append :tileflags)
|
|
(each [_ tile (ipairs tiles)]
|
|
(var flags 0)
|
|
(each [flag _ (pairs tile.flags)]
|
|
(set flags (bit.bor flags (. flag-to-bit flag))))
|
|
(org:append [:db flags])))
|
|
|
|
(fn append-map [map org]
|
|
(org:append :map [:bytes (map.map:fromhex)] :map-entity-count [:db (length map.objects)]))
|
|
|
|
{: loadgfx : savegfx : appendtiles : appendgfx : append-map : flags : flag-to-bit
|
|
: fn-tiles : fn-portraits : fn-font}
|
|
|