#include "qw_eventfactory.h" #include "qw_levelbuilder.h" #include "qw_widgetdialoguemanager.h" #include "qw_textdialoguemanager.h" QWEventFactory::QWEventFactory(QWLevelBuilder *b) : builder(b) {} std::shared_ptr QWEventFactory::createDeleteItEvent(const QJsonObject &json_object) { std::unique_ptr new_event; qDebug() << " Found QWDeleteFromInventoryEvent. " << json_object["id"].toString() << "."; Q_ASSERT(json_object.contains("target")); Q_ASSERT(builder->hash_triggers.contains(json_object["target"].toString())); new_event = std::make_unique(builder->hash_triggers[json_object["target"].toString()]); new_event->setInventoryManager(builder->ptr_inventory); return std::shared_ptr{std::move(new_event)}; } std::shared_ptr QWEventFactory::createChangeLocEvent(const QJsonObject &json_object) { std::unique_ptr new_event; qDebug() << " Found QWChangeLocationEvent. " << json_object["id"].toString() << "."; Q_ASSERT(json_object.contains("location")); Q_ASSERT(builder->hash_locations.contains(json_object["location"].toString())); new_event = std::make_unique(builder->hash_locations[json_object["location"].toString()]); new_event->setScene(builder->ptr_scene); return std::shared_ptr{std::move(new_event)}; } std::shared_ptr QWEventFactory::createChangeTrProperts(const QJsonObject &json_object) { std::unique_ptr new_event; qDebug() << " Found QWChangeTriggerPropertiesEvent. " << json_object["id"].toString() << "."; Q_ASSERT(json_object.contains("target")); Q_ASSERT(builder->hash_triggers.contains(json_object["target"].toString())); new_event = std::make_unique(builder->hash_triggers[json_object["target"].toString()]); if (json_object.contains("x") && json_object.contains("y")) new_event->setParams(json_object["x"].toDouble(), json_object["y"].toDouble(), json_object.contains("path") ? json_object["path"].toString() : "$no_pic"); else new_event->setParams(json_object.contains("path") ? json_object["path"].toString() : "$no_pic"); return std::shared_ptr{std::move(new_event)}; } std::shared_ptr QWEventFactory::createSwitchEventsEvent(const QJsonObject &json_object) { std::unique_ptr new_event; qDebug() << " Found QWSwitchEventsEvent. " << json_object["id"].toString() << "."; Q_ASSERT(json_object.contains("target")); Q_ASSERT(builder->hash_triggers.contains(json_object["target"].toString())); new_event = std::make_unique(builder->hash_triggers[json_object["target"].toString()]); Q_ASSERT(json_object.contains("enable_evs") && json_object.contains("disable_evs")); // Linking events of enabled state QJsonArray evs = json_object["enable_evs"].toArray(); QList> list_events; for (const auto obj : evs) { Q_ASSERT(builder->hash_events.contains(obj.toString())); list_events.append(builder->hash_events[obj.toString()]); } new_event->setEventsOnEnable(list_events); list_events.clear(); // Linking events of disabled state evs = json_object["disable_evs"].toArray(); for (const auto obj : evs) { Q_ASSERT(builder->hash_events.contains(obj.toString())); list_events.append(builder->hash_events[obj.toString()]); } new_event->setEventsOnDisable(list_events); new_event->init(); return std::shared_ptr{std::move(new_event)}; } std::shared_ptr QWEventFactory::createPickupItEvent(const QJsonObject &json_object) { std::unique_ptr new_event; qDebug() << " Found QWPickupItemEvent. " << json_object["id"].toString() << "."; Q_ASSERT(json_object.contains("target")); Q_ASSERT(builder->hash_triggers.contains(json_object["target"].toString())); new_event = std::make_unique(builder->hash_triggers[json_object["target"].toString()]); new_event->setInventoryManager(builder->ptr_inventory); return std::shared_ptr{std::move(new_event)}; } std::shared_ptr QWEventFactory::createEndLevelEvent(const QJsonObject &json_object) { std::unique_ptr new_event; qDebug() << " Found QWEndLevelEvent. " << json_object["id"].toString() << "."; Q_ASSERT(json_object.contains("new_level")); new_event = std::make_unique(json_object["target"].toString()); new_event->setLevelBuilder(builder); return std::shared_ptr{std::move(new_event)}; } std::shared_ptr QWEventFactory::createPlaySoundEvent(const QJsonObject &json_object) { std::unique_ptr new_event; qDebug() << " Found QWPlaySoundEvent. " << json_object["id"].toString() << "."; Q_ASSERT(json_object.contains("sound")); new_event = std::make_unique(json_object["sound"].toString()); new_event->setSoundPlayer(builder->ptr_soundplayer); return std::shared_ptr{std::move(new_event)}; } std::shared_ptr QWEventFactory::createNewGameEvent(const QJsonObject &json_object) { std::unique_ptr new_event; qDebug() << " Found QWNewGameEvent. " << json_object["id"].toString() << "."; Q_ASSERT(json_object.contains("save_file")); new_event = std::make_unique(json_object["save_file"].toString()); new_event->setLevelBuilder(builder); return std::shared_ptr{std::move(new_event)}; } std::shared_ptr QWEventFactory::createQuitGameEvent(const QJsonObject &json_object) { std::unique_ptr new_event; qDebug() << " Found QWQuitGameEvent. " << json_object["id"].toString() << "."; Q_ASSERT(json_object.contains("save_game")); new_event = std::make_unique(json_object["save_game"].toBool()); new_event->setLevelBuilder(builder); return std::shared_ptr{std::move(new_event)}; } std::shared_ptr QWEventFactory::createStartDlgEvent(const QJsonObject &json_object) { std::unique_ptr new_event; qDebug() << " Found QWStartTextDialogueEvent. " << json_object["id"].toString() << "."; Q_ASSERT(json_object.contains("dialogue")); Q_ASSERT(json_object.contains("dialogue_type")); Q_ASSERT(builder->hash_dialogues.contains(json_object["dialogue"].toString())); new_event = std::make_unique(builder->hash_dialogues[json_object["dialogue"].toString()]); switch(json_object["dialogue_type"].toInt()) { case 1: new_event->setDialogueManager(builder->ptr_widget_dlg); break; case 0: new_event->setDialogueManager(builder->ptr_text_dlg); break; default: Q_ASSERT(false); } return std::shared_ptr{std::move(new_event)}; } std::shared_ptr QWEventFactory::createAddTrEvent(const QJsonObject &json_object) { std::unique_ptr new_event; qDebug() << " Found QWAddTriggerEvent. " << json_object["id"].toString() << "."; Q_ASSERT(json_object.contains("trigger")); Q_ASSERT(builder->hash_triggers.contains(json_object["trigger"].toString())); new_event = std::make_unique(builder->hash_triggers[json_object["trigger"].toString()]); Q_ASSERT(json_object.contains("location")); Q_ASSERT(builder->hash_locations.contains(json_object["location"].toString())); new_event->setLocation(builder->hash_locations[json_object["location"].toString()]); return std::shared_ptr{std::move(new_event)}; } std::shared_ptr QWEventFactory::createRemoveTrEvent(const QJsonObject &json_object) { std::unique_ptr new_event; qDebug() << " Found QWRemoveTriggerEvent. " << json_object["id"].toString() << "."; Q_ASSERT(json_object.contains("trigger")); Q_ASSERT(builder->hash_triggers.contains(json_object["trigger"].toString())); new_event = std::make_unique(builder->hash_triggers[json_object["trigger"].toString()]); Q_ASSERT(json_object.contains("location")); Q_ASSERT(builder->hash_locations.contains(json_object["location"].toString())); new_event->setLocation(builder->hash_locations[json_object["location"].toString()]); return std::shared_ptr{std::move(new_event)}; }