even less code; copy/paste in tile editor

This commit is contained in:
Jeremy Penner 2020-10-18 10:53:43 -04:00
parent 65663b9722
commit 033d308662
4 changed files with 20 additions and 14 deletions

View file

@ -1,16 +1,13 @@
(fn attach-imstate [view] (fn attach-imstate [view]
(set view.imstate {}) (set view.imstate {})
(local cls view.__index)
(fn view.on_mouse_pressed [self button x y clicks] (fn view.on_mouse_pressed [self button x y clicks]
(tset self.imstate button :pressed) (tset self.imstate button :pressed)
(cls.on_mouse_pressed self button x y clicks)) (self.__index.on_mouse_pressed self button x y clicks))
(fn view.on_mouse_moved [self x y dx dy]
(cls.on_mouse_moved self x y dx dy))
(fn view.on_mouse_released [self button x y] (fn view.on_mouse_released [self button x y]
(tset self.imstate button :released) (tset self.imstate button :released)
(cls.on_mouse_released self button x y)) (self.__index.on_mouse_released self button x y))
(fn view.draw [self] (fn view.draw [self]
(cls.draw self) (self.__index.draw self)
(when (= self.imstate.left :released) (when (= self.imstate.left :released)
(set self.imstate.active nil)) (set self.imstate.active nil))
(each [_ button (pairs [:left :middle :right])] (each [_ button (pairs [:left :middle :right])]

View file

@ -14,11 +14,17 @@
"tileedit:save" (fn [] (core.active_view:save) (core.log "Saved tiles")) "tileedit:save" (fn [] (core.active_view:save) (core.log "Saved tiles"))
"tileedit:next-tile" #(core.active_view:select-rel 1) "tileedit:next-tile" #(core.active_view:select-rel 1)
"tileedit:previous-tile" #(core.active_view:select-rel -1) "tileedit:previous-tile" #(core.active_view:select-rel -1)
"tileedit:copy" #(system.set_clipboard (: (core.active_view:tile) :tohex))
"tileedit:paste"
#(when (= (length (system.get_clipboard)) 64)
(core.active_view:update-tile (: (system.get_clipboard) :fromhex)))
}) })
(keymap.add { (keymap.add {
"ctrl+s" "tileedit:save" "ctrl+s" "tileedit:save"
"left" "tileedit:previous-tile" "left" "tileedit:previous-tile"
"right" "tileedit:next-tile" "right" "tileedit:next-tile"
"ctrl+c" "tileedit:copy"
"ctrl+v" "tileedit:paste"
}) })

View file

@ -58,7 +58,7 @@
(fn TileView.tile [self] (or (. self.tiles self.itile) (string.rep "\0" 32))) (fn TileView.tile [self] (or (. self.tiles self.itile) (string.rep "\0" 32)))
(fn TileView.draw-tile [self tile x y] (fn TileView.draw-tile-editor [self tile x y]
(when (not (active? self :tile)) (when (not (active? self :tile))
(set self.bit nil)) (set self.bit nil))
(activate self :tile x y (* (+ pixel-size 1) 16) (* (+ pixel-size 1) 16)) (activate self :tile x y (* (+ pixel-size 1) 16) (* (+ pixel-size 1) 16))
@ -89,12 +89,9 @@
(tset self.tilesprites itile (tiledraw.tile-to-sprite (. self.tiles itile)))) (tset self.tilesprites itile (tiledraw.tile-to-sprite (. self.tiles itile))))
(. self.tilesprites itile)) (. self.tilesprites itile))
(fn TileView.draw [self] (fn TileView.draw-tile-selector [self x y]
(self:draw_background style.background) (var tilex x)
(local (x y) (values (+ self.position.x 10) (+ self.position.y 10))) (var tiley y)
(self:draw-tile (self:tile) x y)
(var tilex (+ self.position.x 10))
(var tiley (+ self.position.y (* 18 (+ pixel-size 1))))
(local tile-size (* 16 sprite-scale)) (local tile-size (* 16 sprite-scale))
(each [itile _ (ipairs self.tiles)] (each [itile _ (ipairs self.tiles)]
(love.graphics.draw (self:tilesprite itile) tilex tiley 0 sprite-scale sprite-scale) (love.graphics.draw (self:tilesprite itile) tilex tiley 0 sprite-scale sprite-scale)
@ -107,6 +104,12 @@
(set tilex (+ self.position.x 10)) (set tilex (+ self.position.x 10))
(set tiley (+ tiley tile-size 4))))) (set tiley (+ tiley tile-size 4)))))
(fn TileView.draw [self]
(self:draw_background style.background)
(local (x y) (values (+ self.position.x 10) (+ self.position.y 10)))
(self:draw-tile-editor (self:tile) x y)
(self:draw-tile-selector x (+ y (* 18 (+ pixel-size 1)))))
(fn TileView.get_name [self] "Tile Editor") (fn TileView.get_name [self] "Tile Editor")
TileView TileView

