diff --git a/TR5Main/Scripting/GameScriptSinkInfo.cpp b/TR5Main/Scripting/GameScriptSinkInfo.cpp new file mode 100644 index 000000000..0f9ff7b9a --- /dev/null +++ b/TR5Main/Scripting/GameScriptSinkInfo.cpp @@ -0,0 +1,109 @@ +#pragma once +#include "framework.h" +#include "GameScriptSinkInfo.h" +#include "GameScriptPosition.h" +#include +/*** +Sink info + +@classmod SinkInfo +@pragma nostrip +*/ + +extern bool const WarningsAsErrors; + +constexpr auto LUA_CLASS_NAME{ "SinkInfo" }; + +static auto index_error = index_error_maker(GameScriptSinkInfo, LUA_CLASS_NAME); + +GameScriptSinkInfo::GameScriptSinkInfo(SINK_INFO & ref, bool temp) : m_sink{ref}, m_temporary{ temp } +{}; + +GameScriptSinkInfo::~GameScriptSinkInfo() { + if (m_temporary) + { + s_callbackRemoveName(m_sink.luaName); + } +} + +void GameScriptSinkInfo::Register(sol::state* state) +{ + state->new_usertype(LUA_CLASS_NAME, + sol::meta_function::index, index_error, + + /// (@{Position}) position in level + // @mem pos + "pos", sol::property(&GameScriptSinkInfo::GetPos, &GameScriptSinkInfo::SetPos), + + /// (string) unique string identifier. + // e.g. "door_back_room" or "cracked_greek_statue" + // @mem name + "name", sol::property(&GameScriptSinkInfo::GetName, &GameScriptSinkInfo::SetName), + + /// (int) strength. + // Strength of the sink, with higher numbers providing stronger currents. Will be clamped to [1, 32]. + // @mem strength + "strength", sol::property(&GameScriptSinkInfo::GetStrength, &GameScriptSinkInfo::SetStrength), + + /// (int) box index. + // I don't know what this does and it's not actually in the engine yet + // @mem boxIndex + "boxIndex", sol::property(&GameScriptSinkInfo::GetBoxIndex, &GameScriptSinkInfo::SetBoxIndex) + ); +} + +GameScriptPosition GameScriptSinkInfo::GetPos() const +{ + return GameScriptPosition{ m_sink.x, m_sink.y, m_sink.z }; +} + +void GameScriptSinkInfo::SetPos(GameScriptPosition const& pos) +{ + m_sink.x = pos.x; + m_sink.y = pos.y; + m_sink.z = pos.z; +} + +std::string GameScriptSinkInfo::GetName() const +{ + return m_sink.luaName; +} + +void GameScriptSinkInfo::SetName(std::string const & id) +{ + if (id.empty() && WarningsAsErrors) + throw std::runtime_error("Name cannot be blank"); + + // remove the old name if we have one + s_callbackRemoveName(m_sink.luaName); + + // un-register any other sinks using this name. + // maybe we should throw an error if another sink + // already uses the name... + s_callbackRemoveName(id); + m_sink.luaName = id; + // todo add error checking + s_callbackSetName(id, m_sink); +} + +int GameScriptSinkInfo::GetStrength() const +{ + return m_sink.strength; +} + +void GameScriptSinkInfo::SetStrength(int str) +{ + m_sink.strength = std::clamp(str, 1, 32); +} + +int GameScriptSinkInfo::GetBoxIndex() const +{ + + return m_sink.boxIndex; +} + +void GameScriptSinkInfo::SetBoxIndex(int b) +{ + m_sink.boxIndex = b; +} + diff --git a/TR5Main/Scripting/GameScriptSinkInfo.h b/TR5Main/Scripting/GameScriptSinkInfo.h new file mode 100644 index 000000000..d8284bb9e --- /dev/null +++ b/TR5Main/Scripting/GameScriptSinkInfo.h @@ -0,0 +1,32 @@ +#pragma once + +#include "GameScriptNamedBase.h" +#include "phd_global.h" + +namespace sol { + class state; +} +class GameScriptPosition; + +class GameScriptSinkInfo : public GameScriptNamedBase +{ +public: + GameScriptSinkInfo(SINK_INFO& ref, bool temp); + ~GameScriptSinkInfo(); + static void Register(sol::state *); + GameScriptPosition GetPos() const; + void SetPos(GameScriptPosition const& pos); + + int GetStrength() const; + void SetStrength(int strength); + + int GetBoxIndex() const; + void SetBoxIndex(int Room); + + std::string GetName() const; + void SetName(std::string const &); + +private: + SINK_INFO & m_sink; + bool m_temporary; +}; diff --git a/TR5Main/TR5Main.vcxproj b/TR5Main/TR5Main.vcxproj index 1f01898fe..92d253571 100644 --- a/TR5Main/TR5Main.vcxproj +++ b/TR5Main/TR5Main.vcxproj @@ -391,6 +391,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\" + @@ -686,6 +687,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\" +