1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00
This commit is contained in:
ZavGaro 2025-06-12 21:30:20 +02:00 committed by GitHub
commit fde21e7b03
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 42 additions and 8 deletions

View file

@ -85,8 +85,13 @@ local function check_mod_configuration(world_path, all_mods)
-- Build the table of errors
local with_error = {}
for _, mod in ipairs(config_status.satisfied_mods) do
if not mod.valid then
with_error[mod.virtual_path] = { type = "error", reason = "invalid" }
end
end
for _, mod in ipairs(config_status.unsatisfied_mods) do
local error = { type = "warning" }
local error = { type = "warning", reason = "unsatisfied_depends" }
with_error[mod.virtual_path] = error
for _, depname in ipairs(mod.unsatisfied_depends) do
@ -155,6 +160,24 @@ local function get_formspec(data)
local hard_deps_str = table.concat(hard_deps, ",")
local soft_deps_str = table.concat(soft_deps, ",")
local error_message = ""
local error = with_error[mod.virtual_path]
if error and
error.type == "error" and
-- do not display "unsatisfied_depends" error as message because is
-- is displayed by dependency list
error.reason ~= "unsatisfied_depends"
then
error_message = error_message ..
minetest.colorize(mt_color_red, fgettext("Errors:")) .. "\n"
if error.reason == "invalid" then
error_message = error_message .. fgettext(
"Mod is incomplete because it has no \"init.lua\" file. " ..
"Dependencies are not visible because of this.")
end
end
retval = retval ..
"label[0,0.7;" .. fgettext("Mod:") .. "]" ..
"label[0.75,0.7;" .. mod.name .. "]"
@ -163,7 +186,8 @@ local function get_formspec(data)
if soft_deps_str == "" then
retval = retval ..
"label[0,1.25;" ..
fgettext("No (optional) dependencies") .. "]"
fgettext("No (optional) dependencies") .. "]" ..
"textarea[0.25,1.75;5.75,7.2;;" .. error_message .. ";]"
else
retval = retval ..
"label[0,1.25;" .. fgettext("No hard dependencies") ..
@ -171,7 +195,8 @@ local function get_formspec(data)
"label[0,1.75;" .. fgettext("Optional dependencies:") ..
"]" ..
"textlist[0,2.25;5,4;world_config_optdepends;" ..
soft_deps_str .. ";0]"
soft_deps_str .. ";0]" ..
"textarea[0.25,6.5;3.45,1.75;;" .. error_message .. ";]"
end
else
if soft_deps_str == "" then
@ -179,7 +204,8 @@ local function get_formspec(data)
"label[0,1.25;" .. fgettext("Dependencies:") .. "]" ..
"textlist[0,1.75;5,4;world_config_depends;" ..
hard_deps_str .. ";0]" ..
"label[0,6;" .. fgettext("No optional dependencies") .. "]"
"label[0,6;" .. fgettext("No optional dependencies") .. "]" ..
"textarea[0.25,6.5;3.45,1.75;;" .. error_message .. ";]"
else
retval = retval ..
"label[0,1.25;" .. fgettext("Dependencies:") .. "]" ..
@ -188,7 +214,8 @@ local function get_formspec(data)
"label[0,3.9;" .. fgettext("Optional dependencies:") ..
"]" ..
"textlist[0,4.375;5,1.8;world_config_optdepends;" ..
soft_deps_str .. ";0]"
soft_deps_str .. ";0]" ..
"textarea[0.25,6.5;3.45,1.75;;" .. error_message .. ";]"
end
end
end

View file

@ -34,6 +34,7 @@ struct ModSpec
std::unordered_set<std::string> optdepends;
std::unordered_set<std::string> unsatisfied_depends;
bool valid = true; /// False if incomplete
bool part_of_modpack = false;
bool is_modpack = false;

View file

@ -2599,4 +2599,7 @@ void push_mod_spec(lua_State *L, const ModSpec &spec, bool include_unsatisfied)
lua_rawseti(L, -2, i++);
}
lua_setfield(L, -2, "unsatisfied_depends");
lua_pushboolean(L, spec.valid);
lua_setfield(L, -2, "valid");
}

View file

@ -233,6 +233,11 @@ std::string ScriptApiBase::getCurrentModNameInsecure(lua_State *L)
void ScriptApiBase::loadMod(const std::string &script_path,
const std::string &mod_name)
{
if (!fs::IsFile(script_path)) {
throw ModError("Failed to load mod \"" + mod_name
+ "\" as it's initialization script at \"" + script_path
+ "\" does not exist. Try to reinstall/update mod or disable it.");
}
ModNameStorer mod_name_storer(getStack(), mod_name);
loadScript(script_path);

View file

@ -461,9 +461,7 @@ int ModApiMainMenu::l_check_mod_configuration(lua_State *L)
spec.name = fs::GetFilenameFromPath(modpath.c_str());
spec.path = modpath;
spec.virtual_path = virtual_path;
if (!parseModContents(spec)) {
throw LuaError("Not a mod!");
}
spec.valid = parseModContents(spec);
}
modmgr.addMods(modSpecs);