mirror of
https://github.com/tobspr/shapez.io.git
synced 2026-03-02 03:39:21 +00:00
Fix tslint errors
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user