Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/reference/common/core.js
Show First 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | |||||
* a named unit template. | * a named unit template. | ||||
* | * | ||||
* @param {string} templateName | * @param {string} templateName | ||||
*/ | */ | ||||
function getTemplateListsFromUnit(templateName) | function getTemplateListsFromUnit(templateName) | ||||
{ | { | ||||
if (!templateName || !Engine.TemplateExists(templateName)) | if (!templateName || !Engine.TemplateExists(templateName)) | ||||
return {}; | return {}; | ||||
let template = loadTemplate(templateName); | let template = loadTemplate(templateName); | ||||
let templateLists = { | let templateLists = loadProductionQueue(template); | ||||
"structures": [], | |||||
"units": [], | |||||
"techs": [] | |||||
}; | |||||
templateLists.structures = []; | |||||
if (template.Builder && template.Builder.Entities._string) | if (template.Builder && template.Builder.Entities._string) | ||||
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) && templateLists.structures.indexOf(build) === -1) | if (Engine.TemplateExists(build) && templateLists.structures.indexOf(build) === -1) | ||||
templateLists.structures.push(build); | templateLists.structures.push(build); | ||||
} | } | ||||
if (template.ProductionQueue) | |||||
{ | |||||
if (template.ProductionQueue.Entities) | |||||
for (let build of template.ProductionQueue.Entities._string.split(" ")) | |||||
{ | |||||
build = build.replace(/\{(civ|native)\}/g, g_SelectedCiv); | |||||
if (Engine.TemplateExists(build) && templateLists.units.indexOf(build) === -1) | |||||
templateLists.units.push(build); | |||||
} | |||||
if (template.ProductionQueue.Technologies) | |||||
for (let research of template.ProductionQueue.Technologies._string.split(" ")) | |||||
{ | |||||
if (research.indexOf("{civ}") != -1) | |||||
{ | |||||
let civResearch = research.replace("{civ}", g_SelectedCiv); | |||||
research = techDataExists(civResearch) ? | |||||
civResearch : research.replace("{civ}", "generic"); | |||||
} | |||||
if (templateLists.techs.indexOf(research) === -1) | |||||
templateLists.techs.push(research); | |||||
} | |||||
} | |||||
return templateLists; | return templateLists; | ||||
} | } | ||||
/** | /** | ||||
* Compiles lists of buildable or researchable entities from a named | * Compiles lists of buildable or researchable entities from a named | ||||
* structure template. | * structure template. | ||||
* | * | ||||
* @param {string} templateName | * @param {string} templateName | ||||
*/ | */ | ||||
function getTemplateListsFromStructure(templateName) | function getTemplateListsFromStructure(templateName) | ||||
{ | { | ||||
if (!templateName || !Engine.TemplateExists(templateName)) | if (!templateName || !Engine.TemplateExists(templateName)) | ||||
return {}; | return {}; | ||||
let template = loadTemplate(templateName); | let template = loadTemplate(templateName); | ||||
let templateLists = { | let templateLists = loadProductionQueue(template); | ||||
if (template.WallSet) | |||||
for (let wSegm in template.WallSet.Templates) | |||||
{ | |||||
let wEntities = getTemplateListsFromStructure(template.WallSet.Templates[wSegm]); | |||||
for (let entity of wEntities.techs) | |||||
if (templateLists.techs.indexOf(entity) === -1) | |||||
templateLists.techs.push(entity); | |||||
} | |||||
return templateLists; | |||||
} | |||||
function loadProductionQueue(template) | |||||
{ | |||||
let production = { | |||||
"techs": [], | "techs": [], | ||||
"units": [] | "units": [] | ||||
}; | }; | ||||
if (template.ProductionQueue) | if (!template.ProductionQueue) | ||||
{ | return production; | ||||
if (template.ProductionQueue.Entities && template.ProductionQueue.Entities._string) | if (template.ProductionQueue.Entities && template.ProductionQueue.Entities._string) | ||||
for (let build of template.ProductionQueue.Entities._string.split(" ")) | for (let templateName of template.ProductionQueue.Entities._string.split(" ")) | ||||
{ | { | ||||
build = build.replace(/\{(civ|native)\}/g, g_SelectedCiv); | templateName = templateName.replace(/\{(civ|native)\}/g, g_SelectedCiv); | ||||
if (Engine.TemplateExists(build) && templateLists.units.indexOf(build) === -1) | if (Engine.TemplateExists(templateName)) | ||||
templateLists.units.push(build); | production.units.push(templateName); | ||||
} | } | ||||
if (template.ProductionQueue.Technologies && template.ProductionQueue.Technologies._string) | if (template.ProductionQueue.Technologies && template.ProductionQueue.Technologies._string) | ||||
for (let research of template.ProductionQueue.Technologies._string.split(" ")) | for (let technologyName of template.ProductionQueue.Technologies._string.split(" ")) | ||||
{ | { | ||||
if (research.indexOf("{civ}") != -1) | if (technologyName.indexOf("{civ}") != -1) | ||||
{ | { | ||||
let civResearch = research.replace("{civ}", g_SelectedCiv); | let civTechName = technologyName.replace("{civ}", g_SelectedCiv); | ||||
research = techDataExists(civResearch) ? | technologyName = techDataExists(civTechName) ? civTechName : technologyName.replace("{civ}", "generic"); | ||||
civResearch : research.replace("{civ}", "generic"); | |||||
} | |||||
if (templateLists.techs.indexOf(research) === -1) | |||||
templateLists.techs.push(research); | |||||
} | |||||
} | } | ||||
if (template.WallSet) | if (isPairTech(technologyName)) | ||||
for (let wSegm in template.WallSet.Templates) | for (let pairTechnologyName of loadTechnologyPair(technologyName).techs) | ||||
{ | production.techs.push(pairTechnologyName); | ||||
let wEntities = getTemplateListsFromStructure(template.WallSet.Templates[wSegm]); | else | ||||
for (let entity of wEntities.techs) | production.techs.push(technologyName); | ||||
if (templateLists.techs.indexOf(entity) === -1) | |||||
templateLists.techs.push(entity); | |||||
} | } | ||||
return templateLists; | return production; | ||||
} | } |
Wildfire Games · Phabricator