Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/campaign/newcampaign_modal.js
- This file was added.
var g_CampaignID = null; | |||||
var g_CampaignState = null; | |||||
function init(data) | |||||
{ | |||||
elexis: I guess thats a 2-liner. | |||||
let gameSelection = Engine.GetGUIObjectByName("gameSelection"); | |||||
gameSelection.selected = -1; | |||||
let campaigns = Engine.ListDirectoryFiles("campaignsaves/", "*.0adcampaign", false); | |||||
if (!campaigns.length) | |||||
{ | |||||
gameSelection.list = [translate("No ongoing campaigns.")]; | |||||
Done Inline ActionsShouldn't that alos have a list_data entry? At least it sounds like it might bug if we add code to display a tooltip upon selection. elexis: Shouldn't that alos have a `list_data` entry? At least it sounds like it might bug if we add… | |||||
gameSelection.list_data = [""]; | |||||
} | |||||
else | |||||
{ | |||||
gameSelection.list = campaigns.map(path => generateLabel(pathToGame(path))); | |||||
gameSelection.list_data = campaigns.map(path => pathToGame(path)); | |||||
} | |||||
if (data) | |||||
{ | |||||
g_CampaignID = data.campaignID; | |||||
g_CampaignState = data.campaignData; | |||||
} | |||||
} | |||||
function selectionChanged() | |||||
{ | |||||
let gameSelection = Engine.GetGUIObjectByName("gameSelection"); | |||||
Engine.GetGUIObjectByName("deleteGameButton").enabled = gameSelection.selected !== -1; | |||||
elexisUnsubmitted Not Done Inline Actions===, !== only if the type is relevant (for consistency) elexis: `===`, `!==` only if the type is relevant (for consistency) | |||||
} | |||||
function createAndStartCampaign() | |||||
Not Done Inline ActionsYes (for instance deleting the comment as requested in prior reviews) elexis: Yes (for instance deleting the comment as requested in prior reviews) | |||||
{ | |||||
let name = g_CampaignID + "_1"; | |||||
// TODO: use VFS::NextNumberedFilename like save games instead. | |||||
if (Engine.FileExists("campaignsaves/" + name + ".0adcampaign")) | |||||
{ | |||||
// get other campaigns following that template | |||||
let campaigns = Engine.ListDirectoryFiles("campaignsaves/", g_CampaignID + "_*.0adcampaign", false); | |||||
let max = 1; | |||||
for (let camp of campaigns) | |||||
{ | |||||
let nb = camp.replace("campaignsaves/" + g_CampaignID + "_", "").replace(".0adcampaign", ""); | |||||
if (+nb > max) | |||||
max = +nb; | |||||
} | |||||
name = g_CampaignID + "_" + (max+1); | |||||
} | |||||
saveCampaign(name, { "userDescription": Engine.GetGUIObjectByName("saveGameDesc").caption, "campaign": g_CampaignID }); | |||||
elexisUnsubmitted Not Done Inline Actionsassigning object properties on a separate line each arranges it more cleanly elexis: assigning object properties on a separate line each arranges it more cleanly | |||||
// inform user config that we are playing this campaign | |||||
Engine.ConfigDB_CreateValue("user", "currentcampaign", name); | |||||
Engine.ConfigDB_WriteValueToFile("user", "currentcampaign", name, "config/user.cfg"); | |||||
loadCurrentCampaignSave(); | |||||
} | |||||
Not Done Inline Actionswraitii you can't code. leper: wraitii you can't code. | |||||
Not Done Inline ActionsSome of the C++ code has functions to pick a subsequent number, but for this it might be nice to use the number padded with 0s or the date (+time?). leper: Some of the C++ code has functions to pick a subsequent number, but for this it might be nice… |
Wildfire Games · Phabricator
I guess thats a 2-liner.