2021-12-21 01:40:18 +00:00
|
|
|
(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))
|
2021-12-24 04:36:20 +00:00
|
|
|
(local {: attach-imstate : button : reform : horiz-wrapper : group-wrapper} (util.require :editor.imgui))
|
2021-12-21 01:40:18 +00:00
|
|
|
|
|
|
|
(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)))))
|
|
|
|
|
2021-12-21 15:36:38 +00:00
|
|
|
(fn tile-selector [{: view &as form} selected-itile ?key]
|
|
|
|
(var selected-itile selected-itile)
|
2021-12-24 04:36:20 +00:00
|
|
|
(let [g (group-wrapper form)
|
2021-12-22 03:04:43 +00:00
|
|
|
wrap (horiz-wrapper form)]
|
2021-12-21 15:36:38 +00:00
|
|
|
(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)))
|
2021-12-24 04:36:20 +00:00
|
|
|
(when (g button (reform form {:tag [:tile itile] : w : h}))
|
|
|
|
(set selected-itile itile))
|
|
|
|
(wrap form))))
|
|
|
|
(g)
|
2021-12-22 03:04:43 +00:00
|
|
|
selected-itile))
|
2021-12-21 01:40:18 +00:00
|
|
|
|
|
|
|
(fn GraphicsEditView.draw-tile-selector [self form ?key]
|
2021-12-24 04:36:20 +00:00
|
|
|
(match (tile-selector (reform form {:scale self.sprite-scale :w form.w}) (when (= self.tilekey ?key) self.itile) ?key)
|
2021-12-21 01:40:18 +00:00
|
|
|
selected-itile (do (set self.itile selected-itile)
|
|
|
|
(set self.tilekey ?key))))
|
|
|
|
|
|
|
|
GraphicsEditView
|