mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-30 08:47:58 +03:00
Improved savegame system
This commit is contained in:
parent
5c376c0f95
commit
94b5a6f61a
8 changed files with 212 additions and 22 deletions
|
@ -320,7 +320,7 @@ void GameScript::PlaySoundEffect(__int16 id, __int32 flags)
|
|||
SoundEffect(id, NULL, flags);
|
||||
}
|
||||
|
||||
void GameScript::AssignVariables()
|
||||
void GameScript::AssignItemsAndLara()
|
||||
{
|
||||
for (__int32 i = 0; i < NUM_ITEMS; i++)
|
||||
m_items[i].NativeItem = NULL;
|
||||
|
@ -343,4 +343,98 @@ void GameScript::SetItem(__int32 index, ITEM_INFO* item)
|
|||
m_items[index].NativeItem = item;
|
||||
}
|
||||
|
||||
void GameScript::GetGlobalVariables(vector<LuaVariable>* list)
|
||||
{
|
||||
LuaVariable variable;
|
||||
|
||||
m_globals.for_each([&](sol::object const& key, sol::object const& value) {
|
||||
variable.Name = (char*)key.as<string>().c_str();
|
||||
if (value.is<bool>())
|
||||
{
|
||||
variable.Type = LUA_VARIABLE_TYPE_BOOL;
|
||||
variable.BoolValue = value.as<bool>();
|
||||
}
|
||||
else if (value.is<__int32>())
|
||||
{
|
||||
variable.Type = LUA_VARIABLE_TYPE_INT;
|
||||
variable.IntValue = value.as<__int32>();
|
||||
}
|
||||
else if (value.is<float>())
|
||||
{
|
||||
variable.Type = LUA_VARIABLE_TYPE_FLOAT;
|
||||
variable.FloatValue = value.as<float>();
|
||||
}
|
||||
else if (value.is<string>())
|
||||
{
|
||||
variable.Type = LUA_VARIABLE_TYPE_STRING;
|
||||
variable.StringValue = (char*)value.as<string>().c_str();
|
||||
}
|
||||
|
||||
list->push_back(variable);
|
||||
});
|
||||
}
|
||||
|
||||
void GameScript::GetLocalVariables(vector<LuaVariable>* list)
|
||||
{
|
||||
LuaVariable variable;
|
||||
|
||||
m_locals.for_each([&](sol::object const& key, sol::object const& value) {
|
||||
variable.Name = key.as<string>();
|
||||
if (value.is<bool>())
|
||||
{
|
||||
variable.Type = LUA_VARIABLE_TYPE_BOOL;
|
||||
variable.BoolValue = value.as<bool>();
|
||||
}
|
||||
else if (value.is<__int32>())
|
||||
{
|
||||
variable.Type = LUA_VARIABLE_TYPE_INT;
|
||||
variable.IntValue = value.as<__int32>();
|
||||
}
|
||||
else if (value.is<float>())
|
||||
{
|
||||
variable.Type = LUA_VARIABLE_TYPE_FLOAT;
|
||||
variable.FloatValue = value.as<float>();
|
||||
}
|
||||
else if (value.is<string>())
|
||||
{
|
||||
variable.Type = LUA_VARIABLE_TYPE_STRING;
|
||||
variable.StringValue = value.as<string>();
|
||||
}
|
||||
|
||||
list->push_back(variable);
|
||||
});
|
||||
}
|
||||
|
||||
void GameScript::SetGlobalVariables(vector<LuaVariable>* list)
|
||||
{
|
||||
for (__int32 i = 0; i < list->size(); i++)
|
||||
{
|
||||
LuaVariable variable = (*list)[i];
|
||||
if (variable.Type == LUA_VARIABLE_TYPE_BOOL)
|
||||
m_globals[variable.Name] = variable.BoolValue;
|
||||
else if (variable.Type == LUA_VARIABLE_TYPE_INT)
|
||||
m_globals[variable.Name] = variable.IntValue;
|
||||
else if (variable.Type == LUA_VARIABLE_TYPE_FLOAT)
|
||||
m_globals[variable.Name] = variable.FloatValue;
|
||||
else if (variable.Type == LUA_VARIABLE_TYPE_STRING)
|
||||
m_globals[variable.Name] = variable.StringValue;
|
||||
}
|
||||
}
|
||||
|
||||
void GameScript::SetLocalVariables(vector<LuaVariable>* list)
|
||||
{
|
||||
for (__int32 i = 0; i < list->size(); i++)
|
||||
{
|
||||
LuaVariable variable = (*list)[i];
|
||||
if (variable.Type == LUA_VARIABLE_TYPE_BOOL)
|
||||
m_locals[variable.Name] = variable.BoolValue;
|
||||
else if (variable.Type == LUA_VARIABLE_TYPE_INT)
|
||||
m_locals[variable.Name] = variable.IntValue;
|
||||
else if (variable.Type == LUA_VARIABLE_TYPE_FLOAT)
|
||||
m_locals[variable.Name] = variable.FloatValue;
|
||||
else if (variable.Type == LUA_VARIABLE_TYPE_STRING)
|
||||
m_locals[variable.Name] = variable.StringValue;
|
||||
}
|
||||
}
|
||||
|
||||
GameScript* g_GameScript;
|
Loading…
Add table
Add a link
Reference in a new issue