• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

BuckarooBanzay / mapblock_lib / 8748698230

19 Apr 2024 05:08AM UTC coverage: 19.22% (-35.6%) from 54.827%
8748698230

Pull #3

github

BuckarooBanzay
mtt action
Pull Request #3: mtt action

202 of 1051 relevant lines covered (19.22%)

16.77 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

19.15
/chatcommands/multi.lua
1

2
-- resolves a user-provided schema path to a filename
3
-- examples:
4
-- "mything" -> mapblock_lib.schema_path .. "/mything.zip"
5
-- TBD: "mymod:mypath/mything" -> minetest.get_modpath("mymod") .. "mypath/mything.zip"
6
function mapblock_lib.resolve_schema_path(name)
2✔
7
        local parts = {}
×
8
        for str in string.gmatch(name, "([^:]+)") do
×
9
                table.insert(parts, str)
×
10
        end
11

12
        if #parts == 2 then
×
13
                -- mod:path
14
                local mp = minetest.get_modpath(parts[1])
×
15
                if not mp then
×
16
                        return nil, "mod not found: '" .. parts[1] .. "'"
×
17
                end
18
                return mp .. "/" .. parts[2] .. ".zip"
×
19
        else
20
                -- worldpath prefix
21
                return mapblock_lib.schema_path .. "/" .. parts[1] .. ".zip"
×
22
        end
23

24
end
25

26
minetest.register_chatcommand("mapblock_pos1", {
2✔
27
        privs = { mapblock_lib = true },
1✔
28
        description = "selects the current mapblock as pos1 for multi mapblock export/import",
29
        func = function(name)
30
                local player = minetest.get_player_by_name(name)
×
31
                if not player then
×
32
                        return false, "player not found"
×
33
                end
34

35
                local pos = player:get_pos()
×
36
                local mapblock_pos = mapblock_lib.get_mapblock(pos)
×
37
                mapblock_lib.set_pos(1, name, mapblock_pos)
×
38

39
                return true, "selected mapblock " .. minetest.pos_to_string(mapblock_pos) .. " as pos1"
×
40
        end
41
})
42

43
minetest.register_chatcommand("mapblock_pos2", {
2✔
44
        privs = { mapblock_lib = true },
1✔
45
        description = "selects the current mapblock as pos2 for multi mapblock export/import",
46
        func = function(name)
47
                local player = minetest.get_player_by_name(name)
×
48
                if not player then
×
49
                        return false, "player not found"
×
50
                end
51

52
                local pos = player:get_pos()
×
53
                local mapblock_pos = mapblock_lib.get_mapblock(pos)
×
54
                mapblock_lib.set_pos(2, name, mapblock_pos)
×
55

56
                return true, "selected mapblock " .. minetest.pos_to_string(mapblock_pos) .. " as pos2"
×
57
        end
58
})
59

60
minetest.register_chatcommand("mapblock_save", {
2✔
61
        privs = { mapblock_lib = true },
1✔
62
        description = "saves the current mapblocks region",
63
        params = "<filename>",
64
        func = function(name, params)
65

66
                local pos1 = mapblock_lib.get_pos(1, name)
×
67
                local pos2 = mapblock_lib.get_pos(2, name)
×
68

69
                if not pos1 or not pos2 then
×
70
                        return false, "select a region with /mapblock_pos[1|2] first"
×
71
                end
72

73
                if not params or params == "" then
×
74
                        return false, "specify a name for the schema"
×
75
                end
76

77
                pos1, pos2 = mapblock_lib.sort_pos(pos1, pos2)
×
78
                local filename, err = mapblock_lib.resolve_schema_path(params)
×
79
                if err then
×
80
                        return false, err
×
81
                end
82

83
                mapblock_lib.create_catalog(filename, pos1, pos2, {
×
84
                        callback = function(total_count, micros)
85
                                minetest.chat_send_player(name, "[mapblock_lib] saved " .. total_count ..
×
86
                                        " mapblocks to '" .. filename .. "' in " .. micros/1000 .. " ms")
×
87
                        end,
88
                        progress_callback = function(p)
89
                                minetest.chat_send_player(name, "[mapblock_lib] save-progress: " .. math.floor(p*1000)/10 .. " %")
×
90
                        end
91
                })
92

93
                return true, "Started saving to '" .. filename .. "'"
×
94
        end
95
})
96

