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_CampaignData = null; | |||||
// TODO: refuse empty names | |||||
elexis: I guess thats a 2-liner. | |||||
function init(data) | |||||
{ | |||||
// load existing campaigns | |||||
let gameSelection = Engine.GetGUIObjectByName("gameSelection"); | |||||
gameSelection.selected = -1; | |||||
let campaigns = Engine.BuildDirEntList("campaignsaves/", "*.0adcampaign", false); | |||||
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… | |||||
if (!campaigns.length) | |||||
gameSelection.list = [translate("No ongoing campaigns.")]; | |||||
else | |||||
{ | |||||
gameSelection.list = campaigns.map(path => generateLabel(pathToGame(path))); | |||||
gameSelection.list_data = campaigns.map(path => pathToGame(path)); | |||||
} | |||||
if (data) | |||||
{ | |||||
g_CampaignID = data.campaignID; | |||||
g_CampaignData = data.campaignData; | |||||
} | |||||
} | |||||
function selectionChanged() | |||||
{ | |||||
let gameSelection = Engine.GetGUIObjectByName("gameSelection"); | |||||
if (gameSelection.selected === -1) | |||||
return; | |||||
Not Done Inline Actions===, !== only if the type is relevant (for consistency) elexis: `===`, `!==` only if the type is relevant (for consistency) | |||||
// TODO: do something? | |||||
} | |||||
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) | |||||
function startCampaign() | |||||
{ | |||||
// TODO: handle overwrite and so on | |||||
// temp: prefill campaign name | |||||
realStartCampaign(Engine.GetGUIObjectByName("saveGameDesc").caption); | |||||
} | |||||
function realStartCampaign(desc) | |||||
{ | |||||
let name = g_CampaignID + "_1"; | |||||
// if file already exists, pick the number above the existing ones. Don't bother making it dense. | |||||
if (Engine.FileExists("campaignsaves/" + name + ".0adcampaign")) | |||||
{ | |||||
// get other campaigns following that template | |||||
let campaigns = Engine.BuildDirEntList("campaignsaves/", g_CampaignID + "_*.0adcampaign", false); | |||||
let max = 1; | |||||
for (let camp of campaigns) | |||||
{ | |||||
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 | |||||
let nb = camp.replace("campaignsaves/" + g_CampaignID + "_","").replace(".0adcampaign",""); | |||||
if (+nb > max) | |||||
max = +nb; | |||||
} | |||||
name = g_CampaignID + "_" + (max+1); | |||||
leperUnsubmitted 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… | |||||
// sanity check | |||||
if (Engine.FileExists("campaignsaves/" + name + ".0adcampaign")) | |||||
{ | |||||
error("tell wraitii he can't code"); | |||||
leperUnsubmitted Not Done Inline Actionswraitii you can't code. leper: wraitii you can't code. | |||||
return; | |||||
} | |||||
} | |||||
saveCampaign(name, {"userDescription" : desc, "campaign" : g_CampaignID}) | |||||
// 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(); | |||||
} | |||||
No newline at end of file |
Wildfire Games · Phabricator
I guess thats a 2-liner.