Ticket #3747: 3747_alternate_v3.patch
File 3747_alternate_v3.patch, 10.2 KB (added by , 7 years ago) |
---|
-
binaries/data/mods/public/globalscripts/Technologies.js
diff --git a/binaries/data/mods/public/globalscripts/Technologies.js b/binaries/data/mods/public/globalscripts/Technologies.js index 8361d0630..a1f60ed84 100644
a b function GetTechModifiedProperty(currentTechModifications, classes, propertyName 44 44 } 45 45 46 46 /** 47 * Derives modifications (to be applied to entities) from a given technology 48 * 49 * @param techTemplate The technology template to derive the modifications from. 50 * @return Object containing the relevant modifications. 51 */ 52 function DeriveModificationsFromTech(techTemplate) 53 { 54 if (!techTemplate.modifications) 55 return {}; 56 57 let techMods = {}; 58 let techAffects = []; 59 if (techTemplate.affects && techTemplate.affects.length) 60 for (let affected of techTemplate.affects) 61 techAffects.push(affected.split(/\s+/)); 62 else 63 techAffects.push([]); 64 65 for (let mod of techTemplate.modifications) 66 { 67 let affects = techAffects.slice(); 68 if (mod.affects) 69 { 70 let specAffects = mod.affects.split(/\s+/); 71 for (let a in affects) 72 affects[a] = affects[a].concat(specAffects); 73 } 74 75 let newModifier = { 76 "affects": affects 77 }; 78 for (let idx in mod) 79 if (idx !== "value" && idx !== "affects") 80 newModifier[idx] = mod[idx]; 81 82 if (!techMods[mod.value]) 83 techMods[mod.value] = []; 84 techMods[mod.value].push(newModifier); 85 } 86 return techMods; 87 } 88 89 /** 47 90 * Returns whether the given modification applies to the entity containing the given class list 48 91 */ 49 92 function DoesModificationApply(modification, classes) -
binaries/data/mods/public/globalscripts/Templates.js
diff --git a/binaries/data/mods/public/globalscripts/Templates.js b/binaries/data/mods/public/globalscripts/Templates.js index db54ca469..4374e8041 100644
a b function GetTemplateDataHelper(template, player, auraTemplates, resources) 87 87 current_value = current_value[property] || 0; 88 88 current_value = +current_value; 89 89 90 if ( !player)91 return current_value;90 if (player) 91 return ApplyValueModificationsToTemplate(tech_type, current_value, player, template); 92 92 93 return ApplyValueModificationsToTemplate(tech_type, current_value, player, template); 93 if (typeof g_CurrentModifiers !== "undefined") 94 return GetTechModifiedProperty(g_CurrentModifiers, GetIdentityClasses(template.Identity), tech_type, current_value); 95 96 return current_value; 94 97 }; 95 98 96 99 let ret = {}; … … function GetTemplateDataHelper(template, player, auraTemplates, resources) 298 301 "generic": template.Identity.GenericName 299 302 }; 300 303 ret.icon = template.Identity.Icon; 301 ret.tooltip = 304 ret.tooltip = template.Identity.Tooltip; 302 305 ret.requiredTechnology = template.Identity.RequiredTechnology; 303 306 ret.visibleIdentityClasses = GetVisibleIdentityClasses(template.Identity); 304 307 } … … function GetTemplateDataHelper(template, player, auraTemplates, resources) 344 347 } 345 348 346 349 /** 347 * Get information about a technology template.350 * Get basic information about a technology template. 348 351 * @param template A valid template as obtained by loading the tech JSON file. 349 * @param civ Civilization for which the specific name should be returned.350 * @param resources An instance of the Resources prototype.351 352 */ 352 function GetTechnology DataHelper(template, civ, resources)353 function GetTechnologyBasicDataHelper(template, civ) 353 354 { 354 355 let ret = {}; 355 356 356 // Get specific name for this civ or else the generic specific name357 let specific;358 if (template.specificName)359 specific = template.specificName[civ] || template.specificName.generic;360 361 357 ret.name = { 362 "specific": specific,363 358 "generic": template.genericName, 364 359 }; 365 360 366 ret.icon = template.icon ? "technologies/" + template.icon : null; 361 if (template.icon) 362 ret.icon = "technologies/" + template.icon; 363 else 364 ret.icon = null; 365 366 ret.description = template.description; 367 ret.reqs = DeriveTechnologyRequirements(template, civ); 368 369 return ret; 370 } 371 372 /** 373 * Get information about a technology template. 374 * @param template A valid template as obtained by loading the tech JSON file. 375 * @param civ Civilization for which the specific name should be returned. 376 */ 377 function GetTechnologyDataHelper(template, civ, resources) 378 { 379 let ret = GetTechnologyBasicDataHelper(template, civ); 380 381 if (template.specificName) 382 ret.name.specific = template.specificName[civ] || template.specificName.generic; 367 383 368 384 ret.cost = { "time": template.researchTime ? +template.researchTime : 0 }; 369 385 for (let type of resources.GetCodes()) … … function GetTechnologyDataHelper(template, civ, resources) 372 388 ret.tooltip = template.tooltip; 373 389 ret.requirementsTooltip = template.requirementsTooltip || ""; 374 390 375 ret.reqs = DeriveTechnologyRequirements(template, civ);376 377 ret.description = template.description;378 379 391 return ret; 380 392 } 381 393 -
binaries/data/mods/public/gui/structree/helper.js
diff --git a/binaries/data/mods/public/gui/structree/helper.js b/binaries/data/mods/public/gui/structree/helper.js index da01b79e1..ca2c3dbb7 100644
a b function loadTechData(templateName) 24 24 { 25 25 if (!(templateName in g_TechnologyData)) 26 26 { 27 varfilename = "simulation/data/technologies/" + templateName + ".json";28 vardata = Engine.ReadJSONFile(filename);29 translateObjectKeys(data, ["genericName", "tooltip" ]);27 let filename = "simulation/data/technologies/" + templateName + ".json"; 28 let data = Engine.ReadJSONFile(filename); 29 translateObjectKeys(data, ["genericName", "tooltip", "description"]); 30 30 31 31 g_TechnologyData[templateName] = data; 32 32 } … … function loadAuraData(templateName) 48 48 return g_AuraData[templateName]; 49 49 } 50 50 51 function findAllAutoResearchedTechs() 52 { 53 let path = "simulation/data/technologies/"; 54 let techFiles = Engine.BuildDirEntList(path, "*.json", true); 55 let techList = []; 56 57 for (let filename of techFiles) 58 { 59 let templateName = filename.slice(path.length, -5); 60 let data = loadTechData(templateName); 61 62 if (!data || !data.autoResearch) 63 continue; 64 65 techList.push(templateName); 66 } 67 68 return techList; 69 } 70 71 function deriveCurrentModifications() 72 { 73 g_CurrentModifiers = {}; 74 for (let templateName of g_AutoResearchTechList) 75 { 76 let data = loadTechData(templateName); 77 let modifier = GetTechnologyBasicDataHelper(data, g_SelectedCiv); 78 79 if (!modifier.reqs) 80 continue; 81 82 modifier.modifications = data.modifications; 83 modifier.affects = data.affects; 84 85 let derivedModifiers = DeriveModificationsFromTech(modifier); 86 for (let modPath in derivedModifiers) 87 { 88 if (!g_CurrentModifiers[modPath]) 89 g_CurrentModifiers[modPath] = []; 90 g_CurrentModifiers[modPath] = g_CurrentModifiers[modPath].concat(derivedModifiers[modPath]); 91 } 92 } 93 } 94 51 95 /** 52 96 * This is needed because getEntityCostTooltip in tooltip.js needs to get 53 97 * the template data of the different wallSet pieces. In the session this -
binaries/data/mods/public/gui/structree/structree.js
diff --git a/binaries/data/mods/public/gui/structree/structree.js b/binaries/data/mods/public/gui/structree/structree.js index 20f20fdcb..a79f480e5 100644
a b var g_ParsedData = { 8 8 var g_Lists = {}; 9 9 var g_CivData = {}; 10 10 var g_SelectedCiv = ""; 11 var g_CurrentModifiers = {}; 11 12 var g_CallbackSet = false; 12 13 var g_ResourceData = new Resources(); 14 var g_AutoResearchTechList = []; 13 15 14 16 /** 15 17 * Initialize the dropdown containing all the available civs … … function init(data = {}) 26 28 if (!civList.length) 27 29 return; 28 30 31 g_AutoResearchTechList = findAllAutoResearchedTechs(); 32 29 33 var civSelection = Engine.GetGUIObjectByName("civSelection"); 30 34 civSelection.list = civList.map(c => c.name); 31 35 civSelection.list_data = civList.map(c => c.code); … … function selectCiv(civCode) 56 60 return; 57 61 } 58 62 63 deriveCurrentModifications(); 64 59 65 g_Lists = { 60 66 "units": [], 61 67 "structures": [], -
binaries/data/mods/public/simulation/components/TechnologyManager.js
diff --git a/binaries/data/mods/public/simulation/components/TechnologyManager.js b/binaries/data/mods/public/simulation/components/TechnologyManager.js index 33a372df6..356864313 100644
a b TechnologyManager.prototype.ResearchTechnology = function(tech) 270 270 // store the modifications in an easy to access structure 271 271 if (template.modifications) 272 272 { 273 var affects = [];274 if (template.affects && template.affects.length > 0)273 let derivedModifiers = DeriveModificationsFromTech(template); 274 for (let modifierPath in derivedModifiers) 275 275 { 276 for (let affect of template.affects) 277 { 278 // Put the list of classes into an array for convenient access 279 affects.push(affect.split(/\s+/)); 280 } 281 } 282 else 283 { 284 affects.push([]); 285 } 286 287 // We add an item to this.modifications for every modification in the template.modifications array 288 for (var i in template.modifications) 289 { 290 var modification = template.modifications[i]; 291 if (!this.modifications[modification.value]) 292 this.modifications[modification.value] = []; 293 294 var modAffects = affects.slice(); 295 if (modification.affects) 296 { 297 var extraAffects = modification.affects.split(/\s+/); 298 for (var a in modAffects) 299 modAffects[a] = modAffects[a].concat(extraAffects); 300 } 301 302 var mod = {"affects": modAffects}; 303 304 // copy the modification data into our new data structure 305 for (var j in modification) 306 if (j !== "value" && j !== "affects") 307 mod[j] = modification[j]; 276 if (!this.modifications[modifierPath]) 277 this.modifications[modifierPath] = []; 278 this.modifications[modifierPath] = this.modifications[modifierPath].concat(derivedModifiers[modifierPath]); 308 279 309 this.modifications[modification.value].push(mod); 310 var component = modification.value.split("/")[0]; 280 let component = modifierPath.split("/")[0]; 311 281 if (!modifiedComponents[component]) 312 282 modifiedComponents[component] = []; 313 modifiedComponents[component].push(modifi cation.value);314 this.modificationCache[modifi cation.value] = {};283 modifiedComponents[component].push(modifierPath); 284 this.modificationCache[modifierPath] = {}; 315 285 } 316 286 } 317 287