mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-06-06 01:24:04 +00:00
Minor fixes and add save button
This commit is contained in:
parent
b01d38e55d
commit
330c98267a
BIN
res/ui/icons/save.png
Normal file
BIN
res/ui/icons/save.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 728 B |
@ -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 {
|
&.settings {
|
||||||
background-image: uiResource("icons/settings.png");
|
background-image: uiResource("icons/settings.png");
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { GameRoot } from "./root";
|
import { GameRoot } from "./root";
|
||||||
import { globalConfig, IS_DEBUG } from "../core/config";
|
import { globalConfig, IS_DEBUG } from "../core/config";
|
||||||
import { Math_max } from "../core/builtins";
|
import { Math_max } from "../core/builtins";
|
||||||
|
import { createLogger } from "../core/logging";
|
||||||
|
|
||||||
// How important it is that a savegame is created
|
// How important it is that a savegame is created
|
||||||
/**
|
/**
|
||||||
@ -11,15 +12,10 @@ export const enumSavePriority = {
|
|||||||
asap: 100,
|
asap: 100,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Internals
|
const logger = createLogger("autosave");
|
||||||
let MIN_INTERVAL_SECS = 15;
|
|
||||||
|
|
||||||
if (G_IS_DEV && IS_DEBUG) {
|
// Internals
|
||||||
// // Testing
|
let MIN_INTERVAL_SECS = 60;
|
||||||
// MIN_INTERVAL_SECS = 1;
|
|
||||||
// MAX_INTERVAL_SECS = 1;
|
|
||||||
MIN_INTERVAL_SECS = 9999999;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class AutomaticSave {
|
export class AutomaticSave {
|
||||||
constructor(root) {
|
constructor(root) {
|
||||||
@ -50,6 +46,7 @@ export class AutomaticSave {
|
|||||||
// Bad idea
|
// Bad idea
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check when the last save was, but make sure that if it fails, we don't spam
|
// 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());
|
const lastSaveTime = Math_max(this.lastSaveAttempt, this.root.savegame.getRealLastUpdate());
|
||||||
|
|
||||||
@ -72,7 +69,7 @@ export class AutomaticSave {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (shouldSave) {
|
if (shouldSave) {
|
||||||
// log(this, "Saving automatically");
|
logger.log("Saving automatically");
|
||||||
this.lastSaveAttempt = Date.now();
|
this.lastSaveAttempt = Date.now();
|
||||||
this.doSave();
|
this.doSave();
|
||||||
}
|
}
|
||||||
|
@ -52,13 +52,17 @@ export class HUDGameMenu extends BaseHUDPart {
|
|||||||
|
|
||||||
this.musicButton = makeDiv(menuButtons, null, ["button", "music"]);
|
this.musicButton = makeDiv(menuButtons, null, ["button", "music"]);
|
||||||
this.sfxButton = makeDiv(menuButtons, null, ["button", "sfx"]);
|
this.sfxButton = makeDiv(menuButtons, null, ["button", "sfx"]);
|
||||||
|
this.saveButton = makeDiv(menuButtons, null, ["button", "save", "animEven"]);
|
||||||
this.settingsButton = makeDiv(menuButtons, null, ["button", "settings"]);
|
this.settingsButton = makeDiv(menuButtons, null, ["button", "settings"]);
|
||||||
|
|
||||||
this.trackClicks(this.musicButton, this.toggleMusic);
|
this.trackClicks(this.musicButton, this.toggleMusic);
|
||||||
this.trackClicks(this.sfxButton, this.toggleSfx);
|
this.trackClicks(this.sfxButton, this.toggleSfx);
|
||||||
|
this.trackClicks(this.saveButton, this.startSave);
|
||||||
|
|
||||||
this.musicButton.classList.toggle("muted", this.root.app.settings.getAllSettings().musicMuted);
|
this.musicButton.classList.toggle("muted", this.root.app.settings.getAllSettings().musicMuted);
|
||||||
this.sfxButton.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() {
|
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() {
|
toggleMusic() {
|
||||||
const newValue = !this.root.app.settings.getAllSettings().musicMuted;
|
const newValue = !this.root.app.settings.getAllSettings().musicMuted;
|
||||||
this.root.app.settings.updateSetting("musicMuted", newValue);
|
this.root.app.settings.updateSetting("musicMuted", newValue);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import { gItemRegistry } from "../core/global_registries";
|
import { gItemRegistry } from "../core/global_registries";
|
||||||
import { ShapeItem } from "./items/shape_item";
|
import { ShapeItem } from "./items/shape_item";
|
||||||
|
import { ColorItem } from "./items/color_item";
|
||||||
|
|
||||||
export function initItemRegistry() {
|
export function initItemRegistry() {
|
||||||
gItemRegistry.register(ShapeItem);
|
gItemRegistry.register(ShapeItem);
|
||||||
|
gItemRegistry.register(ColorItem);
|
||||||
}
|
}
|
||||||
|
@ -187,14 +187,6 @@ export class Savegame extends ReadWriteProxy {
|
|||||||
if (!dump) {
|
if (!dump) {
|
||||||
return false;
|
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);
|
const shadowData = Object.assign({}, this.currentData);
|
||||||
shadowData.dump = dump;
|
shadowData.dump = dump;
|
||||||
|
@ -165,7 +165,7 @@ export class InGameState extends GameState {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.stageLeavingGame();
|
this.stageLeavingGame();
|
||||||
this.doSave(false, true).then(() => {
|
this.doSave().then(() => {
|
||||||
this.stageDestroyed();
|
this.stageDestroyed();
|
||||||
this.moveToState(stateId, payload);
|
this.moveToState(stateId, payload);
|
||||||
});
|
});
|
||||||
@ -424,6 +424,7 @@ export class InGameState extends GameState {
|
|||||||
|
|
||||||
// First update the game data
|
// First update the game data
|
||||||
logger.log("Starting to save game ...");
|
logger.log("Starting to save game ...");
|
||||||
|
this.core.root.signals.gameSaved.dispatch();
|
||||||
this.savegame.updateData(this.core.root);
|
this.savegame.updateData(this.core.root);
|
||||||
return this.savegame.writeSavegameAndMetadata().catch(err => {
|
return this.savegame.writeSavegameAndMetadata().catch(err => {
|
||||||
logger.warn("Failed to save:", err);
|
logger.warn("Failed to save:", err);
|
||||||
|
@ -10,10 +10,7 @@ function accessNestedPropertyReverse(obj, keys) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
const rusha = require("rusha");
|
|
||||||
|
|
||||||
const salt = accessNestedPropertyReverse(globalConfig, ["file", "info"]);
|
const salt = accessNestedPropertyReverse(globalConfig, ["file", "info"]);
|
||||||
const encryptKey = globalConfig.info.sgSalt;
|
|
||||||
|
|
||||||
onmessage = function (event) {
|
onmessage = function (event) {
|
||||||
const { jobId, job, data } = event.data;
|
const { jobId, job, data } = event.data;
|
||||||
|
Loading…
Reference in New Issue
Block a user