1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-19 19:53:53 +00:00

Allow menu scripts to send global events while a game is loaded

This commit is contained in:
uramer 2024-02-03 12:02:44 +01:00
parent 1338e884a9
commit 8c6a1ae8c0

View file

@ -1,6 +1,7 @@
#include "corebindings.hpp"
#include <chrono>
#include <stdexcept>
#include <components/debug/debuglog.hpp>
#include <components/esm3/loadfact.hpp>
@ -133,7 +134,14 @@ namespace MWLua
sol::table api(context.mLua->sol(), sol::create);
for (auto& [k, v] : LuaUtil::getMutableFromReadOnly(initCorePackage(context)))
api[k] = v;
api["sendGlobalEvent"] = sol::nil;
api["sendGlobalEvent"] = [context](std::string eventName, const sol::object& eventData) {
if (MWBase::Environment::get().getStateManager()->getState() == MWBase::StateManager::State_NoGame)
{
throw std::logic_error("Can't send global events when no game is loaded");
}
context.mLuaEvents->addGlobalEvent(
{ std::move(eventName), LuaUtil::serialize(eventData, context.mSerializer) });
};
api["sound"] = sol::nil;
api["vfx"] = sol::nil;
return LuaUtil::makeReadOnly(api);