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

Initial support for saving games

This commit is contained in:
tobspr
2020-05-14 21:54:11 +02:00
parent 23874c43dc
commit b01d38e55d
44 changed files with 690 additions and 777 deletions

View File

@@ -1,13 +1,9 @@
import { DrawParameters } from "../../core/draw_parameters";
import { createLogger } from "../../core/logging";
import { extendSchema } from "../../savegame/serialization";
import { BaseItem } from "../base_item";
import { enumColorsToHexCode, enumColors } from "../colors";
import { makeOffscreenBuffer } from "../../core/buffer_utils";
import { globalConfig } from "../../core/config";
import { round1Digit } from "../../core/utils";
import { Math_max, Math_round } from "../../core/builtins";
import { smoothenDpi } from "../../core/dpi_manager";
import { DrawParameters } from "../../core/draw_parameters";
import { types } from "../../savegame/serialization";
import { BaseItem } from "../base_item";
import { enumColors, enumColorsToHexCode } from "../colors";
/** @enum {string} */
const enumColorToMapBackground = {
@@ -22,9 +18,15 @@ export class ColorItem extends BaseItem {
}
static getSchema() {
return extendSchema(BaseItem.getCachedSchema(), {
// TODO
});
return types.enum(enumColors);
}
serialize() {
return this.color;
}
deserialize(data) {
this.color = data;
}
/**
@@ -33,7 +35,6 @@ export class ColorItem extends BaseItem {
constructor(color) {
super();
this.color = color;
this.bufferGenerator = this.internalGenerateColorBuffer.bind(this);
}

View File

@@ -1,10 +1,7 @@
import { BaseItem } from "../base_item";
import { DrawParameters } from "../../core/draw_parameters";
import { extendSchema } from "../../savegame/serialization";
import { types } from "../../savegame/serialization";
import { BaseItem } from "../base_item";
import { ShapeDefinition } from "../shape_definition";
import { createLogger } from "../../core/logging";
const logger = createLogger("shape_item");
export class ShapeItem extends BaseItem {
static getId() {
@@ -12,9 +9,15 @@ export class ShapeItem extends BaseItem {
}
static getSchema() {
return extendSchema(BaseItem.getCachedSchema(), {
// TODO
});
return types.string;
}
serialize() {
return this.definition.getHash();
}
deserialize(data) {
this.definition = ShapeDefinition.fromShortKey(data);
}
/**