-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapIO.lua
71 lines (63 loc) · 1.53 KB
/
mapIO.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
json = require 'json4lua/json/json'
function split(source, delimiters)
local elements = {}
local pattern = '([^'..delimiters..']+)'
string.gsub(source, pattern, function(value) elements[#elements + 1] = value; end);
return elements
end
function printArray(arr)
for x,y in pairs(arr) do
io.write(y.." ")
end
print()
end
function convertArrayToInt(arr)
for x,y in pairs(arr) do
arr[x] = tonumber(y)
end
return arr
end
function loadPortals(mapNum)
portalsFile = love.filesystem.newFile("portals"..tostring(mapNum))
portalsFile:open("r")
doors = {}
newDoor = {}
porIter = portalsFile:lines()
i = 1
for door in porIter do
x,y,m,s,t = string.match(door,"(%d+),(%d+),(%d+),(%d+),(%d+)")
pX = tonumber(x)
pY = tonumber(y)
toMap = tonumber(m)
toX = tonumber(s)
toY = tonumber(t)
newDoor = {pX,pY,toMap,toX,toY}
doors[i] = newDoor
i = i +1
end
return doors
end
function loadMapOLD(fromMap, player, mapNumber)
mapName = "map"..tostring(mapNumber)
mapFile = love.filesystem.newFile(mapName)
mapFile:open("r")
map = {}
mapIter = mapFile:lines()
mapPos = 1
for x in mapIter do
res = split(x,",")
map[mapPos] = convertArrayToInt(res)
mapPos = mapPos + 1
end
mapFile:close()
newMap = { tiles = map,portals = loadPortals(mapNumber)}
return newMap
end
function loadMap(fromMap, player, mapNumber)
mapFile = "retrocrossing/maps/map"..tostring(mapNumber)..".json"
mapFile = io.open(mapFile,"r")
input = mapFile:read("*all")
map = json.decode(input)
mapFile:close()
return map
end