Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/reference/common/load.js
Show All 30 Lines | |||||
* @return {object} Object containing raw template data. | * @return {object} Object containing raw template data. | ||||
*/ | */ | ||||
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. | ||||
let data = clone(Engine.GetTemplate(templateName)); | let data = clone(Engine.GetTemplate(templateName)); | ||||
translateObjectKeys(data, ["GenericName", "SpecificName", "Tooltip"]); | translateObjectKeys(data, ["GenericName", "SpecificName", "Tooltip", "History"]); | ||||
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); | ||||
if (data.Identity.Civ != "gaia" && g_SelectedCiv != "gaia" && data.Identity.Civ != g_SelectedCiv) | |||||
elexis: first or second condition redundant with the third. | |||||
s0600204AuthorUnsubmitted Not Done Inline ActionsHow so? (It is possible I'm missing something) If the first argument is removed, the following warning will display for sheep and palisade walls. If the second argument is removed, the following warning will display on viewer page init before g_SelectedCiv has had a chance to be set to anything but its default. If the third argument is removed, we get a warning for every single template loaded. For any of these cases, we shouldn't give a warning. s0600204: How so? (It is possible I'm missing something)
If the first argument is removed, the following… | |||||
warn("The \"" + templateName + "\" template has a defined civ of \"" + data.Identity.Civ + "\". " + | |||||
"This does not match the currently selected civ \"" + g_SelectedCiv + "\"."); | |||||
Done Inline ActionsThe warning targets coders and modders, so internally defined not needed and better use the template identifier name. Perhaps it could be shortened. elexis: The warning targets coders and modders, so `internally defined` not needed and better use the… | |||||
g_TemplateData[templateName] = data; | g_TemplateData[templateName] = data; | ||||
} | } | ||||
return g_TemplateData[templateName]; | return g_TemplateData[templateName]; | ||||
} | } | ||||
/** | /** | ||||
* Loads raw technology template. | * Loads raw technology template. | ||||
* | * | ||||
* Loads from local cache if available, else from file system. | * Loads from local cache if available, else from file system. | ||||
* | * | ||||
* @param {string} templateName | * @param {string} templateName | ||||
* @return {object} Object containing raw template data. | * @return {object} Object containing raw template data. | ||||
*/ | */ | ||||
function loadTechData(templateName) | function loadTechData(templateName) | ||||
{ | { | ||||
if (!(templateName in g_TechnologyData)) | if (!(templateName in g_TechnologyData)) | ||||
{ | { | ||||
let data = Engine.ReadJSONFile(g_TechnologyPath + templateName + ".json"); | let data = Engine.ReadJSONFile(g_TechnologyPath + templateName + ".json"); | ||||
translateObjectKeys(data, ["genericName", "tooltip"]); | translateObjectKeys(data, ["genericName", "tooltip", "description"]); | ||||
g_TechnologyData[templateName] = data; | g_TechnologyData[templateName] = data; | ||||
} | } | ||||
return g_TechnologyData[templateName]; | return g_TechnologyData[templateName]; | ||||
} | } | ||||
function techDataExists(templateName) | function techDataExists(templateName) | ||||
Show All 23 Lines | |||||
} | } | ||||
/** | /** | ||||
* Load and parse unit from entity template. | * Load and parse unit from entity template. | ||||
* | * | ||||
* @param {string} templateName | * @param {string} templateName | ||||
* @return Sanitized object about the requested unit or null if entity template doesn't exist. | * @return Sanitized object about the requested unit or null if entity template doesn't exist. | ||||
*/ | */ | ||||
function loadUnit(templateName) | function loadUnit(templateName) | ||||
Done Inline Actionsbad space elexis: bad space | |||||
{ | { | ||||
if (!Engine.TemplateExists(templateName)) | if (!Engine.TemplateExists(templateName)) | ||||
return null; | return null; | ||||
let template = loadTemplate(templateName); | let template = loadTemplate(templateName); | ||||
let unit = GetTemplateDataHelper(template, null, g_AuraData, g_ResourceData, g_DamageTypes, g_CurrentModifiers); | let unit = GetTemplateDataHelper(template, null, g_AuraData, g_ResourceData, g_DamageTypes, g_CurrentModifiers); | ||||
unit.name.internal = templateName; | |||||
unit.history = template.Identity.History; | |||||
if (template.ProductionQueue) | if (template.ProductionQueue) | ||||
{ | { | ||||
unit.production = {}; | unit.production = {}; | ||||
if (template.ProductionQueue.Entities) | if (template.ProductionQueue.Entities) | ||||
{ | { | ||||
unit.production.units = []; | unit.production.units = []; | ||||
for (let build of template.ProductionQueue.Entities._string.split(" ")) | for (let build of template.ProductionQueue.Entities._string.split(" ")) | ||||
Show All 18 Lines | if (template.ProductionQueue.Technologies) | ||||
for (let tech of loadTechnologyPair(research).techs) | for (let tech of loadTechnologyPair(research).techs) | ||||
unit.production.techs.push(tech); | unit.production.techs.push(tech); | ||||
else | else | ||||
unit.production.techs.push(research); | unit.production.techs.push(research); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (template.Identity.Rank) | |||||
unit.promotion = { | |||||
"current_rank": template.Identity.Rank, | |||||
"entity": template.Promotion && template.Promotion.Entity | |||||
Done Inline Actionsunneeded parentheses. elexis: unneeded parentheses.
Possibly `template.Promotion && template.Promotion.Entity` if `undefined`… | |||||
}; | |||||
if (template.Builder && template.Builder.Entities._string) | if (template.Builder && template.Builder.Entities._string) | ||||
{ | { | ||||
unit.builder = []; | unit.builder = []; | ||||
for (let build of template.Builder.Entities._string.split(" ")) | for (let build of template.Builder.Entities._string.split(" ")) | ||||
{ | { | ||||
build = build.replace(/\{(civ|native)\}/g, g_SelectedCiv); | build = build.replace(/\{(civ|native)\}/g, g_SelectedCiv); | ||||
if (Engine.TemplateExists(build)) | if (Engine.TemplateExists(build)) | ||||
unit.builder.push(build); | unit.builder.push(build); | ||||
} | } | ||||
} | } | ||||
if (unit.upgrades) | if (unit.upgrades) | ||||
unit.upgrades = getActualUpgradeData(unit.upgrades); | unit.upgrades = getActualUpgradeData(unit.upgrades); | ||||
if (template.ResourceSupply) | |||||
unit.supply = { | |||||
"type": template.ResourceSupply.Type.split("."), | |||||
"amount": template.ResourceSupply.Amount, | |||||
}; | |||||
return unit; | return unit; | ||||
} | } | ||||
/** | /** | ||||
* Load and parse structure from entity template. | * Load and parse structure from entity template. | ||||
* | * | ||||
* @param {string} templateName | * @param {string} templateName | ||||
* @return {object} Sanitized data about the requested structure or null if entity template doesn't exist. | * @return {object} Sanitized data about the requested structure or null if entity template doesn't exist. | ||||
*/ | */ | ||||
function loadStructure(templateName) | function loadStructure(templateName) | ||||
{ | { | ||||
if (!Engine.TemplateExists(templateName)) | if (!Engine.TemplateExists(templateName)) | ||||
return null; | return null; | ||||
let template = loadTemplate(templateName); | let template = loadTemplate(templateName); | ||||
let structure = GetTemplateDataHelper(template, null, g_AuraData, g_ResourceData, g_DamageTypes, g_CurrentModifiers); | let structure = GetTemplateDataHelper(template, null, g_AuraData, g_ResourceData, g_DamageTypes, g_CurrentModifiers); | ||||
structure.name.internal = templateName; | |||||
structure.history = template.Identity.History; | |||||
structure.production = { | structure.production = { | ||||
"technology": [], | "technology": [], | ||||
"units": [] | "units": [] | ||||
}; | }; | ||||
if (template.ProductionQueue) | if (template.ProductionQueue) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | if (health.min == health.max) | ||||
structure.health = health.min; | structure.health = health.min; | ||||
else | else | ||||
structure.health = sprintf(translate("%(health_min)s to %(health_max)s"), { | structure.health = sprintf(translate("%(health_min)s to %(health_max)s"), { | ||||
"health_min": health.min, | "health_min": health.min, | ||||
"health_max": health.max | "health_max": health.max | ||||
}); | }); | ||||
} | } | ||||
if (template.ResourceSupply) | |||||
structure.supply = { | |||||
"type": template.ResourceSupply.Type.split("."), | |||||
"amount": template.ResourceSupply.Amount, | |||||
}; | |||||
return structure; | return structure; | ||||
} | } | ||||
function loadResource(templateName) | |||||
{ | |||||
let template = loadTemplate(templateName); | |||||
let resource = GetTemplateDataHelper(template, null, g_AuraData, g_ResourceData, g_DamageTypes, g_CurrentModifiers); | |||||
resource.name.internal = templateName; | |||||
resource.history = template.Identity.History; | |||||
resource.supply = { | |||||
"type": template.ResourceSupply.Type.split("."), | |||||
"amount": template.ResourceSupply.Amount, | |||||
}; | |||||
return resource; | |||||
} | |||||
/** | /** | ||||
* Load and parse technology from json template. | * Load and parse technology from json template. | ||||
* | * | ||||
* @param {string} templateName | * @param {string} templateName | ||||
* @return {object} Sanitized data about the requested technology. | * @return {object} Sanitized data about the requested technology. | ||||
*/ | */ | ||||
function loadTechnology(techName) | function loadTechnology(techName) | ||||
{ | { | ||||
let template = loadTechData(techName); | let template = loadTechData(techName); | ||||
let tech = GetTechnologyDataHelper(template, g_SelectedCiv, g_ResourceData); | let tech = GetTechnologyDataHelper(template, g_SelectedCiv, g_ResourceData); | ||||
tech.name.internal = "tech/" + techName; | |||||
if (template.pair !== undefined) | if (template.pair !== undefined) | ||||
{ | { | ||||
tech.pair = template.pair; | tech.pair = template.pair; | ||||
tech.reqs = mergeRequirements(tech.reqs, loadTechnologyPair(template.pair).reqs); | tech.reqs = mergeRequirements(tech.reqs, loadTechnologyPair(template.pair).reqs); | ||||
} | } | ||||
return tech; | return tech; | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
first or second condition redundant with the third.