Move game data to one centralized location
This commit is contained in:
parent
79c8791dac
commit
34766e3709
|
@ -5,7 +5,6 @@
|
|||
|
||||
(local FontEditView (TileView:extend))
|
||||
|
||||
(fn FontEditView.spritegen [self] tiledraw.char-to-sprite)
|
||||
(fn FontEditView.tilesize [self] (values 8 8))
|
||||
(fn FontEditView.tilekeys [self] [:gfx])
|
||||
(fn FontEditView.map-bitxy [self x y] (values y x))
|
||||
|
@ -14,7 +13,7 @@
|
|||
(local char (string.char (+ self.itile 0x20 -1)))
|
||||
(renderer.draw_text style.big_font char x y style.text))
|
||||
(love.graphics.setColor 1 1 1 1))
|
||||
(fn FontEditView.filename [self] tiles.fn-font)
|
||||
(fn FontEditView.resource-key [self] :font)
|
||||
(fn FontEditView.get_name [self] "Font Editor")
|
||||
|
||||
FontEditView
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
(local tiles (require :game.tiles))
|
||||
(local tiledraw (require :editor.tiledraw))
|
||||
(local util (require :lib.util))
|
||||
(local files (require :game.files))
|
||||
(local {: attach-imstate : mouse-inside : activate : active? : button} (util.require :editor.imstate))
|
||||
|
||||
(local GraphicsEditView (View:extend))
|
||||
|
@ -11,18 +12,17 @@
|
|||
|
||||
(fn GraphicsEditView.new [self]
|
||||
(GraphicsEditView.super.new self)
|
||||
(set self.tilecache (tiledraw.TileCache (tiles.loadgfx (self:filename)) (self:spritegen)))
|
||||
(set self.tilecache (files.cache (self:resource-key)))
|
||||
(set self.itile 1)
|
||||
(set self.scrollheight math.huge)
|
||||
(set self.scrollable true)
|
||||
(attach-imstate self))
|
||||
(fn GraphicsEditView.get_scrollable_size [self] self.scrollheight)
|
||||
(fn GraphicsEditView.spritegen [self] tiledraw.tile-to-sprite)
|
||||
(fn GraphicsEditView.resource-key [self] :tiles)
|
||||
(fn GraphicsEditView.tilesize [self] (values 16 16))
|
||||
(fn GraphicsEditView.tilebytelen [self] (let [(w h) (self:tilesize)] (/ (* w h) 8)))
|
||||
(fn GraphicsEditView.filename [self] tiles.fn-tiles)
|
||||
(fn GraphicsEditView.reload [self]
|
||||
(self.tilecache:load (tiles.loadgfx (self:filename))))
|
||||
(fn GraphicsEditView.reload [self] (files.reload))
|
||||
(fn GraphicsEditView.save [self] (files.save))
|
||||
|
||||
(fn GraphicsEditView.select-rel [self ditile]
|
||||
(when self.itile
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
(local common (require :core.common))
|
||||
|
||||
(let [commands {}]
|
||||
(each [_ name (ipairs [:tile :portrait :font :brush])]
|
||||
(each [_ name (ipairs [:tile :portrait :font :brush :map])]
|
||||
(local cls (require (.. "editor." name "edit")))
|
||||
(tset commands (.. "honeylisp:" name "-editor") (fn []
|
||||
(local node (core.root_view:get_active_node))
|
||||
|
@ -18,8 +18,7 @@
|
|||
(command.add nil commands))
|
||||
|
||||
(local fileeditors
|
||||
{:map {:view MapEditView :filefilter "^game/map%d+%.json"}
|
||||
:screen {:view ScreenEditView :filefilter "^game/.*%.screen"}})
|
||||
{:screen {:view ScreenEditView :filefilter "^game/.*%.screen"}})
|
||||
|
||||
(each [type {: view : filefilter} (pairs fileeditors)]
|
||||
(command.add nil
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
(local style (require :core.style))
|
||||
(local util (require :lib.util))
|
||||
(local lume (require :lib.lume))
|
||||
(local files (require :game.files))
|
||||
(local {: mouse-inside : activate : active? : checkbox : textfield : textbutton : dropdown} (util.require :editor.imstate))
|
||||
(local {: tilestrip-to-sprite} (util.require :editor.tiledraw))
|
||||
(local {: encode-yx : encode-itile : decode-itile} (util.require :game.tiles))
|
||||
|
@ -14,11 +15,11 @@
|
|||
(local tilew (* sprite-scale 14))
|
||||
(local tileh (* sprite-scale 16))
|
||||
|
||||
(fn MapEditView.new [self filename]
|
||||
(fn MapEditView.new [self]
|
||||
(MapEditView.super.new self)
|
||||
(set self.sprite-scale sprite-scale)
|
||||
(set self.stripcache {})
|
||||
(set self.mapfilename filename)
|
||||
(set self.ilevel 1)
|
||||
(self:reload))
|
||||
|
||||
; map is stored bottom-to-top
|
||||
|
@ -59,6 +60,18 @@
|
|||
(when (. objects (+ iobjectsrc 1))
|
||||
(move-object objects (+ iobjectsrc 1) iobjectsrc)))
|
||||
|
||||
(fn MapEditView.draw-map-selector [self x y]
|
||||
(renderer.draw_text style.font "Map" x (+ y (/ style.padding.y 2)) style.text)
|
||||
(let [options {}
|
||||
level-count (length files.game.levels)
|
||||
_ (do (for [i 1 level-count] (tset options i i))
|
||||
(table.insert options :New))
|
||||
(ilevel yNext) (dropdown self :map-selector self.ilevel options (+ x 50) y 100)]
|
||||
(when (not= ilevel self.ilevel)
|
||||
(set self.ilevel (if (= ilevel :New) (+ level-count 1) ilevel))
|
||||
(self:load-level))
|
||||
(- yNext y)))
|
||||
|
||||
(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))
|
||||
|
@ -90,6 +103,7 @@
|
|||
(love.graphics.draw sprite x y 0 self.sprite-scale self.sprite-scale))
|
||||
|
||||
(fn MapEditView.draw-map-editor [self x y]
|
||||
(love.graphics.setColor 1 1 1 1)
|
||||
(activate self :map x y (* tilew mapw) (* tileh maph))
|
||||
(var iobject-over nil)
|
||||
(for [my 1 maph]
|
||||
|
@ -179,27 +193,23 @@
|
|||
(when do-advanced (set object.advanced (not object.advanced)))
|
||||
y))
|
||||
|
||||
(fn MapEditView.load-level [self]
|
||||
(set self.stripcache {})
|
||||
(when (= (. files.game.levels self.ilevel) nil)
|
||||
(tset files.game.levels self.ilevel {:map (string.rep "\0" (* mapw maph)) :objects []}))
|
||||
(set self.level (. files.game.levels self.ilevel)))
|
||||
|
||||
(fn MapEditView.reload [self]
|
||||
(MapEditView.super.reload self)
|
||||
(local (loaded level) (pcall #(util.readjson self.mapfilename)))
|
||||
(set self.level
|
||||
(match (and loaded (type level))
|
||||
false {:map (string.rep "\0" (* mapw maph)) :objects []}
|
||||
:string {:map (level:fromhex) :objects []}
|
||||
:table (doto level (tset :map (level.map:fromhex))))))
|
||||
|
||||
(fn MapEditView.save [self]
|
||||
(util.writejson self.mapfilename
|
||||
(doto (lume.clone self.level)
|
||||
(tset :map (self.level.map:tohex)))))
|
||||
(self:load-level))
|
||||
|
||||
(fn MapEditView.draw [self]
|
||||
(var x (+ self.position.x style.padding.x (- self.scroll.x)))
|
||||
(var y (+ self.position.y style.padding.y (- self.scroll.y)))
|
||||
(self:draw_background style.background)
|
||||
(self:draw_scrollbar)
|
||||
(love.graphics.setColor 1 1 1 1)
|
||||
(local ytop y)
|
||||
(set y (+ y (self:draw-map-selector x y) style.padding.y))
|
||||
(self:draw-map-editor x y)
|
||||
(set y (+ y (* tileh maph) style.padding.y))
|
||||
(set y (+ y (self:draw-tile-selector x y (- self.size.x (* style.padding.x 2)))))
|
||||
|
@ -223,6 +233,6 @@
|
|||
|
||||
(set self.scrollheight (- y (+ self.position.y style.padding.y (- self.scroll.y)))))
|
||||
|
||||
(fn MapEditView.get_name [self] (.. "Map: " self.mapfilename))
|
||||
(fn MapEditView.get_name [self] (.. "Map " self.ilevel))
|
||||
|
||||
MapEditView
|
||||
|
|
|
@ -6,10 +6,9 @@
|
|||
|
||||
(local PortraitView (TileView:extend))
|
||||
|
||||
(fn PortraitView.spritegen [self] tiledraw.portrait-to-sprite)
|
||||
(fn PortraitView.tilesize [self] (values 32 32))
|
||||
(fn PortraitView.tilekeys [self] [:gfx])
|
||||
(fn PortraitView.filename [self] tiles.fn-portraits)
|
||||
(fn PortraitView.resource-key [self] :portraits)
|
||||
(fn PortraitView.map-bitxy [self x y]
|
||||
(local quadrant (+ (if (>= x 16) 2 0) (if (>= y 16) 1 0)))
|
||||
(local tilex
|
||||
|
|
|
@ -85,8 +85,6 @@
|
|||
(fn TileView.update-tile [self newtile]
|
||||
(self.tilecache:update-tile self.itile newtile self.tilekey))
|
||||
|
||||
(fn TileView.save [self] (tiles.savegfx (self:filename) self.tilecache.tiles))
|
||||
|
||||
(fn TileView.draw [self]
|
||||
(self:draw_background style.background)
|
||||
(self:draw_scrollbar)
|
||||
|
@ -100,6 +98,7 @@
|
|||
(set selector-y (+ selector-y selector-h pixel-size)))
|
||||
(set self.scrollheight (- selector-y y)))
|
||||
|
||||
(fn TileView.resource-key [self] :tiles)
|
||||
(fn TileView.get_name [self] "Tile Editor")
|
||||
|
||||
TileView
|
||||
|
|
60
game/files.fnl
Normal file
60
game/files.fnl
Normal file
|
@ -0,0 +1,60 @@
|
|||
(local util (require :lib.util))
|
||||
(local lume (require :lib.lume))
|
||||
(local tile (require :game.tiles))
|
||||
(local tiledraw (require :editor.tiledraw))
|
||||
|
||||
(local files (util.hot-table ...))
|
||||
|
||||
(local filename "game/game.json")
|
||||
|
||||
(fn deserialize [key value]
|
||||
(match key
|
||||
(where (or :tiles :portraits :font)) (tile.deserialize value)
|
||||
:levels (do (set value.map (value.map:fromhex)) value)
|
||||
_ value))
|
||||
|
||||
(fn serialize [key value]
|
||||
(match key
|
||||
(where (or :tiles :portraits :font)) (tile.serialize value)
|
||||
:levels (do (set value.map (value.map:tohex)) value)
|
||||
_ value))
|
||||
|
||||
(fn files.load []
|
||||
(set files.game
|
||||
(if (util.file-exists filename)
|
||||
(let [game (util.readjson filename)]
|
||||
(each [k v (pairs game)]
|
||||
(tset game k (lume.map v #(deserialize k (lume.clone $1)))))
|
||||
game)
|
||||
{:tiles [] :portraits [] :font [] :levels []}))
|
||||
files.game)
|
||||
|
||||
(fn files.save []
|
||||
(let [game {}]
|
||||
(each [k v (pairs files.game)]
|
||||
(tset game k (lume.map v #(serialize k (lume.clone $1)))))
|
||||
(util.writejson filename game)))
|
||||
|
||||
(fn new-cache [game key]
|
||||
(let [spritegen (match key
|
||||
:font tiledraw.char-to-sprite
|
||||
:portraits tiledraw.portrait-to-sprite
|
||||
_ tiledraw.tile-to-sprite)
|
||||
gfx (. game key)]
|
||||
(tiledraw.TileCache gfx spritegen)))
|
||||
|
||||
(fn files.cache [key]
|
||||
(when (= (?. files :tilecaches key) nil)
|
||||
(util.nested-tset files [:tilecaches key] (new-cache files.game key)))
|
||||
(. files.tilecaches key))
|
||||
|
||||
(fn files.reload []
|
||||
(files.load)
|
||||
(when files.tilecaches
|
||||
(each [key cache (pairs files.tilecaches)]
|
||||
(cache:load (. files.game key)))))
|
||||
|
||||
(when (= files.game nil)
|
||||
(files.load))
|
||||
|
||||
files.hot
|
|
@ -1 +0,0 @@
|
|||
[{"flags":[],"gfx":"0000000000000000"},{"flags":[],"gfx":"081C1C1C08000800"},{"flags":[],"gfx":"3636241200000000"},{"flags":[],"gfx":"123F1212123F1200"},{"flags":[],"gfx":"083C0A1C281E0800"},{"flags":[],"gfx":"0026160834320000"},{"flags":[],"gfx":"0E1B1B062F1B3600"},{"flags":[],"gfx":"0C0C080400000000"},{"flags":[],"gfx":"180C0606060C1800"},{"flags":[],"gfx":"0C18303030180C00"},{"flags":[],"gfx":"082A1C081C2A0800"},{"flags":[],"gfx":"000C0C3F3F0C0C00"},{"flags":[],"gfx":"000000000C0C0804"},{"flags":[],"gfx":"0000001E1E000000"},{"flags":[],"gfx":"00000000000C0C00"},{"flags":[],"gfx":"002030180C060200"},{"flags":[],"gfx":"1C26263E26261C00"},{"flags":[],"gfx":"181C181818183C00"},{"flags":[],"gfx":"1C2620180C063E00"},{"flags":[],"gfx":"1C26201820261C00"},{"flags":[],"gfx":"2626263C30303000"},{"flags":[],"gfx":"3E061E2020201E00"},{"flags":[],"gfx":"1C26061E26261C00"},{"flags":[],"gfx":"3E2630180C0C0C00"},{"flags":[],"gfx":"1C26261C26261C00"},{"flags":[],"gfx":"1C26263C20201C00"},{"flags":[],"gfx":"000C0C000C0C0000"},{"flags":[],"gfx":"000C0C000C0C0804"},{"flags":[],"gfx":"30180C060C183000"},{"flags":[],"gfx":"00003E003E000000"},{"flags":[],"gfx":"060C1830180C0600"},{"flags":[],"gfx":"1C3630180C000C00"},{"flags":[],"gfx":"1E33212D3D011E00"},{"flags":[],"gfx":"1C3E26263E262600"},{"flags":[],"gfx":"1E26261E26261E00"},{"flags":[],"gfx":"1C26060606261C00"},{"flags":[],"gfx":"1E26262626261E00"},{"flags":[],"gfx":"3E06061E06063E00"},{"flags":[],"gfx":"3E06061E06060600"},{"flags":[],"gfx":"1C26063626263C00"},{"flags":[],"gfx":"2626263E26262600"},{"flags":[],"gfx":"3C18181818183C00"},{"flags":[],"gfx":"3C30303036361C00"},{"flags":[],"gfx":"2626261E26262600"},{"flags":[],"gfx":"0606060606063E00"},{"flags":[],"gfx":"373F2B2B23232300"},{"flags":[],"gfx":"26262E3626262600"},{"flags":[],"gfx":"1C26262626261C00"},{"flags":[],"gfx":"1E26261E06060600"},{"flags":[],"gfx":"1C26262626363C00"},{"flags":[],"gfx":"1E26261E26262600"},{"flags":[],"gfx":"3C26061C20221E00"},{"flags":[],"gfx":"3F0C0C0C0C0C0C00"},{"flags":[],"gfx":"2626262626261C00"},{"flags":[],"gfx":"2626261C1C1C0800"},{"flags":[],"gfx":"2323232B2B2A3600"},{"flags":[],"gfx":"2626261C26262600"},{"flags":[],"gfx":"2626261C18181800"},{"flags":[],"gfx":"3E3E30180C063E00"},{"flags":[],"gfx":"1C0C0C0C0C0C1C00"},{"flags":[],"gfx":"0002060C18302000"},{"flags":[],"gfx":"1C18181818181C00"},{"flags":[],"gfx":"081C260000000000"},{"flags":[],"gfx":"0000000000003E00"},{"flags":[],"gfx":"0C0C100000000000"}]
|
1
game/game.json
Normal file
1
game/game.json
Normal file
File diff suppressed because one or more lines are too long
|
@ -1 +0,0 @@
|
|||
{"loadword":"","map":"000000000000000000000000000000000000000000606060606060606060606060606060606060000060000000000000000000000000000000006000006000000000000000000000000000000000600000600000A00000000000000000004000000060000060000000000000000000000000000000006000006000000000000000000000000000000000600000600000000000000000000000000000000060000060000000000000000080808080800000006000006000000000000000000000000000000000600000606060606060606060606060606060606060000000000000000000000000000000000000000000","player":{"y":4,"x":5},"tickword":"","moveword":"","objects":[{"x":15,"linkentity":"","func":"cat","y":8,"name":"","linkword":""},{"x":5,"linkentity":"","func":"fish","name":"","linkword":"","y":8},{"x":13,"linkentity":"","func":"pot","name":"","linkword":"","y":4},{"x":12,"linkentity":"","func":"suspiciouspot","linkword":"","name":"","y":4},{"x":11,"linkentity":"","func":"pot","linkword":"","name":"","y":4},{"x":14,"linkentity":"","func":"pot","linkword":"","name":"","y":4},{"x":15,"linkentity":"","func":"pot","linkword":"","name":"","y":4}]}
|
|
@ -1 +0,0 @@
|
|||
[{"gfx":"000000000000000000000000000000000000007C7C7E7E7E7E7E7E7E7E7E7E7E00000000707F7F7F7F7F7F7F7F7F7F7F7E7E7E7E7F7F7F7F7F7F7F7F7F7F7F7F0000000F0F1F1F1F1F1F1F1F1F1F1F1F000000000000000000000000000000001F1F1F1F7F7F7F7F7F7F7F7F7F7F7F7F00000000077F7F7F7F7F7F7F7F7F7F7F","label":"pplayer","flags":[]},{"gfx":"00000000004040606060707070707070000000000000010103037F7F7F7F7F7F707060604000000000000000000000007F7F7F7F7F7F7800004040406060606000000000001018383C3C7F7F7F7F7F7F000000000000000000000000000000007F7F7F3F0F67717C7F7F7F7F7F7F7F7F00007C7E7F7F7F7F7F7F7F7F7F7F7F7F","label":"pcat","flags":[]},{"gfx":"80808080808080808080D5818181858480808080808080808080AA80808080808484848484A4848484A48484848494D0809090D0D4F5D5D5D5D5D480808080AA80808080808080808080D5808080808080808080808080808080AAA0A0A0A888808080808AA8AAAAAA828080808080D588888888888889898888888888888A82","label":"pangryfish","flags":[]}]
|
|
@ -82,5 +82,5 @@
|
|||
(find-itile tiles label (+ itile 1))))
|
||||
|
||||
{: loadgfx : savegfx : appendtiles : appendgfx : append-portraitwords : flags : flag-to-bit : find-itile
|
||||
: fn-tiles : fn-portraits : fn-font : encode-yx : encode-itile : decode-itile}
|
||||
: fn-tiles : fn-portraits : fn-font : encode-yx : encode-itile : decode-itile : serialize : deserialize}
|
||||
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
[{"gfx":"8080808080808080808080808080808080808080808080808080808080808080","word":"","label":"","flags":{"walkable":true}},{"gfx":"8080C0C0C0C0E0F0F8FCE6E6E0B0B0B0808183838383878F9FBFE7E7868C8C8C","word":"","label":"player-frame1","flags":[]},{"gfx":"8080808084CCFCFCFCFCFCF8F0B0B0B080808080E1E1E1F1B99F9F8F8F8C8C8C","word":"","label":"","flags":[]},{"gfx":"D5D5D5858585A5A5A5A5858585D5D5D5AAAAAAA8A8A8A9A9A9A9A8A8A8AAAAAA","word":"","label":"","flags":[]},{"gfx":"8080D4D0D0D0D4D45454D4D4D4D0808080808A8282828A8A8A0A0A8A8A828080","word":"pot","label":"","flags":[]},{"gfx":"8080808080D490948484A48494D080808080808080AA88A8A0A5A5A0A88A8080","word":"","label":"","flags":[]},{"gfx":"8080D4D0D0D0D4D45454D4D4D4D0808080808A8282828A8A8A0A0A8A8A828080","word":"","label":"","flags":[]},{"gfx":"000000A0908884827E0A0A0A0000000000000000201008040785858500000000","word":"","label":"","flags":[]},{"gfx":"000014040414500000000000A888A8800000282020280A010101010195919580","word":"","label":"","flags":[]},{"gfx":"00008C92921C60105010781C0E070300000098A4A41C030504050F1C38706000","word":"","label":"","flags":[]},{"gfx":"000000004040000000D4D4ECECECD480000000000202010101AAAAB6B6B6AA80","word":"","label":"","flags":[]},{"gfx":"0000000000004828282828482800000000000000000004050505050405000000","word":"","label":"","flags":[]}]
|
Loading…
Reference in a new issue