2017-08-26 10:57:11 -07:00
|
|
|
/**
|
|
|
|
|
* Array of structure template names when given a civ and a phase name.
|
|
|
|
|
*/
|
|
|
|
|
var g_BuildList = {};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Array of template names that can be trained from a unit, given a civ and unit template name.
|
|
|
|
|
*/
|
|
|
|
|
var g_TrainList = {};
|
|
|
|
|
|
2017-07-31 05:49:00 -07:00
|
|
|
/**
|
|
|
|
|
* Initialize the page
|
|
|
|
|
*
|
|
|
|
|
* @param {object} data - Parameters passed from the code that calls this page into existence.
|
|
|
|
|
*/
|
|
|
|
|
function init(data = {})
|
|
|
|
|
{
|
|
|
|
|
let civList = Object.keys(g_CivData).map(civ => ({
|
|
|
|
|
"name": g_CivData[civ].Name,
|
|
|
|
|
"code": civ,
|
|
|
|
|
})).sort(sortNameIgnoreCase);
|
|
|
|
|
|
|
|
|
|
if (!civList.length)
|
|
|
|
|
{
|
|
|
|
|
closePage();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_ParsedData = {
|
|
|
|
|
"units": {},
|
|
|
|
|
"structures": {},
|
|
|
|
|
"techs": {},
|
|
|
|
|
"phases": {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let civSelection = Engine.GetGUIObjectByName("civSelection");
|
|
|
|
|
civSelection.list = civList.map(c => c.name);
|
|
|
|
|
civSelection.list_data = civList.map(c => c.code);
|
|
|
|
|
civSelection.selected = data.civ ? civSelection.list_data.indexOf(data.civ) : 0;
|
2018-02-23 12:54:28 -08:00
|
|
|
|
|
|
|
|
Engine.GetGUIObjectByName("civinfo").tooltip = colorizeHotkey(translate("%(hotkey)s: Switch to History."), "civinfo");
|
|
|
|
|
Engine.GetGUIObjectByName("close").tooltip = colorizeHotkey(translate("%(hotkey)s: Close Structure Tree."), "cancel");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function switchToCivInfoPage()
|
|
|
|
|
{
|
2019-08-16 11:46:04 -07:00
|
|
|
Engine.PopGuiPage({ "civ": g_SelectedCiv, "nextPage": "page_civinfo.xml" });
|
2018-02-23 12:54:28 -08:00
|
|
|
}
|
|
|
|
|
|
2019-08-15 06:29:11 -07:00
|
|
|
function closePage()
|
2018-02-23 12:54:28 -08:00
|
|
|
{
|
2019-08-16 11:46:04 -07:00
|
|
|
Engine.PopGuiPage({ "civ": g_SelectedCiv, "page": "page_structree.xml" });
|
2017-07-31 05:49:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param {string} civCode
|
|
|
|
|
*/
|
|
|
|
|
function selectCiv(civCode)
|
|
|
|
|
{
|
|
|
|
|
if (civCode === g_SelectedCiv || !g_CivData[civCode])
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
g_SelectedCiv = civCode;
|
|
|
|
|
|
|
|
|
|
g_CurrentModifiers = deriveModifications(g_AutoResearchTechList);
|
|
|
|
|
|
|
|
|
|
// If a buildList already exists, then this civ has already been parsed
|
2017-08-26 10:57:11 -07:00
|
|
|
if (g_BuildList[g_SelectedCiv])
|
2017-07-31 05:49:00 -07:00
|
|
|
{
|
|
|
|
|
draw();
|
|
|
|
|
drawPhaseIcons();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let templateLists = compileTemplateLists(civCode);
|
|
|
|
|
|
|
|
|
|
for (let u of templateLists.units.keys())
|
|
|
|
|
if (!g_ParsedData.units[u])
|
2018-02-10 20:09:28 -08:00
|
|
|
g_ParsedData.units[u] = loadEntityTemplate(u);
|
2017-07-31 05:49:00 -07:00
|
|
|
|
|
|
|
|
for (let s of templateLists.structures.keys())
|
|
|
|
|
if (!g_ParsedData.structures[s])
|
2018-02-10 20:09:28 -08:00
|
|
|
g_ParsedData.structures[s] = loadEntityTemplate(s);
|
2017-07-31 05:49:00 -07:00
|
|
|
|
|
|
|
|
// Load technologies
|
|
|
|
|
g_ParsedData.techs[civCode] = {};
|
|
|
|
|
for (let techcode of templateLists.techs.keys())
|
|
|
|
|
if (basename(techcode).startsWith("phase"))
|
|
|
|
|
g_ParsedData.phases[techcode] = loadPhase(techcode);
|
|
|
|
|
else
|
|
|
|
|
g_ParsedData.techs[civCode][techcode] = loadTechnology(techcode);
|
|
|
|
|
|
|
|
|
|
// Establish phase order
|
2018-01-01 22:38:09 -08:00
|
|
|
g_ParsedData.phaseList = UnravelPhases(g_ParsedData.phases);
|
2017-07-31 05:49:00 -07:00
|
|
|
|
|
|
|
|
// Load any required generic phases that aren't already loaded
|
|
|
|
|
for (let phasecode of g_ParsedData.phaseList)
|
|
|
|
|
if (!g_ParsedData.phases[phasecode])
|
|
|
|
|
g_ParsedData.phases[phasecode] = loadPhase(phasecode);
|
|
|
|
|
|
|
|
|
|
// Group production and upgrade lists of structures by phase
|
|
|
|
|
for (let structCode of templateLists.structures.keys())
|
|
|
|
|
{
|
|
|
|
|
let structInfo = g_ParsedData.structures[structCode];
|
|
|
|
|
structInfo.phase = getPhaseOfTemplate(structInfo);
|
|
|
|
|
let structPhaseIdx = g_ParsedData.phaseList.indexOf(structInfo.phase);
|
|
|
|
|
|
|
|
|
|
// If this building is shared with another civ,
|
|
|
|
|
// it may have already gone through the grouping process already
|
2018-01-26 14:18:35 -08:00
|
|
|
if (!Array.isArray(structInfo.production.techs))
|
2017-07-31 05:49:00 -07:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// Sort techs by phase
|
|
|
|
|
let newProdTech = {};
|
2018-01-26 14:18:35 -08:00
|
|
|
for (let prod of structInfo.production.techs)
|
2017-07-31 05:49:00 -07:00
|
|
|
{
|
|
|
|
|
let phase = getPhaseOfTechnology(prod);
|
|
|
|
|
if (phase === false)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (g_ParsedData.phaseList.indexOf(phase) < structPhaseIdx)
|
|
|
|
|
phase = structInfo.phase;
|
|
|
|
|
|
|
|
|
|
if (!(phase in newProdTech))
|
|
|
|
|
newProdTech[phase] = [];
|
|
|
|
|
|
|
|
|
|
newProdTech[phase].push(prod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sort units by phase
|
|
|
|
|
let newProdUnits = {};
|
|
|
|
|
for (let prod of structInfo.production.units)
|
|
|
|
|
{
|
|
|
|
|
let phase = getPhaseOfTemplate(g_ParsedData.units[prod]);
|
|
|
|
|
if (phase === false)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (g_ParsedData.phaseList.indexOf(phase) < structPhaseIdx)
|
|
|
|
|
phase = structInfo.phase;
|
|
|
|
|
|
|
|
|
|
if (!(phase in newProdUnits))
|
|
|
|
|
newProdUnits[phase] = [];
|
|
|
|
|
|
|
|
|
|
newProdUnits[phase].push(prod);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_ParsedData.structures[structCode].production = {
|
2018-01-26 14:18:35 -08:00
|
|
|
"techs": newProdTech,
|
2017-07-31 05:49:00 -07:00
|
|
|
"units": newProdUnits
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Sort upgrades by phase
|
|
|
|
|
let newUpgrades = {};
|
|
|
|
|
if (structInfo.upgrades)
|
|
|
|
|
for (let upgrade of structInfo.upgrades)
|
|
|
|
|
{
|
|
|
|
|
let phase = getPhaseOfTemplate(upgrade);
|
|
|
|
|
|
|
|
|
|
if (g_ParsedData.phaseList.indexOf(phase) < structPhaseIdx)
|
|
|
|
|
phase = structInfo.phase;
|
|
|
|
|
|
|
|
|
|
if (!newUpgrades[phase])
|
|
|
|
|
newUpgrades[phase] = [];
|
|
|
|
|
newUpgrades[phase].push(upgrade);
|
|
|
|
|
}
|
|
|
|
|
g_ParsedData.structures[structCode].upgrades = newUpgrades;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Determine the buildList for the civ (grouped by phase)
|
|
|
|
|
let buildList = {};
|
|
|
|
|
let trainerList = [];
|
|
|
|
|
for (let pha of g_ParsedData.phaseList)
|
|
|
|
|
buildList[pha] = [];
|
|
|
|
|
for (let structCode of templateLists.structures.keys())
|
|
|
|
|
{
|
|
|
|
|
let phase = g_ParsedData.structures[structCode].phase;
|
|
|
|
|
buildList[phase].push(structCode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (let unitCode of templateLists.units.keys())
|
|
|
|
|
{
|
|
|
|
|
let unitTemplate = g_ParsedData.units[unitCode];
|
2018-01-26 14:18:35 -08:00
|
|
|
if (!unitTemplate.production.units.length && !unitTemplate.production.techs.length && !unitTemplate.upgrades)
|
2017-07-31 05:49:00 -07:00
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
trainerList.push(unitCode);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-26 10:57:11 -07:00
|
|
|
g_BuildList[g_SelectedCiv] = buildList;
|
|
|
|
|
g_TrainList[g_SelectedCiv] = trainerList;
|
2017-07-31 05:49:00 -07:00
|
|
|
|
|
|
|
|
draw();
|
|
|
|
|
drawPhaseIcons();
|
|
|
|
|
}
|