deprecate gfxedit2

This commit is contained in:
Jeremy Penner 2021-12-26 14:04:34 -06:00
parent e6eee86a91
commit 7b6893d6e3
7 changed files with 28 additions and 97 deletions

View file

@ -1,6 +1,5 @@
(local util (require :lib.util)) (local util (require :lib.util))
(local {: defmulti : defmethod} (util.require :lib.multimethod)) (local {: defmulti : defmethod} (util.require :lib.multimethod))
(local {: textfield} (util.require :editor.imstate))
(local actions (util.hot-table ...)) (local actions (util.hot-table ...))

View file

@ -3,7 +3,7 @@
(local tiledraw (require :editor.tiledraw)) (local tiledraw (require :editor.tiledraw))
(local util (require :lib.util)) (local util (require :lib.util))
(local files (require :game.files)) (local files (require :game.files))
(local {: attach-imstate : mouse-inside : activate : active? : button} (util.require :editor.imstate)) (local {: attach-imstate : button : reform : horiz-wrapper : group-wrapper} (util.require :editor.imgui))
(local GraphicsEditView (View:extend)) (local GraphicsEditView (View:extend))
@ -37,26 +37,28 @@
(let [sprite (self.tilecache:sprite itile ?key)] (let [sprite (self.tilecache:sprite itile ?key)]
(when sprite (when sprite
(love.graphics.setColor 1 1 1) (love.graphics.setColor 1 1 1)
(love.graphics.draw sprite x y 0 self.sprite-scale self.sprite-scale)))) (love.graphics.draw sprite x y 0 self.sprite-scale self.sprite-scale)
(values (* (sprite:getWidth) self.sprite-scale) (* (sprite:getHeight) self.sprite-scale)))))
(fn GraphicsEditView.draw-tile-selector [self x y w ?key] (fn tile-selector [{: view &as form} selected-itile ?key]
(var tilex x) (var selected-itile selected-itile)
(var tiley y) (let [g (group-wrapper form)
(var (pixw pixh) (self:tilesize)) wrap (horiz-wrapper form)]
(when (= files.game.platform :ii) (set pixw (* (/ pixw 8) 7))) (for [itile 1 (length view.tilecache.tiles)]
(local tilew (* self.sprite-scale pixw)) (let [{: x : y} form
(local tileh (* self.sprite-scale pixh)) (w h) (view:draw-sprite x y itile ?key)]
(for [itile 1 (length self.tilecache.tiles)] (when (and w h)
(self:draw-sprite tilex tiley itile ?key) (when (= itile selected-itile)
(when (and (= itile self.itile) (= ?key self.tilekey)) (love.graphics.rectangle :line (- x 2) (- y 2) (+ w 4) (+ h 4)))
(love.graphics.rectangle :line (- tilex 2) (- tiley 2) (+ tilew 4) (+ tileh 4))) (when (g button (reform form {:tag [:tile itile] : w : h}))
(when (button self [:tile itile] tilex tiley tilew tileh) (set selected-itile itile))
(set self.itile itile) (wrap form))))
(set self.tilekey ?key)) (g)
(set tilex (+ tilex tilew 4)) selected-itile))
(when (>= (+ tilex tilew) (+ x w))
(set tilex x) (fn GraphicsEditView.draw-tile-selector [self form ?key]
(set tiley (+ tiley tileh 4)))) (match (tile-selector (reform form {:scale self.sprite-scale :w form.w}) (when (= self.tilekey ?key) self.itile) ?key)
(+ tiley tileh (- y))) selected-itile (do (set self.itile selected-itile)
(set self.tilekey ?key))))
GraphicsEditView GraphicsEditView

View file

