mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-28 17:09:41 +00:00
Lua Context: Replace exclusive bools with type enum
This commit is contained in:
parent
5d3aa62e56
commit
80ced23a69
3 changed files with 21 additions and 17 deletions
|
@ -15,8 +15,13 @@ namespace MWLua
|
|||
|
||||
struct Context
|
||||
{
|
||||
bool mIsMenu;
|
||||
bool mIsGlobal;
|
||||
enum Type
|
||||
{
|
||||
Menu,
|
||||
Global,
|
||||
Local,
|
||||
};
|
||||
Type mType;
|
||||
LuaManager* mLuaManager;
|
||||
LuaUtil::LuaState* mLua;
|
||||
LuaUtil::UserdataSerializer* mSerializer;
|
||||
|
|
|
@ -83,25 +83,24 @@ namespace MWLua
|
|||
|
||||
void LuaManager::init()
|
||||
{
|
||||
Context context;
|
||||
context.mIsMenu = false;
|
||||
context.mIsGlobal = true;
|
||||
context.mLuaManager = this;
|
||||
context.mLua = &mLua;
|
||||
context.mObjectLists = &mObjectLists;
|
||||
context.mLuaEvents = &mLuaEvents;
|
||||
context.mSerializer = mGlobalSerializer.get();
|
||||
Context globalContext;
|
||||
globalContext.mType = Context::Global;
|
||||
globalContext.mLuaManager = this;
|
||||
globalContext.mLua = &mLua;
|
||||
globalContext.mObjectLists = &mObjectLists;
|
||||
globalContext.mLuaEvents = &mLuaEvents;
|
||||
globalContext.mSerializer = mGlobalSerializer.get();
|
||||
|
||||
Context localContext = context;
|
||||
localContext.mIsGlobal = false;
|
||||
Context localContext = globalContext;
|
||||
localContext.mType = Context::Local;
|
||||
localContext.mSerializer = mLocalSerializer.get();
|
||||
|
||||
Context menuContext = context;
|
||||
menuContext.mIsMenu = true;
|
||||
Context menuContext = globalContext;
|
||||
menuContext.mType = Context::Menu;
|
||||
|
||||
for (const auto& [name, package] : initCommonPackages(context))
|
||||
for (const auto& [name, package] : initCommonPackages(globalContext))
|
||||
mLua.addCommonPackage(name, package);
|
||||
for (const auto& [name, package] : initGlobalPackages(context))
|
||||
for (const auto& [name, package] : initGlobalPackages(globalContext))
|
||||
mGlobalScripts.addPackage(name, package);
|
||||
for (const auto& [name, package] : initMenuPackages(menuContext))
|
||||
mMenuScripts.addPackage(name, package);
|
||||
|
|
|
@ -295,7 +295,7 @@ namespace MWLua
|
|||
{
|
||||
std::string_view menuCache = "openmw_ui_menu";
|
||||
std::string_view gameCache = "openmw_ui_game";
|
||||
std::string_view cacheKey = context.mIsMenu ? menuCache : gameCache;
|
||||
std::string_view cacheKey = context.mType == Context::Menu ? menuCache : gameCache;
|
||||
{
|
||||
sol::state_view& lua = context.mLua->sol();
|
||||
if (lua[cacheKey] != sol::nil)
|
||||
|
|
Loading…
Reference in a new issue