97
minetest.register_chatcommand("mapblock_load", {
2✔
98
        privs = { mapblock_lib = true },
1✔
99
        description = "loads a saved mapblock region",
100
        params = "<filename>",
101
        func = function(name, params)
102
                local pos1 = mapblock_lib.get_pos(1, name)
×
103

104
                if not pos1 then
×
105
                        return false, "select /mapblocks_pos1 first"
×
106
                end
107

108
                if not params or params == "" then
×
109
                        return false, "specify a name for the schema"
×
110
                end
111

112
                local filename, err = mapblock_lib.resolve_schema_path(params)
×
113
                if err then
×
114
                        return false, err
×
115
                end
116

117
                local catalog
118
                catalog, err = mapblock_lib.get_catalog(filename)
×
119
                if err then
×
120
                        return false, err
×
121
                end
122
                catalog:deserialize_all(pos1, {
×
123
                        callback = function(total_count, micros)
124
                                minetest.chat_send_player(name, "[mapblock_lib] loaded " .. total_count ..
×
125
                                        " mapblocks to '" .. filename .. "' in " .. micros/1000 .. " ms")
×
126
                        end,
127
                        progress_callback = function(p)
128
                                minetest.chat_send_player(name, "[mapblock_lib] load-progress: " .. math.floor(p*1000)/10 .. " %")
×
129
                        end
130
                })
131

132
                return true, "Started loading from '" .. filename .. "'"
×
133
        end
134
})
135

136
minetest.register_chatcommand("mapblock_allocate", {
2✔
137
        privs = { mapblock_lib = true },
1✔
138
        description = "allocates a saved mapblock region",
139
        params = "<filename>",
140
        func = function(name, params)
141
                local pos1 = mapblock_lib.get_pos(1, name)
×
142

143
                if not pos1 then
×
144
                        return false, "select /mapblocks_pos1 first"
×
145
                end
146

147
                if not params or params == "" then
×
148
                        return false, "specify a name for the schema"
×
149
                end
150

151
                local filename, err = mapblock_lib.resolve_schema_path(params)
×
152
                if err then
×
153
                        return false, err
×
154
                end
155

156
                local catalog
157
                catalog, err = mapblock_lib.get_catalog(filename)
×
158
                if err then
×
159
                        return false, "Error: " .. err
×
160
                end
161

162
                local size = catalog:get_size()
×
163
                mapblock_lib.set_pos(2, name, vector.subtract(vector.add(pos1, size), 1))
×
164

165
                return true, "Allocated: '" .. filename .. "' with size: " .. minetest.pos_to_string(size)
×
166
        end
167
})
168

169
minetest.register_chatcommand("mapblock_load_plain", {
2✔
170
        privs = { mapblock_lib = true },
1✔
171
        description = "loads a saved (single-file) mapblock region",
172
        params = "<filename>",
173
        func = function(name, params)
174
                local pos1 = mapblock_lib.get_pos(1, name)
×
175

176
                if not pos1 then
×
177
                        return false, "select /mapblocks_pos1 first"
×
178
                end
179

180
                if not params or params == "" then
×
181
                        return false, "specify a name for the schema"
×
182
                end
183

184
                local prefix = mapblock_lib.schema_path .. "/" .. params
×
185

186
                local success, err = mapblock_lib.deserialize(pos1, prefix)
×
187

188
                return success, err or "Loaded mapblock from '" .. prefix .. "'"
×
189
        end
190
})
191

192
-- register aliases
193
minetest.register_chatcommand("mb_pos1", minetest.registered_chatcommands["mapblock_pos1"])
1✔
194
minetest.register_chatcommand("mb_pos2", minetest.registered_chatcommands["mapblock_pos2"])
1✔
195
minetest.register_chatcommand("mb_load", minetest.registered_chatcommands["mapblock_load"])
1✔
196
minetest.register_chatcommand("mb_save", minetest.registered_chatcommands["mapblock_save"])
1✔
197
minetest.register_chatcommand("mb_alloc", minetest.registered_chatcommands["mapblock_allocate"])
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc