#include "GameScript.h" GameScript::GameScript() { m_lua.open_libraries(sol::lib::base); m_lua.new_usertype("GameScriptSettings", "screenWidth", &GameScriptSettings::ScreenWidth, "screenHeight", &GameScriptSettings::ScreenHeight, "windowTitle", &GameScriptSettings::WindowTitle, "enableDynamicShadows", &GameScriptSettings::EnableDynamicShadows ); m_lua.new_usertype("SkyLayer", sol::constructors(), "r", &GameScriptSkyLayer::R, "g", &GameScriptSkyLayer::G, "b", &GameScriptSkyLayer::B, "speed", &GameScriptSkyLayer::CloudSpeed ); m_lua.new_usertype("Fog", sol::constructors(), "r", &GameScriptFog::R, "g", &GameScriptFog::G, "b", &GameScriptFog::B ); m_lua.new_usertype("Level", sol::constructors(), "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; m_lua["settings"] = &m_settings; m_strings.resize(NUM_STRINGS); 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 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; } bool GameScript::ExecuteScript(char* luaFilename) { string script = loadScriptFromFile(luaFilename); m_lua.script(script); return true; } char* GameScript::GetString(__int32 id) { return ((char*)m_strings[id - 1].c_str()); } GameScriptSettings* GameScript::GetSettings() { return &m_settings; } 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; } GameScript* g_Script;