Add m_camerasMapName, AddLuaNameCamera, RemoveLuaNameCamera, GetCameraByName, and GetMeshByName.

This commit is contained in:
hispidence 2021-07-23 02:09:52 +01:00
parent cb59e06493
commit 5257a3c074
2 changed files with 79 additions and 15 deletions

View file

@ -106,7 +106,17 @@ be removed from the game if the MeshInfo object is destroyed.
@return a non-owning MeshInfo referencing the mesh.
*/
m_lua->set_function("GetMeshByName", &GameScript::GetMeshByName, this);
auto makeReadOnlyTable = [this](std::string const & tableName, auto const& container)
/***
Get a CameraInfo by its name. This is non-owning, meaning the actual camera will not
be removed from the game if the CameraInfo object is destroyed.
@function GetCameraByName
@tparam string name the unique name of the camera as set in, or generated by, Tomb Editor
@return a non-owning CameraInfo referencing the camera.
*/
m_lua->set_function("GetCameraByName", &GameScript::GetCameraByName, this);
auto makeReadOnlyTable = [this](std::string const & tableName, auto const& container)
{
auto mt = tableName + "Meta";
// Put all the data in the metatable
@ -145,6 +155,12 @@ be removed from the game if the MeshInfo object is destroyed.
[this](std::string const& str) { return RemoveLuaNameMesh(str); }
);
GameScriptCameraInfo::Register(m_lua);
GameScriptCameraInfo::SetNameCallbacks(
[this](std::string const& str, LEVEL_CAMERA_INFO & info) { return AddLuaNameCamera(str, info); },
[this](std::string const& str) { return RemoveLuaNameCamera(str); }
);
GameScriptPosition::Register(m_lua);
GameScriptRotation::Register(m_lua);
GameScriptColor::Register(m_lua);
@ -192,6 +208,16 @@ bool GameScript::AddLuaNameMesh(std::string const& luaName, MESH_INFO& infoRef)
return m_meshesMapName.insert(std::pair<std::string, MESH_INFO&>(luaName, infoRef)).second;
}
bool GameScript::RemoveLuaNameCamera(std::string const & luaName)
{
return m_camerasMapName.erase(luaName);
}
bool GameScript::AddLuaNameCamera(std::string const& luaName, LEVEL_CAMERA_INFO& infoRef)
{
return m_camerasMapName.insert(std::pair<std::string, LEVEL_CAMERA_INFO&>(luaName, infoRef)).second;
}
void GameScript::FreeLevelScripts()
{
/*
@ -371,6 +397,38 @@ std::unique_ptr<GameScriptItemInfo> GameScript::GetItemByName(std::string const
return std::make_unique<GameScriptItemInfo>(m_itemsMapName[name], false);
}
std::unique_ptr<GameScriptMeshInfo> GameScript::GetMeshByName(std::string const & name)
{
if (m_meshesMapName.find(name) == m_meshesMapName.end())
{
if (WarningsAsErrors)
{
std::string error{ "Mesh name not found: " };
error += name;
throw std::runtime_error{error};
}
return std::unique_ptr<GameScriptMeshInfo>(nullptr);
}
return std::make_unique<GameScriptMeshInfo>(m_meshesMapName.at(name), false);
}
std::unique_ptr<GameScriptCameraInfo> GameScript::GetCameraByName(std::string const & name)
{
if (m_camerasMapName.find(name) == m_camerasMapName.end())
{
if (WarningsAsErrors)
{
std::string error{ "Camera name not found: " };
error += name;
throw std::runtime_error{error};
}
return std::unique_ptr<GameScriptCameraInfo>(nullptr);
}
return std::make_unique<GameScriptCameraInfo>(m_camerasMapName.at(name), false);
}
void GameScript::PlayAudioTrack(std::string const & trackName, bool looped)
{
S_CDPlay(trackName, looped);