13 #include <qiodevice.h>
15 #include <qscriptengine.h>
153 for (
auto rule : other->
myRules)
186 void convert(QScriptValue& value, QList<QStringList>& list)
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());
205 QString full = QString(
"%1/%2/%3").arg(settings.datadir, settings.mapdir,
myPath);
207 file.open(QIODevice::ReadOnly);
209 QByteArray data = file.readAll();
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);
242 QList<QStringList> lists;
243 QScriptValue p = v.property(
"pre");
247 p = v.property(
"post");
252 qScriptValueToSequence(v.property(
"include"), items);
256 qScriptValueToSequence(v.property(
"msg"), items);
259 p = v.property(
"replies");
279 return tmp.replace(
'"',
"\\\"").replace(
'\n',
"\\n");
285 foreach(
const QString& line, list)
287 one.append(
"\"" +
convert(line) +
"\"");
289 return "[" + one.join(
", ") +
"]";
292 QString
convert(
const QList<QStringList>& data)
296 foreach(
const QStringList& list, data)
301 return "[" + lines.join(
", ") +
"]";
308 if (!rule->
include().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\" : ";
363 qDebug() <<
"MessageFile saving" <<
myPath;
365 QString data =
"{\n";
367 data +=
" \"location\" : \"" +
myLocation +
"\",\n";
368 data +=
" \"rules\": [\n ";
377 data +=
rules.join(
", ");
380 QString full = QString(
"%1/%2/%3").arg(settings.datadir, settings.mapdir,
myPath);
382 file.open(QIODevice::WriteOnly | QIODevice::Truncate);
383 file.write(data.toLatin1());
405 foreach(QStringList list, conditions) {
406 if (list.size() > 1 && (list[0] ==
"quest" || list[0] ==
"questdone") && list[1] == quest->wrappedItem()->quest_code) {