mirror of
https://github.com/tobspr/shapez.io.git
synced 2024-10-27 20:34:29 +00:00
Fix tslint errors
This commit is contained in:
parent
cf5d776270
commit
85951615a9
@ -1,3 +1,5 @@
|
||||
// @ts-nocheck
|
||||
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const utils = require("./buildutils");
|
||||
|
@ -1,3 +1,5 @@
|
||||
// @ts-nocheck
|
||||
|
||||
const path = require("path");
|
||||
const webpack = require("webpack");
|
||||
const utils = require("./buildutils");
|
||||
|
@ -8,6 +8,7 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "./gulp/gulp main.serveDev",
|
||||
"tslint": "cd src/js && tsc",
|
||||
"prettier-all": "prettier --write src/**/*.* && prettier --write gulp/**/*.*"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -22,17 +22,10 @@ export class AtlasDefinition {
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
export const atlasFiles = require
|
||||
// @ts-ignore
|
||||
.context("../../../res_built/atlas/", false, /.*\.json/i)
|
||||
.keys()
|
||||
.map(f => f.replace(/^\.\//gi, ""))
|
||||
.map(f => require("../../../res_built/atlas/" + f))
|
||||
.map(data => new AtlasDefinition(data));
|
||||
|
||||
// export const atlasDefinitions = {
|
||||
// qualityPreload: atlasFiles.filter((atlas) => atlas.meta.image.indexOf("_preload") >= 0),
|
||||
// qualityLow: atlasFiles.filter((atlas) => atlas.meta.image.indexOf("_low") >= 0),
|
||||
// qualityMedium: atlasFiles.filter((atlas) => atlas.meta.image.indexOf("_medium") >= 0),
|
||||
// qualityHigh: atlasFiles.filter((atlas) => atlas.meta.image.indexOf("_high") >= 0),
|
||||
// };
|
||||
|
@ -1,13 +1,7 @@
|
||||
import { GameRoot } from "../game/root";
|
||||
import {
|
||||
makeOffscreenBuffer,
|
||||
freeCanvas,
|
||||
getBufferVramUsageBytes,
|
||||
getBufferStats,
|
||||
clearBufferBacklog,
|
||||
} from "./buffer_utils";
|
||||
import { clearBufferBacklog, freeCanvas, getBufferStats, makeOffscreenBuffer } from "./buffer_utils";
|
||||
import { createLogger } from "./logging";
|
||||
import { round2Digits, round1Digit } from "./utils";
|
||||
import { round1Digit } from "./utils";
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
|
@ -1,11 +1,21 @@
|
||||
import { createLogger } from "./logging";
|
||||
|
||||
const logger = createLogger("singleton_factory");
|
||||
|
||||
// simple factory pattern
|
||||
export class SingletonFactory {
|
||||
constructor() {
|
||||
constructor(id) {
|
||||
this.id = id;
|
||||
|
||||
// Store array as well as dictionary, to speed up lookups
|
||||
this.entries = [];
|
||||
this.idToEntry = {};
|
||||
}
|
||||
|
||||
getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
register(classHandle) {
|
||||
// First, construct instance
|
||||
const instance = new classHandle();
|
||||
@ -39,6 +49,7 @@ export class SingletonFactory {
|
||||
findById(id) {
|
||||
const entry = this.idToEntry[id];
|
||||
if (!entry) {
|
||||
logger.error("Object with id", id, "is not registered!");
|
||||
assert(false, "Factory: Object with id '" + id + "' is not registered!");
|
||||
return null;
|
||||
}
|
||||
@ -68,6 +79,14 @@ export class SingletonFactory {
|
||||
return this.entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all registered ids
|
||||
* @returns {Array<string>}
|
||||
*/
|
||||
getAllIds() {
|
||||
return Object.keys(this.idToEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns amount of stored entries
|
||||
* @returns {number}
|
||||
|
@ -436,26 +436,6 @@ export function formatBigNumber(num, divider = ".") {
|
||||
return sign + "" + num;
|
||||
}
|
||||
|
||||
// if (num > 1e51) return sign + T.common.number_format.sedecillion.replace("%amount%", "" + roundSmart(num / 1e51));
|
||||
// if (num > 1e48)
|
||||
// return sign + T.common.number_format.quinquadecillion.replace("%amount%", "" + roundSmart(num / 1e48));
|
||||
// if (num > 1e45)
|
||||
// return sign + T.common.number_format.quattuordecillion.replace("%amount%", "" + roundSmart(num / 1e45));
|
||||
// if (num > 1e42) return sign + T.common.number_format.tredecillion.replace("%amount%", "" + roundSmart(num / 1e42));
|
||||
// if (num > 1e39) return sign + T.common.number_format.duodecillions.replace("%amount%", "" + roundSmart(num / 1e39));
|
||||
// if (num > 1e36) return sign + T.common.number_format.undecillions.replace("%amount%", "" + roundSmart(num / 1e36));
|
||||
// if (num > 1e33) return sign + T.common.number_format.decillions.replace("%amount%", "" + roundSmart(num / 1e33));
|
||||
// if (num > 1e30) return sign + T.common.number_format.nonillions.replace("%amount%", "" + roundSmart(num / 1e30));
|
||||
// if (num > 1e27) return sign + T.common.number_format.octillions.replace("%amount%", "" + roundSmart(num / 1e27));
|
||||
// if (num >= 1e24) return sign + T.common.number_format.septillions.replace("%amount%", "" + roundSmart(num / 1e24));
|
||||
// if (num >= 1e21) return sign + T.common.number_format.sextillions.replace("%amount%", "" + roundSmart(num / 1e21));
|
||||
// if (num >= 1e18) return sign + T.common.number_format.quintillions.replace("%amount%", "" + roundSmart(num / 1e18));
|
||||
// if (num >= 1e15) return sign + T.common.number_format.quantillions.replace("%amount%", "" + roundSmart(num / 1e15));
|
||||
// if (num >= 1e12) return sign + T.common.number_format.trillions.replace("%amount%", "" + roundSmart(num / 1e12));
|
||||
// if (num >= 1e9) return sign + T.common.number_format.billions.replace("%amount%", "" + roundSmart(num / 1e9));
|
||||
// if (num >= 1e6) return sign + T.common.number_format.millions.replace("%amount%", "" + roundSmart(num / 1e6));
|
||||
// if (num > 99999) return sign + T.common.number_format.thousands.replace("%amount%", "" + roundSmart(num / 1e3));
|
||||
|
||||
let rest = num;
|
||||
let out = "";
|
||||
|
||||
@ -474,7 +454,7 @@ export function formatBigNumber(num, divider = ".") {
|
||||
* @param {string=} divider THe divider for numbers like 50,000 (divider=',')
|
||||
* @returns {string}
|
||||
*/
|
||||
export function formatBigNumberFull(num, divider = T.common.number_format.divider_thousands || " ") {
|
||||
export function formatBigNumberFull(num, divider = ",") {
|
||||
if (num < 1000) {
|
||||
return num + "";
|
||||
}
|
||||
@ -492,65 +472,6 @@ export function formatBigNumberFull(num, divider = T.common.number_format.divide
|
||||
return out.substring(0, out.length - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats an amount of seconds into something like "5s ago"
|
||||
* @param {number} secs Seconds
|
||||
* @returns {string}
|
||||
*/
|
||||
export function formatSecondsToTimeAgo(secs) {
|
||||
const seconds = Math_floor(secs);
|
||||
const minutes = Math_floor(seconds / 60);
|
||||
const hours = Math_floor(minutes / 60);
|
||||
const days = Math_floor(hours / 24);
|
||||
|
||||
const trans = T.common.time;
|
||||
|
||||
if (seconds <= 60) {
|
||||
if (seconds <= 1) {
|
||||
return trans.one_second_before;
|
||||
}
|
||||
return trans.seconds_before.replace("%amount%", "" + seconds);
|
||||
} else if (minutes <= 60) {
|
||||
if (minutes <= 1) {
|
||||
return trans.one_minute_before;
|
||||
}
|
||||
return trans.minutes_before.replace("%amount%", "" + minutes);
|
||||
} else if (hours <= 60) {
|
||||
if (hours <= 1) {
|
||||
return trans.one_hour_before;
|
||||
}
|
||||
return trans.hours_before.replace("%amount%", "" + hours);
|
||||
} else {
|
||||
if (days <= 1) {
|
||||
return trans.one_day_before;
|
||||
}
|
||||
return trans.days_before.replace("%amount%", "" + days);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats seconds into a readable string like "5h 23m"
|
||||
* @param {number} secs Seconds
|
||||
* @returns {string}
|
||||
*/
|
||||
export function formatSeconds(secs) {
|
||||
const trans = T.common.time;
|
||||
secs = Math_ceil(secs);
|
||||
if (secs < 60) {
|
||||
return trans.seconds_short.replace("%seconds%", "" + secs);
|
||||
} else if (secs < 60 * 60) {
|
||||
const minutes = Math_floor(secs / 60);
|
||||
const seconds = secs % 60;
|
||||
return trans.minutes_seconds_short
|
||||
.replace("%seconds%", "" + seconds)
|
||||
.replace("%minutes%", "" + minutes);
|
||||
} else {
|
||||
const hours = Math_floor(secs / 3600);
|
||||
const minutes = Math_floor(secs / 60) % 60;
|
||||
return trans.hours_minutes_short.replace("%minutes%", "" + minutes).replace("%hours%", "" + hours);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delayes a promise so that it will resolve after a *minimum* amount of time only
|
||||
* @param {Promise<any>} promise The promise to delay
|
||||
|
@ -143,11 +143,7 @@ export class ShapeDefinitionManager extends BasicSerializableObject {
|
||||
*/
|
||||
getDefinitionFromSimpleShapes(subShapes, color = enumColors.uncolored) {
|
||||
const shapeLayer = /** @type {import("./shape_definition").ShapeLayer} */ (subShapes.map(
|
||||
subShape => ({
|
||||
subShape,
|
||||
rotation: 0,
|
||||
color,
|
||||
})
|
||||
subShape => ({ subShape, color })
|
||||
));
|
||||
|
||||
return this.registerOrReturnHandle(new ShapeDefinition({ layers: [shapeLayer] }));
|
||||
|
4
src/js/globals.d.ts
vendored
4
src/js/globals.d.ts
vendored
@ -148,7 +148,7 @@ declare interface Math {
|
||||
}
|
||||
|
||||
declare interface String {
|
||||
padStart(size: number, fill: string): string;
|
||||
padStart(size: number, fill?: string): string;
|
||||
padEnd(size: number, fill: string): string;
|
||||
}
|
||||
|
||||
@ -170,6 +170,8 @@ declare interface SingletonFactoryTemplate<T> {
|
||||
entries: Array<T>;
|
||||
idToEntry: any;
|
||||
|
||||
getId(): string;
|
||||
getAllIds(): Array<string>;
|
||||
register(classHandle: new (...args: any[]) => T): void;
|
||||
hasId(id: string): boolean;
|
||||
findById(id: string): T;
|
||||
|
@ -30,7 +30,7 @@ export class BaseSetting {
|
||||
/**
|
||||
* @param {Application} app
|
||||
* @param {Element} element
|
||||
* @param {HUDModalDialogs} dialogs
|
||||
* @param {any} dialogs
|
||||
*/
|
||||
bind(app, element, dialogs) {
|
||||
this.app = app;
|
||||
|
@ -141,24 +141,6 @@ export class SavegameSerializer {
|
||||
// entities
|
||||
errorReason = errorReason || root.entityMgr.deserialize(savegame.entityMgr);
|
||||
|
||||
// resources
|
||||
errorReason =
|
||||
errorReason ||
|
||||
this.internal.deserializeEntityArrayFixedType(
|
||||
root,
|
||||
savegame.entities.resources,
|
||||
this.internal.deserializeResource
|
||||
);
|
||||
|
||||
// buildings
|
||||
errorReason =
|
||||
errorReason ||
|
||||
this.internal.deserializeEntityArray(
|
||||
root,
|
||||
savegame.entities.buildings,
|
||||
this.internal.deserializeBuilding
|
||||
);
|
||||
|
||||
// other stuff
|
||||
errorReason = errorReason || root.time.deserialize(savegame.time);
|
||||
errorReason = errorReason || root.camera.deserialize(savegame.camera);
|
||||
|
@ -270,8 +270,7 @@ export function deserializeSchema(obj, schema, data, baseclassErrorResult = null
|
||||
|
||||
const errorStatus = schema[key].deserializeWithVerify(data[key], obj, key, obj.root);
|
||||
if (errorStatus) {
|
||||
error(
|
||||
"serialization",
|
||||
logger.error(
|
||||
"Deserialization failed with error '" + errorStatus + "' on object",
|
||||
obj,
|
||||
"and key",
|
||||
@ -294,17 +293,17 @@ export function deserializeSchema(obj, schema, data, baseclassErrorResult = null
|
||||
export function verifySchema(schema, data) {
|
||||
for (const key in schema) {
|
||||
if (!data.hasOwnProperty(key)) {
|
||||
error("verify", "Data", data, "does not contain", key, "(schema:", schema, ")");
|
||||
logger.error("Data", data, "does not contain", key, "(schema:", schema, ")");
|
||||
return "verify: missing key required by schema in stored data: " + key;
|
||||
}
|
||||
if (!schema[key].allowNull() && (data[key] === null || data[key] === undefined)) {
|
||||
error("verify", "Data", data, "has null value for", key, "(schema:", schema, ")");
|
||||
logger.error("Data", data, "has null value for", key, "(schema:", schema, ")");
|
||||
return "verify: non-nullable entry is null: " + key;
|
||||
}
|
||||
|
||||
const errorStatus = schema[key].verifySerializedValue(data[key]);
|
||||
if (errorStatus) {
|
||||
error("verify", errorStatus);
|
||||
logger.error(errorStatus);
|
||||
return "verify: " + errorStatus;
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import { Vector } from "../core/vector";
|
||||
import { createLogger } from "../core/logging";
|
||||
import { gMetaBuildingRegistry } from "../core/global_registries";
|
||||
import { Entity } from "../game/entity";
|
||||
import { MapResourcesSystem } from "../game/systems/map_resources";
|
||||
|
||||
const logger = createLogger("serializer_internal");
|
||||
|
||||
@ -80,61 +81,6 @@ export class SerializerInternal {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a building
|
||||
* @param {GameRoot} root
|
||||
* @param {{ $: string, data: any }} payload
|
||||
*/
|
||||
deserializeBuilding(root, payload) {
|
||||
const data = payload.data;
|
||||
const id = payload.$;
|
||||
if (!gMetaBuildingRegistry.hasId(id)) {
|
||||
return "Metaclass not found for building: '" + id + "'";
|
||||
}
|
||||
const meta = gMetaBuildingRegistry.findById(id);
|
||||
if (!meta) {
|
||||
return "Metaclass not found for building: '" + id + "'";
|
||||
}
|
||||
|
||||
const tile = new Vector(data.x, data.y).toTileSpace();
|
||||
const instance = root.logic.internalPlaceBuildingLocalClientOnly({
|
||||
tile: tile,
|
||||
metaBuilding: meta,
|
||||
uid: data.uid,
|
||||
});
|
||||
|
||||
// Apply component specific properties
|
||||
const errorStatus = this.deserializeComponents(instance, data.components);
|
||||
if (errorStatus) {
|
||||
return errorStatus;
|
||||
}
|
||||
|
||||
// Apply enhancements
|
||||
instance.updateEnhancements();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a blueprint
|
||||
* @param {GameRoot} root
|
||||
* @param {any} data
|
||||
* @returns {string|void}
|
||||
*/
|
||||
deserializeBlueprint(root, data) {
|
||||
const id = data.meta;
|
||||
const metaClass = gMetaBuildingRegistry.findById(id);
|
||||
if (!metaClass) {
|
||||
return "Metaclass not found for blueprint: '" + id + "'";
|
||||
}
|
||||
|
||||
const tile = new Vector(data.x, data.y).toTileSpace();
|
||||
const instance = root.logic.internalPlaceBlueprintLocalClientOnly({
|
||||
tile: tile,
|
||||
metaBuilding: metaClass,
|
||||
uid: data.uid,
|
||||
});
|
||||
return this.deserializeComponents(instance, data.components);
|
||||
}
|
||||
|
||||
/////// COMPONENTS ////
|
||||
|
||||
/**
|
||||
@ -161,20 +107,4 @@ export class SerializerInternal {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a resource
|
||||
* @param {GameRoot} root
|
||||
* @param {object} data
|
||||
* @returns {string|void}
|
||||
*/
|
||||
deserializeResource(root, data) {
|
||||
const id = data.key;
|
||||
const instance = new MapResource(root, this.neutralFaction, id);
|
||||
root.logic.internalPlaceMapEntityLocalClientOnly(
|
||||
new Vector(data.x, data.y).toTileSpace(),
|
||||
instance,
|
||||
data.uid
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -198,10 +198,10 @@ export class InGameState extends GameState {
|
||||
this.core.initializeRoot(this, this.savegame);
|
||||
|
||||
if (this.savegame.hasGameDump()) {
|
||||
this.app.gameAnalytics.handleGameStarted(this.savegame);
|
||||
this.app.gameAnalytics.handleGameStarted();
|
||||
this.stage4bResumeGame();
|
||||
} else {
|
||||
this.app.gameAnalytics.handleGameStarted(this.savegame);
|
||||
this.app.gameAnalytics.handleGameStarted();
|
||||
this.stage4aInitEmptyGame();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user