mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-30 08:47:58 +03:00
Add GameScriptSinkInfo/SinkInfo.
This commit is contained in:
parent
171d427d77
commit
40933eef0c
3 changed files with 143 additions and 0 deletions
109
TR5Main/Scripting/GameScriptSinkInfo.cpp
Normal file
109
TR5Main/Scripting/GameScriptSinkInfo.cpp
Normal file
|
@ -0,0 +1,109 @@
|
|||
#pragma once
|
||||
#include "framework.h"
|
||||
#include "GameScriptSinkInfo.h"
|
||||
#include "GameScriptPosition.h"
|
||||
#include <sol.hpp>
|
||||
/***
|
||||
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<GameScriptSinkInfo>(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;
|
||||
}
|
||||
|
32
TR5Main/Scripting/GameScriptSinkInfo.h
Normal file
32
TR5Main/Scripting/GameScriptSinkInfo.h
Normal file
|
@ -0,0 +1,32 @@
|
|||
#pragma once
|
||||
|
||||
#include "GameScriptNamedBase.h"
|
||||
#include "phd_global.h"
|
||||
|
||||
namespace sol {
|
||||
class state;
|
||||
}
|
||||
class GameScriptPosition;
|
||||
|
||||
class GameScriptSinkInfo : public GameScriptNamedBase<GameScriptSinkInfo, SINK_INFO &>
|
||||
{
|
||||
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;
|
||||
};
|
|
@ -391,6 +391,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\"</Command>
|
|||
<ClInclude Include="Scripting\GameScriptNamedBase.h" />
|
||||
<ClInclude Include="Scripting\GameScriptPosition.h" />
|
||||
<ClInclude Include="Scripting\GameScriptRotation.h" />
|
||||
<ClInclude Include="Scripting\GameScriptSinkInfo.h" />
|
||||
<ClInclude Include="Scripting\LanguageScript.h" />
|
||||
<ClInclude Include="Renderer\Renderer11.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
|
@ -686,6 +687,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\"</Command>
|
|||
<ClCompile Include="Scripting\GameScriptMeshInfo.cpp" />
|
||||
<ClCompile Include="Scripting\GameScriptPosition.cpp" />
|
||||
<ClCompile Include="Scripting\GameScriptRotation.cpp" />
|
||||
<ClCompile Include="Scripting\GameScriptSinkInfo.cpp" />
|
||||
<ClCompile Include="Scripting\LanguageScript.cpp" />
|
||||
<ClCompile Include="Objects\TR4\Entity\tr4_demigod.cpp" />
|
||||
<ClCompile Include="Objects\TR4\Entity\tr4_guide.cpp" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue