fix font / portrait editors, neut tileset serialization

This commit is contained in:
Jeremy Penner 2020-12-30 12:47:07 -05:00
parent 56ce6d15b6
commit 3fc5ef8e15
5 changed files with 24 additions and 5 deletions

View file

@ -7,6 +7,7 @@
(fn FontEditView.spritegen [self] tiledraw.char-to-sprite)
(fn FontEditView.tilesize [self] (values 8 8))
(fn FontEditView.tilekeys [self] [:gfx])
(fn FontEditView.map-bitxy [self x y] (values y x))
(fn FontEditView.draw-tile-flags [self x y]
(when self.itile

View file

@ -8,6 +8,7 @@
(fn PortraitView.spritegen [self] tiledraw.portrait-to-sprite)
(fn PortraitView.tilesize [self] (values 32 32))
(fn PortraitView.tilekeys [self] [:gfx])
(fn PortraitView.filename [self] tiles.fn-portraits)
(fn PortraitView.map-bitxy [self x y]
(local quadrant (+ (if (>= x 16) 2 0) (if (>= y 16) 1 0)))

View file

@ -20,6 +20,7 @@
(values ibyte ibit)))
(fn TileView.tilesize [self] (values 16 16))
(fn TileView.tilekeys [self] [:gfx :neut])
(fn get-byte [tile ibyte]
(: (tile:sub (+ ibyte 1) (+ ibyte 1)) :byte))
@ -89,13 +90,18 @@
(fn TileView.save [self] (tiles.savegfx (self:filename) self.tilecache.tiles))
(fn TileView.draw-neut-tile-selector [self x y]
(self:draw-tile-selector x (- self.size.x 20) :neut))
(fn TileView.draw [self]
(self:draw_background style.background)
(local (x y) (values (+ self.position.x 10) (+ self.position.y 10)))
(local (editor-w editor-h) (self:draw-tile-editor (self:tile) x y))
(self:draw-tile-flags (+ x editor-w pixel-size) y)
(local top-selector-h (self:draw-tile-selector x (+ y editor-h pixel-size) (- self.size.x 20)))
(self:draw-tile-selector x (+ y editor-h pixel-size top-selector-h pixel-size) (- self.size.x 20) :neut))
(var selector-y (+ y editor-h pixel-size))
(each [_ key (ipairs (self:tilekeys))]
(local selector-h (self:draw-tile-selector x selector-y (- self.size.x 20) key))
(set selector-y (+ selector-y selector-h pixel-size))))
(fn TileView.get_name [self] "Tile Editor")

View file

@ -6,12 +6,23 @@
(each [iflag flag (ipairs flags)]
(tset flag-to-bit flag (bit.lshift 1 (- iflag 1))))
(local encoded-tile-fields [:gfx :neut])
(fn convert [tile field method]
(local oldval (. tile field))
(when oldval
(tset tile field (: oldval method)))
tile)
(fn convert-all [tile method]
(each [_ field (ipairs encoded-tile-fields)]
(convert tile field method))
tile)
(fn deserialize [tile]
(match (type tile)
:string {:gfx (tile:fromhex) :flags {}}
:table (doto tile (tset :gfx (tile.gfx:fromhex)))))
:table (convert-all tile :fromhex)))
(fn serialize [tile] (doto (lume.clone tile) (tset :gfx (tile.gfx:tohex))))
(fn serialize [tile] (convert-all (lume.clone tile) :tohex))
(local fn-tiles "game/tiles.json")
(local fn-portraits "game/portraits.json")

File diff suppressed because one or more lines are too long