mirror of
https://github.com/luanti-org/luanti.git
synced 2025-11-08 11:05:28 +01:00
Allow image formats other than PNG for game backgrounds in the main menu (#16395)
This commit is contained in:
@@ -23,7 +23,7 @@ read_globals = {
|
|||||||
"tracy",
|
"tracy",
|
||||||
|
|
||||||
string = {fields = {"split", "trim"}},
|
string = {fields = {"split", "trim"}},
|
||||||
table = {fields = {"copy", "copy_with_metatables", "getn", "indexof", "keyof", "insert_all"}},
|
table = {fields = {"copy", "copy_with_metatables", "getn", "indexof", "keyof", "insert_all", "shuffle"}},
|
||||||
math = {fields = {"hypot", "round"}},
|
math = {fields = {"hypot", "round"}},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -119,6 +119,9 @@ end
|
|||||||
-- }]]
|
-- }]]
|
||||||
function dump(value, indent)
|
function dump(value, indent)
|
||||||
indent = indent or "\t"
|
indent = indent or "\t"
|
||||||
|
|
||||||
|
assert(type(indent) == "string", "dump()'s second argument should be a string or nil.")
|
||||||
|
|
||||||
local newline = indent == "" and "" or "\n"
|
local newline = indent == "" and "" or "\n"
|
||||||
|
|
||||||
local rope = {}
|
local rope = {}
|
||||||
@@ -873,3 +876,4 @@ function core.parse_coordinates(x, y, z, relative_to)
|
|||||||
local rz = core.parse_relative_number(z, relative_to.z)
|
local rz = core.parse_relative_number(z, relative_to.z)
|
||||||
return rx and ry and rz and vector.new(rx, ry, rz)
|
return rx and ry and rz and vector.new(rx, ry, rz)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ end
|
|||||||
-- Chat command handler
|
-- Chat command handler
|
||||||
--
|
--
|
||||||
|
|
||||||
core.chatcommands = core.registered_chatcommands -- BACKWARDS COMPATIBILITY
|
core.chatcommands = core.registered_chatcommands -- backwards compatibility
|
||||||
|
|
||||||
local msg_time_threshold =
|
local msg_time_threshold =
|
||||||
tonumber(core.settings:get("chatcommand_msg_time_threshold")) or 0.1
|
tonumber(core.settings:get("chatcommand_msg_time_threshold")) or 0.1
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
-- Copyright (C) 2013 sapier
|
-- Copyright (C) 2013 sapier
|
||||||
-- SPDX-License-Identifier: LGPL-2.1-or-later
|
-- SPDX-License-Identifier: LGPL-2.1-or-later
|
||||||
|
|
||||||
|
|
||||||
mm_game_theme = {}
|
mm_game_theme = {}
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
@@ -21,7 +20,7 @@ function mm_game_theme.set_engine(hide_decorations)
|
|||||||
|
|
||||||
core.set_topleft_text("")
|
core.set_topleft_text("")
|
||||||
|
|
||||||
local have_bg = false
|
local have_bg = false
|
||||||
local have_overlay = mm_game_theme.set_engine_single("overlay")
|
local have_overlay = mm_game_theme.set_engine_single("overlay")
|
||||||
|
|
||||||
if not have_overlay then
|
if not have_overlay then
|
||||||
@@ -58,7 +57,7 @@ function mm_game_theme.set_game(gamedetails)
|
|||||||
|
|
||||||
core.set_topleft_text(gamedetails.name)
|
core.set_topleft_text(gamedetails.name)
|
||||||
|
|
||||||
local have_bg = false
|
local have_bg = false
|
||||||
local have_overlay = mm_game_theme.set_game_single("overlay", gamedetails)
|
local have_overlay = mm_game_theme.set_game_single("overlay", gamedetails)
|
||||||
|
|
||||||
if not have_overlay then
|
if not have_overlay then
|
||||||
@@ -83,17 +82,25 @@ end
|
|||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function mm_game_theme.clear_single(identifier)
|
function mm_game_theme.clear_single(identifier)
|
||||||
core.set_background(identifier,"")
|
core.set_background(identifier, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
local valid_image_extensions = {
|
||||||
|
".png",
|
||||||
|
".jpg",
|
||||||
|
".jpeg",
|
||||||
|
}
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function mm_game_theme.set_engine_single(identifier)
|
function mm_game_theme.set_engine_single(identifier)
|
||||||
--try texture pack first
|
--try texture pack first
|
||||||
if mm_game_theme.texturepack ~= nil then
|
if mm_game_theme.texturepack ~= nil then
|
||||||
local path = mm_game_theme.texturepack .. DIR_DELIM .."menu_" ..
|
for _, extension in pairs(valid_image_extensions) do
|
||||||
identifier .. ".png"
|
local path = mm_game_theme.texturepack .. DIR_DELIM .. "menu_" .. identifier .. extension
|
||||||
if core.set_background(identifier,path) then
|
if core.set_background(identifier, path) then
|
||||||
return true
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -106,49 +113,53 @@ function mm_game_theme.set_engine_single(identifier)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function mm_game_theme.set_game_single(identifier, gamedetails)
|
|
||||||
assert(gamedetails ~= nil)
|
|
||||||
|
|
||||||
if mm_game_theme.texturepack ~= nil then
|
|
||||||
local path = mm_game_theme.texturepack .. DIR_DELIM ..
|
function mm_game_theme.set_game_single(identifier, gamedetails)
|
||||||
gamedetails.id .. "_menu_" .. identifier .. ".png"
|
local extensions_randomised = table.copy(valid_image_extensions)
|
||||||
|
table.shuffle(extensions_randomised)
|
||||||
|
for _, extension in pairs(extensions_randomised) do
|
||||||
|
assert(gamedetails ~= nil)
|
||||||
|
|
||||||
|
if mm_game_theme.texturepack ~= nil then
|
||||||
|
local path = mm_game_theme.texturepack .. DIR_DELIM .. gamedetails.id .. "_menu_" .. identifier .. extension
|
||||||
|
if core.set_background(identifier, path) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Find out how many randomized textures the game provides
|
||||||
|
local n = 0
|
||||||
|
local filename
|
||||||
|
local menu_files = core.get_dir_list(gamedetails.path .. DIR_DELIM .. "menu", false)
|
||||||
|
for i = 1, #menu_files do
|
||||||
|
filename = identifier .. "." .. i .. extension
|
||||||
|
if table.indexof(menu_files, filename) == -1 then
|
||||||
|
n = i - 1
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Select random texture, 0 means standard texture
|
||||||
|
n = math.random(0, n)
|
||||||
|
if n == 0 then
|
||||||
|
filename = identifier .. extension
|
||||||
|
else
|
||||||
|
filename = identifier .. "." .. n .. extension
|
||||||
|
end
|
||||||
|
|
||||||
|
local path = gamedetails.path .. DIR_DELIM .. "menu" .. DIR_DELIM .. filename
|
||||||
if core.set_background(identifier, path) then
|
if core.set_background(identifier, path) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
-- Find out how many randomized textures the game provides
|
|
||||||
local n = 0
|
|
||||||
local filename
|
|
||||||
local menu_files = core.get_dir_list(gamedetails.path .. DIR_DELIM .. "menu", false)
|
|
||||||
for i = 1, #menu_files do
|
|
||||||
filename = identifier .. "." .. i .. ".png"
|
|
||||||
if table.indexof(menu_files, filename) == -1 then
|
|
||||||
n = i - 1
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
-- Select random texture, 0 means standard texture
|
|
||||||
n = math.random(0, n)
|
|
||||||
if n == 0 then
|
|
||||||
filename = identifier .. ".png"
|
|
||||||
else
|
|
||||||
filename = identifier .. "." .. n .. ".png"
|
|
||||||
end
|
|
||||||
|
|
||||||
local path = gamedetails.path .. DIR_DELIM .. "menu" ..
|
|
||||||
DIR_DELIM .. filename
|
|
||||||
if core.set_background(identifier, path) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function mm_game_theme.set_dirt_bg()
|
function mm_game_theme.set_dirt_bg()
|
||||||
if mm_game_theme.texturepack ~= nil then
|
if mm_game_theme.texturepack ~= nil then
|
||||||
local path = mm_game_theme.texturepack .. DIR_DELIM .."default_dirt.png"
|
local path = mm_game_theme.texturepack .. DIR_DELIM .. "default_dirt.png"
|
||||||
if core.set_background("background", path, true, 128) then
|
if core.set_background("background", path, true, 128) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user