2021-12-26 20:04:34 +00:00
|
|
|
(local GraphicsEditView (require :editor.gfxedit))
|
2020-10-19 00:13:26 +00:00
|
|
|
(local style (require :core.style))
|
|
|
|
(local util (require :lib.util))
|
2020-10-29 02:59:47 +00:00
|
|
|
(local lume (require :lib.lume))
|
2021-04-24 02:54:28 +00:00
|
|
|
(local files (require :game.files))
|
2021-12-24 04:36:20 +00:00
|
|
|
(local {: show} (util.require :inspector.debug))
|
|
|
|
(local {: mouse-inside : activate : active? : checkbox : textfield : textbutton : textbox : dropdown : labelled-dropdown : under : right-of : reform : group-wrapper} (util.require :editor.imgui))
|
2020-11-22 17:16:48 +00:00
|
|
|
(local {: tilestrip-to-sprite} (util.require :editor.tiledraw))
|
2021-11-14 19:55:41 +00:00
|
|
|
(local {: encode-yx : encode-itile : decode-itile : dimensions} (util.require :game.tiles))
|
2021-04-21 00:13:51 +00:00
|
|
|
(local actions (require :editor.actions))
|
2020-10-19 00:13:26 +00:00
|
|
|
|
|
|
|
(local MapEditView (GraphicsEditView:extend))
|
2020-10-29 02:59:47 +00:00
|
|
|
(local sprite-scale 3)
|
2021-09-06 03:29:16 +00:00
|
|
|
|
2021-11-14 19:55:41 +00:00
|
|
|
(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))
|
2021-12-27 22:59:00 +00:00
|
|
|
(fn MapEditView.dimensions [self ?ilayer] (or (platform (self:layer-type ?ilayer)) (platform)))
|
2021-11-18 02:46:38 +00:00
|
|
|
(fn MapEditView.scaled-dimensions [self ?ilayer]
|
2021-12-27 22:59:00 +00:00
|
|
|
(let [dim (lume.clone (self:dimensions ?ilayer))]
|
2021-11-18 02:46:38 +00:00
|
|
|
(each [_ key (ipairs [:tilew :tileh :xstagger :ystagger])]
|
|
|
|
(when (. dim key) (tset dim key (* sprite-scale (. dim key)))))
|
|
|
|
dim))
|
2021-09-06 03:29:16 +00:00
|
|
|
|
2021-11-14 19:55:41 +00:00
|
|
|
(fn MapEditView.mapw [self ?ilayer] (. (self:dimensions ?ilayer) :mapw))
|
|
|
|
(fn MapEditView.maph [self ?ilayer] (. (self:dimensions ?ilayer) :maph))
|
2021-11-18 02:46:38 +00:00
|
|
|
(fn MapEditView.tilew [self ?ilayer] (. (self:scaled-dimensions ?ilayer) :tilew))
|
|
|
|
(fn MapEditView.tileh [self ?ilayer] (. (self:scaled-dimensions ?ilayer) :tileh))
|
2021-11-14 19:55:41 +00:00
|
|
|
|
2021-12-27 22:59:00 +00:00
|
|
|
(fn MapEditView.empty-map [self ?ilayer] (string.rep "\0" (* (self:mapw ?ilayer) (self:maph ?ilayer))))
|
2020-10-19 00:13:26 +00:00
|
|
|
|
2021-04-24 02:54:28 +00:00
|
|
|
(fn MapEditView.new [self]
|
2020-10-19 00:13:26 +00:00
|
|
|
(MapEditView.super.new self)
|
2020-10-29 02:59:47 +00:00
|
|
|
(set self.sprite-scale sprite-scale)
|
2020-11-22 17:16:48 +00:00
|
|
|
(set self.stripcache {})
|
2021-04-24 02:54:28 +00:00
|
|
|
(set self.ilevel 1)
|
2021-11-14 19:55:41 +00:00
|
|
|
(self:set-ilayer 1)
|
2020-10-29 02:59:47 +00:00
|
|
|
(self:reload))
|
2020-10-19 00:13:26 +00:00
|
|
|
|
|
|
|
; map is stored bottom-to-top
|
2021-12-27 22:59:00 +00:00
|
|
|
(fn MapEditView.imap-from-xy [self mx my ?ilayer]
|
|
|
|
(+ mx -1 (* (self:mapw ?ilayer) (- (self:maph ?ilayer) my))))
|
2020-10-19 00:13:26 +00:00
|
|
|
|
2021-11-14 19:55:41 +00:00
|
|
|
(fn MapEditView.update-map [self map mx my itile]
|
|
|
|
(local imap (self:imap-from-xy mx my))
|
2021-02-11 04:26:08 +00:00
|
|
|
(local enctile (encode-itile itile))
|
2020-10-19 00:13:26 +00:00
|
|
|
(..
|
|
|
|
(map:sub 1 imap)
|
|
|
|
(string.char enctile)
|
|
|
|
(map:sub (+ imap 2))))
|
|
|
|
|
2021-12-27 22:59:00 +00:00
|
|
|
(fn MapEditView.map [self ?ilayer]
|
|
|
|
(if (platform :layers) (or (?. self.level.layers (or ?ilayer self.ilayer)) (self:empty-map ?ilayer))
|
2021-11-14 19:55:41 +00:00
|
|
|
self.level.map))
|
|
|
|
|
2021-12-27 22:59:00 +00:00
|
|
|
(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))
|
2021-02-11 04:26:08 +00:00
|
|
|
(decode-itile enctile))
|
2020-10-19 00:13:26 +00:00
|
|
|
|
|
|
|
(fn MapEditView.set-tile [self mx my itile]
|
2021-11-14 19:55:41 +00:00
|
|
|
(let [updated-map (self:update-map (self:map) mx my itile)]
|
|
|
|
(if (platform :layers) (util.nested-tset self.level [:layers self.ilayer] updated-map)
|
|
|
|
(set self.level.map updated-map))))
|
2020-10-29 02:59:47 +00:00
|
|
|
|
2021-12-27 22:59:00 +00:00
|
|
|
; todo: objects exist on layers
|
2020-10-29 02:59:47 +00:00
|
|
|
(fn MapEditView.iobject-from-xy [self mx my ?iobj]
|
|
|
|
(local iobj (or ?iobj 1))
|
|
|
|
(local obj (. self.level.objects iobj))
|
|
|
|
(when obj
|
|
|
|
(if (and (= obj.x mx) (= obj.y my))
|
|
|
|
iobj
|
|
|
|
(self:iobject-from-xy mx my (+ iobj 1)))))
|
2020-10-30 16:55:47 +00:00
|
|
|
(fn MapEditView.object [self] (. self.level.objects self.iobject))
|
|
|
|
|
|
|
|
(fn move-object [objects iobjectsrc iobjectdst]
|
|
|
|
(each [_ object (pairs objects)]
|
|
|
|
(when (= object.link iobjectsrc)
|
|
|
|
(set object.link iobjectdst)))
|
|
|
|
(tset objects iobjectdst (. objects iobjectsrc))
|
|
|
|
(tset objects iobjectsrc nil)
|
|
|
|
(when (. objects (+ iobjectsrc 1))
|
|
|
|
(move-object objects (+ iobjectsrc 1) iobjectsrc)))
|
|
|
|
|
2021-09-06 03:29:16 +00:00
|
|
|
(fn MapEditView.levels [self]
|
|
|
|
(when (= files.game.levels nil)
|
|
|
|
(set files.game.levels []))
|
|
|
|
files.game.levels)
|
|
|
|
|
2021-12-24 04:36:20 +00:00
|
|
|
(fn MapEditView.draw-map-selector [self form]
|
2021-12-22 03:04:43 +00:00
|
|
|
(let [level-count (length (self:levels))
|
|
|
|
options (icollect [i (util.countiter (+ level-count 1))] (if (<= i level-count) i :New))
|
2021-12-24 04:36:20 +00:00
|
|
|
ilevel (labelled-dropdown (reform form {:tag :map-selector :wdropdown (* 100 SCALE)}) "Map" self.ilevel options)]
|
2021-04-24 02:54:28 +00:00
|
|
|
(when (not= ilevel self.ilevel)
|
|
|
|
(set self.ilevel (if (= ilevel :New) (+ level-count 1) ilevel))
|
2021-12-22 03:04:43 +00:00
|
|
|
(self:load-level))))
|
2021-04-24 02:54:28 +00:00
|
|
|
|
2021-11-14 19:55:41 +00:00
|
|
|
(fn MapEditView.set-ilayer [self ilayer]
|
|
|
|
(set self.ilayer ilayer)
|
|
|
|
(self:set-style (self:layer-type)))
|
|
|
|
|
2021-12-22 03:04:43 +00:00
|
|
|
(fn MapEditView.draw-layer-selector [self {: x : y &as form}]
|
2021-11-14 19:55:41 +00:00
|
|
|
(let [mkopt (fn [ilayer] {: ilayer :label (.. ilayer " (" (self:layer-type ilayer) ")")})
|
|
|
|
options (icollect [ilayer (ipairs (platform :layers))] (mkopt ilayer))
|
2021-12-24 04:36:20 +00:00
|
|
|
selection (labelled-dropdown (reform form {:wdropdown (* 100 SCALE) :tag :layer-selector}) "Layer" (mkopt self.ilayer) options)]
|
2021-11-14 19:55:41 +00:00
|
|
|
(when (not= self.ilayer selection.ilayer)
|
2021-12-22 03:04:43 +00:00
|
|
|
(self:set-ilayer selection.ilayer))))
|
2021-11-14 19:55:41 +00:00
|
|
|
|
2020-10-30 16:55:47 +00:00
|
|
|
(fn MapEditView.linking-obj [self] (. self.level.objects self.iobject-linking))
|
|
|
|
(fn MapEditView.draw-link-line [self x y iobjectSrc color toMouse?]
|
|
|
|
(local objectSrc (. self.level.objects iobjectSrc))
|
|
|
|
(local objectDest (. self.level.objects objectSrc.link))
|
|
|
|
(local coord (fn [c m d] (+ c (* (- m 1) d) (/ d 2))))
|
2021-11-14 19:55:41 +00:00
|
|
|
(local [tilew tileh] [(self:tilew) (self:tileh)])
|
2020-10-30 16:55:47 +00:00
|
|
|
(local xStart (coord x objectSrc.x tilew))
|
|
|
|
(local yStart (coord y objectSrc.y tileh))
|
|
|
|
(when (or toMouse? objectDest)
|
|
|
|
(local xEnd (if toMouse? (love.mouse.getX) (coord x objectDest.x tilew)))
|
|
|
|
(local yEnd (if toMouse? (love.mouse.getY) (coord y objectDest.y tileh)))
|
|
|
|
(love.graphics.setColor (table.unpack color))
|
|
|
|
(love.graphics.line xStart yStart xEnd yEnd)
|
|
|
|
(love.graphics.circle :line xEnd yEnd (/ tilew 5))
|
|
|
|
(love.graphics.setColor 1 1 1)))
|
2020-10-19 00:13:26 +00:00
|
|
|
|
2021-12-22 03:04:43 +00:00
|
|
|
(fn MapEditView.draw-link-lines [self {: x : y} iobject-over]
|
|
|
|
(for [iobject 1 (length self.level.objects)]
|
|
|
|
(self:draw-link-line x y iobject [0 0 1 0.3]))
|
|
|
|
(when (not= iobject-over nil) (self:draw-link-line x y iobject-over [0 0.5 1] false))
|
|
|
|
(when (not= self.iobject-linking nil)
|
|
|
|
(if (= self.imstate.left :released) (set self.iobject-linking nil)
|
|
|
|
(self:draw-link-line x y self.iobject-linking [0 1 0] true))))
|
|
|
|
|
2021-11-18 02:46:38 +00:00
|
|
|
(fn MapEditView.draw-tilestrip [self x y my ?ilayer]
|
2020-11-22 17:16:48 +00:00
|
|
|
; stripcache leaks but honestly who cares
|
|
|
|
(local tilestrip [])
|
2021-12-27 22:59:00 +00:00
|
|
|
(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))
|
2020-11-22 17:16:48 +00:00
|
|
|
(table.insert tilestrip tile)
|
|
|
|
(set stripid (.. stripid (string.char itile))))
|
|
|
|
(var sprite (. self.stripcache stripid))
|
|
|
|
(when (= sprite nil)
|
2021-11-18 02:46:38 +00:00
|
|
|
(set sprite (tilestrip-to-sprite tilestrip (self:layer-type ?ilayer)))
|
2020-11-22 17:16:48 +00:00
|
|
|
(tset self.stripcache stripid sprite))
|
|
|
|
(love.graphics.draw sprite x y 0 self.sprite-scale self.sprite-scale))
|
|
|
|
|
2021-11-18 02:46:38 +00:00
|
|
|
(fn MapEditView.mapsize [self ilayer]
|
|
|
|
(let [{: mapw : maph : tilew : tileh : xstagger : ystagger} (self:scaled-dimensions ilayer)
|
|
|
|
intileh (or ystagger tileh)]
|
|
|
|
[(+ (or xstagger 0) (* mapw tilew)) (+ tileh (* (- maph 1) intileh))]))
|
|
|
|
|
2021-12-22 03:04:43 +00:00
|
|
|
(fn MapEditView.draw-player [self mx my x y]
|
|
|
|
(each [_ player (ipairs (or files.game.players [:player]))]
|
|
|
|
(match (. self.level player)
|
|
|
|
{:x mx :y my} (renderer.draw_text style.font player x y style.text)))
|
|
|
|
(love.graphics.setColor 1 1 1))
|
|
|
|
|
|
|
|
(fn MapEditView.draw-object-box [self iobject x y w h]
|
|
|
|
(when (not= iobject nil)
|
|
|
|
(love.graphics.setColor 1 0 (if (and (= self.itile nil) (= iobject self.iobject)) 1 0))
|
|
|
|
(love.graphics.setLineWidth 3)
|
|
|
|
(love.graphics.rectangle :line x y w h)
|
|
|
|
(love.graphics.setColor 1 1 1)))
|
|
|
|
|
2021-12-27 22:59:00 +00:00
|
|
|
(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))
|
2021-12-22 03:04:43 +00:00
|
|
|
(let [iobject (self:iobject-from-xy mx my)]
|
|
|
|
(match self.imstate.left
|
2021-12-24 04:36:20 +00:00
|
|
|
:down (when (= self.iobject-linking nil) (set self.iobject-linking iobject))
|
2021-12-22 03:04:43 +00:00
|
|
|
:released
|
2021-12-24 04:36:20 +00:00
|
|
|
(do (if (and (not= iobject nil) (= self.iobject-linking iobject))
|
|
|
|
(set self.iobject iobject)
|
2021-12-22 03:04:43 +00:00
|
|
|
|
2021-12-24 04:36:20 +00:00
|
|
|
(not= self.iobject-linking nil)
|
|
|
|
(tset (self:linking-obj) :link iobject)
|
2021-12-22 03:04:43 +00:00
|
|
|
|
2021-12-24 04:36:20 +00:00
|
|
|
(not= self.playerpos nil)
|
|
|
|
(do (tset self.level self.playerpos {:x mx :y my})
|
|
|
|
(set self.playerpos nil))
|
2021-12-22 03:04:43 +00:00
|
|
|
|
2021-12-24 04:36:20 +00:00
|
|
|
(= iobject nil)
|
2021-12-27 22:59:00 +00:00
|
|
|
(let [tile (self.tilecache:tile (self:itile-from-xy mx my ilayer))]
|
2021-12-24 04:36:20 +00:00
|
|
|
(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))))))
|
2021-12-22 03:04:43 +00:00
|
|
|
|
2021-12-27 22:59:00 +00:00
|
|
|
(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))
|
2021-12-22 03:04:43 +00:00
|
|
|
(self:set-tile mx my self.itile)))
|
|
|
|
|
|
|
|
(fn MapEditView.draw-tile-xy-label [self mx my x y h ystagger]
|
|
|
|
(local labely (math.floor (+ y (- (or ystagger 0)) (/ (- (if ystagger (* ystagger 2) h) (style.font:get_height)) 2))))
|
|
|
|
(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))
|
|
|
|
|
2021-12-27 22:59:00 +00:00
|
|
|
(fn MapEditView.draw-map-layer [self {: x : y &as form} ilayer live]
|
2021-04-24 02:54:28 +00:00
|
|
|
(love.graphics.setColor 1 1 1 1)
|
2021-11-18 02:46:38 +00:00
|
|
|
(local {: mapw : maph : tilew : tileh : xstagger : ystagger} (self:scaled-dimensions ilayer))
|
|
|
|
(local intileh (or ystagger tileh))
|
2021-12-27 22:59:00 +00:00
|
|
|
(let [[w h] (self:mapsize ilayer)] (lume.extend form {: w : h :tag [:map ilayer]}))
|
|
|
|
(when live (activate form))
|
2020-10-30 16:55:47 +00:00
|
|
|
(var iobject-over nil)
|
2020-11-22 17:16:48 +00:00
|
|
|
(for [my 1 maph]
|
2021-11-18 02:46:38 +00:00
|
|
|
(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)
|
2021-12-27 22:59:00 +00:00
|
|
|
(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)))
|
2020-10-30 16:55:47 +00:00
|
|
|
|
2021-05-06 01:09:40 +00:00
|
|
|
(fn condition-label [flag]
|
|
|
|
(if flag {:label flag : flag} {:label "<always>"}))
|
|
|
|
|
|
|
|
(fn condition-options []
|
|
|
|
(let [options [(condition-label nil)]]
|
|
|
|
(each [_ flag (ipairs (or files.game.flags []))]
|
|
|
|
(table.insert options (condition-label flag)))
|
|
|
|
options))
|
|
|
|
|
2021-12-22 03:04:43 +00:00
|
|
|
(fn MapEditView.draw-object-code-editor [self form object]
|
2021-04-21 00:13:51 +00:00
|
|
|
(var istep-to-delete nil)
|
|
|
|
(when (not object.steps) (set object.steps []))
|
|
|
|
(each [istep step (ipairs object.steps)]
|
2021-12-24 23:08:01 +00:00
|
|
|
(when (textbutton (reform form {:x (+ form.x (* 280 SCALE)) :into {}}) "X")
|
2021-04-21 00:13:51 +00:00
|
|
|
(set istep-to-delete istep))
|
2021-12-24 23:08:01 +00:00
|
|
|
(set step.condition (. (dropdown (reform form {:x (+ form.x (* 150 SCALE)) :w (* 100 SCALE) :tag [:code-condition istep] :into {}}) (condition-label step.condition) (condition-options)) :flag))
|
|
|
|
(set step.action (dropdown (reform form {:w (* 100 SCALE) :tag [:code-action istep]}) (or step.action (. actions.actionlist 1)) actions.actionlist))
|
|
|
|
(actions.edit step (under form {:w (* 300 SCALE)}) istep)
|
|
|
|
(under form))
|
2021-04-21 00:13:51 +00:00
|
|
|
(when istep-to-delete (table.remove object.steps istep-to-delete))
|
2021-12-24 04:36:20 +00:00
|
|
|
(when (textbutton (under form) "+ New Step")
|
2021-12-22 03:04:43 +00:00
|
|
|
(table.insert object.steps {})))
|
2021-04-21 00:13:51 +00:00
|
|
|
|
2021-06-26 01:55:15 +00:00
|
|
|
(fn advanced? [object]
|
|
|
|
(or object.advanced
|
|
|
|
(and (= object.advanced nil)
|
2021-06-29 03:05:17 +00:00
|
|
|
(not= object.func "")
|
|
|
|
(not= object.func nil))))
|
2021-06-26 01:55:15 +00:00
|
|
|
|
2021-12-22 03:04:43 +00:00
|
|
|
(fn MapEditView.draw-object-advanced-editor [self form object]
|
|
|
|
(let [fieldform {:wlabel (* 100 SCALE) :wtext (* 200 SCALE)}]
|
2021-12-24 04:36:20 +00:00
|
|
|
(set object.func (textfield (reform form fieldform) "Word" object.func))
|
|
|
|
(set object.name (textfield (under form fieldform) "Name" object.name))
|
|
|
|
(set object.linkword (textfield (under form fieldform) "Link word" object.linkword))
|
2021-12-22 03:04:43 +00:00
|
|
|
(if object.link
|
2021-12-24 04:36:20 +00:00
|
|
|
(when (textbutton (under form) "Unlink")
|
2021-12-22 03:04:43 +00:00
|
|
|
(set object.link nil))
|
2021-12-24 04:36:20 +00:00
|
|
|
(set object.linkentity (textfield (under form fieldform) "Link entity" object.linkentity)))))
|
2021-12-22 03:04:43 +00:00
|
|
|
|
|
|
|
(fn MapEditView.draw-object-editor [self form]
|
2021-04-21 00:13:51 +00:00
|
|
|
(let [object (self:object)
|
2021-12-24 04:36:20 +00:00
|
|
|
footer (group-wrapper form)]
|
2021-12-22 03:04:43 +00:00
|
|
|
(if (advanced? object)
|
|
|
|
(self:draw-object-advanced-editor form object)
|
|
|
|
(self:draw-object-code-editor form object))
|
2021-12-24 04:36:20 +00:00
|
|
|
(set self.new-flag-name (footer textbox (under form {:tag :new-flag-name :w (* 200 SCALE)}) self.new-flag-name))
|
|
|
|
|
|
|
|
(when (footer textbutton (right-of form) "+ New Flag")
|
2021-05-06 01:09:40 +00:00
|
|
|
(when (= files.game.flags nil)
|
|
|
|
(set files.game.flags []))
|
2021-12-22 03:04:43 +00:00
|
|
|
(table.insert files.game.flags self.new-flag-name)
|
2021-05-06 01:09:40 +00:00
|
|
|
(set self.new-flag-name ""))
|
2021-12-24 04:36:20 +00:00
|
|
|
(when (footer textbutton (under (footer)) "Delete")
|
2021-04-21 00:13:51 +00:00
|
|
|
(move-object self.level.objects (+ self.iobject 1) self.iobject)
|
|
|
|
(set self.iobject nil))
|
2021-12-24 04:36:20 +00:00
|
|
|
(when (footer textbutton (right-of form) (if (advanced? object) "Simple" "Advanced"))
|
2021-12-22 03:04:43 +00:00
|
|
|
(set object.advanced (not (advanced? object))))
|
2021-12-24 04:36:20 +00:00
|
|
|
(footer)))
|
2020-10-29 02:59:47 +00:00
|
|
|
|
2021-04-24 02:54:28 +00:00
|
|
|
(fn MapEditView.load-level [self]
|
|
|
|
(set self.stripcache {})
|
2021-09-06 03:29:16 +00:00
|
|
|
(when (= (. (self:levels) self.ilevel) nil)
|
2021-11-14 19:55:41 +00:00
|
|
|
(tset (self:levels) self.ilevel {:map (self:empty-map) :objects []}))
|
2021-09-06 03:29:16 +00:00
|
|
|
(set self.level (. (self:levels) self.ilevel))
|
2021-04-25 15:54:12 +00:00
|
|
|
(set self.iobject nil))
|
2021-04-24 02:54:28 +00:00
|
|
|
|
2020-10-29 02:59:47 +00:00
|
|
|
(fn MapEditView.reload [self]
|
|
|
|
(MapEditView.super.reload self)
|
2021-04-24 02:54:28 +00:00
|
|
|
(self:load-level))
|
2020-10-19 00:13:26 +00:00
|
|
|
|
|
|
|
(fn MapEditView.draw [self]
|
|
|
|
(self:draw_background style.background)
|
2021-04-19 02:26:18 +00:00
|
|
|
(self:draw_scrollbar)
|
2021-12-22 03:04:43 +00:00
|
|
|
(let [form (self:form)
|
|
|
|
form-editor (self:form)
|
2021-12-24 04:36:20 +00:00
|
|
|
header (group-wrapper form)
|
|
|
|
_ (header #(self:draw-map-selector $...) form)
|
|
|
|
_ (when (platform :layers) (header #(self:draw-layer-selector $...) (right-of form)))
|
|
|
|
_ (self:draw-map-editor (under (header)))
|
2021-12-22 03:04:43 +00:00
|
|
|
editor-on-side (> self.size.x (+ form.w (* 300 SCALE)))
|
|
|
|
fieldform {:wlabel (* 100 SCALE) :wtext (* 200 SCALE)}]
|
|
|
|
(when editor-on-side
|
|
|
|
(set form-editor.x (+ form.x form.w style.padding.x))
|
|
|
|
(set form-editor.w (- form-editor.w form.w style.padding.x)))
|
2021-12-24 04:36:20 +00:00
|
|
|
(self:draw-tile-selector (under form {:w (if editor-on-side form.w (- self.size.x (* style.padding.x 2)))}))
|
|
|
|
(set self.level.tickword (textfield (under form fieldform) "Tick word" self.level.tickword))
|
|
|
|
(set self.level.moveword (textfield (under form fieldform) "Move word" self.level.moveword))
|
|
|
|
(set self.level.loadword (textfield (under form fieldform) "Load word" self.level.loadword))
|
|
|
|
(when (checkbox (under form) "Edit objects" (= self.itile nil))
|
2021-12-22 03:04:43 +00:00
|
|
|
(set self.itile nil)
|
|
|
|
(set self.playerpos nil))
|
2021-06-26 02:41:00 +00:00
|
|
|
(each [_ player (ipairs (or files.game.players [:player]))]
|
2021-12-24 04:36:20 +00:00
|
|
|
(when (checkbox (under form) (.. "Position " player) (and (= self.itile nil) (= self.playerpos player)))
|
2021-12-22 03:04:43 +00:00
|
|
|
(set self.itile nil)
|
|
|
|
(set self.playerpos player)))
|
|
|
|
(each [_ levelflag (ipairs (or files.game.levelflags []))]
|
2021-12-24 04:36:20 +00:00
|
|
|
(when (checkbox (under form) levelflag (. self.level levelflag))
|
2021-12-22 03:04:43 +00:00
|
|
|
(tset self.level levelflag (not (. self.level levelflag)))))
|
|
|
|
(when (not editor-on-side) (set form-editor.y (+ form.y form.h style.padding.y)))
|
|
|
|
(when self.iobject (self:draw-object-editor form-editor))
|
|
|
|
(self:end-scroll (if (> (+ form.y form.h) (+ form-editor.y (or form-editor.h 0))) form form-editor))))
|
2020-10-19 00:13:26 +00:00
|
|
|
|
2021-04-24 02:54:28 +00:00
|
|
|
(fn MapEditView.get_name [self] (.. "Map " self.ilevel))
|
2020-10-19 00:13:26 +00:00
|
|
|
|
|
|
|
MapEditView
|