Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/globalscripts/Templates.js
/** | /** | ||||
* Loads history and gameplay data of all civs. | * Loads history and gameplay data of all civs. | ||||
* | * | ||||
* @param selectableOnly {boolean} - Only load civs that can be selected | * @param selectableOnly {boolean} - Only load civs that can be selected | ||||
* in the gamesetup. Scenario maps might set non-selectable civs. | * in the gamesetup. Scenario maps might set non-selectable civs. | ||||
*/ | */ | ||||
function loadCivFiles(selectableOnly) | function loadCivFiles(selectableOnly) | ||||
{ | { | ||||
let propertyNames = [ | let propertyNames = [ | ||||
"Code", "Culture", "Name", "Emblem", "History", "Music", "Factions", "CivBonuses", "TeamBonuses", | "Code", "Culture", "Name", "Emblem", "History", "Music", "Factions", "CivBonuses", "TeamBonuses", | ||||
"Structures", "StartEntities", "Formations", "AINames", "SkirmishReplacements", "SelectableInGameSetup"]; | "Structures", "StartEntities", "Formations", "AINames", "SkirmishReplacements", "SelectableInGameSetup"]; | ||||
Stan: I didn't manage to get it work, can you try whether it works for you ? | |||||
let civData = {}; | let civData = {}; | ||||
for (let filename of Engine.ListDirectoryFiles("simulation/data/civs/", "*.json", false)) | for (let filename of Engine.ListDirectoryFiles("simulation/data/civs/", "*.json", false)) | ||||
{ | { | ||||
let data = Engine.ReadJSONFile(filename); | let data = Engine.ReadJSONFile(filename); | ||||
for (let prop of propertyNames) | for (let prop of propertyNames) | ||||
▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Lines | let getAttackEffects = (temp, path) => { | ||||
if (temp.Damage) | if (temp.Damage) | ||||
{ | { | ||||
effects.Damage = {}; | effects.Damage = {}; | ||||
for (let damageType in temp.Damage) | for (let damageType in temp.Damage) | ||||
effects.Damage[damageType] = getEntityValue(path + "/Damage/" + damageType); | effects.Damage[damageType] = getEntityValue(path + "/Damage/" + damageType); | ||||
} | } | ||||
if (temp.Bonuses) | |||||
{ | |||||
effects.Bonuses = {}; | |||||
for (let bonus in temp.Bonuses) | |||||
{ | |||||
effects.Bonuses[bonus] = { | |||||
"classes": temp.Bonuses[bonus].Classes, | |||||
"multiplier": getEntityValue(path + "/Bonuses/" + bonus + "/Multiplier").toFixed(8) | |||||
}; | |||||
} | |||||
} | |||||
// TODO: status effects | // TODO: status effects | ||||
return effects; | return effects; | ||||
}; | }; | ||||
if (template.Attack) | if (template.Attack) | ||||
{ | { | ||||
ret.attack = {}; | ret.attack = {}; | ||||
for (let type in template.Attack) | for (let type in template.Attack) | ||||
{ | { | ||||
let getAttackStat = function(stat) { | let getAttackStat = function(stat) { | ||||
return getEntityValue("Attack/" + type + "/" + stat); | return getEntityValue("Attack/" + type + "/" + stat); | ||||
}; | }; | ||||
ret.attack[type] = { | ret.attack[type] = { | ||||
"minRange": getAttackStat("MinRange"), | "minRange": getAttackStat("MinRange"), | ||||
"maxRange": getAttackStat("MaxRange"), | "maxRange": getAttackStat("MaxRange"), | ||||
"elevationBonus": getAttackStat("ElevationBonus"), | "elevationBonus": getAttackStat("ElevationBonus"), | ||||
}; | }; | ||||
ret.attack[type].elevationAdaptedRange = Math.sqrt(ret.attack[type].maxRange * | ret.attack[type].elevationAdaptedRange = Math.sqrt(ret.attack[type].maxRange * | ||||
(2 * ret.attack[type].elevationBonus + ret.attack[type].maxRange)); | (2 * ret.attack[type].elevationBonus + ret.attack[type].maxRange)); | ||||
ret.attack[type].repeatTime = getAttackStat("RepeatTime"); | ret.attack[type].repeatTime = getAttackStat("RepeatTime"); | ||||
Done Inline Actions{} can be removed since it contains only one statement elexis: {} can be removed since it contains only one statement
still mising semicolon x = y; (check… | |||||
Object.assign(ret.attack[type], getAttackEffects(template.Attack[type], "Attack/" + type)); | Object.assign(ret.attack[type], getAttackEffects(template.Attack[type], "Attack/" + type)); | ||||
if (template.Attack[type].Splash) | if (template.Attack[type].Splash) | ||||
{ | { | ||||
ret.attack[type].splash = { | ret.attack[type].splash = { | ||||
// true if undefined | // true if undefined | ||||
"friendlyFire": template.Attack[type].Splash.FriendlyFire != "false", | "friendlyFire": template.Attack[type].Splash.FriendlyFire != "false", | ||||
"shape": template.Attack[type].Splash.Shape, | "shape": template.Attack[type].Splash.Shape, | ||||
}; | }; | ||||
Object.assign(ret.attack[type].splash, getAttackEffects(template.Attack[type].Splash, "Attack/" + type + "/Splash")); | Object.assign(ret.attack[type].splash, getAttackEffects(template.Attack[type].Splash, "Attack/" + type + "/Splash")); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (template.DeathDamage) | if (template.DeathDamage) | ||||
{ | { | ||||
ret.deathDamage = { | ret.deathDamage = { | ||||
"friendlyFire": template.DeathDamage.FriendlyFire != "false", | "friendlyFire": template.DeathDamage.FriendlyFire != "false", | ||||
}; | }; | ||||
Done Inline Actions.toFixed(x) perhaps? If upgrading of bunuses will be introduced. Freagarach: .toFixed(x) perhaps? If upgrading of bunuses will be introduced. | |||||
Done Inline Actions.toFixed(8) like used below. Stan: .toFixed(8) like used below. | |||||
Object.assign(ret.deathDamage, getAttackEffects(template.DeathDamage, "DeathDamage")); | Object.assign(ret.deathDamage, getAttackEffects(template.DeathDamage, "DeathDamage")); | ||||
} | } | ||||
if (template.Auras && auraTemplates) | if (template.Auras && auraTemplates) | ||||
{ | { | ||||
ret.auras = {}; | ret.auras = {}; | ||||
for (let auraID of template.Auras._string.split(/\s+/)) | for (let auraID of template.Auras._string.split(/\s+/)) | ||||
▲ Show 20 Lines • Show All 316 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
I didn't manage to get it work, can you try whether it works for you ?