@ -1,64 +0,0 @@
(local View (require :core.view))
(local tiles (require :game.tiles))
(local tiledraw (require :editor.tiledraw))
(local util (require :lib.util))
(local files (require :game.files))
(local {: attach-imstate : button : reform : horiz-wrapper : group-wrapper} (util.require :editor.imgui))
(local GraphicsEditView (View:extend))
(local sprite-scale 4)
(set GraphicsEditView.sprite-scale sprite-scale)
(fn GraphicsEditView.new [self]
(GraphicsEditView.super.new self)
(self:set-style (self:initial-style))
(set self.scrollheight math.huge)
(set self.scrollable true)
(attach-imstate self))
(fn GraphicsEditView.get_scrollable_size [self] self.scrollheight)
(fn GraphicsEditView.initial-style [self] :tiles)
(fn GraphicsEditView.tilesize [self]
(let [style (tiles.style self.style)]
(values (or style.editw style.tilew) (or style.edith style.tileh))))
(fn GraphicsEditView.set-style [self key]
(set self.style key)
(set self.tilecache (files.cache key))
(set self.itile 1))
(fn GraphicsEditView.reload [self] (files.reload))
(fn GraphicsEditView.save [self] (files.save))
(fn GraphicsEditView.select-rel [self ditile]
(when self.itile
(local itile (+ self.itile ditile))
(when (>= itile 1) (set self.itile itile))))
(fn GraphicsEditView.draw-sprite [self x y itile ?key]
(let [sprite (self.tilecache:sprite itile ?key)]
(when sprite
(love.graphics.setColor 1 1 1)
(love.graphics.draw sprite x y 0 self.sprite-scale self.sprite-scale)
(values (* (sprite:getWidth) self.sprite-scale) (* (sprite:getHeight) self.sprite-scale)))))
(fn tile-selector [{: view &as form} selected-itile ?key]
(var selected-itile selected-itile)
(let [g (group-wrapper form)
wrap (horiz-wrapper form)]
(for [itile 1 (length view.tilecache.tiles)]
(let [{: x : y} form
(w h) (view:draw-sprite x y itile ?key)]
(when (and w h)
(when (= itile selected-itile)
(love.graphics.rectangle :line (- x 2) (- y 2) (+ w 4) (+ h 4)))
(when (g button (reform form {:tag [:tile itile] : w : h}))
(set selected-itile itile))
(wrap form))))
(g)
selected-itile))
(fn GraphicsEditView.draw-tile-selector [self form ?key]
(match (tile-selector (reform form {:scale self.sprite-scale :w form.w}) (when (= self.tilekey ?key) self.itile) ?key)
selected-itile (do (set self.itile selected-itile)
(set self.tilekey ?key))))
GraphicsEditView

View file

@ -43,12 +43,6 @@
"graphics-editor:next-tile" #(core.active_view:select-rel 1) "graphics-editor:next-tile" #(core.active_view:select-rel 1)
"graphics-editor:previous-tile" #(core.active_view:select-rel -1) "graphics-editor:previous-tile" #(core.active_view:select-rel -1)
}) })
(command.add (cmd-predicate :editor.gfxedit2) {
"graphics-editor:save" (fn [] (core.active_view:save) (core.log "Saved"))
"graphics-editor:reload" (fn [] (core.active_view:reload) (core.log "Reloaded"))
"graphics-editor:next-tile" #(core.active_view:select-rel 1)
"graphics-editor:previous-tile" #(core.active_view:select-rel -1)
})
(command.add (cmd-predicate :editor.tileedit) { (command.add (cmd-predicate :editor.tileedit) {
"tileedit:copy" "tileedit:copy"

View file

@ -1,4 +1,4 @@
(local GraphicsEditView (require :editor.gfxedit2)) (local GraphicsEditView (require :editor.gfxedit))
(local style (require :core.style)) (local style (require :core.style))
(local util (require :lib.util)) (local util (require :lib.util))
(local lume (require :lib.lume)) (local lume (require :lib.lume))

View file

@ -2,7 +2,7 @@
(local TileView (require :editor.tileedit)) (local TileView (require :editor.tileedit))
(local tiledraw (require :editor.tiledraw)) (local tiledraw (require :editor.tiledraw))
(local tiles (require :game.tiles)) (local tiles (require :game.tiles))
(local {: textfield} (util.require :editor.imstate)) (local {: textfield} (util.require :editor.imgui))
(local PortraitView (TileView:extend)) (local PortraitView (TileView:extend))
@ -19,10 +19,10 @@
(local tiley (% y 16)) (local tiley (% y 16))
(local (ibyte ibit) (PortraitView.super.map-bitxy self tilex tiley)) (local (ibyte ibit) (PortraitView.super.map-bitxy self tilex tiley))
(values (+ ibyte (* quadrant 32)) ibit)) (values (+ ibyte (* quadrant 32)) ibit))
(fn PortraitView.draw-tile-flags [self x y] (fn PortraitView.draw-tile-flags [self form]
(local tile (-?> self.tilecache.tiles (. self.itile))) (local tile (-?> self.tilecache.tiles (. self.itile)))
(when tile (when tile
(set tile.label (textfield self "Label" tile.label x (+ y 4) 100 200)))) (set tile.label (textfield form "Label" tile.label))))
(fn PortraitView.get_name [self] "Portrait Editor") (fn PortraitView.get_name [self] "Portrait Editor")

View file

@ -1,4 +1,4 @@
(local GraphicsEditView (require :editor.gfxedit2)) (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 files (require :game.files))