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

blockexchange / blockexchange / 13327716991

14 Feb 2025 10:53AM UTC coverage: 50.79% (+2.4%) from 48.384%
13327716991

push

github

web-flow
refactor to async/await (#74)

237 of 556 new or added lines in 15 files covered. (42.63%)

5 existing lines in 4 files now uncovered.

964 of 1898 relevant lines covered (50.79%)

1870.06 hits per line

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

12.38
/hud.lua
1
local HUD_POSITION = { x = 0.1, y = 0.8 }
1✔
2
local HUD_ALIGNMENT = { x = 1, y = 0 }
1✔
3

4
local HUD_ICON_KEY = "icon"
1✔
5
local HUD_TEXT_KEY = "text"
1✔
6

7
-- playername -> data
8
local hud = {}
1✔
9

10
local function update_player_hud(player)
11
        local playername = player:get_player_name()
×
12

13
        local hud_data = hud[playername]
×
14
        if not hud_data then
×
15
                return
×
16
        end
17

18
        local ctx = blockexchange.get_job_context(playername)
×
19
        local pos = player:get_pos()
×
20
        local area = blockexchange.get_area(pos)
×
21
        local hud_info_available = ctx or area
×
22

23
        if hud_info_available and not hud_data.active then
×
24
                -- enable
25
                hud_data.active = true
×
26
        elseif not hud_info_available and hud_data.active then
×
27
                -- disable
28
                hud_data.active = false
×
29
                player:hud_change(hud_data[HUD_ICON_KEY], "text", "")
×
30
                player:hud_change(hud_data[HUD_TEXT_KEY], "text", "")
×
31
        end
32

33
        local icon_name = ""
×
34
        local text = ""
×
35
        local color = 0x00ff00
×
36

37
        if ctx then
×
38
                if ctx.type == "emerge" then
×
39
                        icon_name = "blockexchange_emerge.png"
×
40
                        text = "Emerging, progress: " .. ctx.progress_percent .. " %"
×
41

42
                elseif ctx.type == "protectioncheck" then
×
43
                        icon_name = "blockexchange_protectioncheck.png"
×
44
                        text = "Protection-check, progress: " .. ctx.progress_percent .. " %"
×
45

46
                elseif ctx.type == "download" then
×
47
                        icon_name = "blockexchange_download.png"
×
NEW
48
                        text = "Downloading '" .. ctx.username .. "/" .. ctx.schemaname ..
×
NEW
49
                                "', progress: " .. ctx.progress_percent .. " %"
×
50

NEW
51
                elseif ctx.type == "download_local" then
×
NEW
52
                        icon_name = "blockexchange_download.png"
×
NEW
53
                        text = "Loading '" .. ctx.schemaname ..
×
UNCOV
54
                                "', progress: " .. ctx.progress_percent .. " %"
×
55

56
                elseif ctx.type == "upload" then
×
57
                        icon_name = "blockexchange_upload.png"
×
NEW
58
                        text = "Uploading '" .. ctx.username .. "/" .. ctx.schemaname ..
×
NEW
59
                                "', progress: " .. ctx.progress_percent .. " %"
×
60

NEW
61
                elseif ctx.type == "upload_local" then
×
NEW
62
                        icon_name = "blockexchange_upload.png"
×
NEW
63
                        text = "Uploading '" .. ctx.schemaname ..
×
UNCOV
64
                                "', progress: " .. ctx.progress_percent .. " %"
×
65

NEW
66
                elseif ctx.type == "upload_update" then
×
67
                        icon_name = "blockexchange_upload.png"
×
68
                        text = "Updating upload, progress: " .. ctx.progress_percent .. " %"
×
69

70
                elseif ctx.type == "cleanup" then
×
71
                        icon_name = "blockexchange_cleanup.png"
×
72
                        text = "Cleanup, progress: " .. ctx.progress_percent .. " %"
×
73

74
                end
75

76
        elseif area then
×
77
                icon_name = "blockexchange_info.png"
×
78
                text = string.format("BX-Area: '%s' Schema: %s/%s", area.id, area.username, area.name)
×
79
                if area.autosave then
×
80
                        text = text .. " [Autosave]"
×
81
                end
82
                if blockexchange.is_area_autosaving(area.id) then
×
83
                        icon_name = "blockexchange_upload.png"
×
84
                end
85
        end
86

87
        if icon_name ~= "" and text ~= "" then
×
88
                -- apply changes
89
                player:hud_change(hud_data[HUD_ICON_KEY], "text", icon_name)
×
90
                player:hud_change(hud_data[HUD_TEXT_KEY], "text", text)
×
91
                player:hud_change(hud_data[HUD_TEXT_KEY], "number", color)
×
92
        end
93

94
end
95

96

97
-- state tracking
98

99
local function create_hud(player)
100
        local meta = player:get_meta()
×
101
        if meta:get_int("bx_hud") ~= 1 then
×
102
                -- not enabled
103
                return
×
104
        end
105

106
        local playername = player:get_player_name()
×
107
        local hud_data = hud[playername]
×
108

109
        if hud_data then
×
110
                -- already enabled
111
                return
×
112
        end
113

114
        hud_data = {}
×
115
        hud[playername] = hud_data
×
116
        hud_data[HUD_ICON_KEY] = player:hud_add({
×
117
                [minetest.features.hud_def_type_field and "type" or "hud_elem_type"] = "image",
×
118
                position = HUD_POSITION,
119
                offset = {x=0, y=0},
120
                text = "",
121
                alignment = HUD_ALIGNMENT,
122
                scale = { x = 1, y = 1 },
123
        })
124

125
        hud_data[HUD_TEXT_KEY] = player:hud_add({
×
126
                [minetest.features.hud_def_type_field and "type" or "hud_elem_type"] = "text",
×
127
                position = HUD_POSITION,
128
                offset = {x=20, y=0},
129
                text = "",
130
                alignment = HUD_ALIGNMENT,
131
                scale = { x = 100, y = 100 },
132
                number = 0x00FF00
×
133
        })
134
end
135

136
local function remove_hud(player)
137
        local playername = player:get_player_name()
×
138
        local hud_data = hud[playername]
×
139
        if hud_data then
×
140
                player:hud_remove(hud_data[HUD_ICON_KEY])
×
141
                player:hud_remove(hud_data[HUD_TEXT_KEY])
×
142
                hud[playername] = nil
×
143
        end
144
end
145

146
-- update periodically
147
local function update_hud()
148
        for _, player in ipairs(minetest.get_connected_players()) do
64✔
149
                update_player_hud(player)
×
150
        end
151
        minetest.after(0.5, update_hud)
64✔
152
end
153
minetest.after(0.5, update_hud)
1✔
154

155
-- remove on leave
156
minetest.register_on_leaveplayer(remove_hud)
1✔
157
-- create on join
158
minetest.register_on_joinplayer(create_hud)
1✔
159

160
function blockexchange.set_player_hud(playername, enabled)
2✔
161
        local player = minetest.get_player_by_name(playername)
×
162
        if not player then
×
163
                return
×
164
        end
165

166
        local meta = player:get_meta()
×
167
        if enabled then
×
168
                meta:set_int("bx_hud", 1)
×
169
                create_hud(player)
×
170
                return true, "Hud enabled"
×
171
        else
172
                meta:set_int("bx_hud", 0)
×
173
                remove_hud(player)
×
174
                return true, "Hud disabled"
×
175
        end
176
end
177

178
minetest.register_chatcommand("bx_hud", {
2✔
179
        description = "Enables or disables the blockexchange hud",
180
        params = "bx_hud [on|off]",
181
        func = function(name, param)
182
                local enabled = param == "on"
×
183
                blockexchange.set_player_hud(name, enabled)
×
184

185
                return true, enabled and "Hud enabled" or "Hud disabled"
×
186
  end
187
})
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