Go to the documentation of this file.
26 quest->setModified(
false);
27 qDebug() <<
"found quests:" <<
myQuests.size();
42 file = fopen(
final,
"r");
48 while (fgets(read,
sizeof(read),
file) != NULL) {
50 if (strcmp(read,
"end_comment\n") == 0) {
51 quest->setComment(comment.trimmed());
59 if (strcmp(read,
"end_setwhen\n") == 0) {
64 read[strlen(read) - 1] =
'\0';
70 if (strcmp(read,
"end_description\n") == 0) {
89 if (strcmp(read,
"end_step\n") == 0) {
94 if (strcmp(read,
"finishes_quest\n") == 0) {
98 if (strcmp(read,
"description\n") == 0) {
103 if (strcmp(read,
"setwhen\n") == 0) {
107 LOG(
llevError,
"quests: invalid line %s in definition of quest %s in file %s!\n",
113 if (strcmp(read,
"end_description\n") == 0) {
131 if (strcmp(read,
"end_quest\n") == 0) {
137 if (strcmp(read,
"description\n") == 0) {
143 if (strncmp(read,
"title ", 6) == 0) {
144 read[strlen(read) - 1] =
'\0';
145 quest->setTitle(read + 6);
149 if (sscanf(read,
"step %d\n", &i)) {
152 quest->steps().append(step);
157 if (sscanf(read,
"restart %d\n", &i)) {
158 quest->setRestart(i != 0);
162 if (strncmp(read,
"face ", 5) == 0) {
163 read[strlen(read) - 1] =
'\0';
168 if (strcmp(read,
"comment\n") == 0) {
174 if (sscanf(read,
"is_system %d\n", &i)) {
175 quest->setSystem(i ?
true :
false);
183 if (strncmp(read,
"quest ", 6) == 0) {
186 read[strlen(read) - 1] =
'\0';
187 quest->setCode(read + 6);
189 LOG(
llevError,
"Quest %s is listed in file %s, but this quest has already been defined\n", read + 6, qPrintable(
filename));
195 if (sscanf(read,
"include %s\n", includefile)) {
197 snprintf(p,
sizeof(p), qPrintable(
filename));
203 if (strncmp(read,
"parent ", 7) == 0) {
204 read[strlen(read) - 1] =
'\0';
207 LOG(
llevError,
"Quest %s was defined before its parent %s", qPrintable(
quest->code()), read + 7);
209 quest->setParent(parent);
213 if (strcmp(read,
"\n") == 0)
216 LOG(
llevError,
"quest: invalid file format for %s, I don't know what to do with the line %s\n",
final, read);
226 if (
quest->code() == code)
234 QList<const Quest*>
quests;
261 bool modified =
false;
264 if (
quest->isModified())
276 if (!
file.open(QIODevice::WriteOnly | QIODevice::Truncate))
278 qDebug() <<
"save error quest file" <<
filename <<
path;
283 qDebug() <<
"saving quests" <<
filename;
285 QTextStream stream(&
file);
288 if (includes.size() > 0)
290 foreach(QString include, includes)
291 stream <<
"include " << include <<
"\n";
297 stream <<
"quest " <<
quest->code() <<
"\n";
298 if (!
quest->title().isEmpty())
299 stream <<
"title " <<
quest->title() <<
"\n";
300 if (
quest->face() !=
nullptr)
301 stream <<
"face " <<
quest->face()->name <<
"\n";
302 if (!
quest->description().isEmpty())
304 stream <<
"description\n" <<
quest->description();
305 if (!
quest->description().endsWith(
"\n"))
307 stream <<
"end_description\n";
309 if (
quest->parent() != NULL)
310 stream <<
"parent " <<
quest->parent()->code() <<
"\n";
311 if (
quest->canRestart())
312 stream <<
"restart 1\n";
313 if (
quest->isSystem())
314 stream <<
"is_system 1\n";
316 if (!
quest->comment().isEmpty())
318 QString
c(
quest->comment());
319 c.replace(
"end_comment",
"end comment");
320 stream <<
"comment\n";
322 if (!
c.endsWith(
"\n"))
324 stream <<
"end_comment\n";
329 stream <<
"step " << step->
step() <<
"\n";
331 stream <<
"finishes_quest\n";
337 stream <<
"end_description\n";
339 if (step->
setWhen().size() > 0)
341 stream <<
"setwhen\n";
342 foreach(QString when, step->
setWhen())
344 stream << when <<
"\n";
346 stream <<
"end_setwhen\n";
348 stream <<
"end_step\n";
352 stream <<
"end_quest\n\n";
384 if (
quest->code() == code)
StringBuffer * stringbuffer_new(void)
void addQuest(const QString &filename, Quest *quest)
static event_registration c
const QString & description() const
char * path_combine_and_normalize(const char *src, const char *dst, char *path, size_t size)
void setCompletion(bool completion)
AssetsManager * getManager()
QHash< QString, QStringList > myIncludes
const QStringList & setWhen() const
void stringbuffer_append_string(StringBuffer *sb, const char *str)
bool isCompletion() const
void loadQuestFile(const QString &filename)
char * stringbuffer_finish(StringBuffer *sb)
Quest * getByCode(const QString &code)
QList< const Quest * > quests() const
void setQuestFile(Quest *quest, const QString &file)
void LOG(LogLevel logLevel, const char *format,...)
void setDescription(const QString &description)
QHash< QString, QList< Quest * > * > myFiles
QString getQuestFile(Quest *quest) const
void saveQuestFile(const QString &filename)
QList< Quest * > myQuests
QStringList getFiles() const
Quest * findByCode(const QString &code)