1
0
forked from 0ad/0ad
Reported by @Mr.lie at
https://wildfiregames.com/forum/topic/108069-diplomacy-broken-since-rev-27722.
Based on a patch by: @elexis
This was SVN commit r27824.
This commit is contained in:
Freagarach 2023-09-04 13:05:36 +00:00
parent 3d2561f096
commit a10e025324
2 changed files with 9 additions and 3 deletions

View File

@ -18,7 +18,7 @@ Diplomacy.prototype.SerializableAttributes = [
Diplomacy.prototype.Serialize = function()
{
const state = {};
for (const key in this.SerializableAttributes)
for (const key of this.SerializableAttributes)
if (this.hasOwnProperty(key))
state[key] = this[key];
@ -27,8 +27,9 @@ Diplomacy.prototype.Serialize = function()
Diplomacy.prototype.Deserialize = function(state)
{
for (const prop in state)
this[prop] = state[prop];
for (const att of this.SerializableAttributes)
if (att in state)
this[att] = state[att];
};
Diplomacy.prototype.Init = function()

View File

@ -77,3 +77,8 @@ diplo = [1, 1, 0];
cmpDiplomacy.SetDiplomacy(diplo);
diplo[1] = -1;
TS_ASSERT(cmpDiplomacy.IsAlly(1));
// (De)serialisation preserves relations.
const deserialisedCmp = SerializationCycle(cmpDiplomacy);
TS_ASSERT(deserialisedCmp.IsAlly(1));