1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Minor fixes and add save button

This commit is contained in:
tobspr
2020-05-14 22:05:06 +02:00
parent b01d38e55d
commit 330c98267a
8 changed files with 47 additions and 21 deletions

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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);
}