Changeset View
Standalone View
binaries/data/mods/public/simulation/components/TechnologyManager.js
function TechnologyManager() {} | function TechnologyManager() {} | ||||
TechnologyManager.prototype.Schema = | TechnologyManager.prototype.Schema = | ||||
"<empty/>"; | "<empty/>"; | ||||
TechnologyManager.prototype.Serialize = function() | TechnologyManager.prototype.Serialize = function() | ||||
Itms: `Serialize` and `Deserialize` do go before `Init`, you can leave them there. | |||||
{ | { | ||||
// The modifications cache will be affected by property reads from the GUI and other places so we shouldn't | // The modifications cache will be affected by property reads from the GUI and other places so we shouldn't | ||||
// serialize it. | // serialize it. | ||||
var ret = {}; | var ret = {}; | ||||
for (var i in this) | for (var i in this) | ||||
{ | { | ||||
if (this.hasOwnProperty(i)) | if (this.hasOwnProperty(i)) | ||||
Show All 20 Lines | this.modificationCache = {}; // Caches the values after technologies have been applied | ||||
// where 5 and 7 are entity id's | // where 5 and 7 are entity id's | ||||
this.classCounts = {}; // stores the number of entities of each Class | this.classCounts = {}; // stores the number of entities of each Class | ||||
this.typeCountsByClass = {}; // stores the number of entities of each type for each class i.e. | this.typeCountsByClass = {}; // stores the number of entities of each type for each class i.e. | ||||
// {"someClass": {"unit/spearman": 2, "unit/cav": 5} "someOtherClass":...} | // {"someClass": {"unit/spearman": 2, "unit/cav": 5} "someOtherClass":...} | ||||
// Some technologies are automatically researched when their conditions are met. They have no cost and are | // 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. | // researched instantly. This allows civ bonuses and more complicated technologies. | ||||
this.autoResearchTech = {}; | // Only serialize names | ||||
this.autoResearchTech = new Set(); | |||||
var allTechs = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager).GetAllTechs(); | var allTechs = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager).GetAllTechs(); | ||||
for (var key in allTechs) | for (var key in allTechs) | ||||
{ | { | ||||
if (allTechs[key].autoResearch || allTechs[key].top) | if (allTechs[key].autoResearch || allTechs[key].top) | ||||
Not Done Inline ActionsBe more explicit about the "data" and maybe explain where we get them from upon deserialization. Itms: Be more explicit about the "data" and maybe explain where we get them from upon deserialization. | |||||
this.autoResearchTech[key] = allTechs[key]; | this.autoResearchTech.add(key); | ||||
} | } | ||||
}; | }; | ||||
TechnologyManager.prototype.OnUpdate = function() | TechnologyManager.prototype.OnUpdate = function() | ||||
{ | { | ||||
this.UpdateAutoResearch(); | this.UpdateAutoResearch(); | ||||
Not Done Inline ActionsIs there a reason why you don't copy the entire contents and erase the cache and the autoresearched techs? The code here doesn't seem very clear to me compared to the deleted version. But that's personal taste I suppose. Itms: Is there a reason why you don't copy the entire contents and erase the cache and the… | |||||
Not Done Inline ActionsConditional copy seemed nicer than copy + delete, also it avoids any hardcoded property name checks. elexis: Conditional copy seemed nicer than copy + delete, also it avoids any hardcoded property name… | |||||
}; | }; | ||||
// This function checks if the requirements of any autoresearch techs are met and if they are it researches them | // This function checks if the requirements of any autoresearch techs are met and if they are it researches them | ||||
TechnologyManager.prototype.UpdateAutoResearch = function() | TechnologyManager.prototype.UpdateAutoResearch = function() | ||||
{ | { | ||||
var cmpDataTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager); | var cmpDataTempMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager); | ||||
for (var key in this.autoResearchTech) | for (let key of this.autoResearchTech) | ||||
{ | { | ||||
var tech = cmpDataTempMan.GetTechnologyTemplate(key); | var tech = cmpDataTempMan.GetTechnologyTemplate(key); | ||||
if ((tech.autoResearch && this.CanResearch(key)) | if ((tech.autoResearch && this.CanResearch(key)) | ||||
|| (tech.top && (this.IsTechnologyResearched(tech.top) || this.IsTechnologyResearched(tech.bottom)))) | || (tech.top && (this.IsTechnologyResearched(tech.top) || this.IsTechnologyResearched(tech.bottom)))) | ||||
{ | { | ||||
delete this.autoResearchTech[key]; | this.autoResearchTech.delete(key); | ||||
this.ResearchTechnology(key); | this.ResearchTechnology(key); | ||||
Not Done Inline ActionsI would put that code in Deserialize because that shouldn't be callable by anything else. Itms: I would put that code in `Deserialize` because that shouldn't be callable by anything else. | |||||
Not Done Inline Actionscalled on init too elexis: called on init too | |||||
return; // We will have recursively handled any knock-on effects so can just return | return; // We will have recursively handled any knock-on effects so can just return | ||||
} | } | ||||
Not Done Inline Actionssad we need to get the interface twice, bb: sad we need to get the interface twice,
Actually is there a need for doing so? can't we pass as… | |||||
Not Done Inline ActionsPerhaps I should read better, the techdata should be retrieved when deserializing, not serializing (otherwise patch would be useless) bb: Perhaps I should read better, the techdata should be retrieved when deserializing, not… | |||||
} | } | ||||
}; | }; | ||||
TechnologyManager.prototype.GetTechnologyTemplate = function(tech) | TechnologyManager.prototype.GetTechnologyTemplate = function(tech) | ||||
{ | { | ||||
return Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager).GetTechnologyTemplate(tech); | return Engine.QueryInterface(SYSTEM_ENTITY, IID_DataTemplateManager).GetTechnologyTemplate(tech); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 406 Lines • Show Last 20 Lines |
Serialize and Deserialize do go before Init, you can leave them there.