-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlevels.lua
55 lines (40 loc) · 1009 Bytes
/
levels.lua
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
-- Level reading and loading
local L ={}
function L.splitNumbers( str )
local results = {};
for m in str:gmatch("[^%s]+") do
results[#results+1] = m+0;
end
return results
end
function L.splitLine( str, width )
end
function L.readLevels()
local allLevels = {}
contents, size = love.filesystem.read('assets/levels.txt')
-- Setup
local str = contents
local start = 1
local i, tmp = string.find( str, '\n' )
local mode = 0
local tmp_x, tmp_y = 0,0
local count = 0
while i ~= nil do
local sub = string.sub( str, 1, i )
local rest = string.sub( str, i+1 )
if mode == 0 then -- level number
print(tonumber(sub))
mode = mode + 1
elseif mode == 1 then -- size_x, size_y
local size = L.splitNumbers( sub )
print( size[1], size[2] )
mode = mode + 1
elseif mode == 2 then -- board line
print(sub)
end
str = rest
i, tmp = string.find(str, '\n')
end
end
--export namespace
return L