mirror of
https://github.com/Mr-X-GTA/YimMenu.git
synced 2025-06-18 23:17:52 +08:00
52 lines
1.3 KiB
C++
52 lines
1.3 KiB
C++
#include "script_connection_service.hpp"
|
|
|
|
namespace big
|
|
{
|
|
script_connection* script_connection_service::get_connection(const std::string& script_name, std::optional<player_ptr> target)
|
|
{
|
|
auto hash = rage::joaat(script_name);
|
|
|
|
for (auto& cxn : m_script_connections)
|
|
if (cxn->get_script_hash() == hash
|
|
&& ((!target && !cxn->get_target())
|
|
|| (target && cxn->get_target() && target->get()->id() == cxn->get_target()->get()->id())))
|
|
return cxn.get();
|
|
|
|
return nullptr;
|
|
}
|
|
|
|
script_connection_service::script_connection_service()
|
|
{
|
|
g_script_connection_service = this;
|
|
}
|
|
|
|
script_connection_service::~script_connection_service()
|
|
{
|
|
g_script_connection_service = nullptr;
|
|
}
|
|
|
|
script_connection* script_connection_service::create_connection(const std::string& script_name, std::optional<player_ptr> target)
|
|
{
|
|
if (auto cxn = get_connection(script_name, target))
|
|
return cxn;
|
|
|
|
auto cxn = std::make_unique<script_connection>(script_name, target);
|
|
auto ret = cxn.get();
|
|
m_script_connections.push_back(std::move(cxn));
|
|
|
|
return ret;
|
|
}
|
|
|
|
void script_connection_service::on_tick()
|
|
{
|
|
std::erase_if(m_script_connections, [](auto& cxn) {
|
|
if (cxn.get()->should_cleanup())
|
|
{
|
|
cxn.get()->cleanup();
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
});
|
|
}
|
|
} |