Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/structree/structree.js
var g_ParsedData = { | var g_ParsedData = { | ||||
"units": {}, | "units": {}, | ||||
"structures": {}, | "structures": {}, | ||||
"techs": {}, | "techs": {}, | ||||
"phases": {} | "phases": {} | ||||
}; | }; | ||||
var g_Lists = {}; | var g_Lists = {}; | ||||
var g_CivData = {}; | var g_CivData = {}; | ||||
var g_SelectedCiv = ""; | var g_SelectedCiv = ""; | ||||
var g_CurrentModifiers = {}; | |||||
var g_CallbackSet = false; | var g_CallbackSet = false; | ||||
var g_ResourceData = new Resources(); | var g_ResourceData = new Resources(); | ||||
bb: Perhaps move this to helper file where it is used.
I believe it is good to have this global, so… | |||||
/** | /** | ||||
* Initialize the dropdown containing all the available civs | * Initialize the dropdown containing all the available civs | ||||
*/ | */ | ||||
function init(data = {}) | function init(data = {}) | ||||
{ | { | ||||
g_CivData = loadCivData(true); | g_CivData = loadCivData(true); | ||||
let civList = Object.keys(g_CivData).map(civ => ({ | let civList = Object.keys(g_CivData).map(civ => ({ | ||||
"name": g_CivData[civ].Name, | "name": g_CivData[civ].Name, | ||||
"code": civ, | "code": civ, | ||||
})).sort(sortNameIgnoreCase); | })).sort(sortNameIgnoreCase); | ||||
if (!civList.length) | if (!civList.length) | ||||
return; | return; | ||||
var civSelection = Engine.GetGUIObjectByName("civSelection"); | var civSelection = Engine.GetGUIObjectByName("civSelection"); | ||||
Done Inline ActionsI guess this can be merged with variable definition. bb: I guess this can be merged with variable definition. | |||||
civSelection.list = civList.map(c => c.name); | civSelection.list = civList.map(c => c.name); | ||||
civSelection.list_data = civList.map(c => c.code); | civSelection.list_data = civList.map(c => c.code); | ||||
if(data.civ) | if(data.civ) | ||||
Not Done Inline Actionssry have to notice this ugliness, no change needed in this patch. bb: sry have to notice this ugliness, no change needed in this patch. | |||||
{ | { | ||||
civSelection.selected = civSelection.list_data.indexOf(data.civ); | civSelection.selected = civSelection.list_data.indexOf(data.civ); | ||||
selectCiv(data.civ); | selectCiv(data.civ); | ||||
} | } | ||||
else | else | ||||
civSelection.selected = 0; | civSelection.selected = 0; | ||||
if (data.callback) | if (data.callback) | ||||
g_CallbackSet = true; | g_CallbackSet = true; | ||||
} | } | ||||
function selectCiv(civCode) | function selectCiv(civCode) | ||||
{ | { | ||||
if (civCode === g_SelectedCiv || !g_CivData[civCode]) | if (civCode === g_SelectedCiv || !g_CivData[civCode]) | ||||
return; | return; | ||||
g_SelectedCiv = civCode; | g_SelectedCiv = civCode; | ||||
deriveAutoresearchedModifications(); | |||||
// If a buildList already exists, then this civ has already been parsed | // If a buildList already exists, then this civ has already been parsed | ||||
if (g_CivData[g_SelectedCiv].buildList) | if (g_CivData[g_SelectedCiv].buildList) | ||||
{ | { | ||||
draw(); | draw(); | ||||
return; | return; | ||||
} | } | ||||
g_Lists = { | g_Lists = { | ||||
▲ Show 20 Lines • Show All 216 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Perhaps move this to helper file where it is used.
I believe it is good to have this global, so we don't recalculate on civ selection.