50 lines
1.2 KiB
C++
50 lines
1.2 KiB
C++
#include "qw_removetriggerevent.h"
|
|
#include "models/qw_trigger.h"
|
|
|
|
QWRemoveTriggerEvent::QWRemoveTriggerEvent(const std::shared_ptr<QWTrigger> &tr) :
|
|
trigger(tr)
|
|
{
|
|
Q_ASSERT(trigger);
|
|
}
|
|
|
|
void QWRemoveTriggerEvent::execute()
|
|
{
|
|
Q_ASSERT(location);
|
|
|
|
if (!location->triggers().contains(trigger))
|
|
return;
|
|
|
|
location->removeTrigger(trigger);
|
|
|
|
if (location == ptr_scene->currentLocation())
|
|
ptr_scene->removeItem(trigger.get());
|
|
}
|
|
|
|
////////////////////////
|
|
|
|
void QWRemoveTriggerEvent::setLocation(const std::shared_ptr<QWLocation> &loc) noexcept
|
|
{
|
|
location = loc;
|
|
Q_ASSERT(location);
|
|
}
|
|
|
|
void QWRemoveTriggerEvent::setTrigger(const std::shared_ptr<QWTrigger> &tr) noexcept
|
|
{
|
|
trigger = tr;
|
|
Q_ASSERT(trigger);
|
|
}
|
|
|
|
////////////////////////
|
|
|
|
void QWRemoveTriggerEvent::writeToJson(QJsonObject &event_data)
|
|
{
|
|
event_data.insert("id", tag());
|
|
event_data.insert("type", EVENT_TYPE::REMOVE_TRIGGER);
|
|
event_data.insert("location", location->tag());
|
|
event_data.insert("trigger", trigger->tag());
|
|
|
|
qDebug() << " The remove_trigger event:\n" << " id " << tag()
|
|
<< "\n location :" << location->tag()
|
|
<< "\n trigger :" << trigger->tag();
|
|
}
|