TombEngine/TR5Main/Scripting/GameScript.cpp

155 lines
3.6 KiB
C++
Raw Normal View History

2018-09-02 09:29:36 +02:00
#include "GameScript.h"
GameScript::GameScript()
{
m_lua.open_libraries(sol::lib::base);
m_lua.new_usertype<GameScriptSettings>("GameScriptSettings",
"screenWidth", &GameScriptSettings::ScreenWidth,
"screenHeight", &GameScriptSettings::ScreenHeight,
"windowTitle", &GameScriptSettings::WindowTitle,
"enableDynamicShadows", &GameScriptSettings::EnableDynamicShadows
);
2018-09-02 21:13:34 +02:00
m_lua.new_usertype<GameScriptSkyLayer>("SkyLayer",
sol::constructors<GameScriptSkyLayer(byte, byte, byte, __int16)>(),
"r", &GameScriptSkyLayer::R,
"g", &GameScriptSkyLayer::G,
"b", &GameScriptSkyLayer::B,
"speed", &GameScriptSkyLayer::CloudSpeed
);
m_lua.new_usertype<GameScriptFog>("Fog",
sol::constructors<GameScriptFog(byte, byte, byte)>(),
"r", &GameScriptFog::R,
"g", &GameScriptFog::G,
"b", &GameScriptFog::B
);
m_lua.new_usertype<GameScriptLevel>("Level",
sol::constructors<GameScriptLevel()>(),
"name", &GameScriptLevel::Name,
"script", &GameScriptLevel::ScriptFileName,
"filename", &GameScriptLevel::FileName,
"loadscreen", &GameScriptLevel::LoadScreenFileName,
"soundtrack", &GameScriptLevel::Soundtrack,
"layer1", &GameScriptLevel::Layer1,
"layer2", &GameScriptLevel::Layer2,
"fog", &GameScriptLevel::Fog,
"horizon", &GameScriptLevel::Horizon,
"coladdhorizon", &GameScriptLevel::ColAddHorizon
);
m_levels.resize(NUM_LEVELS);
m_lua["levels"] = &m_levels;
2018-09-02 09:29:36 +02:00
m_lua["settings"] = &m_settings;
2018-09-02 21:13:34 +02:00
m_strings.resize(NUM_STRINGS);
2018-09-02 09:29:36 +02:00
m_lua["strings"] = &m_strings;
}
GameScript::~GameScript()
{
}
string GameScript::loadScriptFromFile(char* luaFilename)
{
ifstream ifs(luaFilename, ios::in | ios::binary | ios::ate);
ifstream::pos_type fileSize = ifs.tellg();
ifs.seekg(0, ios::beg);
vector<char> bytes(fileSize);
ifs.read(bytes.data(), fileSize);
return string(bytes.data(), fileSize);
}
bool GameScript::LoadGameStrings(char* luaFilename)
{
string script = loadScriptFromFile(luaFilename);
m_lua.script(script);
return true;
}
bool GameScript::LoadGameSettings(char* luaFilename)
{
string script = loadScriptFromFile(luaFilename);
m_lua.script(script);
return true;
}
2018-09-02 21:13:34 +02:00
2018-09-02 09:29:36 +02:00
bool GameScript::ExecuteScript(char* luaFilename)
2018-09-02 21:13:34 +02:00
{
2018-09-02 09:29:36 +02:00
string script = loadScriptFromFile(luaFilename);
m_lua.script(script);
return true;
}
char* GameScript::GetString(__int32 id)
{
2018-09-02 21:13:34 +02:00
return ((char*)m_strings[id - 1].c_str());
2018-09-02 09:29:36 +02:00
}
GameScriptSettings* GameScript::GetSettings()
{
return &m_settings;
}
2018-09-02 21:13:34 +02:00
GameScriptLevel* GameScript::GetLevel(__int32 id)
{
return m_levels[id];
}
GameScriptLevel* GameScript::GetTitle()
{
return m_title;
}
void GameScript::SetHorizon(bool horizon, bool colAddHorizon)
{
DrawHorizon = horizon;
ColAddHorizon = colAddHorizon;
}
void GameScript::SetLayer1(byte r, byte g, byte b, __int16 speed)
{
SkyColor1.r = r;
SkyColor1.g = g;
SkyColor1.b = b;
SkyVelocity1 = speed;
SkyColorLayer1.x = r / 255.0f;
SkyColorLayer1.y = g / 255.0f;
SkyColorLayer1.z = b / 255.0f;
SkySpeedLayer1 = speed;
}
void GameScript::SetLayer2(byte r, byte g, byte b, __int16 speed)
{
SkyColor2.r = r;
SkyColor2.g = g;
SkyColor2.b = b;
SkyVelocity2 = speed;
SkyColorLayer2.x = r / 255.0f;
SkyColorLayer2.y = g / 255.0f;
SkyColorLayer2.z = b / 255.0f;
SkySpeedLayer2 = speed;
}
void GameScript::SetFog(byte r, byte g, byte b, __int16 startDistance, __int16 endDistance)
{
FogColor.x = r / 255.0f;
FogColor.y = g / 255.0f;
FogColor.z = b / 255.0f;
FogInDistance = startDistance;
FogOutDistance = endDistance;
}
2018-09-02 09:29:36 +02:00
GameScript* g_Script;