(local util (require :lib.util)) (local lume (require :lib.lume)) (local flags [:walkable :neutable :debris]) (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))) (fn appendtiles [tiles org] (each [_ tile (ipairs tiles)] (when tile.label (org:append tile.label)) (org:append [:bytes tile.gfx]))) (fn appendmaps [org] (local map (util.readjson "game/map00001.json")) (org:append :map [:bytes (map.map:fromhex)])) {: loadtiles : savetiles : appendtiles : appendmaps : flags}