quest-wizard/models/events/qw_changelocationevent.cpp

53 lines
1.4 KiB
C++
Raw Permalink Normal View History

2023-02-09 08:41:24 -05:00
#include "qw_changelocationevent.h"
#include "../qw_location.h"
#include "../qw_trigger.h"
QWChangeLocationEvent::QWChangeLocationEvent(const std::shared_ptr<QWLocation> &location) :
target_location(location)
{
Q_ASSERT(target_location);
}
void QWChangeLocationEvent::execute()
{
const QList<std::shared_ptr<QWTrigger>> &triggers = target_location->triggers();
// We clear all the triggers from previous location
ptr_scene->clearLocation();
ptr_scene->setCurrentLocation(target_location);
if (const auto & tr = target_location->firstVisitTrigger(); tr && !target_location->discovered())
tr->activate();
target_location->setDiscovered(true);
int z = 0;
// The first item will be below the others. The last item - above.
// Triggers[0] must be background.
for (auto &trigger : triggers)
{
trigger->setZValue(-1 * ++z);
ptr_scene->addItem(trigger.get());
}
}
////////////////////////
void QWChangeLocationEvent::setLocation(const std::shared_ptr<QWLocation> &location) noexcept
{
target_location = location;
}
////////////////////////
void QWChangeLocationEvent::writeToJson(QJsonObject &event_data)
{
event_data.insert("id", tag());
event_data.insert("type", EVENT_TYPE::CHANGE_LOCATION);
event_data.insert("location", target_location->tag());
qDebug() << " The move_to_location event:\n" << " id " << tag()
<< "\n location :" << target_location->tag();
}