Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/common/campaigns/CampaignRun.js
// Cached run for CampaignRun.getCurrentRun() | // Cached run for CampaignRun.getCurrentRun() | |||||||||
// TODO: Move this to a static member once linters accept it. | // TODO: Move this to a static member once linters accept it. | |||||||||
var g_CurrentCampaignRun; | var g_CurrentCampaignRun; | |||||||||
class CampaignRunDoesNotExistError extends Error | ||||||||||
{ | ||||||||||
toString() | ||||||||||
{ | ||||||||||
return sprintf(translate("Campaign file %(file)s does not exist."), { | ||||||||||
FreagarachUnsubmitted Not Done Inline Actions
Freagarach: | ||||||||||
"file": this.message | ||||||||||
}); | ||||||||||
} | ||||||||||
}; | ||||||||||
Lint: no-extra-semi Unnecessary semicolon. Lint: no-extra-semi: Unnecessary semicolon. | ||||||||||
class CampaignTemplateCannotLoadError extends Error | ||||||||||
{ | ||||||||||
toString() | ||||||||||
{ | ||||||||||
return sprintf(translate("Campaign template %(file)s does not exist (perhaps it comes from a mod?)."), { | ||||||||||
Not Done Inline Actions
Freagarach: | ||||||||||
"file": this.message | ||||||||||
}); | ||||||||||
} | ||||||||||
} | ||||||||||
/** | /** | |||||||||
* A campaign "Run" saves metadata on a campaign progession. | * A campaign "Run" saves metadata on a campaign progession. | |||||||||
* It is equivalent to a saved game for a game. | * It is equivalent to a saved game for a game. | |||||||||
* It is named a "run" in an attempt to disambiguate with saved games from campaign runs, | * It is named a "run" in an attempt to disambiguate with saved games from campaign runs, | |||||||||
* campaign templates, and the actual concept of a campaign at large. | * campaign templates, and the actual concept of a campaign at large. | |||||||||
* | * | |||||||||
* The intent is that this file should be lightweight to load/save. | * The intent is that this file should be lightweight to load/save. | |||||||||
*/ | */ | |||||||||
▲ Show 20 Lines • Show All 104 Lines • ▼ Show 20 Lines | return sprintf(translate("%(userDesc)s - %(templateName)s"), { | |||||||||
"userDesc": this.meta.userDescription, | "userDesc": this.meta.userDescription, | |||||||||
"templateName": this.template.Name | "templateName": this.template.Name | |||||||||
}); | }); | |||||||||
} | } | |||||||||
load() | load() | |||||||||
{ | { | |||||||||
if (!Engine.FileExists("saves/campaigns/" + this.filename + ".0adcampaign")) | if (!Engine.FileExists("saves/campaigns/" + this.filename + ".0adcampaign")) | |||||||||
throw new Error("Campaign file does not exist"); | throw new CampaignRunDoesNotExistError(this.filename); | |||||||||
let data = Engine.ReadJSONFile("saves/campaigns/" + this.filename + ".0adcampaign"); | let data = Engine.ReadJSONFile("saves/campaigns/" + this.filename + ".0adcampaign"); | |||||||||
this.data = data.data; | this.data = data.data; | |||||||||
this.meta = data.meta; | this.meta = data.meta; | |||||||||
this.template = CampaignTemplate.getTemplate(data.template_identifier); | this.template = CampaignTemplate.getTemplate(data.template_identifier); | |||||||||
if (!this.template) | if (!this.template) | |||||||||
throw new Error("Campaign template " + data.template_identifier + " does not exist (perhaps it comes from a mod?)"); | throw new CampaignTemplateCannotLoadError(data.template_identifier); | |||||||||
return this; | return this; | |||||||||
} | } | |||||||||
save() | save() | |||||||||
{ | { | |||||||||
let data = { | let data = { | |||||||||
"data": this.data, | "data": this.data, | |||||||||
"meta": this.meta, | "meta": this.meta, | |||||||||
Show All 13 Lines |
Wildfire Games · Phabricator