- [NEW] editor.load
- [NEW] editor.save
This commit is contained in:
@@ -24,9 +24,39 @@ editor = {
|
||||
editor.oy = 0
|
||||
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()
|
||||
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,
|
||||
|
||||
update = function()
|
||||
@@ -63,6 +93,10 @@ editor = {
|
||||
editor.current_layer=2
|
||||
elseif key.press(key.F) then
|
||||
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
|
||||
|
||||
if mouse.down(mouse.LEFT) then
|
||||
|
||||
Reference in New Issue
Block a user