quest-wizard/models/events/qw_addtriggerevent.cpp

50 lines
1.2 KiB
C++
Raw Permalink Normal View History

2023-02-09 08:41:24 -05:00
#include "qw_addtriggerevent.h"
#include "models/qw_trigger.h"
QWAddTriggerEvent::QWAddTriggerEvent(const std::shared_ptr<QWTrigger> &tr) :
trigger(tr)
{
Q_ASSERT(trigger);
}
void QWAddTriggerEvent::execute()
{
Q_ASSERT(location);
if (location->triggers().contains(trigger))
return;
location->addTriggers(trigger);
if (location == ptr_scene->currentLocation())
ptr_scene->addItem(trigger.get());
}
////////////////////////
void QWAddTriggerEvent::setLocation(const std::shared_ptr<QWLocation> &loc) noexcept
{
location = loc;
Q_ASSERT(location);
}
void QWAddTriggerEvent::setTrigger(const std::shared_ptr<QWTrigger> &tr) noexcept
{
trigger = tr;
Q_ASSERT(trigger);
}
////////////////////////
void QWAddTriggerEvent::writeToJson(QJsonObject &event_data)
{
event_data.insert("id", tag());
event_data.insert("type", EVENT_TYPE::ADD_TRIGGER);
event_data.insert("location", location->tag());
event_data.insert("trigger", trigger->tag());
qDebug() << " The add_trigger event:\n" << " id " << tag()
<< "\n location :" << location->tag()
<< "\n trigger :" << trigger->tag();
}