show all map layers at once
This commit is contained in:
parent
d01ec40181
commit
2c06782600
|
@ -14,9 +14,9 @@
|
|||
|
||||
(fn platform [?key] (let [p (dimensions)] (if ?key (. p ?key) p)))
|
||||
(fn MapEditView.layer-type [self ?ilayer] (or (?. (platform :layers) (or ?ilayer self.ilayer)) :tiles))
|
||||
(fn MapEditView.dimensions [self ?ilayer] (or (platform (self:layer-type)) (platform)))
|
||||
(fn MapEditView.dimensions [self ?ilayer] (or (platform (self:layer-type ?ilayer)) (platform)))
|
||||
(fn MapEditView.scaled-dimensions [self ?ilayer]
|
||||
(let [dim (lume.clone (self:dimensions))]
|
||||
(let [dim (lume.clone (self:dimensions ?ilayer))]
|
||||
(each [_ key (ipairs [:tilew :tileh :xstagger :ystagger])]
|
||||
(when (. dim key) (tset dim key (* sprite-scale (. dim key)))))
|
||||
dim))
|
||||
|
@ -26,7 +26,7 @@
|
|||
(fn MapEditView.tilew [self ?ilayer] (. (self:scaled-dimensions ?ilayer) :tilew))
|
||||
(fn MapEditView.tileh [self ?ilayer] (. (self:scaled-dimensions ?ilayer) :tileh))
|
||||
|
||||
(fn MapEditView.empty-map [self] (string.rep "\0" (* (self:mapw) (self:maph))))
|
||||
(fn MapEditView.empty-map [self ?ilayer] (string.rep "\0" (* (self:mapw ?ilayer) (self:maph ?ilayer))))
|
||||
|
||||
(fn MapEditView.new [self]
|
||||
(MapEditView.super.new self)
|
||||
|
@ -37,8 +37,8 @@
|
|||
(self:reload))
|
||||
|
||||
; map is stored bottom-to-top
|
||||
(fn MapEditView.imap-from-xy [self mx my]
|
||||
(+ mx -1 (* (self:mapw) (- (self:maph) my))))
|
||||
(fn MapEditView.imap-from-xy [self mx my ?ilayer]
|
||||
(+ mx -1 (* (self:mapw ?ilayer) (- (self:maph ?ilayer) my))))
|
||||
|
||||
(fn MapEditView.update-map [self map mx my itile]
|
||||
(local imap (self:imap-from-xy mx my))
|
||||
|
@ -48,13 +48,13 @@
|
|||
(string.char enctile)
|
||||
(map:sub (+ imap 2))))
|
||||
|
||||
(fn MapEditView.map [self]
|
||||
(if (platform :layers) (or (?. self.level.layers self.ilayer) (self:empty-map))
|
||||
(fn MapEditView.map [self ?ilayer]
|
||||
(if (platform :layers) (or (?. self.level.layers (or ?ilayer self.ilayer)) (self:empty-map ?ilayer))
|
||||
self.level.map))
|
||||
|
||||
(fn MapEditView.itile-from-xy [self mx my]
|
||||
(local imap (+ (self:imap-from-xy mx my) 1))
|
||||
(local enctile (string.byte (string.sub (self:map) imap imap)))
|
||||
(fn MapEditView.itile-from-xy [self mx my ?ilayer]
|
||||
(local imap (+ (self:imap-from-xy mx my ?ilayer) 1))
|
||||
(local enctile (or (string.byte (string.sub (self:map ?ilayer) imap imap)) 0))
|
||||
(decode-itile enctile))
|
||||
|
||||
(fn MapEditView.set-tile [self mx my itile]
|
||||
|
@ -62,6 +62,7 @@
|
|||
(if (platform :layers) (util.nested-tset self.level [:layers self.ilayer] updated-map)
|
||||
(set self.level.map updated-map))))
|
||||
|
||||
; todo: objects exist on layers
|
||||
(fn MapEditView.iobject-from-xy [self mx my ?iobj]
|
||||
(local iobj (or ?iobj 1))
|
||||
(local obj (. self.level.objects iobj))
|
||||
|
@ -131,10 +132,10 @@
|
|||
(fn MapEditView.draw-tilestrip [self x y my ?ilayer]
|
||||
; stripcache leaks but honestly who cares
|
||||
(local tilestrip [])
|
||||
(var stripid "")
|
||||
(for [mx 1 (self:mapw)]
|
||||
(local itile (self:itile-from-xy mx my))
|
||||
(local tile (?. self.tilecache.tiles itile :gfx))
|
||||
(var stripid (tostring ?ilayer))
|
||||
(for [mx 1 (self:mapw ?ilayer)]
|
||||
(local itile (self:itile-from-xy mx my ?ilayer))
|
||||
(local tile (?. (files.cache (self:layer-type ?ilayer)) :tiles itile :gfx))
|
||||
(table.insert tilestrip tile)
|
||||
(set stripid (.. stripid (string.char itile))))
|
||||
(var sprite (. self.stripcache stripid))
|
||||
|
@ -161,8 +162,8 @@
|
|||
(love.graphics.rectangle :line x y w h)
|
||||
(love.graphics.setColor 1 1 1)))
|
||||
|
||||
(fn MapEditView.handle-mouseedits-object [self mx my x y w h]
|
||||
(when (and (active? self :map) (mouse-inside x y w h))
|
||||
(fn MapEditView.handle-mouseedits-object [self mx my x y w h ilayer]
|
||||
(when (and (active? self [:map ilayer]) (mouse-inside x y w h))
|
||||
(let [iobject (self:iobject-from-xy mx my)]
|
||||
(match self.imstate.left
|
||||
:down (when (= self.iobject-linking nil) (set self.iobject-linking iobject))
|
||||
|
@ -178,13 +179,13 @@
|
|||
(set self.playerpos nil))
|
||||
|
||||
(= iobject nil)
|
||||
(let [tile (self.tilecache:tile (self:itile-from-xy mx my))]
|
||||
(let [tile (self.tilecache:tile (self:itile-from-xy mx my ilayer))]
|
||||
(table.insert self.level.objects {:x mx :y my :func (or tile.word "")})
|
||||
(set self.iobject (length self.level.objects))))
|
||||
(set self.iobject-linking nil))))))
|
||||
|
||||
(fn MapEditView.handle-mouseedits-tile [self mx my x y w h]
|
||||
(when (and (active? self :map) (mouse-inside x y w h) (not= (self:itile-from-xy mx my) self.itile))
|
||||
(fn MapEditView.handle-mouseedits-tile [self mx my x y w h ilayer]
|
||||
(when (and (active? self [:map ilayer]) (mouse-inside x y w h) (not= (self:itile-from-xy mx my ilayer) self.itile))
|
||||
(self:set-tile mx my self.itile)))
|
||||
|
||||
(fn MapEditView.draw-tile-xy-label [self mx my x y h ystagger]
|
||||
|
@ -192,31 +193,39 @@
|
|||
(renderer.draw_text style.font (string.format "%x" (encode-yx {:x mx :y my})) (+ x 20) labely style.text)
|
||||
(love.graphics.setColor 1 1 1))
|
||||
|
||||
(fn MapEditView.draw-map-editor [self {: x : y &as form} ilayer]
|
||||
(fn MapEditView.draw-map-layer [self {: x : y &as form} ilayer live]
|
||||
(love.graphics.setColor 1 1 1 1)
|
||||
(local {: mapw : maph : tilew : tileh : xstagger : ystagger} (self:scaled-dimensions ilayer))
|
||||
(local intileh (or ystagger tileh))
|
||||
(let [[w h] (self:mapsize ilayer)] (lume.extend form {: w : h :tag :map}))
|
||||
(activate form)
|
||||
(let [[w h] (self:mapsize ilayer)] (lume.extend form {: w : h :tag [:map ilayer]}))
|
||||
(when live (activate form))
|
||||
(var iobject-over nil)
|
||||
(for [my 1 maph]
|
||||
(local tiley (+ y (* (- my 1) (or ystagger tileh))))
|
||||
(local intiley (+ tiley (- tileh intileh)))
|
||||
(local xoff (if (and xstagger (= (% my 2) 0)) xstagger 0))
|
||||
(self:draw-tilestrip (+ x xoff) tiley my ilayer)
|
||||
(for [mx 1 mapw]
|
||||
(local tilex (+ x (* (- mx 1) tilew) xoff))
|
||||
(local iobject (self:iobject-from-xy mx my))
|
||||
(when (= self.itile nil)
|
||||
(self:draw-player mx my tilex intiley)
|
||||
(self:draw-object-box iobject tilex intiley tilew intileh))
|
||||
(if self.itile
|
||||
(self:handle-mouseedits-tile mx my tilex intiley tilew intileh)
|
||||
(self:handle-mouseedits-object mx my tilex intiley tilew intileh))
|
||||
(when (mouse-inside tilex intiley tilew intileh)
|
||||
(when (not= iobject nil) (set iobject-over iobject))
|
||||
(self:draw-tile-xy-label mx my tilex intiley tileh ystagger))))
|
||||
(when (= self.itile nil) (self:draw-link-lines form iobject-over)))
|
||||
(when live
|
||||
(for [mx 1 mapw]
|
||||
(local tilex (+ x (* (- mx 1) tilew) xoff))
|
||||
(local iobject (self:iobject-from-xy mx my))
|
||||
(when (= self.itile nil)
|
||||
(self:draw-player mx my tilex intiley)
|
||||
(self:draw-object-box iobject tilex intiley tilew intileh))
|
||||
(if self.itile
|
||||
(self:handle-mouseedits-tile mx my tilex intiley tilew intileh ilayer)
|
||||
(self:handle-mouseedits-object mx my tilex intiley tilew intileh ilayer))
|
||||
(when (mouse-inside tilex intiley tilew intileh)
|
||||
(when (not= iobject nil) (set iobject-over iobject))
|
||||
(self:draw-tile-xy-label mx my tilex intiley tileh ystagger)))))
|
||||
(when (and live (= self.itile nil))
|
||||
(self:draw-link-lines form iobject-over)))
|
||||
|
||||
(fn MapEditView.draw-map-editor [self form]
|
||||
(let [g (group-wrapper form)]
|
||||
(each [ilayer (ipairs (platform :layers))]
|
||||
(self:draw-map-layer (g) ilayer (= ilayer self.ilayer)))
|
||||
(g)))
|
||||
|
||||
(fn condition-label [flag]
|
||||
(if flag {:label flag : flag} {:label "<always>"}))
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue