Differential D3347 Diff 17093 ps/trunk/binaries/data/mods/public/gui/reference/common/TemplateLoader.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/reference/common/TemplateLoader.js
Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Lines | deriveProductionQueue(template, civCode) | ||||
if (!template.ProductionQueue) | if (!template.ProductionQueue) | ||||
return production; | return production; | ||||
if (template.ProductionQueue.Entities && template.ProductionQueue.Entities._string) | if (template.ProductionQueue.Entities && template.ProductionQueue.Entities._string) | ||||
for (let templateName of template.ProductionQueue.Entities._string.split(" ")) | for (let templateName of template.ProductionQueue.Entities._string.split(" ")) | ||||
{ | { | ||||
templateName = templateName.replace(/\{(civ|native)\}/g, civCode); | templateName = templateName.replace(/\{(civ|native)\}/g, civCode); | ||||
if (Engine.TemplateExists(templateName)) | if (Engine.TemplateExists(templateName)) | ||||
production.units.push(this.getBaseTemplateName(templateName, civCode)); | production.units.push(templateName); | ||||
} | } | ||||
let appendTechnology = (technologyName) => { | let appendTechnology = (technologyName) => { | ||||
let technology = this.loadTechnologyTemplate(technologyName, civCode); | let technology = this.loadTechnologyTemplate(technologyName, civCode); | ||||
if (DeriveTechnologyRequirements(technology, civCode)) | if (DeriveTechnologyRequirements(technology, civCode)) | ||||
production.techs.push(technologyName); | production.techs.push(technologyName); | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | for (let templateName of listFiles(path, ".json", true)) | ||||
continue; | continue; | ||||
auraList.push(filename); | auraList.push(filename); | ||||
} | } | ||||
return auraList; | return auraList; | ||||
} | } | ||||
/** | /** | ||||
* Returns the name of a template's base form (without `_house`, `_trireme`, or similar), | * A template may be a variant of another template, | ||||
* or the template's own name if the base is of a different promotion rank. | * eg. `*_house`, `*_trireme`, or a promotion. | ||||
* | |||||
* This method returns an array containing: | |||||
* [0] - The template's basename | |||||
* [1] - The variant type | |||||
* [2] - Further information (if available) | |||||
* | |||||
* e.g.: | |||||
* units/athen/infantry_swordsman_e | |||||
* -> ["units/athen/infantry_swordsman_b", TemplateVariant.promotion, "elite"] | |||||
* | |||||
* units/brit/support_female_citizen_house | |||||
* -> ["units/brit/support_female_citizen", TemplateVariant.unlockedByTechnology, "unlock_female_house"] | |||||
*/ | */ | ||||
getBaseTemplateName(templateName, civCode) | getVariantBaseAndType(templateName, civCode) | ||||
{ | { | ||||
if (!templateName || !Engine.TemplateExists(templateName)) | if (!templateName || !Engine.TemplateExists(templateName)) | ||||
return undefined; | return undefined; | ||||
templateName = removeFiltersFromTemplateName(templateName); | templateName = removeFiltersFromTemplateName(templateName); | ||||
let template = this.loadEntityTemplate(templateName, civCode); | let template = this.loadEntityTemplate(templateName, civCode); | ||||
if (!dirname(templateName) || dirname(template["@parent"]) != dirname(templateName)) | if (!dirname(templateName) || dirname(template["@parent"]) != dirname(templateName)) | ||||
return templateName; | return [templateName, TemplateVariant.base]; | ||||
let parentTemplate = this.loadEntityTemplate(template["@parent"], civCode); | let parentTemplate = this.loadEntityTemplate(template["@parent"], civCode); | ||||
let inheritedVariance = this.getVariantBaseAndType(template["@parent"], civCode); | |||||
if (parentTemplate.Identity && ( | if (parentTemplate.Identity) | ||||
parentTemplate.Identity.Civ && parentTemplate.Identity.Civ != template.Identity.Civ || | { | ||||
parentTemplate.Identity.Rank && parentTemplate.Identity.Rank != template.Identity.Rank | if (parentTemplate.Identity.Civ && parentTemplate.Identity.Civ != template.Identity.Civ) | ||||
)) | return [templateName, TemplateVariant.base]; | ||||
return templateName; | |||||
if (!parentTemplate.Cost) | if (parentTemplate.Identity.Rank && parentTemplate.Identity.Rank != template.Identity.Rank) | ||||
return templateName; | return [inheritedVariance[0], TemplateVariant.promotion, template.Identity.Rank.toLowerCase()]; | ||||
} | |||||
if (parentTemplate.Upgrade) | if (parentTemplate.Upgrade) | ||||
for (let upgrade in parentTemplate.Upgrade) | for (let upgrade in parentTemplate.Upgrade) | ||||
if (parentTemplate.Upgrade[upgrade].Entity) | if (parentTemplate.Upgrade[upgrade].Entity) | ||||
return templateName; | return [inheritedVariance[0], TemplateVariant.upgrade, upgrade.toLowerCase()]; | ||||
if (template.Identity.RequiredTechnology) | |||||
return [inheritedVariance[0], TemplateVariant.unlockedByTechnology, template.Identity.RequiredTechnology]; | |||||
if (parentTemplate.Cost) | |||||
for (let res in parentTemplate.Cost.Resources) | for (let res in parentTemplate.Cost.Resources) | ||||
if (+parentTemplate.Cost.Resources[res]) | if (+parentTemplate.Cost.Resources[res]) | ||||
return this.getBaseTemplateName(template["@parent"], civCode); | return [inheritedVariance[0], TemplateVariant.trainable]; | ||||
return templateName; | warn("Template variance unknown: " + templateName); | ||||
return [templateName, TemplateVariant.unknown]; | |||||
} | } | ||||
isPairTech(technologyCode) | isPairTech(technologyCode) | ||||
{ | { | ||||
return !!this.loadTechnologyTemplate(technologyCode).top; | return !!this.loadTechnologyTemplate(technologyCode).top; | ||||
} | } | ||||
isPhaseTech(technologyCode) | isPhaseTech(technologyCode) | ||||
Show All 23 Lines |
Wildfire Games · Phabricator