2020-10-19 00:13:26 +00:00
|
|
|
(local View (require :core.view))
|
|
|
|
(local tiles (require :game.tiles))
|
|
|
|
(local tiledraw (require :editor.tiledraw))
|
|
|
|
(local util (require :lib.util))
|
2021-04-24 02:54:28 +00:00
|
|
|
(local files (require :game.files))
|
2020-10-19 00:13:26 +00:00
|
|
|
(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)
|
2021-04-24 02:54:28 +00:00
|
|
|
(set self.tilecache (files.cache (self:resource-key)))
|
2020-10-19 00:13:26 +00:00
|
|
|
(set self.itile 1)
|
2021-04-19 02:26:18 +00:00
|
|
|
(set self.scrollheight math.huge)
|
|
|
|
(set self.scrollable true)
|
2020-10-19 00:13:26 +00:00
|
|
|
(attach-imstate self))
|
2021-04-19 02:26:18 +00:00
|
|
|
(fn GraphicsEditView.get_scrollable_size [self] self.scrollheight)
|
2021-04-24 02:54:28 +00:00
|
|
|
(fn GraphicsEditView.resource-key [self] :tiles)
|
2020-11-22 03:50:11 +00:00
|
|
|
(fn GraphicsEditView.tilesize [self] (values 16 16))
|
2021-01-17 02:40:04 +00:00
|
|
|
(fn GraphicsEditView.tilebytelen [self] (let [(w h) (self:tilesize)] (/ (* w h) 8)))
|
2021-04-24 02:54:28 +00:00
|
|
|
(fn GraphicsEditView.reload [self] (files.reload))
|
|
|
|
(fn GraphicsEditView.save [self] (files.save))
|
2020-10-29 02:59:47 +00:00
|
|
|
|
2020-10-19 00:13:26 +00:00
|
|
|
(fn GraphicsEditView.select-rel [self ditile]
|
2020-10-29 02:59:47 +00:00
|
|
|
(when self.itile
|
|
|
|
(local itile (+ self.itile ditile))
|
|
|
|
(when (>= itile 1) (set self.itile itile))))
|
2020-10-19 00:13:26 +00:00
|
|
|
|
2020-12-24 03:17:33 +00:00
|
|
|
(fn GraphicsEditView.draw-sprite [self x y itile ?key]
|
|
|
|
(love.graphics.draw (self.tilecache:sprite itile ?key) x y 0 self.sprite-scale self.sprite-scale))
|
2020-10-19 00:13:26 +00:00
|
|
|
|
2020-12-24 03:17:33 +00:00
|
|
|
(fn GraphicsEditView.draw-tile-selector [self x y w ?key]
|
2020-10-19 00:13:26 +00:00
|
|
|
(var tilex x)
|
|
|
|
(var tiley y)
|
2020-11-22 03:50:11 +00:00
|
|
|
(var (pixw pixh) (self:tilesize))
|
|
|
|
(set pixw (* (/ pixw 8) 7))
|
|
|
|
(local tilew (* self.sprite-scale pixw))
|
|
|
|
(local tileh (* self.sprite-scale pixh))
|
2020-10-19 00:13:26 +00:00
|
|
|
(for [itile 1 (length self.tilecache.tiles)]
|
2020-12-24 03:17:33 +00:00
|
|
|
(self:draw-sprite tilex tiley itile ?key)
|
|
|
|
(when (and (= itile self.itile) (= ?key self.tilekey))
|
2020-11-22 03:50:11 +00:00
|
|
|
(love.graphics.rectangle :line (- tilex 2) (- tiley 2) (+ tilew 4) (+ tileh 4)))
|
|
|
|
(when (button self [:tile itile] tilex tiley tilew tileh)
|
2020-12-24 03:17:33 +00:00
|
|
|
(set self.itile itile)
|
|
|
|
(set self.tilekey ?key))
|
2020-11-22 17:16:48 +00:00
|
|
|
(set tilex (+ tilex tilew 4))
|
2020-11-22 03:50:11 +00:00
|
|
|
(when (>= (+ tilex tilew) (+ x w))
|
2020-10-19 00:13:26 +00:00
|
|
|
(set tilex x)
|
2020-12-24 03:17:33 +00:00
|
|
|
(set tiley (+ tiley tileh 4))))
|
|
|
|
(+ tiley tileh (- y)))
|
2020-10-19 00:13:26 +00:00
|
|
|
|
|
|
|
GraphicsEditView
|