Changeset View
Standalone View
binaries/data/mods/public/gui/structree/helper.js
const g_TechnologyPath = "simulation/data/technologies/"; | |||||
const g_AuraPath = "simulation/data/auras/"; | |||||
var g_TemplateData = {}; | var g_TemplateData = {}; | ||||
var g_TechnologyData = {}; | var g_TechnologyData = {}; | ||||
var g_AuraData = {}; | var g_AuraData = {}; | ||||
// Must be defined after g_TechnologyData object is declared. | |||||
bb: period | |||||
const g_AutoResearchTechList = findAllAutoResearchedTechs(); | |||||
function loadTemplate(templateName) | function loadTemplate(templateName) | ||||
{ | { | ||||
if (!(templateName in g_TemplateData)) | if (!(templateName in g_TemplateData)) | ||||
{ | { | ||||
// We need to clone the template because we want to perform some translations. | // We need to clone the template because we want to perform some translations. | ||||
var data = clone(Engine.GetTemplate(templateName)); | var data = clone(Engine.GetTemplate(templateName)); | ||||
translateObjectKeys(data, ["GenericName", "SpecificName", "Tooltip"]); | translateObjectKeys(data, ["GenericName", "SpecificName", "Tooltip"]); | ||||
if (data.Auras) | if (data.Auras) | ||||
for (let auraID of data.Auras._string.split(/\s+/)) | for (let auraID of data.Auras._string.split(/\s+/)) | ||||
loadAuraData(auraID); | loadAuraData(auraID); | ||||
g_TemplateData[templateName] = data; | g_TemplateData[templateName] = data; | ||||
} | } | ||||
return g_TemplateData[templateName]; | return g_TemplateData[templateName]; | ||||
} | } | ||||
function loadTechData(templateName) | function loadTechData(templateName) | ||||
{ | { | ||||
if (!(templateName in g_TechnologyData)) | if (!(templateName in g_TechnologyData)) | ||||
{ | { | ||||
var filename = "simulation/data/technologies/" + templateName + ".json"; | let data = Engine.ReadJSONFile(g_TechnologyPath + templateName + ".json"); | ||||
var data = Engine.ReadJSONFile(filename); | translateObjectKeys(data, ["genericName", "tooltip", "description"]); | ||||
Done Inline Actionsvariable unneeded. bb: variable unneeded. | |||||
Not Done Inline ActionsBut arguably nicer to read. Changing anyway, s0600204: But arguably nicer to read. Changing anyway, | |||||
translateObjectKeys(data, ["genericName", "tooltip"]); | |||||
g_TechnologyData[templateName] = data; | g_TechnologyData[templateName] = data; | ||||
} | } | ||||
return g_TechnologyData[templateName]; | return g_TechnologyData[templateName]; | ||||
} | } | ||||
function loadAuraData(templateName) | function loadAuraData(templateName) | ||||
{ | { | ||||
if (!(templateName in g_AuraData)) | if (!(templateName in g_AuraData)) | ||||
{ | { | ||||
let filename = "simulation/data/auras/" + templateName + ".json"; | let data = Engine.ReadJSONFile(g_AuraPath + templateName + ".json"); | ||||
Done Inline ActionsAlso unneeded bb: Also unneeded | |||||
let data = Engine.ReadJSONFile(filename); | |||||
translateObjectKeys(data, ["auraName", "auraDescription"]); | translateObjectKeys(data, ["auraName", "auraDescription"]); | ||||
g_AuraData[templateName] = data; | g_AuraData[templateName] = data; | ||||
} | } | ||||
return g_AuraData[templateName]; | return g_AuraData[templateName]; | ||||
} | } | ||||
function findAllAutoResearchedTechs() | |||||
{ | |||||
let techList = []; | |||||
Done Inline Actionsunneeded variable bb: unneeded variable | |||||
Not Done Inline ActionsTrue, but would make the for statement more unpleasant to read, imo. s0600204: True, but would make the `for` statement more unpleasant to read, imo. | |||||
Not Done Inline ActionsMeh, it's not too bad. Changed it anyway. s0600204: Meh, it's not too bad. Changed it anyway. | |||||
Done Inline ActionsNuke path and make it global. bb: Nuke `path` and make it global. | |||||
for (let filename of Engine.BuildDirEntList(g_TechnologyPath, "*.json", true)) | |||||
{ | |||||
// -5 to strip off the file extension | |||||
let templateName = filename.slice(g_TechnologyPath.length, -5); | |||||
Done Inline Actionsgood bb: good | |||||
let data = loadTechData(templateName); | |||||
Done Inline ActionsSome comment about the -5 wouldn't hurt. bb: Some comment about the `-5` wouldn't hurt. | |||||
if (data && data.autoResearch) | |||||
techList.push(templateName); | |||||
Done Inline ActionsAs there only 1 statement follows in the loop, I would invert the cases and so remove the continue. bb: As there only 1 statement follows in the loop, I would invert the cases and so remove the… | |||||
} | |||||
return techList; | |||||
} | |||||
function deriveAutoresearchedModifications() | |||||
wraitiiUnsubmitted Not Done Inline ActionsThis should be put in Technologies.js. Do not use g_AutoResearchTechList, pass a list of technologies (ideally template names, otherwise loaded templates) as a parameter instead. Do not change g_CurrentModifiers, return the object instead. (basically make this a pure function in Technologies.js) This will make it possible to call getEntityValue (see comment above) with an arbitrary modifier object, which will be useful for D302 and the future in general. wraitii: This should be put in Technologies.js.
Do not use g_AutoResearchTechList, pass a list of… | |||||
{ | |||||
g_CurrentModifiers = {}; | |||||
for (let templateName of g_AutoResearchTechList) | |||||
Done Inline ActionsName confusing as we are only looping over autoresearched techs. bb: Name confusing as we are only looping over autoresearched techs. | |||||
{ | |||||
let data = loadTechData(templateName); | |||||
let modifier = GetTechnologyBasicDataHelper(data, g_SelectedCiv); | |||||
if (!modifier.reqs) | |||||
continue; | |||||
modifier.modifications = data.modifications; | |||||
modifier.affects = data.affects; | |||||
let derivedModifiers = DeriveModificationsFromTech(modifier); | |||||
for (let modPath in derivedModifiers) | |||||
{ | |||||
if (!g_CurrentModifiers[modPath]) | |||||
g_CurrentModifiers[modPath] = []; | |||||
g_CurrentModifiers[modPath] = g_CurrentModifiers[modPath].concat(derivedModifiers[modPath]); | |||||
} | |||||
} | |||||
} | |||||
/** | /** | ||||
* This is needed because getEntityCostTooltip in tooltip.js needs to get | * This is needed because getEntityCostTooltip in tooltip.js needs to get | ||||
* the template data of the different wallSet pieces. In the session this | * the template data of the different wallSet pieces. In the session this | ||||
* function does some caching, but here we do that in loadTemplate already. | * function does some caching, but here we do that in loadTemplate already. | ||||
*/ | */ | ||||
function GetTemplateData(templateName) | function GetTemplateData(templateName) | ||||
{ | { | ||||
var template = loadTemplate(templateName); | var template = loadTemplate(templateName); | ||||
▲ Show 20 Lines • Show All 67 Lines • Show Last 20 Lines |
period