diff --git a/res/ui/icons/save.png b/res/ui/icons/save.png new file mode 100644 index 00000000..d48274bc Binary files /dev/null and b/res/ui/icons/save.png differ diff --git a/src/css/ingame_hud/game_menu.scss b/src/css/ingame_hud/game_menu.scss index c9a5c7f1..61da1eff 100644 --- a/src/css/ingame_hud/game_menu.scss +++ b/src/css/ingame_hud/game_menu.scss @@ -42,6 +42,29 @@ } } + &.save { + background-image: uiResource("icons/save.png"); + @include MakeAnimationWrappedEvenOdd(0.5s ease-in-out) { + 0% { + transform: scale(1, 1); + } + + 70% { + transform: scale(1.5, 1.5) rotate(20deg); + opacity: 0.2; + } + + 85% { + transform: scale(0.9, 0.9); + opacity: 1; + } + + 90% { + transform: scale(1.1, 1.1); + } + } + } + &.settings { background-image: uiResource("icons/settings.png"); } diff --git a/src/js/game/automatic_save.js b/src/js/game/automatic_save.js index 03686603..6c80976f 100644 --- a/src/js/game/automatic_save.js +++ b/src/js/game/automatic_save.js @@ -1,6 +1,7 @@ import { GameRoot } from "./root"; import { globalConfig, IS_DEBUG } from "../core/config"; import { Math_max } from "../core/builtins"; +import { createLogger } from "../core/logging"; // How important it is that a savegame is created /** @@ -11,15 +12,10 @@ export const enumSavePriority = { asap: 100, }; -// Internals -let MIN_INTERVAL_SECS = 15; +const logger = createLogger("autosave"); -if (G_IS_DEV && IS_DEBUG) { - // // Testing - // MIN_INTERVAL_SECS = 1; - // MAX_INTERVAL_SECS = 1; - MIN_INTERVAL_SECS = 9999999; -} +// Internals +let MIN_INTERVAL_SECS = 60; export class AutomaticSave { constructor(root) { @@ -50,6 +46,7 @@ export class AutomaticSave { // Bad idea 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()); @@ -72,7 +69,7 @@ export class AutomaticSave { break; } if (shouldSave) { - // log(this, "Saving automatically"); + logger.log("Saving automatically"); this.lastSaveAttempt = Date.now(); this.doSave(); } diff --git a/src/js/game/hud/parts/game_menu.js b/src/js/game/hud/parts/game_menu.js index fc129cea..db633355 100644 --- a/src/js/game/hud/parts/game_menu.js +++ b/src/js/game/hud/parts/game_menu.js @@ -52,13 +52,17 @@ export class HUDGameMenu extends BaseHUDPart { this.musicButton = makeDiv(menuButtons, null, ["button", "music"]); this.sfxButton = makeDiv(menuButtons, null, ["button", "sfx"]); + this.saveButton = makeDiv(menuButtons, null, ["button", "save", "animEven"]); this.settingsButton = makeDiv(menuButtons, null, ["button", "settings"]); this.trackClicks(this.musicButton, this.toggleMusic); this.trackClicks(this.sfxButton, this.toggleSfx); + this.trackClicks(this.saveButton, this.startSave); this.musicButton.classList.toggle("muted", this.root.app.settings.getAllSettings().musicMuted); this.sfxButton.classList.toggle("muted", this.root.app.settings.getAllSettings().musicMuted); + + this.root.signals.gameSaved.add(this.onGameSaved, this); } update() { @@ -75,6 +79,16 @@ export class HUDGameMenu extends BaseHUDPart { } } + onGameSaved() { + console.log("ON GAME SAVED"); + this.saveButton.classList.toggle("animEven"); + this.saveButton.classList.toggle("animOdd"); + } + + startSave() { + this.root.gameState.doSave(); + } + toggleMusic() { const newValue = !this.root.app.settings.getAllSettings().musicMuted; this.root.app.settings.updateSetting("musicMuted", newValue); diff --git a/src/js/game/item_registry.js b/src/js/game/item_registry.js index 2ecb89c5..b6a77836 100644 --- a/src/js/game/item_registry.js +++ b/src/js/game/item_registry.js @@ -1,6 +1,8 @@ import { gItemRegistry } from "../core/global_registries"; import { ShapeItem } from "./items/shape_item"; +import { ColorItem } from "./items/color_item"; export function initItemRegistry() { gItemRegistry.register(ShapeItem); + gItemRegistry.register(ColorItem); } diff --git a/src/js/savegame/savegame.js b/src/js/savegame/savegame.js index 3c52abfc..55286b93 100644 --- a/src/js/savegame/savegame.js +++ b/src/js/savegame/savegame.js @@ -187,14 +187,6 @@ export class Savegame extends ReadWriteProxy { if (!dump) { return false; } - const parsed = JSON.stringify(compressObject(dump)); - const compressed = compressX64(parsed); - - console.log("Regular: ", Math.round(parsed.length / 1024.0), "KB"); - console.log("Compressed: ", Math.round(compressed.length / 1024.0), "KB"); - - // let duration = performanceNow() - timer; - // console.log("TOOK", duration, "ms to generate dump:", dump); const shadowData = Object.assign({}, this.currentData); shadowData.dump = dump; diff --git a/src/js/states/ingame.js b/src/js/states/ingame.js index 0aa036ff..cb2d336a 100644 --- a/src/js/states/ingame.js +++ b/src/js/states/ingame.js @@ -165,7 +165,7 @@ export class InGameState extends GameState { return; } this.stageLeavingGame(); - this.doSave(false, true).then(() => { + this.doSave().then(() => { this.stageDestroyed(); this.moveToState(stateId, payload); }); @@ -424,6 +424,7 @@ export class InGameState extends GameState { // First update the game data logger.log("Starting to save game ..."); + this.core.root.signals.gameSaved.dispatch(); this.savegame.updateData(this.core.root); return this.savegame.writeSavegameAndMetadata().catch(err => { logger.warn("Failed to save:", err); diff --git a/src/js/webworkers/compression.worker.js b/src/js/webworkers/compression.worker.js index d1e661e4..0bcb0ea6 100644 --- a/src/js/webworkers/compression.worker.js +++ b/src/js/webworkers/compression.worker.js @@ -10,10 +10,7 @@ function accessNestedPropertyReverse(obj, keys) { return result; } -const rusha = require("rusha"); - const salt = accessNestedPropertyReverse(globalConfig, ["file", "info"]); -const encryptKey = globalConfig.info.sgSalt; onmessage = function (event) { const { jobId, job, data } = event.data;