Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/globalscripts/Templates.js
Show All 22 Lines | for (let filename of Engine.ListDirectoryFiles("simulation/data/civs/", "*.json", false)) | ||||
if (!selectableOnly || data.SelectableInGameSetup) | if (!selectableOnly || data.SelectableInGameSetup) | ||||
civData[data.Code] = data; | civData[data.Code] = data; | ||||
} | } | ||||
return civData; | return civData; | ||||
} | } | ||||
/** | /** | ||||
* Gets an array of all classes for this identity template | * Gets an array of all classes for this identity template | ||||
Freagarach: +`.` | |||||
Done Inline Actionsis string[] proper JsDoc or should it be Array? bb: is `string[]` proper JsDoc or should it be `Array`? | |||||
Done Inline ActionsStan: Seems so https://stackoverflow.com/questions/14611995/how-to-specify-an-array-of-objects-as-a… | |||||
*/ | */ | ||||
function GetIdentityClasses(template) | function GetIdentityClasses(template) | ||||
{ | { | ||||
var classList = []; | let classList = []; | ||||
if (template.Classes && template.Classes._string) | if (template.Classes && template.Classes._string) | ||||
classList = classList.concat(template.Classes._string.split(/\s+/)); | for (let entClass of template.Classes._string.split(/\s+/)) | ||||
classList.push(entClass); | |||||
Done Inline ActionsWondered whether there should be a comment explaining why we add this space here, to just remove it later. Maybe instead of a comment add an unit test with an entity that has just 1 class of 1 character, this will blame anyone changing it too. bb: Wondered whether there should be a comment explaining why we add this space here, to just… | |||||
Done Inline ActionsOkay will add a unit test. Stan: Okay will add a unit test. | |||||
bbUnsubmitted Done Inline Actionsdid you also try classList.push(...template.Classes._string.split(/\s+/))? bb: did you also try `classList.push(...template.Classes._string.split(/\s+/))`? | |||||
StanAuthorUnsubmitted Done Inline ActionsNo but I thought that the spread operator was bad for performance, and in my tests, for push was always faster than everything else. Stan: No but I thought that the spread operator was bad for performance, and in my tests, for push… | |||||
if (template.VisibleClasses && template.VisibleClasses._string) | if (template.VisibleClasses && template.VisibleClasses._string) | ||||
classList = classList.concat(template.VisibleClasses._string.split(/\s+/)); | for (let entClass of template.VisibleClasses._string.split(/\s+/)) | ||||
classList.push(entClass); | |||||
if (template.Rank) | if (template.Rank) | ||||
classList = classList.concat(template.Rank); | classList.push(template.Rank); | ||||
return classList; | return classList; | ||||
} | }; | ||||
Done Inline Actionswondered if removing the > 1 would be different in performance => seems indifferent bb: wondered if removing the `> 1` would be different in performance => seems indifferent | |||||
Done Inline ActionsThanks for testimg. Stan: Thanks for testimg. | |||||
/** | /** | ||||
* Gets an array with all classes for this identity template | * Gets an array with all classes for this identity template | ||||
* that should be shown in the GUI | * that should be shown in the GUI | ||||
*/ | */ | ||||
function GetVisibleIdentityClasses(template) | function GetVisibleIdentityClasses(template) | ||||
{ | { | ||||
if (template.VisibleClasses && template.VisibleClasses._string) | if (template.VisibleClasses && template.VisibleClasses._string) | ||||
return template.VisibleClasses._string.split(/\s+/); | return template.VisibleClasses._string.split(/\s+/); | ||||
Show All 29 Lines | function MatchesClassList(classes, match) | ||||
for (let sublist of match) | for (let sublist of match) | ||||
{ | { | ||||
// If the elements are still strings, split them by space or by '+' | // If the elements are still strings, split them by space or by '+' | ||||
if (typeof sublist == "string") | if (typeof sublist == "string") | ||||
sublist = sublist.split(/[+\s]+/); | sublist = sublist.split(/[+\s]+/); | ||||
if (sublist.every(c => (c[0] == "!" && classes.indexOf(c.substr(1)) == -1) | if (sublist.every(c => (c[0] == "!" && classes.indexOf(c.substr(1)) == -1) | ||||
|| (c[0] != "!" && classes.indexOf(c) != -1))) | || (c[0] != "!" && classes.indexOf(c) != -1))) | ||||
return true; | return true; | ||||
Done Inline ActionsSpaces. Freagarach: Spaces. | |||||
Done Inline Actionsspaces seem fine here bb: spaces seem fine here | |||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* Gets the value originating at the value_path as-is, with no modifiers applied. | * Gets the value originating at the value_path as-is, with no modifiers applied. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 449 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
+.