-
Notifications
You must be signed in to change notification settings - Fork 0
/
catalog.spec.lua
115 lines (96 loc) · 3.28 KB
/
catalog.spec.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
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
local pos1 = { x=-32, y=-32, z=-32 }
local pos2 = { x=64, y=32, z=64 }
local mb_pos1 = { x=0, y=0, z=0 }
local mb_pos2 = { x=1, y=1, z=1 }
local filename = minetest.get_worldpath() .. "/mapblocks/test.zip"
-- emerge area
mtt.emerge_area(pos1, pos2)
mtt.register("read existing catalog", function(callback)
local c, err = mapblock_lib.get_catalog(minetest.get_modpath("mapblock_lib") .. "/test/street_straight.zip")
assert(err == nil, "err is nil")
local size = c:get_size()
assert(size.x == 1, "x-size match")
assert(size.y == 1, "y-size match")
assert(size.z == 1, "z-size match")
assert(c:has_mapblock({x=0,y=0,z=0}), "mapblock exists")
assert(not c:has_mapblock({x=0,y=0,z=1}), "mapblock does not exist")
-- test get_node() accessor
local node = c:get_node({x=0,y=0,z=0})
assert(node.name == "default:stone")
assert(node.param1 == 15)
assert(node.param2 == 0)
node = c:get_node({x=15,y=15,z=15})
assert(node.name == "air")
assert(node.param1 == 15)
assert(node.param2 == 0)
assert(not c:get_node({x=0,y=16,z=0}))
callback()
end)
-- catalog
mtt.register("creating catalog", function(callback)
mapblock_lib.create_catalog(filename, mb_pos1, mb_pos2, {
callback = function() callback() end,
progress_callback = function(p)
print("progress: " .. p)
end
})
end)
mtt.register("reading catalog", function(callback)
local c, err = mapblock_lib.get_catalog(filename)
assert(err == nil, "err is nil")
local size = c:get_size()
assert(size.x == 2, "x-size match")
assert(size.y == 2, "y-size match")
assert(size.z == 2, "z-size match")
callback()
end)
mtt.register("reading non-existent catalog", function(callback)
local c, err = mapblock_lib.get_catalog(filename .. "blah")
assert(c == nil, "catalog is nil")
assert(err, "err is not nil")
callback()
end)
mtt.register("deserializing one mapblock from the catalog", function(callback)
local c, err = mapblock_lib.get_catalog(filename)
assert(err == nil, "err is nil")
c:deserialize({x=0,y=0,z=0}, {x=10,y=10,z=10})
local mb1 = mapblock_lib.serialize_mapblock({x=0,y=0,z=0})
local mb2 = mapblock_lib.serialize_mapblock({x=10,y=10,z=10})
local equal
equal, err = mapblock_lib.compare_mapblock(mb1, mb2)
if err then
error(err)
end
assert(equal, "deserialized mapblock is equal to the serialized")
callback()
end)
mtt.register("deserializing all mapblocks from the catalog", function(callback)
local c, err = mapblock_lib.get_catalog(filename)
assert(err == nil, "err is nil")
c:deserialize_all({x=0,y=1,z=2}, {
callback = function() callback() end,
progress_callback = function(p)
print("progress: " .. p)
end,
error_callback = error
})
end)
mtt.register("comparing all mapblocks from the catalog", function(callback)
for x=mb_pos1.x,mb_pos2.x do
for y=mb_pos1.y,mb_pos2.y do
for z=mb_pos1.z,mb_pos2.z do
local mapblock_pos = {x=x,y=y,z=z}
local target_pos = {x=x,y=1+y,z=2+z}
local mb1 = mapblock_lib.serialize_mapblock(mapblock_pos)
local mb2 = mapblock_lib.serialize_mapblock(target_pos)
local equal, err = mapblock_lib.compare_mapblock(mb1, mb2)
if err then
error(err .. ", mapblock " .. minetest.pos_to_string(mapblock_pos) ..
" -> " .. minetest.pos_to_string(target_pos))
end
assert(equal, "deserialized mapblock is equal to the serialized")
end
end
end
callback()
end)