Index: binaries/data/mods/public/simulation/components/TechnologyManager.js =================================================================== --- binaries/data/mods/public/simulation/components/TechnologyManager.js +++ binaries/data/mods/public/simulation/components/TechnologyManager.js @@ -3,21 +3,6 @@ TechnologyManager.prototype.Schema = ""; -TechnologyManager.prototype.Serialize = function() -{ - // The modifications cache will be affected by property reads from the GUI and other places so we shouldn't - // serialize it. - - var ret = {}; - for (var i in this) - { - if (this.hasOwnProperty(i)) - ret[i] = this[i]; - } - ret.modificationCache = {}; - return ret; -}; - TechnologyManager.prototype.Init = function() { this.researchedTechs = {}; // technologies which have been researched @@ -40,12 +25,44 @@ // Some technologies are automatically researched when their conditions are met. They have no cost and are // researched instantly. This allows civ bonuses and more complicated technologies. + this.LoadAutoresearchedTechs(Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager).ListAllTechs()); +}; + +TechnologyManager.prototype.Serialize = function() +{ + // The technology data will be affected by property reads from the GUI and other places so we shouldn't serialize it. + let data = { + "modificationCache": {}, + "autoResearchTech": Object.keys(this.autoResearchTech) + }; + + for (let propertyName in this) + if (this.hasOwnProperty(propertyName) && !data[propertyName]) + data[propertyName] = this[propertyName]; + + return data; +}; + +TechnologyManager.prototype.Deserialize = function(data) +{ + for (let propertyName in data) + if (propertyName != "autoResearchTech") + this[propertyName] = data[propertyName]; + + this.LoadAutoresearchedTechs(data.autoResearchTech); +}; + +TechnologyManager.prototype.LoadAutoresearchedTechs = function(techNames) +{ + let cmpDataTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager); + this.autoResearchTech = {}; - var allTechs = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager).GetAllTechs(); - for (var key in allTechs) + + for (let techName of techNames) { - if (allTechs[key].autoResearch || allTechs[key].top) - this.autoResearchTech[key] = allTechs[key]; + let tech = cmpDataTemplateManager.GetTechnologyTemplate(techName); + if (tech.autoResearch || tech.top) + this.autoResearchTech[techName] = tech; } };