honeylisp/editor/gfxedit.fnl

45 lines
1.5 KiB
Fennel

(local View (require :core.view))
(local tiles (require :game.tiles))
(local tiledraw (require :editor.tiledraw))
(local util (require :lib.util))
(local {: attach-imstate : mouse-inside : activate : active? : button} (util.require :editor.imstate))
(local GraphicsEditView (View:extend))
(local sprite-scale 4)
(set GraphicsEditView.sprite-scale sprite-scale)
(fn GraphicsEditView.new [self]
(GraphicsEditView.super.new self)
(set self.tilecache (tiledraw.TileCache (tiles.loadtiles)))
(set self.itile 1)
(attach-imstate self))
(fn GraphicsEditView.reload [self]
(self.tilecache:load (tiles.loadtiles)))
(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]
(love.graphics.draw (self.tilecache:sprite itile) x y 0 self.sprite-scale self.sprite-scale))
(fn GraphicsEditView.draw-tile-selector [self x y w]
(var tilex x)
(var tiley y)
(local tile-size (* 16 self.sprite-scale))
(for [itile 1 (length self.tilecache.tiles)]
(self:draw-sprite tilex tiley itile)
(when (= itile self.itile)
(love.graphics.rectangle :line (- tilex 2) (- tiley 2) (+ (* 14 self.sprite-scale) 4) (+ tile-size 4)))
(when (button self [:tile itile] tilex tiley tile-size tile-size)
(set self.itile itile))
(set tilex (+ tilex tile-size))
(when (>= (+ tilex tile-size) (+ x w))
(set tilex x)
(set tiley (+ tiley tile-size 4)))))
GraphicsEditView