|
|
|
@ -11,6 +11,7 @@ |
|
|
|
#include "appfat.h" |
|
|
|
#include "appfat.h" |
|
|
|
#include "engine/assets.hpp" |
|
|
|
#include "engine/assets.hpp" |
|
|
|
#include "lua/modules/audio.hpp" |
|
|
|
#include "lua/modules/audio.hpp" |
|
|
|
|
|
|
|
#include "lua/modules/hellfire.hpp" |
|
|
|
#include "lua/modules/i18n.hpp" |
|
|
|
#include "lua/modules/i18n.hpp" |
|
|
|
#include "lua/modules/items.hpp" |
|
|
|
#include "lua/modules/items.hpp" |
|
|
|
#include "lua/modules/log.hpp" |
|
|
|
#include "lua/modules/log.hpp" |
|
|
|
@ -42,6 +43,8 @@ struct LuaState { |
|
|
|
|
|
|
|
|
|
|
|
std::optional<LuaState> CurrentLuaState; |
|
|
|
std::optional<LuaState> CurrentLuaState; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<tl::function_ref<void()>> IsModChangeHandlers; |
|
|
|
|
|
|
|
|
|
|
|
// A Lua function that we use to generate a `require` implementation.
|
|
|
|
// A Lua function that we use to generate a `require` implementation.
|
|
|
|
constexpr std::string_view RequireGenSrc = R"lua( |
|
|
|
constexpr std::string_view RequireGenSrc = R"lua( |
|
|
|
function requireGen(env, loaded, loadFn) |
|
|
|
function requireGen(env, loaded, loadFn) |
|
|
|
@ -198,17 +201,32 @@ sol::environment CreateLuaSandbox() |
|
|
|
return sandbox; |
|
|
|
return sandbox; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AddModsChangedHandler(tl::function_ref<void()> callback) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
IsModChangeHandlers.push_back(callback); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void LuaReloadActiveMods() |
|
|
|
void LuaReloadActiveMods() |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Loaded without a sandbox.
|
|
|
|
// Loaded without a sandbox.
|
|
|
|
CurrentLuaState->events = RunScript(/*env=*/std::nullopt, "devilutionx.events", /*optional=*/false); |
|
|
|
CurrentLuaState->events = RunScript(/*env=*/std::nullopt, "devilutionx.events", /*optional=*/false); |
|
|
|
CurrentLuaState->commonPackages["devilutionx.events"] = CurrentLuaState->events; |
|
|
|
CurrentLuaState->commonPackages["devilutionx.events"] = CurrentLuaState->events; |
|
|
|
|
|
|
|
|
|
|
|
for (std::string_view modname : GetOptions().Mods.GetActiveModList()) { |
|
|
|
gbIsHellfire = false; |
|
|
|
|
|
|
|
UnloadModArchives(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string_view> modnames = GetOptions().Mods.GetActiveModList(); |
|
|
|
|
|
|
|
LoadModArchives(modnames); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (std::string_view modname : modnames) { |
|
|
|
std::string packageName = StrCat("mods.", modname, ".init"); |
|
|
|
std::string packageName = StrCat("mods.", modname, ".init"); |
|
|
|
RunScript(CreateLuaSandbox(), packageName, /*optional=*/true); |
|
|
|
RunScript(CreateLuaSandbox(), packageName, /*optional=*/true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (tl::function_ref<void()> handler : IsModChangeHandlers) { |
|
|
|
|
|
|
|
handler(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
LuaEvent("LoadModsComplete"); |
|
|
|
LuaEvent("LoadModsComplete"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -243,6 +261,7 @@ void LuaInitialize() |
|
|
|
"devilutionx.player", LuaPlayerModule(lua), |
|
|
|
"devilutionx.player", LuaPlayerModule(lua), |
|
|
|
"devilutionx.render", LuaRenderModule(lua), |
|
|
|
"devilutionx.render", LuaRenderModule(lua), |
|
|
|
"devilutionx.towners", LuaTownersModule(lua), |
|
|
|
"devilutionx.towners", LuaTownersModule(lua), |
|
|
|
|
|
|
|
"devilutionx.hellfire", LuaHellfireModule(lua), |
|
|
|
"devilutionx.message", [](std::string_view text) { EventPlrMsg(text, UiFlags::ColorRed); }, |
|
|
|
"devilutionx.message", [](std::string_view text) { EventPlrMsg(text, UiFlags::ColorRed); }, |
|
|
|
// This package is loaded without a sandbox:
|
|
|
|
// This package is loaded without a sandbox:
|
|
|
|
"inspect", RunScript(/*env=*/std::nullopt, "inspect", /*optional=*/false)); |
|
|
|
"inspect", RunScript(/*env=*/std::nullopt, "inspect", /*optional=*/false)); |
|
|
|
|