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