-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.lua
More file actions
60 lines (44 loc) · 963 Bytes
/
map.lua
File metadata and controls
60 lines (44 loc) · 963 Bytes
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
local geotable = {}
local function pos_hash(pos)
return pos.x + 10000*pos.y + 100000000*pos.z
end
local function location(pos)
local h = pos_hash(pos)
local v = geotable[h]
if (not v) then
v = {}
geotable[h]=v
end
return v
end
local function set_walkable(pos,walkable)
local l=location(pos)
l.walkable=walkable
l.walkable_timestamp = os.day()*100 + os.time()
end
local function is_walkable(pos)
local l=location(pos)
return l.walkable
end
local function save()
saveString(textutils.serialize(geotable),"map.txt")
end
local function load()
local file = fs.open("map.txt", "r")
local sTable = file.readAll()
file.close()
geotable = textutils.unserialize(sTable)
end
local function package()
return {
--pos_hash = pos_hash,
location = location,
set_walkable = set_walkable,
is_walkable = is_walkable,
save = save,
load = load
}
end
export = package()
map = export
return export