- [NEW] editor.load

- [NEW] editor.save
This commit is contained in:
2025-11-05 16:00:29 +01:00
parent 47fb840d80
commit fc99ad06a4
4 changed files with 38 additions and 2 deletions

View File

@@ -24,9 +24,39 @@ editor = {
editor.oy = 0 editor.oy = 0
end, end,
load = function(level)
local base_name = "level" .. tostring(level)
local file = io.open("data/" .. base_name .. ".lev", "r")
if file then
for line in file:lines() do
local key,value = line:match("^(.+)=(.+)$")
if key and value then
if key == "start-x" then
editor.ox = tonumber(value)
elseif key == "start-y" then
editor.oy = tonumber(value)
end
end
end
editor.num = level
surf.free(editor.map_surf[1])
surf.free(editor.map_surf[2])
editor.map_surf[1] = surf.load(base_name .. "_1.gif")
editor.map_surf[2] = surf.load(base_name .. "_2.gif")
else
print("No s'ha trobat l'arxiu!")
end
end,
save = function() save = function()
local base_name = "level" + tostring(editor.num) local base_name = "level" .. tostring(editor.num)
local file = io.open("data/" .. base_name .. ".lev", "w")
if file then
file:write("start-x=" .. tostring(editor.ox) .. "\n")
file:write("start-y=" .. tostring(editor.oy) .. "\n")
end
surf.save(editor.map_surf[1], "data/" .. base_name .. "_1.gif")
surf.save(editor.map_surf[2], "data/" .. base_name .. "_2.gif")
end, end,
update = function() update = function()
@@ -63,6 +93,10 @@ editor = {
editor.current_layer=2 editor.current_layer=2
elseif key.press(key.F) then elseif key.press(key.F) then
editor.fill(tx//8, ty//8, map.tile(mx/8, my/8)) editor.fill(tx//8, ty//8, map.tile(mx/8, my/8))
elseif key.down(key.LCTRL) and key.press(key.S) then
editor.save()
elseif key.down(key.LCTRL) and key.press(key.L) then
editor.load(1)
end end
if mouse.down(mouse.LEFT) then if mouse.down(mouse.LEFT) then

2
data/level1.lev Normal file
View File

@@ -0,0 +1,2 @@
start-x=-24
start-y=-24

BIN
data/level1_1.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 493 B

BIN
data/level1_2.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 B