-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.lua
More file actions
143 lines (93 loc) · 2.03 KB
/
Copy pathmap.lua
File metadata and controls
143 lines (93 loc) · 2.03 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
-- File for gestion of map Ulysse.B
maps = {}
currentMap = {}
local numTypeFile = 2
local NameOfCurrentMap = ""
local PatchMapInfo = "map.info"
local mapDir = "map"
function getCurrentMap()
return currentMap
end
function LoadAllMap()
print("Start to load..")
if(love.filesystem.exists(mapDir)) then
else
love.filesystem.createDirectory(mapDir)
end
print(mapDir)
cpt = 1
for line in love.filesystem.lines(PatchMapInfo) do
maps[cpt] = getMap(line)
cpt= cpt+1
end
currentMap = maps[1]
print(#maps .. " num of map")
end
-- Create the Map when not exist (TheFile)
function createFileMap( nameMap )
for i=1,numTypeFile do
patch = getPatch(nameMap,i)
f = love.filesystem.newFile(patch)
f:open("w")
tx = 50
ty = 50
case = "1"
for y=1,ty do
for x=1,tx do
f:write(case)
end
if(ty == y) then
else
f:write("\n")
end
end
f:close()
end
end
-- Load File of Map
function LoadMap( nameMap )
newMap = {}
for i=1,numTypeFile do
newMap[i] = {}
lignes = love.filesystem.lines(getPatch(nameMap,i))
cpt = 1
for lignes in love.filesystem.lines(getPatch(nameMap,i)) do
newMap[i][cpt] = lignes
cpt = cpt + 1
end
end
return newMap
end
-- Get Or Create Map
function getMap( nameMap )
if(mapExists(nameMap)) then
return LoadMap(nameMap)
else
createFileMap(nameMap)
return nil
end
end
-- type is integer and nameMap is the name / return the patch with type and name
function getPatch(nameMap,Type)
patch = mapDir.."/" .. nameMap
if(Type == 1) then
patch = patch .. ".map"
else
if(Type == 2) then
patch = patch .. ".col"
else
end
end
return patch
end
function mapExists( nameMap )
isExist = true
-- Verif if different file of a map exist
for i=1,numTypeFile do
if(love.filesystem.exists( getPatch(nameMap,i) )) then
else
isExist = false
end
end
return isExist
end