quest-wizard/models/events/qw_switcheventsevent.cpp

76 lines
1.9 KiB
C++
Raw Normal View History

2023-02-09 08:41:24 -05:00
#include "../qw_trigger.h"
#include "qw_switcheventsevent.h"
QWSwitchEventsEvent::QWSwitchEventsEvent(const std::shared_ptr<QWTrigger> &tr) :
ptr_target(tr),
b_active(false)
{
Q_ASSERT(ptr_target);
}
void QWSwitchEventsEvent::execute()
{
/* QWActivateItemEvent changes its state,
* Now we send other list of events for the linked trigger. */
b_active = !b_active;
ptr_target->setEvents(b_active ? list_enabled_events : list_disabled_events);
}
void QWSwitchEventsEvent::init()
{
ptr_target->setEvents(list_disabled_events);
}
////////////////////////
void QWSwitchEventsEvent::setTarget(const std::shared_ptr<QWTrigger> &tr) noexcept
{
ptr_target = tr;
}
std::shared_ptr<QWTrigger> QWSwitchEventsEvent::target() const noexcept
{
return ptr_target;
}
void QWSwitchEventsEvent::setEventsOnEnable(const QList<std::shared_ptr<QWAbstractEvent>> &evs) noexcept
{
list_enabled_events = evs;
}
void QWSwitchEventsEvent::setEventsOnDisable(const QList<std::shared_ptr<QWAbstractEvent>> &evs) noexcept
{
list_disabled_events = evs;
}
////////////////////////
void QWSwitchEventsEvent::writeToJson(QJsonObject & event_data)
{
event_data.insert("id", tag());
event_data.insert("type", EVENT_TYPE::SWITCH_EVENTS);
event_data.insert("target", ptr_target->tag());
QJsonArray trs_en, trs_dis;
for (const auto & ev : list_enabled_events) {
trs_en.append(ev->tag());
}
event_data.insert("enable_evs", trs_en);
for (const auto & ev : list_disabled_events) {
trs_dis.append(ev->tag());
}
event_data.insert("disable_evs", trs_dis);
qDebug() << " The switch_events event:\n" << " id " << tag()
<< "\n trs_en :";
for (const auto tr : trs_en)
qDebug() << " " << tr.toString();
qDebug() << "\n trs_dis :";
for (const auto tr : trs_dis)
qDebug() << " " << tr.toString();
}