Ticket #3747: 3747_alternate_v1-1.patch
File 3747_alternate_v1-1.patch, 9.4 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 b6783e2..e00fa4e 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 e50cbe4..da25a23 100644
a b function GetTemplateDataHelper(template, player, auraTemplates) 79 79 var func; 80 80 if (player) 81 81 func = ApplyValueModificationsToTemplate; 82 else if (g_CurrentModifiers) 83 func = function(property, val, c, template) { 84 return GetTechModifiedProperty(g_CurrentModifiers, GetIdentityClasses(template.Identity), property, val); 85 } 82 86 else 83 87 func = function(a, val, c, d) { return val; } 84 88 … … function GetTemplateDataHelper(template, player, auraTemplates) 283 287 } 284 288 285 289 /** 286 * Get information about a technology template.290 * Get basic information about a technology template. 287 291 * @param template A valid template as obtained by loading the tech JSON file. 288 * @param civ Civilization for which the specific name should be returned.289 292 */ 290 function GetTechnology DataHelper(template, civ)293 function GetTechnologyBasicDataHelper(template) 291 294 { 292 var ret = {}; 293 294 // Get specific name for this civ or else the generic specific name 295 var specific = undefined; 296 if (template.specificName) 297 { 298 if (template.specificName[civ]) 299 specific = template.specificName[civ]; 300 else 301 specific = template.specificName['generic']; 302 } 295 let ret = {}; 303 296 304 297 ret.name = { 305 "specific": specific,306 298 "generic": template.genericName, 307 299 }; 308 300 … … function GetTechnologyDataHelper(template, civ) 310 302 ret.icon = "technologies/" + template.icon; 311 303 else 312 304 ret.icon = null; 305 306 ret.description = template.description; 307 308 return ret; 309 } 310 311 /** 312 * Get information about a technology template. 313 * @param template A valid template as obtained by loading the tech JSON file. 314 * @param civ Civilization for which the specific name should be returned. 315 */ 316 function GetTechnologyDataHelper(template, civ) 317 { 318 let ret = GetTechnologyBasicDataHelper(template); 319 320 if (template.specificName) 321 ret.name.specific = template.specificName[civ] || template.specificName['generic']; 322 313 323 ret.cost = { 314 324 "food": template.cost ? (+template.cost.food) : 0, 315 325 "wood": template.cost ? (+template.cost.wood) : 0, … … function GetTechnologyDataHelper(template, civ) 327 337 if (template.requirements && template.requirements.class) 328 338 ret.classRequirements = {"class": template.requirements.class, "number": template.requirements.number}; 329 339 330 ret.description = template.description;331 332 340 return ret; 333 341 } -
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 8eb8bd3..e0edaa6 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 if (data.requirements !== undefined) 70 { 71 let op = Object.keys(data.requirements)[0]; 72 let val = data.requirements[op]; 73 tech.reqs = calcReqs(op, val); 74 } 75 76 g_ParsedData.modifiers[templateName] = tech; 77 } 78 } 79 51 80 /** 52 81 * Fetch a value from an entity's template 53 82 * -
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 f1f9cc7..ad8ff00 100644
a b TechnologyManager.prototype.ResearchTechnology = function(tech) 267 267 // store the modifications in an easy to access structure 268 268 if (template.modifications) 269 269 { 270 var affects = [];271 if (template.affects && template.affects.length > 0)270 let derivedModifiers = DeriveModificationsFromTech(template); 271 for (let modifierPath in derivedModifiers) 272 272 { 273 for (let affect of template.affects) 274 { 275 // Put the list of classes into an array for convenient access 276 affects.push(affect.split(/\s+/)); 277 } 278 } 279 else 280 { 281 affects.push([]); 282 } 283 284 // We add an item to this.modifications for every modification in the template.modifications array 285 for (var i in template.modifications) 286 { 287 var modification = template.modifications[i]; 288 if (!this.modifications[modification.value]) 289 this.modifications[modification.value] = []; 290 291 var modAffects = affects.slice(); 292 if (modification.affects) 293 { 294 var extraAffects = modification.affects.split(/\s+/); 295 for (var a in modAffects) 296 modAffects[a] = modAffects[a].concat(extraAffects); 297 } 298 299 var mod = {"affects": modAffects}; 300 301 // copy the modification data into our new data structure 302 for (var j in modification) 303 if (j !== "value" && j !== "affects") 304 mod[j] = modification[j]; 273 if (!this.modifications[modifierPath]) 274 this.modifications[modifierPath] = []; 275 this.modifications[modifierPath] = this.modifications[modifierPath].concat(derivedModifiers[modifierPath]); 305 276 306 this.modifications[modification.value].push(mod); 307 var component = modification.value.split("/")[0]; 277 let component = modifierPath.split("/")[0]; 308 278 if (!modifiedComponents[component]) 309 279 modifiedComponents[component] = []; 310 modifiedComponents[component].push(modifi cation.value);311 this.modificationCache[modifi cation.value] = {};280 modifiedComponents[component].push(modifierPath); 281 this.modificationCache[modifierPath] = {}; 312 282 } 313 283 } 314 284