Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/reference/viewer/viewer.js
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
var g_RankIconPath = "session/icons/ranks/"; | var g_RankIconPath = "session/icons/ranks/"; | ||||
/** | /** | ||||
* Page initialisation. May also eventually pre-draw/arrange objects. | * Page initialisation. May also eventually pre-draw/arrange objects. | ||||
* | * | ||||
* @param {object} data - Contains the civCode and the name of the template to display. | * @param {object} data - Contains the civCode and the name of the template to display. | ||||
* @param {string} data.templateName | * @param {string} data.templateName | ||||
* @param {string} [data.civ] | * @param {string} [data.civ] | ||||
* @param {*} [data.callback] - If set and loosely equivalent to true, a callback is | |||||
* assumed to be setup ready be called by the Engine upon | |||||
* closure of this page. | |||||
*/ | */ | ||||
function init(data) | function init(data) | ||||
{ | { | ||||
if (!data || !data.templateName) | if (!data || !data.templateName) | ||||
{ | throw new Error("Viewer: No template provided"); | ||||
error("Viewer: No template provided"); | |||||
closePage(); | |||||
return; | |||||
} | |||||
if (data.callback) | |||||
g_CallbackSet = true; | |||||
let templateName = removeFiltersFromTemplateName(data.templateName); | let templateName = removeFiltersFromTemplateName(data.templateName); | ||||
let isTech = techDataExists(templateName); | let isTech = techDataExists(templateName); | ||||
// Attempt to get the civ code from the template, or, if | // Attempt to get the civ code from the template, or, if | ||||
// it's a technology, from the researcher's template. | // it's a technology, from the researcher's template. | ||||
if (!isTech) | if (!isTech) | ||||
{ | { | ||||
// Catch and redirect if template is a non-promotion variant of | // Catch and redirect if template is a non-promotion variant of | ||||
// another (ie. units/{civ}_support_female_citizen_house). | // another (ie. units/{civ}_support_female_citizen_house). | ||||
templateName = getBaseTemplateName(templateName); | templateName = getBaseTemplateName(templateName); | ||||
g_SelectedCiv = loadTemplate(templateName).Identity.Civ; | g_SelectedCiv = loadTemplate(templateName).Identity.Civ; | ||||
} | } | ||||
if (g_SelectedCiv == "gaia" && data.civ) | if (g_SelectedCiv == "gaia" && data.civ) | ||||
g_SelectedCiv = data.civ; | g_SelectedCiv = data.civ; | ||||
g_TemplateLists = compileTemplateLists(g_SelectedCiv); | g_TemplateLists = compileTemplateLists(g_SelectedCiv); | ||||
g_CurrentModifiers = deriveModifications(g_AutoResearchTechList); | g_CurrentModifiers = deriveModifications(g_AutoResearchTechList); | ||||
g_Template = isTech ? loadTechnology(templateName) : loadEntityTemplate(templateName); | g_Template = isTech ? loadTechnology(templateName) : loadEntityTemplate(templateName); | ||||
if (!g_Template) | if (!g_Template) | ||||
{ | throw new Error("Viewer: unable to recognise or load template (" + templateName + ")"); | ||||
error("Viewer: unable to recognise or load template (" + templateName + ")"); | |||||
closePage(); | |||||
return; | |||||
} | |||||
g_StatsFunctions = [getEntityCostTooltip].concat(g_StatsFunctions); | g_StatsFunctions = [getEntityCostTooltip].concat(g_StatsFunctions); | ||||
draw(); | draw(); | ||||
} | } | ||||
/** | /** | ||||
* Populate the UI elements. | * Populate the UI elements. | ||||
▲ Show 20 Lines • Show All 121 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator