Changeset View
Standalone View
binaries/data/mods/public/gui/reference/common/core.js
var g_SelectedCiv = ""; | var g_SelectedCiv = "gaia"; | ||||
elexis: (I've always wondered about the filename `core.js`. Sounds more like C++ stuff. Perhaps it… | |||||
var g_CallbackSet = false; | var g_CallbackSet = false; | ||||
function closePage() | function closePage() | ||||
{ | { | ||||
if (g_CallbackSet) | if (g_CallbackSet) | ||||
Engine.PopGuiPageCB(0); | Engine.PopGuiPageCB(0); | ||||
else | else | ||||
Engine.PopGuiPage(); | Engine.PopGuiPage(); | ||||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | |||||
* @param {string} templateName | * @param {string} templateName | ||||
*/ | */ | ||||
function getTemplateListsFromUnit(templateName) | function getTemplateListsFromUnit(templateName) | ||||
{ | { | ||||
if (!templateName || !Engine.TemplateExists(templateName)) | if (!templateName || !Engine.TemplateExists(templateName)) | ||||
return {}; | return {}; | ||||
let template = loadTemplate(templateName); | let template = loadTemplate(templateName); | ||||
// If this is a non-promotion variant (ie. {civ}_support_female_citizen_house) | |||||
// then it is functionally equivalent to another unit being processed, so skip it. | |||||
if (getBaseTemplateName(templateName) != templateName) | |||||
return {}; | |||||
let templateLists = { | let templateLists = { | ||||
"structures": [], | "structures": [], | ||||
"units": [], | "units": [], | ||||
"techs": [] | "techs": [] | ||||
}; | }; | ||||
if (template.Builder && template.Builder.Entities._string) | if (template.Builder && template.Builder.Entities._string) | ||||
for (let build of template.Builder.Entities._string.split(" ")) | for (let build of template.Builder.Entities._string.split(" ")) | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | function getTemplateListsFromStructure(templateName) | ||||
}; | }; | ||||
if (template.ProductionQueue) | if (template.ProductionQueue) | ||||
{ | { | ||||
if (template.ProductionQueue.Entities && template.ProductionQueue.Entities._string) | if (template.ProductionQueue.Entities && template.ProductionQueue.Entities._string) | ||||
for (let build of template.ProductionQueue.Entities._string.split(" ")) | for (let build of template.ProductionQueue.Entities._string.split(" ")) | ||||
{ | { | ||||
build = build.replace(/\{(civ|native)\}/g, g_SelectedCiv); | build = build.replace(/\{(civ|native)\}/g, g_SelectedCiv); | ||||
if (Engine.TemplateExists(build) && templateLists.units.indexOf(build) === -1) | if (Engine.TemplateExists(build)) | ||||
{ | |||||
if (templateLists.units.indexOf(build) == -1) | |||||
templateLists.units.push(build); | templateLists.units.push(build); | ||||
let baseBuild = getBaseTemplateName(build); | |||||
if (baseBuild != build && templateLists.units.indexOf(baseBuild) == -1) | |||||
templateLists.units.push(baseBuild); | |||||
} | |||||
elexisUnsubmitted Done Inline ActionsSorry but we should nuke the quadruplication before one of the copies is extended, D1192 elexis: Sorry but we should nuke the quadruplication before one of the copies is extended, D1192 | |||||
s0600204AuthorUnsubmitted Done Inline ActionsThis revision now requires D1192 s0600204: This revision now requires D1192 | |||||
} | } | ||||
if (template.ProductionQueue.Technologies && template.ProductionQueue.Technologies._string) | if (template.ProductionQueue.Technologies && template.ProductionQueue.Technologies._string) | ||||
for (let research of template.ProductionQueue.Technologies._string.split(" ")) | for (let research of template.ProductionQueue.Technologies._string.split(" ")) | ||||
{ | { | ||||
if (research.indexOf("{civ}") != -1) | if (research.indexOf("{civ}") != -1) | ||||
{ | { | ||||
let civResearch = research.replace("{civ}", g_SelectedCiv); | let civResearch = research.replace("{civ}", g_SelectedCiv); | ||||
Show All 11 Lines | for (let wSegm in template.WallSet.Templates) | ||||
let wEntities = getTemplateListsFromStructure(template.WallSet.Templates[wSegm]); | let wEntities = getTemplateListsFromStructure(template.WallSet.Templates[wSegm]); | ||||
for (let entity of wEntities.techs) | for (let entity of wEntities.techs) | ||||
if (templateLists.techs.indexOf(entity) === -1) | if (templateLists.techs.indexOf(entity) === -1) | ||||
templateLists.techs.push(entity); | templateLists.techs.push(entity); | ||||
} | } | ||||
return templateLists; | return templateLists; | ||||
} | } | ||||
/** | |||||
* Returns the name of a template's base (as dictated by the selection | |||||
* group name), or the template's own name if the template is its own base. | |||||
Not Done Inline Actionsfor example foo returns bar elexis: for example foo returns bar | |||||
* | |||||
Done Inline ActionsIt' easier for the reader if the type of the argument is always the same. For example one could alwasy pass a string and add a new variable for that one occurrence where currently an object is passed. elexis: It' easier for the reader if the type of the argument is always the same. For example one could… | |||||
Done Inline ActionsI don't see the SelectionGroupName dictating any template name:
So we may not rely on selection group names being template names or paths. Ranks were only the first use case, but (1) the name of the property SelectionGroupName, (2) all code that we have for it (grouping of elexis: I don't see the SelectionGroupName dictating any template name:
> "<element… | |||||
Not Done Inline ActionsRewritten function to not use SelectionGroupName at all. See if you prefer this new version. s0600204: Rewritten function to not use `SelectionGroupName` at all. See if you prefer this new version. | |||||
Done Inline ActionsShould define in one sentence what a template base is, since it's a new term. (Better would be to avoid it however). I didn't understand the function. How can templateName be a mirage, by "mirage|templatename"? elexis: Should define in one sentence what a template base is, since it's a new term. (Better would be… | |||||
* We have entities, such as the female-citizen and some champions, that | |||||
* can be trained initially in certain structures (civic centre, fortress) | |||||
* and then, once a given technology has been researched, in further | |||||
* structures (houses, barracks, ships). In this case, a `*_house`, | |||||
* `*_barracks`, `*_trireme`, or other `{original}_{*}` variant is used | |||||
Done Inline Actions2x \n elexis: 2x \n | |||||
* which is functionally identical to the original it is based on, but | |||||
* with a different technology requirement. | |||||
* | |||||
* We don't test for differing tech-requirements so as to support other | |||||
* potential variant types, such as a unit having a different cost | |||||
* depending on where it is trained (although admittedly there are other | |||||
* ways of achieving that without using a different template file). | |||||
* | |||||
* The exception to this is that we don't return a base that is of a | |||||
* different promotion rank to the provided template. | |||||
elexisUnsubmitted Done Inline ActionsTLDR, KISS For example: Returns the selection group name, or rank or foo of the given template. elexis: TLDR, KISS
For example: Returns the selection group name, or rank or foo of the given template. | |||||
* | |||||
* @param {string} templateName | |||||
* @return {string} The base template name. | |||||
*/ | |||||
function getBaseTemplateName(templateName) | |||||
{ | |||||
if (!templateName || !Engine.TemplateExists(templateName)) | |||||
Done Inline Actions(> 0 could be omitted I suppose?) elexis: (`> 0` could be omitted I suppose?) | |||||
return undefined; | |||||
let template = loadTemplate(templateName); | |||||
if (!template.Identity || !template.Identity.SelectionGroupName || | |||||
templateName == template.Identity.SelectionGroupName) | |||||
return templateName; | |||||
Not Done Inline Actions(Can we avoid the !template.Identity.SelectionGroupName check or does it possibly complain about undefined?) elexis: (Can we avoid the `!template.Identity.SelectionGroupName` check or does it possibly complain… | |||||
Not Done Inline ActionsHmm... if I remove that check, then lines 219-26 become, in essence: if ({string} == {undefined}) [ignored] if (not {something_false_in_vast_majority_of_cases}) return undefined Yeah... no. s0600204: Hmm... if I remove that check, then lines 219-26 become, in essence:
```
if ({string} ==… | |||||
let selectionName = template.Identity.SelectionGroupName; | |||||
if (!template.Identity.Rank) | |||||
return selectionName; | |||||
let selectionTemplate = loadTemplate(selectionName); | |||||
if (!selectionTemplate.Identity || !selectionTemplate.Identity.Rank || | |||||
selectionTemplate.Identity.Rank == template.Identity.Rank) | |||||
Done Inline ActionsIt's a convention to have the operators on the previous line. (I recall sanderd17 saying its to make it clear that there isnt a missing semicolon. But mostly having a globally unique codestyle is a more important incentive IMO).
elexis: It's a convention to have the operators on the previous line. (I recall sanderd17 saying its to… | |||||
Not Done Inline ActionsWeird. I'd think we'd want || on a new line for much the same reason we put { on a new line - makes it easier to notice that this line is a continuation of the conditional statement. Particularly as brackets are skipped here. Either way, it's not mentioned on the coding conventions wiki page. s0600204: Weird. I'd think we'd want `||` on a new line for much the same reason we put `{` on a new line… | |||||
return selectionName; | |||||
return templateName; | |||||
} | |||||
/** | |||||
* @param {string} objectName | |||||
* @param {string} templateName | |||||
*/ | |||||
elexisUnsubmitted Done Inline ActionsguiObjectName, comments can go. elexis: guiObjectName, comments can go.
The importance of JSdoc comments lies in minimizing the… | |||||
function setViewerOnPress(objectName, templateName) | |||||
{ | |||||
let viewerFunc = () => { | |||||
Engine.PushGuiPage("page_viewer.xml", { | |||||
"templateName": templateName, | |||||
"civ": g_SelectedCiv, | |||||
elexisUnsubmitted Done Inline Actions-, elexis: -, | |||||
}); | |||||
}; | |||||
Engine.GetGUIObjectByName(objectName).onPress = viewerFunc; | |||||
Engine.GetGUIObjectByName(objectName).onPressRight = viewerFunc; | |||||
} | |||||
Done Inline Actionsunused function? elexis: unused function? |
(I've always wondered about the filename core.js. Sounds more like C++ stuff. Perhaps it should be common/reference.js?