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

blockexchange / blockexchange / 13331571900

14 Feb 2025 02:48PM UTC coverage: 52.251% (+0.4%) from 51.84%
13331571900

push

github

BuckarooBanzay
deduplicate schemapart code

12 of 13 new or added lines in 5 files covered. (92.31%)

48 existing lines in 8 files now uncovered.

975 of 1866 relevant lines covered (52.25%)

1898.59 hits per line

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

6.76
/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",
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

21
                        local progress_percent = math.floor(progress * 100 * 10) / 10
×
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
NEW
28
                        local schemapart = blockexchange.create_schemapart(data, relative_pos, schema_uid)
×
29

30
                        -- upload part online
31
                        local _, err = await(blockexchange.api.create_schemapart(token, schemapart))
×
32
                        if err then
×
33
                                error("create error at " .. minetest.pos_to_string(relative_pos) .. ": " .. err, 0)
×
34
                        end
35

36
                        -- create an array with mod names
37
                        local mod_names_list = {}
×
38
                        for k in pairs(mod_names) do
×
39
                                table.insert(mod_names_list, k)
×
40
                        end
41

42
                        _, err = await(blockexchange.api.create_schemamods(token, schema_uid, mod_names_list))
×
43
                        if err then
×
44
                                error("error creating mod-list: " .. err, 0)
×
45
                        end
46
                end
47

48
                if ctx.cancel then
×
49
                        error("canceled", 0)
×
50
                end
51

52
                await(Promise.after(blockexchange.min_delay))
×
53
        end)
54

55
        blockexchange.set_job_context(playername, ctx, promise)
×
56
        return promise
×
57
end
58

59
-- update a region of a schema
60
function blockexchange.save_update_area(playername, pos1, pos2, save_pos1, save_pos2, username, schema_uid)
2✔
61
        -- clip to schema area
62
        save_pos1, save_pos2 = blockexchange.clip_area(pos1, pos2, save_pos1, save_pos2)
×
63

64
        -- get offset within schema area
65
        local offset_pos1 = blockexchange.get_schemapart_offset(pos1, save_pos1)
×
66
        local _, offset_pos2 = blockexchange.get_schemapart_offset(pos1, save_pos2)
×
67

68
        -- get absolute coords
69
        local abs_pos1 = vector.add(pos1, offset_pos1)
×
70
        local abs_pos2 = vector.add(pos1, offset_pos2)
×
71

72
        abs_pos1, abs_pos2 = blockexchange.clip_area(pos1, pos2, abs_pos1, abs_pos2)
×
73
        abs_pos1, abs_pos2 = blockexchange.sort_pos(abs_pos1, abs_pos2)
×
74

75
        return blockexchange.save_update(playername, pos1, abs_pos1, abs_pos2, username, schema_uid)
×
76
end
77

78
-- update a region on a single position
79
function blockexchange.save_update_pos(playername, pos1, pos2, pos, username, schema_uid)
2✔
80
        local offset_pos1, offset_pos2 = blockexchange.get_schemapart_offset(pos1, pos)
×
81
        local abs_pos1 = vector.add(pos1, offset_pos1)
×
82
        local abs_pos2 = vector.add(pos1, offset_pos2)
×
83

84
        abs_pos1, abs_pos2 = blockexchange.clip_area(pos1, pos2, abs_pos1, abs_pos2)
×
85
        return blockexchange.save_update(playername, pos1, abs_pos1, abs_pos2, username, schema_uid)
×
86
end
87

88
Promise.register_chatcommand("bx_save_update", {
2✔
89
    params = "[area_id?]",
90
    description = "uploads selected changes or the whole area",
91
    func = function(name, area_id)
UNCOV
92
        local area, err_msg = blockexchange.select_player_area(name, area_id)
×
93
        if err_msg then
×
UNCOV
94
            return true, err_msg
×
95
        end
96

97
        local claims = blockexchange.get_claims(name)
×
UNCOV
98
        if not claims then
×
UNCOV
99
            return true, "Not logged in"
×
100
        end
101

102
        if claims.username ~= area.username then
×
UNCOV
103
            return true, "You are not authorized to update that schema"
×
104
        end
105

106
        local pos1 = blockexchange.get_pos(1, name)
×
UNCOV
107
        local pos2 = blockexchange.get_pos(2, name)
×
108

109
        if not pos1 or not pos2 then
×
110
            -- upload everything
UNCOV
111
            pos1 = area.pos1
×
112
            pos2 = area.pos2
×
113
        end
114

115
        -- partial update with the marked area
UNCOV
116
        pos1, pos2 = blockexchange.sort_pos(pos1, pos2)
×
117

UNCOV
118
                return Promise.async(function(await)
×
119
                        local _, err = await(
×
UNCOV
120
                                blockexchange.save_update_area(name, area.pos1, area.pos2, pos1, pos2, claims.username, area.schema_uid)
×
121
                        )
122
                        if err then
×
123
                                error("save error: " .. err, 0)
×
124
                        end
125

126
                        local schema
UNCOV
127
                        schema, err = await(blockexchange.api.get_schema_by_uid(area.schema_uid))
×
UNCOV
128
                        if err then
×
UNCOV
129
                                error("fetch new schema error: " .. err, 0)
×
130
                        elseif not schema then
×
131
                                error("schema not found: " .. area.schema_uid, 0)
×
132
                        end
133

134
                        -- update mtime
UNCOV
135
                        area.mtime = schema.mtime
×
UNCOV
136
            blockexchange.save_areas()
×
137
                end)
138
    end
139
})
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