diff --git a/binaries/data/mods/public/gui/reference/common/core.js b/binaries/data/mods/public/gui/reference/common/core.js index 24eb337478..ab15cee8a1 100644 --- a/binaries/data/mods/public/gui/reference/common/core.js +++ b/binaries/data/mods/public/gui/reference/common/core.js @@ -93,14 +93,12 @@ function getTemplateListsFromUnit(templateName) { if (!templateName || !Engine.TemplateExists(templateName)) return {}; + let template = loadTemplate(templateName); - let templateLists = { - "structures": [], - "units": [], - "techs": [] - }; + let templateLists = loadProductionQueue(template); + templateLists.structures = []; if (template.Builder && template.Builder.Entities._string) for (let build of template.Builder.Entities._string.split(" ")) { @@ -109,30 +107,6 @@ function getTemplateListsFromUnit(templateName) 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; } @@ -146,36 +120,10 @@ function getTemplateListsFromStructure(templateName) { if (!templateName || !Engine.TemplateExists(templateName)) return {}; + let template = loadTemplate(templateName); - let templateLists = { - "techs": [], - "units": [] - }; - - if (template.ProductionQueue) - { - if (template.ProductionQueue.Entities && template.ProductionQueue.Entities._string) - 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 && template.ProductionQueue.Technologies._string) - 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); - } - } + let templateLists = loadProductionQueue(template); if (template.WallSet) for (let wSegm in template.WallSet.Templates) @@ -188,3 +136,40 @@ function getTemplateListsFromStructure(templateName) return templateLists; } + +function loadProductionQueue(template) +{ + let production = { + "techs": [], + "units": [] + }; + + if (!template.ProductionQueue) + return production; + + if (template.ProductionQueue.Entities && template.ProductionQueue.Entities._string) + for (let templateName of template.ProductionQueue.Entities._string.split(" ")) + { + templateName = templateName.replace(/\{(civ|native)\}/g, g_SelectedCiv); + if (Engine.TemplateExists(templateName)) + production.units.push(templateName); + } + + if (template.ProductionQueue.Technologies && template.ProductionQueue.Technologies._string) + for (let technologyName of template.ProductionQueue.Technologies._string.split(" ")) + { + if (technologyName.indexOf("{civ}") != -1) + { + let civTechName = technologyName.replace("{civ}", g_SelectedCiv); + technologyName = techDataExists(civTechName) ? civTechName : technologyName.replace("{civ}", "generic"); + } + + if (isPairTech(technologyName)) + for (let pairTechnologyName of loadTechnologyPair(technologyName).techs) + production.techs.push(pairTechnologyName); + else + production.techs.push(technologyName); + } + + return production; +} diff --git a/binaries/data/mods/public/gui/reference/common/load.js b/binaries/data/mods/public/gui/reference/common/load.js index 7b21fd1308..053f40ab7f 100644 --- a/binaries/data/mods/public/gui/reference/common/load.js +++ b/binaries/data/mods/public/gui/reference/common/load.js @@ -108,39 +108,7 @@ function loadUnit(templateName) let template = loadTemplate(templateName); let unit = GetTemplateDataHelper(template, null, g_AuraData, g_ResourceData, g_DamageTypes, g_CurrentModifiers); - - if (template.ProductionQueue) - { - unit.production = {}; - if (template.ProductionQueue.Entities) - { - unit.production.units = []; - for (let build of template.ProductionQueue.Entities._string.split(" ")) - { - build = build.replace(/\{(civ|native)\}/g, g_SelectedCiv); - if (Engine.TemplateExists(build)) - unit.production.units.push(build); - } - } - if (template.ProductionQueue.Technologies) - { - unit.production.techs = []; - 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 (isPairTech(research)) - for (let tech of loadTechnologyPair(research).techs) - unit.production.techs.push(tech); - else - unit.production.techs.push(research); - } - } - } + unit.production = loadProductionQueue(template); if (template.Builder && template.Builder.Entities._string) { @@ -173,37 +141,7 @@ function loadStructure(templateName) let template = loadTemplate(templateName); let structure = GetTemplateDataHelper(template, null, g_AuraData, g_ResourceData, g_DamageTypes, g_CurrentModifiers); - structure.production = { - "technology": [], - "units": [] - }; - - if (template.ProductionQueue) - { - if (template.ProductionQueue.Entities && template.ProductionQueue.Entities._string) - for (let build of template.ProductionQueue.Entities._string.split(" ")) - { - build = build.replace(/\{(civ|native)\}/g, g_SelectedCiv); - if (Engine.TemplateExists(build)) - structure.production.units.push(build); - } - - if (template.ProductionQueue.Technologies && template.ProductionQueue.Technologies._string) - 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 (isPairTech(research)) - for (let tech of loadTechnologyPair(research).techs) - structure.production.technology.push(tech); - else - structure.production.technology.push(research); - } - } + structure.production = loadProductionQueue(template); if (structure.upgrades) structure.upgrades = getActualUpgradeData(structure.upgrades); @@ -234,8 +172,8 @@ function loadStructure(templateName) let wPart = loadStructure(structure.wallSet.templates[wSegm]); structure.wallset[wSegm] = wPart; - for (let research of wPart.production.technology) - structure.production.technology.push(research); + for (let research of wPart.production.techs) + structure.production.techs.push(research); if (wPart.upgrades) structure.upgrades = structure.upgrades.concat(wPart.upgrades); diff --git a/binaries/data/mods/public/gui/reference/structree/draw.js b/binaries/data/mods/public/gui/reference/structree/draw.js index 71e0c5b4b2..5f220200f6 100644 --- a/binaries/data/mods/public/gui/reference/structree/draw.js +++ b/binaries/data/mods/public/gui/reference/structree/draw.js @@ -81,8 +81,8 @@ function draw() ++p; } - if (stru.production.technology[prod_pha]) - for (let prod of stru.production.technology[prod_pha]) + if (stru.production.techs[prod_pha]) + for (let prod of stru.production.techs[prod_pha]) { prod = clone(basename(prod).startsWith("phase") ? g_ParsedData.phases[prod] : diff --git a/binaries/data/mods/public/gui/reference/structree/structree.js b/binaries/data/mods/public/gui/reference/structree/structree.js index 6a43fd9994..f30b534f09 100644 --- a/binaries/data/mods/public/gui/reference/structree/structree.js +++ b/binaries/data/mods/public/gui/reference/structree/structree.js @@ -97,12 +97,12 @@ function selectCiv(civCode) // If this building is shared with another civ, // it may have already gone through the grouping process already - if (!Array.isArray(structInfo.production.technology)) + if (!Array.isArray(structInfo.production.techs)) continue; // Sort techs by phase let newProdTech = {}; - for (let prod of structInfo.production.technology) + for (let prod of structInfo.production.techs) { let phase = getPhaseOfTechnology(prod); if (phase === false) @@ -135,7 +135,7 @@ function selectCiv(civCode) } g_ParsedData.structures[structCode].production = { - "technology": newProdTech, + "techs": newProdTech, "units": newProdUnits }; @@ -170,7 +170,7 @@ function selectCiv(civCode) for (let unitCode of templateLists.units.keys()) { let unitTemplate = g_ParsedData.units[unitCode]; - if ((!unitTemplate.production || !Object.keys(unitTemplate.production).length) && !unitTemplate.upgrades) + if (!unitTemplate.production.units.length && !unitTemplate.production.techs.length && !unitTemplate.upgrades) continue; trainerList.push(unitCode);