mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-08 03:28:03 +03:00
Make SetLevelFunc and GetLevelFunc only store the function in m_levelFuncs.
Store the function in m_levelFuncs instead of the table itself.
This commit is contained in:
parent
b5d8fe06ad
commit
70cc036605
2 changed files with 16 additions and 15 deletions
|
@ -420,7 +420,10 @@ void GameScript::ResetLevelTables()
|
||||||
|
|
||||||
sol::protected_function GameScript::GetLevelFunc(sol::table tab, std::string const& luaName)
|
sol::protected_function GameScript::GetLevelFunc(sol::table tab, std::string const& luaName)
|
||||||
{
|
{
|
||||||
return tab.raw_get<sol::protected_function>(luaName);
|
if (m_levelFuncs.find(luaName) == m_levelFuncs.end())
|
||||||
|
return sol::lua_nil;
|
||||||
|
|
||||||
|
return m_levelFuncs.at(luaName);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameScript::SetLevelFunc(sol::table tab, std::string const& luaName, sol::object value)
|
bool GameScript::SetLevelFunc(sol::table tab, std::string const& luaName, sol::object value)
|
||||||
|
@ -429,11 +432,9 @@ bool GameScript::SetLevelFunc(sol::table tab, std::string const& luaName, sol::o
|
||||||
{
|
{
|
||||||
case sol::type::lua_nil:
|
case sol::type::lua_nil:
|
||||||
m_levelFuncs.erase(luaName);
|
m_levelFuncs.erase(luaName);
|
||||||
tab.raw_set(luaName, value);
|
|
||||||
break;
|
break;
|
||||||
case sol::type::function:
|
case sol::type::function:
|
||||||
m_levelFuncs.insert(luaName);
|
m_levelFuncs.insert_or_assign(luaName, value.as<sol::protected_function>());
|
||||||
tab.raw_set(luaName, value);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
std::string error{ "Could not assign LevelFuncs." };
|
std::string error{ "Could not assign LevelFuncs." };
|
||||||
|
|
|
@ -65,7 +65,7 @@ private:
|
||||||
DisplayStringMap m_userDisplayStrings{};
|
DisplayStringMap m_userDisplayStrings{};
|
||||||
std::unordered_map<std::string, VarMapVal> m_nameMap{};
|
std::unordered_map<std::string, VarMapVal> m_nameMap{};
|
||||||
std::unordered_map<std::string, short> m_itemsMapName{};
|
std::unordered_map<std::string, short> m_itemsMapName{};
|
||||||
std::unordered_set<std::string> m_levelFuncs{};
|
std::unordered_map<std::string, sol::protected_function> m_levelFuncs{};
|
||||||
sol::protected_function m_onStart{};
|
sol::protected_function m_onStart{};
|
||||||
sol::protected_function m_onLoad{};
|
sol::protected_function m_onLoad{};
|
||||||
sol::protected_function m_onControlPhase{};
|
sol::protected_function m_onControlPhase{};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue