Ticket #4239: serialization-fix.patch
File serialization-fix.patch, 5.6 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/components/Auras.js
6 6 "</attribute>" + 7 7 "<text a:help='A whitespace-separated list of aura files, placed under simulation/data/auras/'/>"; 8 8 9 Auras.prototype.Serialize = function() 10 { 11 let ret = {}; 12 for (let key in this) 13 { 14 if (!this.hasOwnProperty(key)) 15 continue; 16 17 // Don't serialize the templates themselves 18 if (key == "auras") 19 continue; 20 21 ret[key] = this[key]; 22 } 23 24 return ret; 25 }; 26 27 Auras.prototype.Deserialize = function(data) 28 { 29 for (let key in data) 30 if (data.hasOwnProperty(key)) 31 this[key] = data[key]; 32 33 // Reload aura templates from the disk 34 this.auras = {}; 35 let cmpDataTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager); 36 for (let name of this.GetAuraNames()) 37 this.auras[name] = cmpDataTemplateManager.GetAuraTemplate(name); 38 }; 39 9 40 Auras.prototype.Init = function() 10 41 { 11 42 let cmpDataTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager); 12 43 this.auras = {}; 13 44 this.affectedPlayers = {}; 14 let auraNames = this.GetAuraNames(); 15 for (let name of auraNames) 45 for (let name of this.GetAuraNames()) 16 46 { 17 47 this.affectedPlayers[name] = []; 18 48 this.auras[name] = cmpDataTemplateManager.GetAuraTemplate(name); -
binaries/data/mods/public/simulation/components/DataTemplateManager.js
15 15 this.GetTechnologyTemplate(techNames[i]); 16 16 }; 17 17 18 DataTemplateManager.prototype.Serialize = null; // we have no dynamic state to save 19 20 DataTemplateManager.prototype.Deserialize = function() 21 { 22 this.Init(); 23 }; 24 18 25 DataTemplateManager.prototype.GetTechnologyTemplate = function(template) 19 26 { 20 27 if (!this.allTechs[template]) -
binaries/data/mods/public/simulation/components/TechnologyManager.js
5 5 6 6 TechnologyManager.prototype.Serialize = function() 7 7 { 8 // The modifications cache will be affected by property reads from the GUI and other places so we shouldn't 9 // serialize it. 8 let ret = {}; 10 9 11 var ret = {}; 12 for (var i in this) 10 for (let key in this) 13 11 { 14 if (this.hasOwnProperty(i)) 15 ret[i] = this[i]; 12 if (!this.hasOwnProperty(key)) 13 continue; 14 15 // The modifications cache will be affected by property reads from the GUI and 16 // other places so we shouldn't serialize it. 17 if (key == "modificationCache") 18 continue; 19 20 // Only serialize the template name of researched technologies, to avoid serialization issues. 21 if (key == "researchedTechs") 22 { 23 ret[key] = []; 24 for (let templateName in this[key]) 25 ret[key].push(templateName); 26 continue; 27 } 28 29 ret[key] = this[key]; 16 30 } 17 ret.modificationCache = {}; 31 18 32 return ret; 19 33 }; 20 34 35 TechnologyManager.prototype.Deserialize = function(data) 36 { 37 for (let key in data) 38 { 39 if (!data.hasOwnProperty(key)) 40 continue; 41 42 if (key == "researchedTechs") 43 { 44 this[key] = {}; 45 for (let templateName of data[key]) 46 this[key][templateName] = this.GetTechnologyTemplate(templateName); 47 continue; 48 } 49 50 this[key] = data[key]; 51 } 52 53 this.modificationCache = {}; 54 }; 55 21 56 TechnologyManager.prototype.Init = function() 22 57 { 23 58 this.researchedTechs = {}; // technologies which have been researched … … 40 75 41 76 // Some technologies are automatically researched when their conditions are met. They have no cost and are 42 77 // researched instantly. This allows civ bonuses and more complicated technologies. 43 this.autoResearchTech = {};44 varallTechs = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager).GetAllTechs();45 for ( varkey in allTechs)78 this.autoResearchTech = []; 79 let allTechs = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager).GetAllTechs(); 80 for (let key in allTechs) 46 81 { 47 82 if (allTechs[key].autoResearch || allTechs[key].top) 48 this.autoResearchTech [key] = allTechs[key];83 this.autoResearchTech.push(key); 49 84 } 50 85 }; 51 86 … … 58 93 // This function checks if the requirements of any autoresearch techs are met and if they are it researches them 59 94 TechnologyManager.prototype.UpdateAutoResearch = function() 60 95 { 61 varcmpDataTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager);62 for ( var keyin this.autoResearchTech)96 let cmpDataTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager); 97 for (let i in this.autoResearchTech) 63 98 { 64 var tech = cmpDataTempMan.GetTechnologyTemplate(key); 65 if ((tech.autoResearch && this.CanResearch(key)) 99 let template = this.autoResearchTech[i]; 100 let tech = cmpDataTempMan.GetTechnologyTemplate(template); 101 if ((tech.autoResearch && this.CanResearch(template)) 66 102 || (tech.top && (this.IsTechnologyResearched(tech.top) || this.IsTechnologyResearched(tech.bottom)))) 67 103 { 68 delete this.autoResearchTech[key]; 69 this.ResearchTechnology(key); 104 // Remove the technology from the autoresearch list and research it 105 this.autoResearchTech.splice(i, 1); 106 this.ResearchTechnology(template); 70 107 return; // We will have recursively handled any knock-on effects so can just return 71 108 } 72 109 }