diff --git a/Source/Editor.lua b/Source/Editor.lua index d785831..b9f66a5 100644 --- a/Source/Editor.lua +++ b/Source/Editor.lua @@ -13,7 +13,7 @@ local tilemapEditor = gfx.tilemap.new() tilemapEditor:setImageTable(tileTable) local tiles = {} -tilemapEditor:setSize(10,10) +tilemapEditor:setSize(1000,1000) local imgtiles = gfx.sprite.new(tilemapEditor) local w, h = imgtiles:getSize() imgtiles:moveTo(w/2,h/2) @@ -23,8 +23,8 @@ local positionLerp = {x=0,y=0} local bool2int = {[true]=1,[false]=0} local menu = playdate.getSystemMenu() -local toolTipButton, error -local altClrButton, error +local toolTipButton +local altClrButton local editor = "main" @@ -59,17 +59,56 @@ function updateNewproj() gfx.drawTextInRect(playdate.keyboard.text:upper(),0,125, 210, 80) end +function editLoadName(name) + position = {x=100,y=100} + local data = json.decodeFile("levels/"..name) + levelname = name:match("(.+)%..+$") + inverted = data.inverted + printTable(data) + playdate.display.setInverted(data.inverted) + saveTime = 0 + mode = "editor" + + -- loading tiles + for tile = 1, #tiles, 1 do + tilemapEditor:setTileAtPosition(tiles[tile].x,tiles[tile].y,0) + end + for tile = 1, #data.tiles, 1 do + tilemapEditor:setTileAtPosition(data.tiles[tile].x,data.tiles[tile].y,data.tiles[tile].t) + tiles[tile] = {x=data.tiles[tile].x,y=data.tiles[tile].y,t=data.tiles[tile].t} + end + + toolTipButton = menu:addMenuItem("save",data.inverted, function() + editSave() + end) + altClrButton = menu:addCheckmarkMenuItem("alt colours",inverted, function(value) + playdate.display.setInverted(value) + inverted = value + end) + imgtiles:add() + menuButton:setTitle("save & quit") + playdate.wait(0.1) +end + function playdate.keyboard.keyboardWillHideCallback(ok) if ok == false then page = 0 playdate.wait(0.3) editLoad() else + position = {x=100,y=100} + for tile = 1, #tiles, 1 do + tilemapEditor:setTileAtPosition(tiles[tile].x,tiles[tile].y,0) + end + inverted = false + playdate.display.setInverted(false) + saveTime = 0 mode = "editor" toolTipButton, error = menu:addMenuItem("save",false, function() editSave() end) - altClrButton, error = menu:addCheckmarkMenuItem("alt colours",inverted, function(value) + playdate.wait(0.1) + altClrButton, error = menu:addCheckmarkMenuItem("alt colours",false, function(value) playdate.display.setInverted(value) end) levelname = playdate.keyboard.text:upper() @@ -95,8 +134,9 @@ local curY = math.floor( tileIndex ) * 28 + 3 local curYlerp = -32 function editSave() + playdate.datastore.delete("levels/"..levelname..".json") saveTime = 5 - playdate.datastore.write({tiles = tiles},"levels/"..levelname) + playdate.datastore.write({tiles = tiles, inverted = inverted},"levels/"..levelname) end function editUpdate() @@ -122,8 +162,21 @@ function editUpdate() tilemapEditor:setTileAtPosition(position.x+12,position.y+8,2) tiles[#tiles+1] = {x=position.x + 12, y=position.y + 8, t=2} imgtiles = gfx.sprite.new(tilemapEditor) - w, h = imgtiles:getSize() - imgtiles:moveTo(w/2,h/2) + end + end + end + + if playdate.buttonJustPressed(playdate.kButtonB) then + if editor == "main" then + if math.floor( tileIndex ) == 0 then + tilemapEditor:setTileAtPosition(position.x+12,position.y+8,0) + for tile = 1, #tiles, 1 do + if tiles[tile].x == position.x + 12 and tiles[tile].y == position.y+8 then + table.remove(tiles,tile) + break + end + end + imgtiles = gfx.sprite.new(tilemapEditor) end end end @@ -146,8 +199,11 @@ function editUpdate() -- draw map gfx.setDrawOffset(-positionLerp.x, -positionLerp.y) + imgtiles:update() imgCursor:draw((position.x + 11) * 16, (position.y + 7) * 16) + --gfx.setColor(playdate.graphics.kColorXOR) + --gfx.fillRect((position.x + 11) * 16, (position.y + 7) * 16,16,16) if position.y < 1 then imgCant:drawTiled((position.x-1) * 16,-112,400,112) end @@ -184,8 +240,12 @@ function editClose() editSave() for tile = 1, #tiles, 1 do tilemapEditor:setTileAtPosition(tiles[tile].x,tiles[tile].y,0) + tiles[tile] = nil end + playdate.display.setInverted(false) + imgtiles = gfx.sprite.new(tilemapEditor) imgtiles:remove() playdate.getSystemMenu():removeMenuItem(toolTipButton) + playdate.getSystemMenu():removeMenuItem(altClrButton) menuButton:setTitle("game menu") end \ No newline at end of file diff --git a/Source/Menu.lua b/Source/Menu.lua index f104bcc..7f96e22 100644 --- a/Source/Menu.lua +++ b/Source/Menu.lua @@ -233,5 +233,7 @@ function menuButtonPress(name) elseif menu == "data" then addMap("data/"..name, true) mode = "play" + elseif menu == "edits" then + editLoadName(name) end end \ No newline at end of file diff --git a/Source/gfx/cursor2.png b/Source/gfx/cursor2.png index 90b0f58..aa8315f 100644 Binary files a/Source/gfx/cursor2.png and b/Source/gfx/cursor2.png differ diff --git a/Source/launcher/wrapping-pattern.png b/Source/launcher/wrapping-pattern.png index f6e49ab..e7b9808 100644 Binary files a/Source/launcher/wrapping-pattern.png and b/Source/launcher/wrapping-pattern.png differ