View file

@ -1 +1 @@
["000000020A0820404A4020080A02000000010141511005025302051051410100","00000000020A0820404A4020080A020000000101415110050253020510514101","808080C0C0C0E0C0D0C8C04040404080808083858585828A9282820A08081980","8080C0A0A0A0C0C0D0C8C0501010188080808183838782828A8A920202020380","8080E0B0B0B098C0D0D0C840404060808080878D8D8D99828A8A920202020780","8080C0E0E0E0B0C0D0C8C040404060808080838787878D828A92820202020780","0000000000000000000000000000000000000000000000000000000000000000","007C0C0C0C0C7C007C7E7EAA88888800001F181818181F001F0F979590909000","007C2C0C0C2C7C007C7E7EAA88888800001F18191C191F001F0F979590909000","D5D5D5D5D5D5D5D5D5D5D5D5D5D5D5D5AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","D5D5D5D5D5F5F5FDDDD5D5D5D5D5D5D5AAAAAAAAAEAEBFBFBFABAAAAAAAAAAAA","F7F7DDDDF7F7DDDDF7F7DDDDF7F7DDDDEEEEBBBBEEEEBBBBEEEEBBBBEEEEBBBB","F787A5B1B3B3B1B1B3B3B1B1B3B381DDEEE8B2A6E6E6A6A6E6E6A6A6E6E6A0BB","F78785818383818183838181838381DDEEE8B0A0E0E0A0A0E0E0A0A0E0E0A0BB","F7F7CDCDCFCF8981A3A3A5A5878FDDDDEEECA4A4E4E0A0A1E5E5A5A5E1E8BBBB","F7F7CDCDCFCF898123232525878FDDDDEEECA4A4E4E0A0216565252561E8BBBB"] ["000000020A0820404A4020080A02000000010141511005025302051051410100","00000000020A0820404A4020080A020000000101415110050253020510514101","808080C0C0C0E0C0D0C8C04040404080808083858585828A9282820A08081980","8080C0A0A0A0C0C0D0C8C0501010188080808183838782828A8A920202020380","8080E0B0B0B098C0D0D0C840404060808080878D8D8D99828A8A920202020780","8080C0E0E0E0B0C0D0C8C040404060808080838787878D828A92820202020780","0000000000000000000000000000000000000000000000000000000000000000","007C0C0C0C0C7C007C7E7EAA88888800001F181818181F001F0F979590909000","007C2C0C0C2C7C007C7E7EAA88888800001F18191C191F001F0F979590909000","D5D5D5D5D5D5D5D5D5D5D5D5D5D5D5D5AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA","D5D5D5D5D5F5F5FDDDD5D5D5D5D5D5D5AAAAAAAAAEAEBFBFBFABAAAAAAAAAAAA","F7F7DDDDF7F7DDDDF7F7DDDDF7F7DDDDEEEEBBBBEEEEBBBBEEEEBBBBEEEEBBBB","F787A5B1B3B3B1B1B3B3B1B1B3B381DDEEE8B2A6E6E6A6A6E6E6A6A6E6E6A0BB","F78785818383818183838181838381DDEEE8B0A0E0E0A0A0E0E0A0A0E0E0A0BB","F7F7CDCDCFCF898183838585878FDDDDEEECA4A4E4E4A0A0E0E0A0A0E0E8BBBB","F7F7CDCDCFCF898123232525878FDDDDEEECA4A4E4E0A0216565252561E8BBBB","F7F781D1D3D3D1D1D3D3D1D1D383DDDDEEEE808ACACE8A8BCACA8A8ACAC0BBBB","F7F7ABFBFBFBFBBBBBFBFBFBFBABDDDDEEEED5DFDFDFDFDDDDDFDFDFDFD5BBBB","F7F72B7B7B7B2B6B6B2B7B7B7B2BDDDDEEEE555F5F5F555757555F5F5F55BBBB","F7F3C58DB7F4D98187B7DDDDB7979DC5EECEA1B1ECECB8BAEEECB9B0E6CE8B9B"]