mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-05-10 20:46:47 +03:00
Add implementation of GameScript::InitCallbacks and the C++ holders of the callbacks. This might well be a needless layer of indirection, but it prevents the callbacks being reassigned outside of the class.
This commit is contained in:
parent
76aa8cd786
commit
4c02d6a222
1 changed files with 43 additions and 0 deletions
|
@ -389,4 +389,47 @@ void LuaVariables::SetVariable(std::string key, sol::object value)
|
|||
}
|
||||
}
|
||||
|
||||
void GameScript::OnStart()
|
||||
{
|
||||
m_onStart();
|
||||
}
|
||||
|
||||
void GameScript::OnLoad()
|
||||
{
|
||||
m_onLoad();
|
||||
}
|
||||
|
||||
void GameScript::OnControlPhase()
|
||||
{
|
||||
m_onControlPhase();
|
||||
}
|
||||
|
||||
void GameScript::OnSave()
|
||||
{
|
||||
m_onSave();
|
||||
|
||||
}
|
||||
|
||||
void GameScript::OnEnd()
|
||||
{
|
||||
m_onEnd();
|
||||
}
|
||||
|
||||
void GameScript::InitCallbacks()
|
||||
{
|
||||
auto assignCB = [this](sol::protected_function& func, char const* luaFunc) {
|
||||
func = (*m_lua)[luaFunc];
|
||||
if (WarningsAsErrors && !func.valid())
|
||||
{
|
||||
std::string err{ "Level's script file requires callback \"" };
|
||||
err += std::string{ luaFunc };
|
||||
err += "\"";
|
||||
throw std::runtime_error(err);
|
||||
}
|
||||
};
|
||||
assignCB(m_onStart, "OnStart");
|
||||
assignCB(m_onLoad, "OnLoad");
|
||||
assignCB(m_onControlPhase, "OnControlPhase");
|
||||
assignCB(m_onSave, "OnSave");
|
||||
assignCB(m_onEnd, "OnEnd");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue