This commit is contained in:
PossiblyAxolotl 2022-05-22 14:40:42 -06:00
parent d9adc3662e
commit 7deae09065
4 changed files with 69 additions and 7 deletions

View file

@ -13,7 +13,7 @@ local tilemapEditor = gfx.tilemap.new()
tilemapEditor:setImageTable(tileTable) tilemapEditor:setImageTable(tileTable)
local tiles = {} local tiles = {}
tilemapEditor:setSize(10,10) tilemapEditor:setSize(1000,1000)
local imgtiles = gfx.sprite.new(tilemapEditor) local imgtiles = gfx.sprite.new(tilemapEditor)
local w, h = imgtiles:getSize() local w, h = imgtiles:getSize()
imgtiles:moveTo(w/2,h/2) imgtiles:moveTo(w/2,h/2)
@ -23,8 +23,8 @@ local positionLerp = {x=0,y=0}
local bool2int = {[true]=1,[false]=0} local bool2int = {[true]=1,[false]=0}
local menu = playdate.getSystemMenu() local menu = playdate.getSystemMenu()
local toolTipButton, error local toolTipButton
local altClrButton, error local altClrButton
local editor = "main" local editor = "main"
@ -59,17 +59,56 @@ function updateNewproj()
gfx.drawTextInRect(playdate.keyboard.text:upper(),0,125, 210, 80) gfx.drawTextInRect(playdate.keyboard.text:upper(),0,125, 210, 80)
end 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) function playdate.keyboard.keyboardWillHideCallback(ok)
if ok == false then if ok == false then
page = 0 page = 0
playdate.wait(0.3) playdate.wait(0.3)
editLoad() editLoad()
else 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" mode = "editor"
toolTipButton, error = menu:addMenuItem("save",false, function() toolTipButton, error = menu:addMenuItem("save",false, function()
editSave() editSave()
end) 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) playdate.display.setInverted(value)
end) end)
levelname = playdate.keyboard.text:upper() levelname = playdate.keyboard.text:upper()
@ -95,8 +134,9 @@ local curY = math.floor( tileIndex ) * 28 + 3
local curYlerp = -32 local curYlerp = -32
function editSave() function editSave()
playdate.datastore.delete("levels/"..levelname..".json")
saveTime = 5 saveTime = 5
playdate.datastore.write({tiles = tiles},"levels/"..levelname) playdate.datastore.write({tiles = tiles, inverted = inverted},"levels/"..levelname)
end end
function editUpdate() function editUpdate()
@ -122,8 +162,21 @@ function editUpdate()
tilemapEditor:setTileAtPosition(position.x+12,position.y+8,2) tilemapEditor:setTileAtPosition(position.x+12,position.y+8,2)
tiles[#tiles+1] = {x=position.x + 12, y=position.y + 8, t=2} tiles[#tiles+1] = {x=position.x + 12, y=position.y + 8, t=2}
imgtiles = gfx.sprite.new(tilemapEditor) imgtiles = gfx.sprite.new(tilemapEditor)
w, h = imgtiles:getSize() end
imgtiles:moveTo(w/2,h/2) 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 end
end end
@ -146,8 +199,11 @@ function editUpdate()
-- draw map -- draw map
gfx.setDrawOffset(-positionLerp.x, -positionLerp.y) gfx.setDrawOffset(-positionLerp.x, -positionLerp.y)
imgtiles:update() imgtiles:update()
imgCursor:draw((position.x + 11) * 16, (position.y + 7) * 16) 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 if position.y < 1 then
imgCant:drawTiled((position.x-1) * 16,-112,400,112) imgCant:drawTiled((position.x-1) * 16,-112,400,112)
end end
@ -184,8 +240,12 @@ function editClose()
editSave() editSave()
for tile = 1, #tiles, 1 do for tile = 1, #tiles, 1 do
tilemapEditor:setTileAtPosition(tiles[tile].x,tiles[tile].y,0) tilemapEditor:setTileAtPosition(tiles[tile].x,tiles[tile].y,0)
tiles[tile] = nil
end end
playdate.display.setInverted(false)
imgtiles = gfx.sprite.new(tilemapEditor)
imgtiles:remove() imgtiles:remove()
playdate.getSystemMenu():removeMenuItem(toolTipButton) playdate.getSystemMenu():removeMenuItem(toolTipButton)
playdate.getSystemMenu():removeMenuItem(altClrButton)
menuButton:setTitle("game menu") menuButton:setTitle("game menu")
end end

View file

@ -233,5 +233,7 @@ function menuButtonPress(name)
elseif menu == "data" then elseif menu == "data" then
addMap("data/"..name, true) addMap("data/"..name, true)
mode = "play" mode = "play"
elseif menu == "edits" then
editLoadName(name)
end end
end end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 99 B

After

Width:  |  Height:  |  Size: 127 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.2 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB