2021-07-21 18:17:30 +01:00
|
|
|
#pragma once
|
|
|
|
#include "framework.h"
|
2021-08-04 16:51:28 +01:00
|
|
|
#include "ScriptAssert.h"
|
2021-07-21 18:17:30 +01:00
|
|
|
#include "GameScriptMeshInfo.h"
|
|
|
|
#include "GameScriptPosition.h"
|
|
|
|
#include "GameScriptColor.h"
|
2021-08-20 01:41:14 +01:00
|
|
|
#include "ScriptUtil.h"
|
2021-07-21 18:17:30 +01:00
|
|
|
#include <sol.hpp>
|
|
|
|
/***
|
|
|
|
Mesh info
|
|
|
|
|
2021-08-23 19:16:24 +01:00
|
|
|
@entityclass MeshInfo
|
2021-07-21 18:17:30 +01:00
|
|
|
@pragma nostrip
|
|
|
|
*/
|
|
|
|
|
|
|
|
constexpr auto LUA_CLASS_NAME{ "MeshInfo" };
|
|
|
|
|
|
|
|
static auto index_error = index_error_maker(GameScriptMeshInfo, LUA_CLASS_NAME);
|
2021-08-20 01:41:14 +01:00
|
|
|
static auto newindex_error = newindex_error_maker(GameScriptMeshInfo, LUA_CLASS_NAME);
|
2021-07-21 18:17:30 +01:00
|
|
|
|
2021-07-23 02:04:47 +01:00
|
|
|
GameScriptMeshInfo::GameScriptMeshInfo(MESH_INFO & ref, bool temp) : m_mesh{ref}, m_temporary{ temp }
|
|
|
|
{};
|
|
|
|
|
|
|
|
GameScriptMeshInfo::~GameScriptMeshInfo() {
|
|
|
|
if (m_temporary)
|
|
|
|
{
|
|
|
|
s_callbackRemoveName(m_mesh.luaName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-21 18:17:30 +01:00
|
|
|
void GameScriptMeshInfo::Register(sol::state* state)
|
|
|
|
{
|
|
|
|
state->new_usertype<GameScriptMeshInfo>(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-21 18:17:30 +01:00
|
|
|
|
|
|
|
/// (@{Position}) position in level
|
|
|
|
// @mem pos
|
|
|
|
"pos", sol::property(&GameScriptMeshInfo::GetPos, &GameScriptMeshInfo::SetPos),
|
|
|
|
|
|
|
|
/// (int) y-axis rotation
|
|
|
|
// @mem yRot
|
|
|
|
"yRot", sol::property(&GameScriptMeshInfo::GetRot, &GameScriptMeshInfo::SetRot),
|
|
|
|
|
|
|
|
/// (string) unique string identifier.
|
2021-08-20 01:51:16 +01:00
|
|
|
// e.g. "my\_vase" or "oldrubble"
|
2021-07-21 18:17:30 +01:00
|
|
|
// @mem name
|
|
|
|
"name", sol::property(&GameScriptMeshInfo::GetName, &GameScriptMeshInfo::SetName),
|
|
|
|
|
|
|
|
/// (int) static number
|
|
|
|
// @mem staticNumber
|
|
|
|
"staticNumber", sol::property(&GameScriptMeshInfo::GetStaticNumber, &GameScriptMeshInfo::SetStaticNumber),
|
|
|
|
|
2021-07-23 02:04:47 +01:00
|
|
|
/// (@{Color}) color of mesh
|
2021-07-21 18:17:30 +01:00
|
|
|
// @mem color
|
|
|
|
"color", sol::property(&GameScriptMeshInfo::GetColor, &GameScriptMeshInfo::SetColor),
|
|
|
|
|
|
|
|
/// (int) hp
|
|
|
|
// @mem HP
|
2021-07-23 02:04:47 +01:00
|
|
|
"HP", sol::property(&GameScriptMeshInfo::GetHP, &GameScriptMeshInfo::SetHP)
|
2021-07-21 18:17:30 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
GameScriptPosition GameScriptMeshInfo::GetPos() const
|
|
|
|
{
|
2021-09-10 13:49:45 +03:00
|
|
|
return GameScriptPosition{ m_mesh.pos.xPos, m_mesh.pos.yPos, m_mesh.pos.zPos };
|
2021-07-21 18:17:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameScriptMeshInfo::SetPos(GameScriptPosition const& pos)
|
|
|
|
{
|
2021-09-10 13:49:45 +03:00
|
|
|
m_mesh.pos.xPos = pos.x;
|
|
|
|
m_mesh.pos.yPos = pos.y;
|
|
|
|
m_mesh.pos.zPos = pos.z;
|
2021-07-21 18:17:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int GameScriptMeshInfo::GetRot() const
|
|
|
|
{
|
2021-09-10 13:49:45 +03:00
|
|
|
return m_mesh.pos.yRot;
|
2021-07-21 18:17:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GameScriptMeshInfo::SetRot(int yRot)
|
|
|
|
{
|
2021-09-10 13:49:45 +03:00
|
|
|
m_mesh.pos.yRot = yRot;
|
2021-07-21 18:17:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string GameScriptMeshInfo::GetName() const
|
|
|
|
{
|
|
|
|
return m_mesh.luaName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameScriptMeshInfo::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-21 18:17:30 +01:00
|
|
|
|
|
|
|
// remove the old name if we have one
|
|
|
|
s_callbackRemoveName(m_mesh.luaName);
|
|
|
|
|
|
|
|
// un-register any other objects using this name.
|
|
|
|
// maybe we should throw an error if another object
|
|
|
|
// already uses the name...
|
|
|
|
s_callbackRemoveName(id);
|
|
|
|
m_mesh.luaName = id;
|
|
|
|
// todo add error checking
|
|
|
|
s_callbackSetName(id, m_mesh);
|
|
|
|
}
|
|
|
|
|
|
|
|
int GameScriptMeshInfo::GetStaticNumber() const
|
|
|
|
{
|
|
|
|
return m_mesh.staticNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameScriptMeshInfo::SetStaticNumber(int staticNumber)
|
|
|
|
{
|
|
|
|
m_mesh.staticNumber = staticNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
GameScriptColor GameScriptMeshInfo::GetColor() const
|
|
|
|
{
|
|
|
|
|
|
|
|
return GameScriptColor{ m_mesh.color };
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameScriptMeshInfo::SetColor(GameScriptColor const & col)
|
|
|
|
{
|
|
|
|
m_mesh.color = col;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GameScriptMeshInfo::GetHP() const
|
|
|
|
{
|
|
|
|
return m_mesh.hitPoints;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GameScriptMeshInfo::SetHP(int hp)
|
|
|
|
{
|
|
|
|
m_mesh.hitPoints = hp;
|
|
|
|
}
|