Fix tile editor for neut tower
This commit is contained in:
parent
10b29177a3
commit
4024abd074
|
@ -1,6 +1,7 @@
|
||||||
(local GraphicsEditView (require :editor.gfxedit))
|
(local GraphicsEditView (require :editor.gfxedit))
|
||||||
(local style (require :core.style))
|
(local style (require :core.style))
|
||||||
(local tiles (require :game.tiles))
|
(local tiles (require :game.tiles))
|
||||||
|
(local files (require :game.files))
|
||||||
(local tiledraw (require :editor.tiledraw))
|
(local tiledraw (require :editor.tiledraw))
|
||||||
(local util (require :lib.util))
|
(local util (require :lib.util))
|
||||||
(local {: mouse-inside : activate : active? : checkbox : textfield} (util.require :editor.imstate))
|
(local {: mouse-inside : activate : active? : checkbox : textfield} (util.require :editor.imstate))
|
||||||
|
@ -20,7 +21,9 @@
|
||||||
(values ibyte ibit)))
|
(values ibyte ibit)))
|
||||||
|
|
||||||
(fn TileView.tilesize [self] (values 16 16))
|
(fn TileView.tilesize [self] (values 16 16))
|
||||||
(fn TileView.tilekeys [self] [:gfx])
|
(fn TileView.tilekeys [self]
|
||||||
|
(if files.game.tilesets (icollect [_ key (pairs files.game.tilesets)] key)
|
||||||
|
[:gfx]))
|
||||||
|
|
||||||
(fn get-byte [tile ibyte]
|
(fn get-byte [tile ibyte]
|
||||||
(: (tile:sub (+ ibyte 1) (+ ibyte 1)) :byte))
|
(: (tile:sub (+ ibyte 1) (+ ibyte 1)) :byte))
|
||||||
|
|
|
@ -12,27 +12,30 @@
|
||||||
(when oldval
|
(when oldval
|
||||||
(tset tile field (: oldval method)))
|
(tset tile field (: oldval method)))
|
||||||
tile)
|
tile)
|
||||||
(fn convert-all [tile method]
|
(fn convert-all [tile method root]
|
||||||
|
(let [encoded-tile-fields [:mask]]
|
||||||
|
(each [_ key (pairs (or root.tilesets {:tileset :gfx}))]
|
||||||
|
(table.insert encoded-tile-fields key))
|
||||||
(each [_ field (ipairs encoded-tile-fields)]
|
(each [_ field (ipairs encoded-tile-fields)]
|
||||||
(convert tile field method))
|
(convert tile field method))
|
||||||
tile)
|
tile))
|
||||||
|
|
||||||
(fn tile-deserialize [tile]
|
(fn tile-deserialize [tile root]
|
||||||
(match (type tile)
|
(match (type tile)
|
||||||
:string {:gfx (tile:fromhex) :flags {}}
|
:string {:gfx (tile:fromhex) :flags {}}
|
||||||
:table (convert-all tile :fromhex)))
|
:table (convert-all tile :fromhex root)))
|
||||||
|
|
||||||
(fn tile-serialize [tile] (convert-all (lume.clone tile) :tohex))
|
(fn tile-serialize [tile root] (convert-all (lume.clone tile) :tohex root))
|
||||||
|
|
||||||
(fn deserialize [key value]
|
(fn deserialize [key value root]
|
||||||
(match key
|
(match key
|
||||||
(where (or :tiles :portraits :font)) (tile-deserialize value)
|
(where (or :tiles :portraits :font)) (tile-deserialize value root)
|
||||||
:levels (do (set value.map (value.map:fromhex)) value)
|
:levels (do (set value.map (value.map:fromhex)) value)
|
||||||
_ value))
|
_ value))
|
||||||
|
|
||||||
(fn serialize [key value]
|
(fn serialize [key value root]
|
||||||
(match key
|
(match key
|
||||||
(where (or :tiles :portraits :font)) (tile-serialize value)
|
(where (or :tiles :portraits :font)) (tile-serialize value root)
|
||||||
:levels (do (set value.map (value.map:tohex)) value)
|
:levels (do (set value.map (value.map:tohex)) value)
|
||||||
_ value))
|
_ value))
|
||||||
|
|
||||||
|
@ -48,7 +51,7 @@
|
||||||
(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)
|
game)
|
||||||
{:tiles [] :portraits [] :font [] :levels []}))
|
{:tiles [] :portraits [] :font [] :levels []}))
|
||||||
files.game)
|
files.game)
|
||||||
|
@ -57,7 +60,7 @@
|
||||||
(when ?filename (set files.filename ?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) files.game))))
|
||||||
(util.writejson (filename) game)))
|
(util.writejson (filename) game)))
|
||||||
|
|
||||||
(fn new-cache [game key]
|
(fn new-cache [game key]
|
||||||
|
|
|
@ -14,8 +14,9 @@
|
||||||
(fn appendtiles [org]
|
(fn appendtiles [org]
|
||||||
(local tiles files.game.tiles)
|
(local tiles files.game.tiles)
|
||||||
(local flag-lookup (flag-to-bit))
|
(local flag-lookup (flag-to-bit))
|
||||||
(org:append [:align 0x100] :tileset)
|
(each [tileset key (pairs (or files.game.tilesets {:tileset :gfx}))]
|
||||||
(appendgfx org tiles)
|
(org:append [:align 0x100] tileset)
|
||||||
|
(appendgfx org tiles key (if (= key :gfx) nil (.. key :-))))
|
||||||
(appendgfx org files.game.portraits nil :portrait-)
|
(appendgfx org files.game.portraits nil :portrait-)
|
||||||
(org:append :tileflags)
|
(org:append :tileflags)
|
||||||
(each [_ tile (ipairs tiles)]
|
(each [_ tile (ipairs tiles)]
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -60,6 +60,7 @@
|
||||||
" * Hot code reload"
|
" * Hot code reload"
|
||||||
"* Tape upload"
|
"* Tape upload"
|
||||||
"* ProDOS disk image generation"]
|
"* ProDOS disk image generation"]
|
||||||
|
;; DEMO before tech dive
|
||||||
[h "Assembler"
|
[h "Assembler"
|
||||||
** "Represent instructions using Fennel data literals"
|
** "Represent instructions using Fennel data literals"
|
||||||
" [:lda 0xff]"
|
" [:lda 0xff]"
|
||||||
|
|
1
wrap.fnl
1
wrap.fnl
|
@ -19,7 +19,6 @@
|
||||||
(fn [text]
|
(fn [text]
|
||||||
(local files [])
|
(local files [])
|
||||||
(each [_ item (pairs core.project_files)]
|
(each [_ item (pairs core.project_files)]
|
||||||
(print item.filename)
|
|
||||||
(when (and (= item.type :file) (item.filename:find "^.*/game%.json"))
|
(when (and (= item.type :file) (item.filename:find "^.*/game%.json"))
|
||||||
(table.insert files item.filename)))
|
(table.insert files item.filename)))
|
||||||
(common.fuzzy_match files text))))})
|
(common.fuzzy_match files text))))})
|
||||||
|
|
Loading…
Reference in a new issue