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

blockexchange / blockexchange / 13331372500

14 Feb 2025 02:36PM UTC coverage: 51.84% (+1.1%) from 50.789%
13331372500

push

github

BuckarooBanzay
move hud code to commands

40 of 68 new or added lines in 9 files covered. (58.82%)

1 existing line in 1 file now uncovered.

972 of 1875 relevant lines covered (51.84%)

1890.14 hits per line

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

6.58
/commands/save_update.lua
1
-- update a region
2
function blockexchange.save_update(playername, origin, pos1, pos2, _, schema_uid)
2✔
3
        pos1, pos2 = blockexchange.sort_pos(pos1, pos2)
×
4

5
        local token = blockexchange.get_token(playername)
×
6

7
        local ctx = {
×
8
                hud_icon = "blockexchange_upload.png",
NEW
9
                hud_text = "Saving changes"
×
10
        }
11

12
        local mod_names = {}
×
13

14
        local promise = Promise.async(function(await)
×
15
                for current_pos, relative_pos, progress in blockexchange.iterator(origin, pos1, pos2) do
×
16
                        local current_pos2 = vector.add(current_pos, 15)
×
17
                        current_pos2.x = math.min(current_pos2.x, pos2.x)
×
18
                        current_pos2.y = math.min(current_pos2.y, pos2.y)
×
19
                        current_pos2.z = math.min(current_pos2.z, pos2.z)
×
20

NEW
21
                        local progress_percent = math.floor(progress * 100 * 10) / 10
×
NEW
22
                        ctx.hud_text = "Saving changes, progress: " .. progress_percent .. " %"
×
23

24
                        local data, node_count = blockexchange.serialize_part(current_pos, current_pos2)
×
25
                        blockexchange.collect_node_count(node_count, mod_names)
×
26

27
                        -- package data properly over the wire
28
                        local schemapart = {
×
29
                                schema_uid = schema_uid,
30
                                offset_x = relative_pos.x,
31
                                offset_y = relative_pos.y,
32
                                offset_z = relative_pos.z,
33
                                data = minetest.encode_base64(blockexchange.compress_data(data)),
34
                                metadata = minetest.encode_base64(blockexchange.compress_metadata(data))
×
35
                        }
36

37
                        -- upload part online
38
                        local _, err = await(blockexchange.api.create_schemapart(token, schemapart))
×
39
                        if err then
×
40
                                error("create error at " .. minetest.pos_to_string(relative_pos) .. ": " .. err, 0)
×
41
                        end
42

43
                        -- create an array with mod names
44
                        local mod_names_list = {}
×
45
                        for k in pairs(mod_names) do
×
46
                                table.insert(mod_names_list, k)
×
47
                        end
48

49
                        _, err = await(blockexchange.api.create_schemamods(token, schema_uid, mod_names_list))
×
50
                        if err then
×
51
                                error("error creating mod-list: " .. err, 0)
×
52
                        end
53
                end
54

55
                if ctx.cancel then
×
56
                        error("canceled", 0)
×
57
                end
58

59
                await(Promise.after(blockexchange.min_delay))
×
60
        end)
61

62
        blockexchange.set_job_context(playername, ctx, promise)
×
63
        return promise
×
64
end
65

66
-- update a region of a schema
67
function blockexchange.save_update_area(playername, pos1, pos2, save_pos1, save_pos2, username, schema_uid)
2✔
68
        -- clip to schema area
69
        save_pos1, save_pos2 = blockexchange.clip_area(pos1, pos2, save_pos1, save_pos2)
×
70

71
        -- get offset within schema area
72
        local offset_pos1 = blockexchange.get_schemapart_offset(pos1, save_pos1)
×
73
        local _, offset_pos2 = blockexchange.get_schemapart_offset(pos1, save_pos2)
×
74

75
        -- get absolute coords
76
        local abs_pos1 = vector.add(pos1, offset_pos1)
×
77
        local abs_pos2 = vector.add(pos1, offset_pos2)
×
78

79
        abs_pos1, abs_pos2 = blockexchange.clip_area(pos1, pos2, abs_pos1, abs_pos2)
×
80
        abs_pos1, abs_pos2 = blockexchange.sort_pos(abs_pos1, abs_pos2)
×
81

82
        return blockexchange.save_update(playername, pos1, abs_pos1, abs_pos2, username, schema_uid)
×
83
end
84

85
-- update a region on a single position
86
function blockexchange.save_update_pos(playername, pos1, pos2, pos, username, schema_uid)
2✔
87
        local offset_pos1, offset_pos2 = blockexchange.get_schemapart_offset(pos1, pos)
×
88
        local abs_pos1 = vector.add(pos1, offset_pos1)
×
89
        local abs_pos2 = vector.add(pos1, offset_pos2)
×
90

91
        abs_pos1, abs_pos2 = blockexchange.clip_area(pos1, pos2, abs_pos1, abs_pos2)
×
92
        return blockexchange.save_update(playername, pos1, abs_pos1, abs_pos2, username, schema_uid)
×
93
end
94

95
Promise.register_chatcommand("bx_save_update", {
2✔
96
    params = "[area_id?]",
97
    description = "uploads selected changes or the whole area",
98
    func = function(name, area_id)
99
        -- force-enable the hud
100
        blockexchange.set_player_hud(name, true)
×
101

102
        local area, err_msg = blockexchange.select_player_area(name, area_id)
×
103
        if err_msg then
×
104
            return true, err_msg
×
105
        end
106

107
        local claims = blockexchange.get_claims(name)
×
108
        if not claims then
×
109
            return true, "Not logged in"
×
110
        end
111

112
        if claims.username ~= area.username then
×
113
            return true, "You are not authorized to update that schema"
×
114
        end
115

116
        local pos1 = blockexchange.get_pos(1, name)
×
117
        local pos2 = blockexchange.get_pos(2, name)
×
118

119
        if not pos1 or not pos2 then
×
120
            -- upload everything
121
            pos1 = area.pos1
×
122
            pos2 = area.pos2
×
123
        end
124

125
        -- partial update with the marked area
126
        pos1, pos2 = blockexchange.sort_pos(pos1, pos2)
×
127

128
                return Promise.async(function(await)
×
129
                        local _, err = await(
×
130
                                blockexchange.save_update_area(name, area.pos1, area.pos2, pos1, pos2, claims.username, area.schema_uid)
×
131
                        )
132
                        if err then
×
133
                                error("save error: " .. err, 0)
×
134
                        end
135

136
                        local schema
137
                        schema, err = await(blockexchange.api.get_schema_by_uid(area.schema_uid))
×
138
                        if err then
×
139
                                error("fetch new schema error: " .. err, 0)
×
140
                        elseif not schema then
×
141
                                error("schema not found: " .. area.schema_uid, 0)
×
142
                        end
143

144
                        -- update mtime
145
                        area.mtime = schema.mtime
×
146
            blockexchange.save_areas()
×
147
                end)
148
    end
149
})
1✔
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

© 2026 Coveralls, Inc