You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.4 KiB
C++

#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();
}