Changeset View
Standalone View
binaries/data/mods/public/autostart/autostart.js
class AutoStart | class AutoStart | ||||
{ | { | ||||
constructor(initData) | constructor(cmdLineArgs) | ||||
{ | { | ||||
this.playerAssignments = { | |||||
"local": { | |||||
"player": cmdLineArgs['autostart-player'] || 1, | |||||
"name": "anonymous", | |||||
}, | |||||
}; | |||||
this.settings = new GameSettings().init(); | this.settings = new GameSettings().init(); | ||||
this.settings.fromInitAttributes(initData.attribs); | |||||
this.playerAssignments = initData.playerAssignments; | // Enable cheats in SP | ||||
this.settings.cheats.setEnabled(true); | |||||
this.settings.launchGame(this.playerAssignments, initData.storeReplay); | //parseCmdLineArgs(this.settings, cmdLineArgs); | ||||
Lint: spaced-comment: Expected space or tab after '//' in comment. | |||||
this.settings.fromCmdLineArgs(cmdLineArgs); | |||||
Not Done Inline ActionsI'd like the syntax to be like this: this.settintgs = new Settintgs(cmdLineOrgs, {"enableCheats": true}) phosit: I'd like the syntax to be like this: `this.settintgs = new Settintgs(cmdLineOrgs… | |||||
if ('autostart-nonvisual' in cmdLineArgs) | |||||
this.settings.triggerScripts.customScripts.add("scripts/NonVisualTrigger.js"); | |||||
this.settings.launchGame(this.playerAssignments, !cmdLineArgs['autostart-disable-replay']); | |||||
Not Done Inline ActionsThis seem to be simmilar why detect them differently? prop in object vs object[prop] phosit: This seem to be simmilar why detect them differently? `prop in object` vs `object[prop]` | |||||
Done Inline ActionsThere's actually a difference, one is true for undefined but exists and the other not. In this case I think I'm actually using the more appropriate checks in each place. wraitii: There's actually a difference, one is true for `undefined but exists` and the other not. In… | |||||
Not Done Inline ActionsSo for --autostart-nonvisual=false will result in true, because it exists. You might add a comment explaining that. phosit: So for `--autostart-nonvisual=false` will result in `true`, because it exists.
`--autostart… | |||||
this.onLaunch(); | this.onLaunch(); | ||||
} | } | ||||
onTick() | onTick() | ||||
{ | { | ||||
} | } | ||||
/** | /** | ||||
* In the visual autostart path, we need to show the loading screen. | * In the visual autostart path, we need to show the loading screen. | ||||
*/ | */ | ||||
onLaunch() | onLaunch() | ||||
{ | { | ||||
Engine.SwitchGuiPage("page_loading.xml", { | Engine.SwitchGuiPage("page_loading.xml", { | ||||
"attribs": this.settings.finalizedAttributes, | "attribs": this.settings.finalizedAttributes, | ||||
"playerAssignments": this.playerAssignments | "playerAssignments": this.playerAssignments | ||||
}); | }); | ||||
} | } | ||||
} | } | ||||
function parseCmdLineArgs(settings, cmdLineArgs) | |||||
{ | |||||
const mapType = cmdLineArgs['autostart'].substring(0, cmdLineArgs['autostart'].indexOf('/')); | |||||
Lint: dot-notation ["autostart"] is better written in dot notation. Lint: dot-notation: ["autostart"] is better written in dot notation. | |||||
Lint: dot-notation ["autostart"] is better written in dot notation. Lint: dot-notation: ["autostart"] is better written in dot notation. | |||||
settings.map.setType(mapType); | |||||
settings.map.selectMap("maps/" + cmdLineArgs['autostart']); | |||||
Lint: dot-notation ["autostart"] is better written in dot notation. Lint: dot-notation: ["autostart"] is better written in dot notation. | |||||
settings.mapSize.setSize(cmdLineArgs['autostart-size'] || 192); | |||||
settings.playerCount.setNb(cmdLineArgs['autostart-players'] || 2); | |||||
const getPlayer = (key, i) => { | |||||
if (!cmdLineArgs['autostart-' + key]) | |||||
return; | |||||
var value = cmdLineArgs['autostart-' + key]; | |||||
if (!Array.isArray(value)) | |||||
value = [value]; | |||||
// TODO: support more than 8 players | |||||
return value.find(x => x[0] == i)?.substring(2); | |||||
Lint: consistent-return Arrow function expected no return value. Lint: consistent-return: Arrow function expected no return value. | |||||
} | |||||
Lint: semi Missing semicolon. Lint: semi: Missing semicolon. | |||||
for (let i = 1; i <= settings.playerCount.nbPlayers; ++i) | |||||
{ | |||||
const civ = getPlayer("civ", i) | |||||
Lint: semi Missing semicolon. Lint: semi: Missing semicolon. | |||||
if (civ) | |||||
settings.playerCiv.setValue(i - 1, civ); | |||||
const team = getPlayer("team", i) | |||||
Lint: semi Missing semicolon. Lint: semi: Missing semicolon. | |||||
if (team) | |||||
settings.playerTeam.setValue(i - 1, team); | |||||
const ai = getPlayer("ai", i) | |||||
Lint: semi Missing semicolon. Lint: semi: Missing semicolon. | |||||
if (ai) | |||||
settings.playerAI.set(i - 1, { | |||||
"bot": ai, | |||||
"difficulty": getPlayer("aidiff") || 3, | |||||
"behavior": getPlayer("aibehavior") || "balanced", | |||||
}); | |||||
} | |||||
settings.cheats.setEnabled(true); | |||||
if (cmdLineArgs['autostart-seed'] && cmdLineArgs['autostart-seed'] != -1) | |||||
settings.seeds.seed = cmdLineArgs['autostart-seed']; | |||||
if (cmdLineArgs['autostart-aiseed'] && cmdLineArgs['autostart-aiseed'] != -1) | |||||
settings.seeds.AIseed = cmdLineArgs['autostart-aiseed']; | |||||
if (cmdLineArgs['autostart-ceasefire']) | |||||
settings.seeds.ceaserfire.setValue(+cmdLineArgs['autostart-ceasefire']); | |||||
if ('autostart-nonvisual' in cmdLineArgs) | |||||
settings.triggerScripts.customScripts.add("scripts/NonVisualTrigger.js"); | |||||
const victoryConditions = cmdLineArgs["autostart-victory"]; | |||||
if (Array.isArray(victoryConditions)) | |||||
for (const cond of victoryConditions) | |||||
settings.victoryConditions.setEnabled(cond, true); | |||||
else if (victoryConditions && victoryConditions !== "endless") | |||||
settings.victoryConditions.setEnabled(victoryConditions, true); | |||||
settings.wonder.setDuration(cmdLineArgs['autostart-wonderduration'] || 10); | |||||
settings.relic.setDuration(cmdLineArgs['autostart-relicduration'] || 10); | |||||
settings.relic.setCount(cmdLineArgs['autostart-reliccount'] || 2); | |||||
return settings; | |||||
} |
Expected space or tab after '//' in comment.