From a8b37792e4c9ff3d8a98d72b627050990475eff5 Mon Sep 17 00:00:00 2001 From: tobspr Date: Mon, 22 Jun 2020 12:09:02 +0200 Subject: [PATCH] Allow configuring autosave interval --- gulp/gulpfile.js | 4 +- gulp/sounds.js | 26 +++++++++++ src/js/changelog.js | 11 +++++ src/js/game/automatic_save.js | 10 ++++- src/js/profile/application_settings.js | 60 +++++++++++++++++++++++++- version | 2 +- 6 files changed, 107 insertions(+), 6 deletions(-) diff --git a/gulp/gulpfile.js b/gulp/gulpfile.js index cf0077bd..f2fdd9d4 100644 --- a/gulp/gulpfile.js +++ b/gulp/gulpfile.js @@ -269,7 +269,7 @@ gulp.task("build.prod", gulp.series("utils.cleanup", "step.prod.all", "step.post // Builds everything (standalone-beta) gulp.task( "step.standalone-beta.code", - gulp.series("sounds.fullbuild", "translations.fullBuild", "js.standalone-beta") + gulp.series("sounds.fullbuildHQ", "translations.fullBuild", "js.standalone-beta") ); gulp.task("step.standalone-beta.mainbuild", gulp.parallel("step.baseResources", "step.standalone-beta.code")); gulp.task( @@ -284,7 +284,7 @@ gulp.task( // Builds everything (standalone-prod) gulp.task( "step.standalone-prod.code", - gulp.series("sounds.fullbuild", "translations.fullBuild", "js.standalone-prod") + gulp.series("sounds.fullbuildHQ", "translations.fullBuild", "js.standalone-prod") ); gulp.task("step.standalone-prod.mainbuild", gulp.parallel("step.baseResources", "step.standalone-prod.code")); gulp.task( diff --git a/gulp/sounds.js b/gulp/sounds.js index 0e8dee12..c38e7a6e 100644 --- a/gulp/sounds.js +++ b/gulp/sounds.js @@ -40,6 +40,30 @@ function gulptasksSounds($, gulp, buildFolder) { .pipe(gulp.dest(path.join(builtSoundsDir, "music"))); }); + // Encodes the game music in high quality for the standalone + gulp.task("sounds.musicHQ", () => { + return gulp + .src([path.join(soundsDir, "music", "**", "*.wav"), path.join(soundsDir, "music", "**", "*.mp3")]) + .pipe($.plumber()) + .pipe( + $.cache( + $.fluentFfmpeg("mp3", function (cmd) { + return cmd + .audioBitrate(256) + .audioChannels(2) + .audioFrequency(44100) + .audioCodec("libmp3lame") + .audioFilters(["volume=0.15"]); + }), + { + name: "music-high-quality", + fileCache, + } + ) + ) + .pipe(gulp.dest(path.join(builtSoundsDir, "music"))); + }); + // Encodes the ui sounds gulp.task("sounds.sfxGenerateSprites", () => { return gulp @@ -91,8 +115,10 @@ function gulptasksSounds($, gulp, buildFolder) { }); gulp.task("sounds.buildall", gulp.parallel("sounds.music", "sounds.sfx")); + gulp.task("sounds.buildallHQ", gulp.parallel("sounds.musicHQ", "sounds.sfx")); gulp.task("sounds.fullbuild", gulp.series("sounds.clear", "sounds.buildall", "sounds.copy")); + gulp.task("sounds.fullbuildHQ", gulp.series("sounds.clear", "sounds.buildallHQ", "sounds.copy")); gulp.task("sounds.dev", gulp.series("sounds.buildall", "sounds.copy")); } diff --git a/src/js/changelog.js b/src/js/changelog.js index fa41760b..70736542 100644 --- a/src/js/changelog.js +++ b/src/js/changelog.js @@ -1,4 +1,15 @@ export const CHANGELOG = [ + { + version: "1.1.17", + date: "unreleased", + entries: [ + "Allow configuring autosave interval and disabling it in the settings", + "The soundtrack now has a higher quality on the standalone version than the web version", + "Add setting to disable cut/delete warnings (by hexy)", + "Fix bug where belts in blueprints don't orient correctly (by hexy)", + "Update tutorial image for tier 2 tunnels to explain mix/match (by jimmyshadow1)", + ], + }, { version: "1.1.16", date: "21.06.2020", diff --git a/src/js/game/automatic_save.js b/src/js/game/automatic_save.js index 6c80976f..1b3f13ca 100644 --- a/src/js/game/automatic_save.js +++ b/src/js/game/automatic_save.js @@ -47,10 +47,16 @@ export class AutomaticSave { return; } + const saveInterval = this.root.app.settings.getAutosaveIntervalSeconds(); + if (!saveInterval) { + // Disabled + return; + } + // Check when the last save was, but make sure that if it fails, we don't spam const lastSaveTime = Math_max(this.lastSaveAttempt, this.root.savegame.getRealLastUpdate()); - let secondsSinceLastSave = (Date.now() - lastSaveTime) / 1000.0; + const secondsSinceLastSave = (Date.now() - lastSaveTime) / 1000.0; let shouldSave = false; switch (this.saveImportance) { @@ -61,7 +67,7 @@ export class AutomaticSave { case enumSavePriority.regular: // Could determine if there is a good / bad point here - shouldSave = secondsSinceLastSave > MIN_INTERVAL_SECS; + shouldSave = secondsSinceLastSave > saveInterval; break; default: diff --git a/src/js/profile/application_settings.js b/src/js/profile/application_settings.js index 4a87ef16..1aa2b604 100644 --- a/src/js/profile/application_settings.js +++ b/src/js/profile/application_settings.js @@ -89,6 +89,33 @@ export const movementSpeeds = [ }, ]; +export const autosaveIntervals = [ + { + id: "one_minute", + seconds: 60, + }, + { + id: "two_minutes", + seconds: 120, + }, + { + id: "five_minutes", + seconds: 5 * 60, + }, + { + id: "ten_minutes", + seconds: 10 * 60, + }, + { + id: "twenty_minutes", + seconds: 20 * 60, + }, + { + id: "disabled", + seconds: null, + }, +]; + /** @type {Array} */ export const allApplicationSettings = [ new EnumSetting("language", { @@ -165,6 +192,19 @@ export const allApplicationSettings = [ enabled: !IS_DEMO, }), + new EnumSetting("autosaveInterval", { + options: autosaveIntervals, + valueGetter: interval => interval.id, + textGetter: interval => T.settings.labels.autosaveInterval.intervals[interval.id], + category: categoryGame, + restartRequired: false, + changeCb: + /** + * @param {Application} app + */ + (app, id) => null, + }), + new EnumSetting("refreshRate", { options: ["60", "100", "144", "165", "250", "500"], valueGetter: rate => rate, @@ -220,6 +260,7 @@ class SettingsStorage { this.scrollWheelSensitivity = "regular"; this.movementSpeed = "regular"; this.language = "auto-detect"; + this.autosaveInterval = "two_minutes"; this.alwaysMultiplace = false; this.offerHints = true; @@ -321,6 +362,17 @@ export class ApplicationSettings extends ReadWriteProxy { return 1; } + getAutosaveIntervalSeconds() { + const id = this.getAllSettings().autosaveInterval; + for (let i = 0; i < autosaveIntervals.length; ++i) { + if (autosaveIntervals[i].id === id) { + return autosaveIntervals[i].seconds; + } + } + logger.error("Unknown autosave interval id:", id); + return 120; + } + getIsFullScreen() { return this.getAllSettings().fullscreen; } @@ -416,7 +468,7 @@ export class ApplicationSettings extends ReadWriteProxy { } getCurrentVersion() { - return 14; + return 15; } /** @param {{settings: SettingsStorage, version: number}} data */ @@ -472,6 +524,12 @@ export class ApplicationSettings extends ReadWriteProxy { data.settings.disableCutDeleteWarnings = false; data.version = 14; } + + if (data.version < 15) { + data.settings.autosaveInterval = "two_minutes"; + data.version = 15; + } + return ExplainedResult.good(); } } diff --git a/version b/version index b01de297..95ce23d4 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.1.16 \ No newline at end of file +1.1.17 \ No newline at end of file