Go to the documentation of this file.
13 #include <qiodevice.h>
15 #include <qscriptengine.h>
191 int length =
value.property(
"length").toInt32();
192 for (
int l = 0;
l < length;
l++)
195 QScriptValue sub =
value.property(
l);
197 int subl = sub.property(
"length").toInt32();
198 for (
int s = 0; s < subl; s++)
199 items.append(sub.property(s).toString());
209 file.open(QIODevice::ReadOnly);
212 if (
data.size() == 0)
214 QString script =
data;
215 if (!script.startsWith(
'['))
216 script =
"[" + script +
"]";
219 QScriptEngine engine;
220 value = engine.evaluate(script);
221 if (engine.hasUncaughtException())
223 qDebug() <<
"message file evaluate error" <<
myPath << engine.uncaughtException().toString();
227 QScriptValue first =
value.property(0);
228 myLocation = first.property(
"location").toString();
230 QScriptValue
rules = first.property(
"rules");
231 int length =
rules.property(
"length").toInt32();
232 for (
int r = 0;
r < length;
r++)
236 QScriptValue v =
rules.property(
r);
238 rule->setComment(v.property(
"comment").toString());
241 qScriptValueToSequence(v.property(
"match"), items);
242 rule->setMatch(items);
244 QList<QStringList>
lists;
245 QScriptValue p = v.property(
"pre");
249 p = v.property(
"post");
254 qScriptValueToSequence(v.property(
"include"), items);
255 rule->setInclude(items);
258 qScriptValueToSequence(v.property(
"msg"), items);
259 rule->setMessages(items);
261 p = v.property(
"replies");
281 return tmp.replace(
'"',
"\\\"").replace(
'\n',
"\\n");
291 return "[" + one.join(
", ") +
"]";
298 foreach(
const QStringList&
list,
data)
303 return "[" + lines.join(
", ") +
"]";
310 if (!
rule->include().isEmpty())
313 if (!
rule->preconditions().isEmpty())
321 if (!
rule->comment().isEmpty())
323 result +=
" \"comment\" : \"";
328 result +=
" \"match\" : ";
331 result +=
",\n \"pre\" : ";
334 result +=
",\n \"post\" : ";
337 result +=
",\n \"msg\" : ";
340 if (!
rule->replies().isEmpty())
342 result +=
",\n \"replies\" : ";
356 if (
rule->isModified())
365 qDebug() <<
"MessageFile saving" <<
myPath;
367 QString
data =
"{\n";
370 data +=
" \"rules\": [\n ";
376 rule->setModified(
false);
384 file.open(QIODevice::WriteOnly | QIODevice::Truncate);
405 QList<QStringList> conditions =
rule->preconditions();
406 conditions.append(
rule->postconditions());
407 foreach(QStringList
list, conditions) {
408 if (
list.size() > 1 && (
list[0] ==
"quest" ||
list[0] ==
"questdone") &&
list[1] ==
quest->wrappedItem()->quest_code) {
void copy(const MessageFile *other)
const QString & path() const
void setPostconditions(const QList< QStringList > &postconditions)
QList< CREMapInformation * > & maps()
MessageFile * duplicate() const
QList< QStringList > myPostconditions
const QStringList & messages() const
void setInclude(const QStringList &include)
void setMatch(const QStringList &match)
void convert(QScriptValue &value, QList< QStringList > &list)
MessageFile(AssetWrapper *parent, const QString &path)
const QStringList & include() const
void setLocation(const QString &location)
QList< QStringList > myPreconditions
void setModified(bool modified=true)
void setPath(const QString &path)
void setPreconditions(const QList< QStringList > &preconditions)
void setModified(bool modified=true)
QList< MessageRule * > & rules()
const QList< QStringList > & replies() const
const QString & location() const
void setReplies(const QList< QStringList > &replies)
QList< QStringList > myReplies
QList< MessageRule * > myRules
virtual PossibleUse uses(const AssetWrapper *asset, std::string &) const override
const QStringList & match() const
const QList< QStringList > & preconditions() const
const QList< QStringList > & postconditions() const
void setComment(const QString &comment)
QList< CREMapInformation * > myMaps
void setMessages(const QStringList &messages)
const QString & comment() const