source for my save:
Code: Select all
function Editor:savelevel(filename)
local drop = {}
if filename == nil then
filename = self.roomname
else
self.roomname = filename
end
filename = self.savePath.."Levels/"..filename..".lvl"
local tiles = {}
local doors = {}
for i=1,#Tiles do
if Tiles[i].args.door then
table.insert(doors,Tiles[i])
else
table.insert(tiles,Tiles[i])
end
end
local f = io.open(filename,"w")
local saveString = "{"..self.roomw..","..self.roomh.."}\n"..Tserial.pack(tiles,drop,false).."\n"..Tserial.pack(doors,drop,false)
f:write(filename,saveString)
f:close()
self.console_errtxt = "level \""..filename.."\" saved!"
end
Code: Select all
function Editor:loadlevel(filename)
filename = string.lower(filename)
self.roomname = filename
filename = self.savePath.."Levels/"..filename..".lvl"
local line = {}
if file_check(filename) then
self:clearlevel()
local f = io.open(filename)
for lines in f:lines() do
table.insert(line,lines)
end
f:close()
self.roomw,self.roomh = string.match(tostring(line[1]),'{(%d+),(%d+)}')
self.roomw,self.roomh = tonumber(self.roomw),tonumber(self.roomh)
Tiles = Tserial.unpack(tostring(line[2]),true)
if line[3] ~= nil then
local doors = Tserial.unpack(tostring(line[3]),true)
for d=1,#doors do
table.insert(Tiles,doors[d])
end
end
cam:setWorld(-32,-32,self.roomw+64,self.roomh+64)
self.console_errtxt = "level \""..filename.."\" loaded!"
for i,v in ipairs(Tiles) do
if v.args.playerSpawn then
player.spawnx = v.x+8
player.spawny = v.y+8
player.x = player.spawnx
player.y = player.spawny
end
end
else
self.console_errtxt = "level \""..filename.."\" doesn't exist!"
end
end