Go to the documentation of this file.
13 #include <qiodevice.h>
15 #include <qscriptengine.h>
189 int length =
value.property(
"length").toInt32();
190 for (
int l = 0;
l < length;
l++)
193 QScriptValue sub =
value.property(
l);
195 int subl = sub.property(
"length").toInt32();
196 for (
int s = 0; s < subl; s++)
197 items.append(sub.property(s).toString());
207 file.open(QIODevice::ReadOnly);
210 if (
data.size() == 0)
212 QString script =
data;
213 if (!script.startsWith(
'['))
214 script =
"[" + script +
"]";
217 QScriptEngine engine;
218 value = engine.evaluate(script);
219 if (engine.hasUncaughtException())
221 qDebug() <<
"message file evaluate error" <<
myPath << engine.uncaughtException().toString();
225 QScriptValue first =
value.property(0);
226 myLocation = first.property(
"location").toString();
228 QScriptValue
rules = first.property(
"rules");
229 int length =
rules.property(
"length").toInt32();
230 for (
int r = 0;
r < length;
r++)
234 QScriptValue v =
rules.property(
r);
236 rule->setComment(v.property(
"comment").toString());
239 qScriptValueToSequence(v.property(
"match"), items);
240 rule->setMatch(items);
242 QList<QStringList>
lists;
243 QScriptValue p = v.property(
"pre");
247 p = v.property(
"post");
252 qScriptValueToSequence(v.property(
"include"), items);
253 rule->setInclude(items);
256 qScriptValueToSequence(v.property(
"msg"), items);
257 rule->setMessages(items);
259 p = v.property(
"replies");
279 return tmp.replace(
'"',
"\\\"").replace(
'\n',
"\\n");
289 return "[" + one.join(
", ") +
"]";
296 foreach(
const QStringList&
list,
data)
301 return "[" + lines.join(
", ") +
"]";
308 if (!
rule->include().isEmpty())
311 if (!
rule->preconditions().isEmpty())
319 if (!
rule->comment().isEmpty())
321 result +=
" \"comment\" : \"";
326 result +=
" \"match\" : ";
329 result +=
",\n \"pre\" : ";
332 result +=
",\n \"post\" : ";
335 result +=
",\n \"msg\" : ";
338 if (!
rule->replies().isEmpty())
340 result +=
",\n \"replies\" : ";
354 if (
rule->isModified())
363 qDebug() <<
"MessageFile saving" <<
myPath;
365 QString
data =
"{\n";
368 data +=
" \"rules\": [\n ";
374 rule->setModified(
false);
382 file.open(QIODevice::WriteOnly | QIODevice::Truncate);
403 QList<QStringList> conditions =
rule->preconditions();
404 conditions.append(
rule->postconditions());
405 foreach(QStringList
list, conditions) {
406 if (
list.size() > 1 && (
list[0] ==
"quest" ||
list[0] ==
"questdone") &&
list[1] ==
quest->wrappedItem()->quest_code) {
void copy(const MessageFile *other)
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
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