qtscript: Save/load triggers. Fix scavenger loading.
parent
c7d206b6e9
commit
5be9250bf8
|
@ -2534,8 +2534,10 @@ BOOL loadGame(const char *pGameToLoad, BOOL keepObjects, BOOL freeMem, BOOL User
|
|||
if (saveGameVersion >= VERSION_33)
|
||||
{
|
||||
PLAYERSTATS playerStats;
|
||||
bool scav = game.scavengers;
|
||||
|
||||
game = saveGameData.sGame;
|
||||
game.scavengers = scav; // ok, so this is butt ugly. but i'm just getting inspiration from the rest of the code around here. ok? - per
|
||||
productionPlayer= selectedPlayer;
|
||||
bMultiPlayer = saveGameData.multiPlayer;
|
||||
bMultiMessages = bMultiPlayer;
|
||||
|
|
|
@ -48,6 +48,7 @@ struct timerNode
|
|||
int frameTime;
|
||||
int ms;
|
||||
int player;
|
||||
timerNode() {}
|
||||
timerNode(QScriptEngine *caller, QString val, int plr, int frame) : function(val) { player = plr; ms = frame; frameTime = frame + gameTime; engine = caller; }
|
||||
// implement operator less TODO
|
||||
};
|
||||
|
@ -235,13 +236,14 @@ bool saveScriptStates(const char *filename)
|
|||
QSettings ini(QString("wz::") + filename, QSettings::IniFormat);
|
||||
if (!ini.isWritable())
|
||||
{
|
||||
qWarning("Savegame file not writable");
|
||||
debug(LOG_ERROR, "Savegame file not writable");
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < scripts.size(); ++i)
|
||||
{
|
||||
ini.beginGroup(QString("globals_") + QString::number(i));
|
||||
QScriptEngine *engine = scripts.at(i);
|
||||
QScriptValueIterator it(engine->globalObject());
|
||||
ini.beginGroup(QString("globals_") + QString::number(i));
|
||||
while (it.hasNext())
|
||||
{
|
||||
it.next();
|
||||
|
@ -252,23 +254,73 @@ bool saveScriptStates(const char *filename)
|
|||
}
|
||||
ini.endGroup();
|
||||
}
|
||||
for (int i = 0; i < timers.size(); ++i)
|
||||
{
|
||||
timerNode node = timers.at(i);
|
||||
ini.beginGroup(QString("triggers_") + QString::number(i));
|
||||
ini.setValue("player", node.player);
|
||||
ini.setValue("function", node.function.toUtf8().constData());
|
||||
if (!node.baseobj.isEmpty())
|
||||
{
|
||||
ini.setValue("object", node.baseobj.toUtf8().constData());
|
||||
}
|
||||
ini.setValue("frame", node.frameTime);
|
||||
ini.setValue("ms", node.ms);
|
||||
ini.endGroup();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static QScriptEngine *findEngineForPlayer(int match)
|
||||
{
|
||||
for (int i = 0; i < scripts.size(); ++i)
|
||||
{
|
||||
QScriptEngine *engine = scripts.at(i);
|
||||
int player = engine->globalObject().property("me").toInt32();
|
||||
if (match == player)
|
||||
{
|
||||
return engine;
|
||||
}
|
||||
}
|
||||
ASSERT(false, "Script context for player %d not found", match);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool loadScriptStates(const char *filename)
|
||||
{
|
||||
QSettings ini(QString("wz::") + filename, QSettings::IniFormat);
|
||||
for (int i = 0; i < scripts.size(); ++i)
|
||||
QStringList list = ini.childGroups();
|
||||
debug(LOG_SAVE, "Loading script states for %d script contexts", scripts.size());
|
||||
for (int i = 0; i < list.size(); ++i)
|
||||
{
|
||||
ini.beginGroup(QString("globals_") + QString::number(i));
|
||||
if (list[i].startsWith("triggers_"))
|
||||
{
|
||||
ini.beginGroup(list[i]);
|
||||
timerNode node;
|
||||
node.player = ini.value("player").toInt();
|
||||
node.ms = ini.value("ms").toInt();
|
||||
node.frameTime = ini.value("frame").toInt();
|
||||
debug(LOG_SAVE, "Registering trigger %d for player %d", i, node.player);
|
||||
node.engine = findEngineForPlayer(node.player);
|
||||
node.function = ini.value("function").toString();
|
||||
node.baseobj = ini.value("baseobj", QString()).toString();
|
||||
timers.push_back(node);
|
||||
ini.endGroup();
|
||||
}
|
||||
else if (list[i].startsWith("globals_"))
|
||||
{
|
||||
ini.beginGroup(list[i]);
|
||||
int player = ini.value("me").toInt();
|
||||
QScriptEngine *engine = findEngineForPlayer(player);
|
||||
QStringList keys = ini.childKeys();
|
||||
QScriptEngine *engine = scripts.at(i);
|
||||
debug(LOG_SAVE, "Loading script globals for player %d -- found %d values", player, keys.size());
|
||||
for (int j = 0; j < keys.size(); ++j)
|
||||
{
|
||||
engine->globalObject().setProperty(keys.at(i), engine->toScriptValue(ini.value(keys.at(i))));
|
||||
engine->globalObject().setProperty(keys.at(j), engine->toScriptValue(ini.value(keys.at(j))));
|
||||
}
|
||||
ini.endGroup();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -84,10 +84,6 @@ static QScriptValue js_enumGroup(QScriptContext *context, QScriptEngine *engine)
|
|||
{
|
||||
matches.push_back(psCurr);
|
||||
}
|
||||
if (matches.size() == 0)
|
||||
{
|
||||
return QScriptValue();
|
||||
}
|
||||
QScriptValue result = engine->newArray(matches.size());
|
||||
for (int i = 0; i < matches.size(); i++)
|
||||
{
|
||||
|
@ -134,10 +130,6 @@ static QScriptValue js_enumStruct(QScriptContext *context, QScriptEngine *engine
|
|||
matches.push_back(psStruct);
|
||||
}
|
||||
}
|
||||
if (matches.size() == 0)
|
||||
{
|
||||
return QScriptValue();
|
||||
}
|
||||
QScriptValue result = engine->newArray(matches.size());
|
||||
for (int i = 0; i < matches.size(); i++)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue