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.

115 lines
2.6 KiB
C++

#include "qw_location.h"
#include "qw_trigger.h"
QWLocation::QWLocation() :
flag_discovered(false)
{}
void QWLocation::clearTriggers() noexcept
{
list_triggers.clear();
}
void QWLocation::setTriggers(std::initializer_list<std::shared_ptr<QWTrigger>> &&trs) noexcept
{
list_triggers.clear();
/* For some reason QList(::begin(), ::end())
* doesn't work for MSVC */
#if defined(_MSC_VER)
list_triggers = QList<std::shared_ptr<QWTrigger>>::fromStdList(std::move(trs));
#else
list_triggers = QList(trs.begin(), trs.end());
#endif
}
void QWLocation::setTriggers(const QList<std::shared_ptr<QWTrigger>> &trs) noexcept
{
list_triggers.clear();
list_triggers = trs;
}
void QWLocation::addTriggers(std::initializer_list<std::shared_ptr<QWTrigger>> &&trs) noexcept
{
list_triggers.append(std::move(QList<std::shared_ptr<QWTrigger>>(trs)));
}
void QWLocation::addTriggers(const std::shared_ptr<QWTrigger> &tr) noexcept
{
list_triggers.append(tr);
}
void QWLocation::removeTrigger(const std::shared_ptr<QWTrigger> &tr) noexcept
{
list_triggers.removeOne(tr);
}
QList<std::shared_ptr<QWTrigger>> QWLocation::triggers() const
{
return list_triggers;
}
void QWLocation::setFirstVisitTrigger(const std::shared_ptr<QWTrigger> &tr) noexcept
{
first_visit_trigger = tr;
Q_ASSERT(first_visit_trigger);
}
std::shared_ptr<QWTrigger> QWLocation::firstVisitTrigger() const noexcept
{
return first_visit_trigger;
}
void QWLocation::setDiscovered(bool discovered) noexcept
{
flag_discovered = discovered;
}
bool QWLocation::discovered() const noexcept
{
return flag_discovered;
}
void QWLocation::setMusicPath(const QString &path) noexcept
{
music_path = path;
Q_ASSERT(!music_path.isEmpty());
}
void QWLocation::removeMusic() noexcept
{
music_path.clear();
}
QString QWLocation::musicPath() const noexcept
{
return music_path;
}
////////////////////////
void QWLocation::writeToJson(QJsonObject &location_data)
{
location_data.insert("id", tag());
if (flag_discovered)
location_data.insert("discovered", flag_discovered);
if (!music_path.isEmpty())
location_data.insert("music_path", music_path);
qDebug() << " The location:\n" << " id " << tag()
<< "\n discovered " << flag_discovered
<< "\n music_path " << music_path;
// - Location triggers - //
QJsonArray json_triggers;
for (const auto &trigger : triggers()) {
json_triggers.append(trigger->tag());
qDebug() << " trigger: " << trigger->tag();
}
location_data.insert("trs", json_triggers);
}