2021-07-23 15:59:13 +01:00
|
|
|
#pragma once
|
|
|
|
#include "framework.h"
|
2021-08-04 16:51:28 +01:00
|
|
|
#include "ScriptAssert.h"
|
2021-07-23 15:59:13 +01:00
|
|
|
#include "GameScriptSinkInfo.h"
|
|
|
|
#include "GameScriptPosition.h"
|
2021-08-20 01:41:14 +01:00
|
|
|
#include "ScriptUtil.h"
|
2021-07-23 15:59:13 +01:00
|
|
|
#include <sol.hpp>
|
|
|
|
/***
|
|
|
|
Sink info
|
|
|
|
|
2021-08-23 19:16:24 +01:00
|
|
|
@entityclass SinkInfo
|
2021-07-23 15:59:13 +01:00
|
|
|
@pragma nostrip
|
|
|
|
*/
|
|
|
|
|
|
|
|
constexpr auto LUA_CLASS_NAME{ "SinkInfo" };
|
|
|
|
|
|
|
|
static auto index_error = index_error_maker(GameScriptSinkInfo, LUA_CLASS_NAME);
|
2021-08-20 01:41:14 +01:00
|
|
|
static auto newindex_error = newindex_error_maker(GameScriptSinkInfo, LUA_CLASS_NAME);
|
2021-07-23 15:59:13 +01:00
|
|
|
|
|
|
|
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,
|
2021-08-20 01:41:14 +01:00
|
|
|
sol::meta_function::new_index, newindex_error,
|
2021-07-23 15:59:13 +01:00
|
|
|
|
|
|
|
/// (@{Position}) position in level
|
|
|
|
// @mem pos
|
|
|
|
"pos", sol::property(&GameScriptSinkInfo::GetPos, &GameScriptSinkInfo::SetPos),
|
|
|
|
|
|
|
|
/// (string) unique string identifier.
|
2021-08-20 01:51:16 +01:00
|
|
|
// e.g. "strong\_river\_current" or "propeller\_death\_sink"
|
2021-07-23 15:59:13 +01:00
|
|
|
// @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)
|
|
|
|
{
|
2021-08-04 16:51:28 +01:00
|
|
|
ScriptAssert(!id.empty(), "Name cannot be blank", ERROR_MODE::TERMINATE);
|
2021-07-23 15:59:13 +01:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|