Skip to content

Commit 50a7fac

Browse files
author
Swagtoy
committed
Merge branch 'master' of https://github.com/minetest/minetest into scrollbar-improvements
2 parents 7df76e5 + 13f533d commit 50a7fac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1183
-643
lines changed

.github/workflows/macos.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ on:
2929

3030
jobs:
3131
build:
32-
# use lowest possible macOS running on x86_64 to support more users
33-
runs-on: macos-12
32+
# use lowest possible macOS running on x86_64 supported by brew to support more users
33+
runs-on: macos-13
3434
steps:
3535
- uses: actions/checkout@v4
3636
- name: Install deps

LICENSE.txt

-3
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,10 @@ srifqi:
5757
textures/base/pack/minimap_btn.png
5858

5959
Zughy:
60-
textures/base/pack/cdb_add.png
6160
textures/base/pack/cdb_downloading.png
6261
textures/base/pack/cdb_queued.png
6362
textures/base/pack/cdb_update.png
6463
textures/base/pack/cdb_update_cropped.png
65-
textures/base/pack/cdb_viewonline.png
6664
textures/base/pack/settings_btn.png
6765
textures/base/pack/settings_info.png
6866
textures/base/pack/settings_reset.png
@@ -79,7 +77,6 @@ kilbith:
7977
textures/base/pack/progress_bar_bg.png
8078

8179
SmallJoker:
82-
textures/base/pack/cdb_clear.png
8380
textures/base/pack/server_favorite_delete.png (based on server_favorite.png)
8481

8582
DS:

builtin/common/item_s.lua

+9-10
Original file line numberDiff line numberDiff line change
@@ -166,20 +166,19 @@ function core.is_colored_paramtype(ptype)
166166
end
167167

168168
function core.strip_param2_color(param2, paramtype2)
169-
if not core.is_colored_paramtype(paramtype2) then
170-
return nil
171-
end
172-
if paramtype2 == "colorfacedir" then
173-
param2 = math.floor(param2 / 32) * 32
169+
if paramtype2 == "color" then
170+
return param2
171+
elseif paramtype2 == "colorfacedir" then
172+
return math.floor(param2 / 32) * 32
174173
elseif paramtype2 == "color4dir" then
175-
param2 = math.floor(param2 / 4) * 4
174+
return math.floor(param2 / 4) * 4
176175
elseif paramtype2 == "colorwallmounted" then
177-
param2 = math.floor(param2 / 8) * 8
176+
return math.floor(param2 / 8) * 8
178177
elseif paramtype2 == "colordegrotate" then
179-
param2 = math.floor(param2 / 32) * 32
178+
return math.floor(param2 / 32) * 32
179+
else
180+
return nil
180181
end
181-
-- paramtype2 == "color" requires no modification.
182-
return param2
183182
end
184183

185184
-- Content ID caching

builtin/common/misc_helpers.lua

+10
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,16 @@ function core.formspec_escape(text)
235235
end
236236

237237

238+
local hypertext_escapes = {
239+
["\\"] = "\\\\",
240+
["<"] = "\\<",
241+
[">"] = "\\>",
242+
}
243+
function core.hypertext_escape(text)
244+
return text and text:gsub("[\\<>]", hypertext_escapes)
245+
end
246+
247+
238248
function core.wrap_text(text, max_length, as_table)
239249
local result = {}
240250
local line = {}

builtin/mainmenu/content/contentdb.lua

+94-10
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,23 @@ function contentdb.get_package_by_id(id)
182182
end
183183

184184

185+
function contentdb.calculate_package_id(type, author, name)
186+
local id = author:lower() .. "/"
187+
if (type == nil or type == "game") and #name > 5 and name:sub(#name - 4) == "_game" then
188+
id = id .. name:sub(1, #name - 5)
189+
else
190+
id = id .. name
191+
end
192+
return id
193+
end
194+
195+
196+
function contentdb.get_package_by_info(author, name)
197+
local id = contentdb.calculate_package_id(nil, author, name)
198+
return contentdb.package_by_id[id]
199+
end
200+
201+
185202
-- Create a coroutine from `fn` and provide results to `callback` when complete (dead).
186203
-- Returns a resumer function.
187204
local function make_callback_coroutine(fn, callback)
@@ -415,15 +432,7 @@ local function fetch_pkgs(params)
415432
local aliases = {}
416433

417434
for _, package in pairs(packages) do
418-
local name_len = #package.name
419-
-- This must match what contentdb.update_paths() does!
420-
package.id = package.author:lower() .. "/"
421-
if package.type == "game" and name_len > 5 and package.name:sub(name_len - 4) == "_game" then
422-
package.id = package.id .. package.name:sub(1, name_len - 5)
423-
else
424-
package.id = package.id .. package.name
425-
end
426-
435+
package.id = params.calculate_package_id(package.type, package.author, package.name)
427436
package.url_part = core.urlencode(package.author) .. "/" .. core.urlencode(package.name)
428437

429438
if package.aliases then
@@ -443,7 +452,7 @@ end
443452

444453
function contentdb.fetch_pkgs(callback)
445454
contentdb.loading = true
446-
core.handle_async(fetch_pkgs, nil, function(result)
455+
core.handle_async(fetch_pkgs, { calculate_package_id = contentdb.calculate_package_id }, function(result)
447456
if result then
448457
contentdb.load_ok = true
449458
contentdb.load_error = false
@@ -581,3 +590,78 @@ function contentdb.filter_packages(query, by_type)
581590
end
582591
end
583592
end
593+
594+
595+
function contentdb.get_full_package_info(package, callback)
596+
assert(package)
597+
if package.full_info then
598+
callback(package.full_info)
599+
return
600+
end
601+
602+
local function fetch(params)
603+
local version = core.get_version()
604+
local base_url = core.settings:get("contentdb_url")
605+
606+
local languages
607+
local current_language = core.get_language()
608+
if current_language ~= "" then
609+
languages = { current_language, "en;q=0.8" }
610+
else
611+
languages = { "en" }
612+
end
613+
614+
local url = base_url ..
615+
"/api/packages/" .. params.package.url_part .. "/for-client/?" ..
616+
"protocol_version=" .. core.urlencode(core.get_max_supp_proto()) ..
617+
"&engine_version=" .. core.urlencode(version.string) ..
618+
"&formspec_version=" .. core.urlencode(core.get_formspec_version()) ..
619+
"&include_images=false"
620+
local http = core.get_http_api()
621+
local response = http.fetch_sync({
622+
url = url,
623+
extra_headers = {
624+
"Accept-Language: " .. table.concat(languages, ", ")
625+
},
626+
})
627+
if not response.succeeded then
628+
return nil
629+
end
630+
631+
return core.parse_json(response.data)
632+
end
633+
634+
local function my_callback(value)
635+
package.full_info = value
636+
callback(value)
637+
end
638+
639+
if not core.handle_async(fetch, { package = package }, my_callback) then
640+
core.log("error", "ERROR: async event failed")
641+
callback(nil)
642+
end
643+
end
644+
645+
646+
function contentdb.get_formspec_padding()
647+
-- Padding is increased on Android to account for notches
648+
-- TODO: use Android API to determine size of cut outs
649+
return { x = PLATFORM == "Android" and 1 or 0.5, y = PLATFORM == "Android" and 0.25 or 0.5 }
650+
end
651+
652+
653+
function contentdb.get_formspec_size()
654+
local window = core.get_window_info()
655+
local size = { x = window.max_formspec_size.x, y = window.max_formspec_size.y }
656+
657+
-- Minimum formspec size
658+
local min_x = 15.5
659+
local min_y = 10
660+
if size.x < min_x or size.y < min_y then
661+
local scale = math.max(min_x / size.x, min_y / size.y)
662+
size.x = size.x * scale
663+
size.y = size.y * scale
664+
end
665+
666+
return size
667+
end

0 commit comments

Comments
 (0)