Ticket #3747: 3747_alternate_v2.patch
File 3747_alternate_v2.patch, 9.5 KB (added by , 8 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 ce75e28..4cf0b42 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 8f76311..e0a936c 100644
a b function GetTemplateDataHelper(template, player, auraTemplates) 86 86 current_value = current_value[property] || 0; 87 87 current_value = +current_value; 88 88 89 if ( !player)90 return current_value;89 if (player) 90 return ApplyValueModificationsToTemplate(tech_type, current_value, player, template); 91 91 92 return ApplyValueModificationsToTemplate(tech_type, current_value, player, template); 92 if (typeof g_CurrentModifiers !== "undefined") 93 return GetTechModifiedProperty(g_CurrentModifiers, GetIdentityClasses(template.Identity), tech_type, current_value); 94 95 return current_value; 93 96 }; 94 97 95 98 let ret = {}; … … function GetTemplateDataHelper(template, player, auraTemplates) 335 338 } 336 339 337 340 /** 338 * Get information about a technology template.341 * Get basic information about a technology template. 339 342 * @param template A valid template as obtained by loading the tech JSON file. 340 * @param civ Civilization for which the specific name should be returned.341 343 */ 342 function GetTechnology DataHelper(template, civ)344 function GetTechnologyBasicDataHelper(template) 343 345 { 344 var ret = {}; 345 346 // Get specific name for this civ or else the generic specific name 347 var specific; 348 if (template.specificName) 349 { 350 if (template.specificName[civ]) 351 specific = template.specificName[civ]; 352 else 353 specific = template.specificName['generic']; 354 } 346 let ret = {}; 355 347 356 348 ret.name = { 357 "specific": specific,358 349 "generic": template.genericName, 359 350 }; 360 351 361 ret.icon = template.icon ? "technologies/" + template.icon : null; 352 if (template.icon) 353 ret.icon = "technologies/" + template.icon; 354 else 355 ret.icon = null; 356 357 ret.description = template.description; 358 ret.reqs = DeriveTechnologyRequirements(template); 359 360 return ret; 361 } 362 363 /** 364 * Get information about a technology template. 365 * @param template A valid template as obtained by loading the tech JSON file. 366 * @param civ Civilization for which the specific name should be returned. 367 */ 368 function GetTechnologyDataHelper(template, civ) 369 { 370 let ret = GetTechnologyBasicDataHelper(template); 371 372 if (template.specificName) 373 ret.name.specific = template.specificName[civ] || template.specificName.generic; 362 374 363 375 ret.cost = { 364 376 "food": template.cost ? +template.cost.food : 0, … … function GetTechnologyDataHelper(template, civ) 371 383 ret.tooltip = template.tooltip; 372 384 ret.requirementsTooltip = template.requirementsTooltip || ""; 373 385 374 ret.reqs = DeriveTechnologyRequirements(template);375 376 ret.description = template.description;377 378 386 return ret; 379 387 } -
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 7d2f706..bc7180f 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" ]);30 27 let filename = "simulation/data/technologies/" + templateName + ".json"; 28 let data = Engine.ReadJSONFile(filename); 29 translateObjectKeys(data, ["genericName", "tooltip", "description"]); 30 31 31 g_TechnologyData[templateName] = data; 32 32 } 33 33 … … function loadAuraData(templateName) 48 48 return g_AuraData[templateName]; 49 49 } 50 50 51 function loadAllAutoResearchedTechs() 52 { 53 let path = "simulation/data/technologies/"; 54 let techFiles = Engine.BuildDirEntList(path, "*.json", true); 55 56 for (let filename of techFiles) 57 { 58 let templateName = filename.slice(path.length, -5); 59 let data = loadTechData(templateName); 60 61 if (!data || !data.autoResearch) 62 continue; 63 64 let tech = GetTechnologyBasicDataHelper(data); 65 66 tech.modifications = data.modifications; 67 tech.affects = data.affects; 68 69 g_ParsedData.modifiers[templateName] = tech; 70 } 71 } 72 51 73 /** 52 74 * Fetch a value from an entity's template 53 75 * -
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 1415022..509ffce 100644
a b var g_ParsedData = { 2 2 "units": {}, 3 3 "structures": {}, 4 4 "techs": {}, 5 "phases": {} 5 "phases": {}, 6 "modifiers": {} 6 7 }; 7 8 8 9 var g_Lists = {}; 9 10 var g_CivData = {}; 10 11 var g_SelectedCiv = ""; 12 var g_CurrentModifiers = {}; 11 13 var g_CallbackSet = false; 12 14 13 15 /** … … function init(data = {}) 25 27 if (!civList.length) 26 28 return; 27 29 30 loadAllAutoResearchedTechs(); 31 28 32 var civSelection = Engine.GetGUIObjectByName("civSelection"); 29 33 civSelection.list = civList.map(c => c.name); 30 34 civSelection.list_data = civList.map(c => c.code); … … function selectCiv(civCode) 55 59 return; 56 60 } 57 61 62 // Derive modifications 63 g_CurrentModifiers = {}; 64 for (let modifier in g_ParsedData.modifiers) 65 { 66 modifier = g_ParsedData.modifiers[modifier]; 67 if (modifier.reqs && !modifier.reqs[g_SelectedCiv]) 68 continue; 69 70 let derivedModifiers = DeriveModificationsFromTech(modifier); 71 for (let modPath in derivedModifiers) 72 { 73 if (!g_CurrentModifiers[modPath]) 74 g_CurrentModifiers[modPath] = []; 75 g_CurrentModifiers[modPath] = g_CurrentModifiers[modPath].concat(derivedModifiers[modPath]); 76 } 77 } 78 58 79 g_Lists = { 59 80 "units": [], 60 81 "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 610e3bc..f190ee9 100644
a b TechnologyManager.prototype.ResearchTechnology = function(tech) 264 264 // store the modifications in an easy to access structure 265 265 if (template.modifications) 266 266 { 267 var affects = [];268 if (template.affects && template.affects.length > 0)267 let derivedModifiers = DeriveModificationsFromTech(template); 268 for (let modifierPath in derivedModifiers) 269 269 { 270 for (let affect of template.affects) 271 { 272 // Put the list of classes into an array for convenient access 273 affects.push(affect.split(/\s+/)); 274 } 275 } 276 else 277 { 278 affects.push([]); 279 } 280 281 // We add an item to this.modifications for every modification in the template.modifications array 282 for (var i in template.modifications) 283 { 284 var modification = template.modifications[i]; 285 if (!this.modifications[modification.value]) 286 this.modifications[modification.value] = []; 287 288 var modAffects = affects.slice(); 289 if (modification.affects) 290 { 291 var extraAffects = modification.affects.split(/\s+/); 292 for (var a in modAffects) 293 modAffects[a] = modAffects[a].concat(extraAffects); 294 } 295 296 var mod = {"affects": modAffects}; 297 298 // copy the modification data into our new data structure 299 for (var j in modification) 300 if (j !== "value" && j !== "affects") 301 mod[j] = modification[j]; 270 if (!this.modifications[modifierPath]) 271 this.modifications[modifierPath] = []; 272 this.modifications[modifierPath] = this.modifications[modifierPath].concat(derivedModifiers[modifierPath]); 302 273 303 this.modifications[modification.value].push(mod); 304 var component = modification.value.split("/")[0]; 274 let component = modifierPath.split("/")[0]; 305 275 if (!modifiedComponents[component]) 306 276 modifiedComponents[component] = []; 307 modifiedComponents[component].push(modifi cation.value);308 this.modificationCache[modifi cation.value] = {};277 modifiedComponents[component].push(modifierPath); 278 this.modificationCache[modifierPath] = {}; 309 279 } 310 280 } 311 281