mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-01 01:45:36 +00:00
Allow menu scripts to send global events while a game is loaded
This commit is contained in:
parent
1338e884a9
commit
8c6a1ae8c0
1 changed files with 9 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
#include "corebindings.hpp"
|
#include "corebindings.hpp"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <components/debug/debuglog.hpp>
|
#include <components/debug/debuglog.hpp>
|
||||||
#include <components/esm3/loadfact.hpp>
|
#include <components/esm3/loadfact.hpp>
|
||||||
|
@ -133,7 +134,14 @@ namespace MWLua
|
||||||
sol::table api(context.mLua->sol(), sol::create);
|
sol::table api(context.mLua->sol(), sol::create);
|
||||||
for (auto& [k, v] : LuaUtil::getMutableFromReadOnly(initCorePackage(context)))
|
for (auto& [k, v] : LuaUtil::getMutableFromReadOnly(initCorePackage(context)))
|
||||||
api[k] = v;
|
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["sound"] = sol::nil;
|
||||||
api["vfx"] = sol::nil;
|
api["vfx"] = sol::nil;
|
||||||
return LuaUtil::makeReadOnly(api);
|
return LuaUtil::makeReadOnly(api);
|
||||||
|
|
Loading…
Reference in a new issue