quest-wizard/models/events/qw_newgameevent.cpp

46 lines
1.2 KiB
C++

#include <QRegExp>
#include "qw_newgameevent.h"
#include "qw_globalmetadata.h"
QWNewGameEvent::QWNewGameEvent(const QString &savefile) :
str_savefile(savefile)
{
Q_ASSERT(!str_savefile.isEmpty());
}
void QWNewGameEvent::execute()
{
const QString profile_name = QWGlobalMetadata::valueBy("new_game_dialogue").toString();
str_savefile = composeFileName(profile_name);
Q_ASSERT(!profile_name.isEmpty());
Q_ASSERT(!str_savefile.isEmpty());
ptr_builder->initSaveProfile(str_savefile, profile_name);
ptr_builder->initLevel(QWLevelBuilder::strInitLevel());
}
////////////////////////
QString QWNewGameEvent::composeFileName(const QString &str)
{
//Turn the chosen by user savename into file name.
QString file_name = str;
const QRegExp regexp("[^0-9a-z]+");
file_name = file_name.toLower().remove(regexp);
return file_name;
}
////////////////////////
void QWNewGameEvent::writeToJson(QJsonObject &event_data)
{
event_data.insert("id", tag());
event_data.insert("type", EVENT_TYPE::NEW_GAME);
event_data.insert("save_file", str_savefile);
qDebug() << " The new_game event:\n" << " id " << tag()
<< "\n save_file " << str_savefile;
}