TmpMenu/src/backend/looped_command.cpp
maybegreat48 97a8c5d60b Add more spoofing options and added clang-format (#1020)
* feat(Spoofing): add spoofing
* feat(Spoofing): prepare code for player attach
* remove(PlayerAttach): isn't going to work due to netsync architecture
* fix(GUI): fix scaling
* feat(Project): add clang-format file
* feat(Classes): update classes
* fix(BlackHole): remove unnecessary cleanup
* fix(Formatting): fix formatting for initializer lists
* feat(clang-format): Set tab width and 1 space before comment

Co-authored-by: Yimura <24669514+Yimura@users.noreply.github.com>
2023-03-01 21:27:15 +00:00

54 lines
955 B
C++

#include "looped_command.hpp"
#include "fiber_pool.hpp"
namespace big
{
looped_command::looped_command(const std::string& name, const std::string& label, const std::string& description, bool& toggle) :
bool_command(name, label, description, toggle)
{
g_looped_commands.push_back(this);
}
void looped_command::enable()
{
if (!m_toggle)
{
m_toggle = true;
m_last_enabled = true;
g_fiber_pool->queue_job([this] {
on_enable();
});
}
}
void looped_command::disable()
{
if (m_toggle)
{
m_toggle = false;
m_last_enabled = false;
g_fiber_pool->queue_job([this] {
disable();
});
}
}
void looped_command::refresh()
{
if (m_toggle && !m_last_enabled)
{
m_last_enabled = true;
g_fiber_pool->queue_job([this] {
on_enable();
});
}
else if (!m_toggle && m_last_enabled)
{
m_last_enabled = false;
g_fiber_pool->queue_job([this] {
on_disable();
});
}
}
}