-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor-save.lua
More file actions
57 lines (43 loc) · 1.48 KB
/
editor-save.lua
File metadata and controls
57 lines (43 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--[[
This software is released under the MIT License. See LICENSE.txt for details.
Also, on a non-legal note: I do not recommend reading my code, especially not for educative
purposes. It was written over like three years, and I often forgot how I implemented several
things over time. Also, I was mostly drunk and listening to the Katamari Damacy soundtrack.
So yeah.
]]
local function saveLevel(lvl,items,decs,nmys,filename,folder)
local str = "local function lol(gfx)\nlocal items = newItemList()\n"
for i=1,#items.list do
local item = items.list[i]
str = str.."items:add(newEItem('"..item.s.."',"..item.x..","..item.y..",gfx))\n"
end
str = str.."local decs = {}\n"
for i=1,#decs do
local dec = decs[i]
str = str.."decs["..i.."] = {"..dec[1]..", "..dec[2]..", "..dec[3].."}\n"
end
str = str.."local nmys = {}\n"
for i=1,#nmys do
local nmy = nmys[i]
str = str.."nmys["..i.."] = {"..nmy[1]..", "..nmy[2]..", "..nmy[3].."}\n"
end
str = str.."local lvl = {}\n"
for i=1,#lvl do
str = str.."lvl["..i.."] = {}\n"
for j=1,#lvl[1] do
if lvl[i][j] ~= 0 then
str=str.."lvl["..i.."]["..j.."] = "..lvl[i][j].."\n"
end
end
end
str = str.."return lvl,items,decs,nmys\nend\nreturn lol"
--[[ verkar inte vara nödvändigt
if love.filesystem.exists(folder) then --PROBLEM när mappen finns i huvudmappen, lol
else
love.filesystem.mkdir(folder)
end
]]
love.filesystem.mkdir(folder)
love.filesystem.write(folder.."/"..filename,str)
end
return saveLevel