Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/structree/helper.js
Show First 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | |||||
* @param {string} techName - The Technology's name | * @param {string} techName - The Technology's name | ||||
* @return The name of the phase the technology belongs to, or false if | * @return The name of the phase the technology belongs to, or false if | ||||
* the current civ can't research this tech | * the current civ can't research this tech | ||||
*/ | */ | ||||
function GetPhaseOfTechnology(techName) | function GetPhaseOfTechnology(techName) | ||||
{ | { | ||||
let phaseIdx = -1; | let phaseIdx = -1; | ||||
if (basename(techName).slice(0, 5) === "phase") | if (basename(techName).startsWith("phase")) | ||||
{ | { | ||||
phaseIdx = g_ParsedData.phaseList.indexOf(GetActualPhase(techName)); | phaseIdx = g_ParsedData.phaseList.indexOf(GetActualPhase(techName)); | ||||
if (phaseIdx > 0) | if (phaseIdx > 0) | ||||
return g_ParsedData.phaseList[phaseIdx - 1]; | return g_ParsedData.phaseList[phaseIdx - 1]; | ||||
} | } | ||||
if (!g_ParsedData.techs[g_SelectedCiv][techName]) | if (!g_ParsedData.techs[g_SelectedCiv][techName]) | ||||
warn(g_SelectedCiv + " : " + techName); | { | ||||
let techData = loadTechnology(techName); | |||||
g_ParsedData.techs[g_SelectedCiv][techName] = techData; | |||||
warn("The \"" + techData.name.generic + "\" technology is not researchable in any structure buildable by the " + | |||||
g_SelectedCiv + " civilisation, but is required by something that this civ can research, train or build!"); | |||||
} | |||||
let techReqs = g_ParsedData.techs[g_SelectedCiv][techName].reqs; | let techReqs = g_ParsedData.techs[g_SelectedCiv][techName].reqs; | ||||
if (!techReqs) | if (!techReqs) | ||||
return false; | return false; | ||||
for (let option of techReqs) | for (let option of techReqs) | ||||
if (option.techs) | if (option.techs) | ||||
for (let tech of option.techs) | for (let tech of option.techs) | ||||
{ | { | ||||
if (basename(tech).slice(0, 5) === "phase") | if (basename(tech).startsWith("phase")) | ||||
return tech; | return tech; | ||||
if (basename(tech).startsWith("pair")) | |||||
continue; | |||||
phaseIdx = Math.max(phaseIdx, g_ParsedData.phaseList.indexOf(GetPhaseOfTechnology(tech))); | phaseIdx = Math.max(phaseIdx, g_ParsedData.phaseList.indexOf(GetPhaseOfTechnology(tech))); | ||||
} | } | ||||
return g_ParsedData.phaseList[phaseIdx] || false; | return g_ParsedData.phaseList[phaseIdx] || false; | ||||
} | } | ||||
function GetActualPhase(phaseName) | function GetActualPhase(phaseName) | ||||
{ | { | ||||
if (g_ParsedData.phases[phaseName]) | if (g_ParsedData.phases[phaseName]) | ||||
Show All 16 Lines |
Wildfire Games · Phabricator