24 qDebug() <<
"found quests:" <<
myQuests.size();
38 file = fopen(
final,
"r");
40 LOG(
llevError,
"Can't open %s for reading quests", qPrintable(filename));
44 while (fgets(read,
sizeof(read), file) != NULL) {
46 if (strcmp(read,
"end_setwhen\n") == 0) {
51 read[strlen(read) - 1] =
'\0';
57 if (strcmp(read,
"end_description\n") == 0) {
76 if (strcmp(read,
"end_step\n") == 0) {
81 if (strcmp(read,
"finishes_quest\n") == 0) {
85 if (strcmp(read,
"description\n") == 0) {
90 if (strcmp(read,
"setwhen\n") == 0) {
94 LOG(
llevError,
"quests: invalid line %s in definition of quest %s in file %s!\n",
95 read, qPrintable(quest->
code()), qPrintable(filename));
100 if (strcmp(read,
"end_description\n") == 0) {
118 if (strcmp(read,
"end_quest\n") == 0) {
124 if (strcmp(read,
"description\n") == 0) {
130 if (strncmp(read,
"title ", 6) == 0) {
131 read[strlen(read) - 1] =
'\0';
136 if (sscanf(read,
"step %d\n", &i)) {
139 quest->
steps().append(step);
144 if (sscanf(read,
"restart %d\n", &i)) {
149 if (strncmp(read,
"face ", 5) == 0) {
150 read[strlen(read) - 1] =
'\0';
159 if (strncmp(read,
"quest ", 6) == 0) {
162 read[strlen(read) - 1] =
'\0';
165 LOG(
llevError,
"Quest %s is listed in file %s, but this quest has already been defined\n", read + 6, qPrintable(filename));
171 if (sscanf(read,
"include %s\n", includefile)) {
173 snprintf(p,
sizeof(p), qPrintable(filename));
179 if (strncmp(read,
"parent ", 7) == 0) {
180 read[strlen(read) - 1] =
'\0';
183 LOG(
llevError,
"Quest %s was defined before its parent %s", qPrintable(quest->
code()), read + 7);
189 if (strcmp(read,
"\n") == 0)
192 LOG(
llevError,
"quest: invalid file format for %s, I don't know what to do with the line %s\n",
final, read);
200 if (quest->
code() == code)
208 QList<const Quest*>
quests;
210 quests.append(quest);
221 if (!
myFiles.contains(filename))
222 myFiles[filename] =
new QList<Quest*>();
223 myFiles[filename]->append(quest);
228 foreach(
const QString& filename,
myFiles.keys())
234 QList<Quest*>* list =
myFiles[filename];
235 bool modified =
false;
236 foreach(
Quest* quest, *list)
250 if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate))
252 qDebug() <<
"save error quest file" << filename << path;
257 qDebug() <<
"saving quests" << filename;
259 QTextStream stream(&file);
262 if (includes.size() > 0)
264 foreach(QString include, includes)
265 stream <<
"include " << include <<
"\n";
269 foreach(
Quest* quest, *list)
271 stream <<
"quest " << quest->
code() <<
"\n";
272 if (!quest->
title().isEmpty())
273 stream <<
"title " << quest->
title() <<
"\n";
274 if (!quest->
face().isEmpty())
275 stream <<
"face " << quest->
face() <<
"\n";
281 stream <<
"end_description\n";
283 if (quest->
parent() != NULL)
284 stream <<
"parent " << quest->
parent()->
code() <<
"\n";
286 stream <<
"restart 1\n";
290 stream <<
"step " << step->
step() <<
"\n";
292 stream <<
"finishes_quest\n";
298 stream <<
"end_description\n";
300 if (step->
setWhen().size() > 0)
302 stream <<
"setwhen\n";
303 foreach(QString when, step->
setWhen())
305 stream << when <<
"\n";
307 stream <<
"end_setwhen\n";
309 stream <<
"end_step\n";
313 stream <<
"end_quest\n\n";
324 foreach(QString file,
myFiles.keys())
326 if (
myFiles[file]->contains(quest))
345 if (quest->
code() == code)
const QString & face() const
void setRestart(bool restart)
void setTitle(const QString &title)
bool isCompletion() const
StringBuffer * stringbuffer_new(void)
const QString & code() const
void loadQuestFile(const QString &filename)
const QString & title() const
const QString & description() const
const Quest * parent() const
Quest * findByCode(const QString &code)
QHash< QString, QList< Quest * > * > myFiles
void stringbuffer_append_string(StringBuffer *sb, const char *str)
const QStringList & setWhen() const
void setDescription(const QString &description)
void setQuestFile(Quest *quest, const QString &file)
QHash< QString, QStringList > myIncludes
char * path_combine_and_normalize(const char *src, const char *dst, char *path, size_t size)
QList< const QuestStep * > steps() const
void setCompletion(bool completion)
const QString & description() const
void setCode(const QString &code)
void saveQuestFile(const QString &filename)
void addQuest(const QString &filename, Quest *quest)
void setParent(Quest *parent)
QStringList getFiles() const
QList< Quest * > myQuests
void setDescription(const QString &description)
void LOG(LogLevel logLevel, const char *format,...)
void setModified(bool modified)
QList< const Quest * > quests() const
void setFace(const QString &face)
char * stringbuffer_finish(StringBuffer *sb)
QString getQuestFile(Quest *quest) const
Quest * getByCode(const QString &code)