mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-09 16:21:51 +00:00
Remove unused config properties
Remove globalConfig properties that are not used anywhere, simplify mobile device detection (mostly unused for normal builds) and merge or inline config constants where it makes sense.
This commit is contained in:
parent
f949fb14bd
commit
51c0352079
@ -35,12 +35,6 @@ INGAME_ASSETS.sounds = [];
|
||||
|
||||
const LOADER_TIMEOUT_PER_RESOURCE = 180000;
|
||||
|
||||
// Cloudflare does not send content-length headers with brotli compression,
|
||||
// so store the actual (compressed) file sizes so we can show a progress bar.
|
||||
const HARDCODED_FILE_SIZES = {
|
||||
"async-resources.css": 2216145,
|
||||
};
|
||||
|
||||
export class BackgroundResourcesLoader {
|
||||
/**
|
||||
*
|
||||
@ -86,7 +80,7 @@ export class BackgroundResourcesLoader {
|
||||
/**
|
||||
* @type {((progressHandler: (progress: number) => void) => Promise<void>)[]}
|
||||
*/
|
||||
let promiseFunctions = [];
|
||||
const promiseFunctions = [];
|
||||
|
||||
// CSS
|
||||
for (let i = 0; i < css.length; ++i) {
|
||||
@ -127,7 +121,7 @@ export class BackgroundResourcesLoader {
|
||||
|
||||
// SFX & Music
|
||||
for (let i = 0; i < sounds.length; ++i) {
|
||||
promiseFunctions.push(progress =>
|
||||
promiseFunctions.push(() =>
|
||||
timeoutPromise(this.app.sound.loadSound(sounds[i]), LOADER_TIMEOUT_PER_RESOURCE).catch(
|
||||
err => {
|
||||
logger.warn("Failed to load sound, will not be available:", sounds[i], err);
|
||||
@ -143,7 +137,7 @@ export class BackgroundResourcesLoader {
|
||||
|
||||
let progress = 0;
|
||||
this.resourceStateChangedSignal.dispatch({ progress });
|
||||
let promises = [];
|
||||
const promises = [];
|
||||
|
||||
for (let i = 0; i < promiseFunctions.length; i++) {
|
||||
let lastIndividualProgress = 0;
|
||||
@ -180,27 +174,12 @@ export class BackgroundResourcesLoader {
|
||||
preloadWithProgress(src, progressHandler) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
let notifiedNotComputable = false;
|
||||
|
||||
xhr.open("GET", src, true);
|
||||
xhr.responseType = "arraybuffer";
|
||||
xhr.onprogress = function (ev) {
|
||||
if (ev.lengthComputable) {
|
||||
progressHandler(ev.loaded / ev.total);
|
||||
} else {
|
||||
if (window.location.search.includes("alwaysLogFileSize")) {
|
||||
console.warn("Progress:", src, ev.loaded);
|
||||
}
|
||||
|
||||
if (HARDCODED_FILE_SIZES[src]) {
|
||||
progressHandler(clamp(ev.loaded / HARDCODED_FILE_SIZES[src]));
|
||||
} else {
|
||||
if (!notifiedNotComputable) {
|
||||
notifiedNotComputable = true;
|
||||
console.warn("Progress not computable:", src, ev.loaded);
|
||||
progressHandler(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -208,10 +187,6 @@ export class BackgroundResourcesLoader {
|
||||
if (!xhr.status.toString().match(/^2/)) {
|
||||
reject(src + ": " + xhr.status + " " + xhr.statusText);
|
||||
} else {
|
||||
if (!notifiedNotComputable) {
|
||||
progressHandler(1);
|
||||
}
|
||||
|
||||
const options = {};
|
||||
const headers = xhr.getAllResponseHeaders();
|
||||
const contentType = headers.match(/^Content-Type:\s*(.*?)$/im);
|
||||
@ -228,7 +203,7 @@ export class BackgroundResourcesLoader {
|
||||
|
||||
internalPreloadCss(src, progressHandler) {
|
||||
return this.preloadWithProgress(src, progressHandler).then(blobSrc => {
|
||||
var styleElement = document.createElement("link");
|
||||
const styleElement = document.createElement("link");
|
||||
styleElement.href = blobSrc;
|
||||
styleElement.rel = "stylesheet";
|
||||
styleElement.setAttribute("media", "all");
|
||||
|
||||
@ -1,16 +1,5 @@
|
||||
import debug from "./config.local";
|
||||
|
||||
export const IS_DEBUG =
|
||||
G_IS_DEV &&
|
||||
typeof window !== "undefined" &&
|
||||
window.location.port === "3005" &&
|
||||
(window.location.host.indexOf("localhost:") >= 0 || window.location.host.indexOf("192.168.0.") >= 0) &&
|
||||
window.location.search.indexOf("nodebug") < 0;
|
||||
|
||||
export const SUPPORT_TOUCH = false;
|
||||
|
||||
const smoothCanvas = true;
|
||||
|
||||
export const THIRDPARTY_URLS = {
|
||||
discord: "https://discord.gg/HN7EVzV",
|
||||
github: "https://github.com/tobspr-games/shapez.io",
|
||||
@ -25,13 +14,10 @@ export const THIRDPARTY_URLS = {
|
||||
25: "https://www.youtube.com/watch?v=7OCV1g40Iew&",
|
||||
26: "https://www.youtube.com/watch?v=gfm6dS1dCoY",
|
||||
},
|
||||
|
||||
modBrowser: "https://shapez.mod.io/",
|
||||
};
|
||||
|
||||
export const globalConfig = {
|
||||
// Size of a single tile in Pixels.
|
||||
// NOTICE: Update webpack.production.config too!
|
||||
tileSize: 32,
|
||||
halfTileSize: 16,
|
||||
|
||||
@ -45,9 +31,6 @@ export const globalConfig = {
|
||||
statisticsGraphSlices: 100,
|
||||
analyticsSliceDurationSeconds: G_IS_DEV ? 1 : 10,
|
||||
|
||||
minimumTickRate: 25,
|
||||
maximumTickRate: 500,
|
||||
|
||||
// Map
|
||||
mapChunkSize: 16,
|
||||
chunkAggregateSize: 4,
|
||||
@ -57,7 +40,6 @@ export const globalConfig = {
|
||||
maxBeltShapeBundleSize: 20,
|
||||
|
||||
// Belt speeds
|
||||
// NOTICE: Update webpack.production.config too!
|
||||
beltSpeedItemsPerSecond: 2,
|
||||
minerSpeedItemsPerSecond: 0, // COMPUTED
|
||||
|
||||
@ -65,8 +47,6 @@ export const globalConfig = {
|
||||
|
||||
itemSpacingOnBelts: 0.63,
|
||||
|
||||
wiresSpeedItemsPerSecond: 6,
|
||||
|
||||
undergroundBeltMaxTilesByTier: [5, 9],
|
||||
|
||||
readerAnalyzeIntervalSeconds: 10,
|
||||
@ -91,27 +71,19 @@ export const globalConfig = {
|
||||
stacker: 1 / 8,
|
||||
},
|
||||
|
||||
// Zooming
|
||||
initialZoom: 1.9,
|
||||
minZoomLevel: 0.1,
|
||||
maxZoomLevel: 3,
|
||||
|
||||
// Global game speed
|
||||
gameSpeed: 1,
|
||||
|
||||
warmupTimeSecondsFast: 0.25,
|
||||
warmupTimeSecondsRegular: 0.25,
|
||||
|
||||
smoothing: {
|
||||
smoothMainCanvas: smoothCanvas && true,
|
||||
smoothMainCanvas: true,
|
||||
quality: "low" as ImageSmoothingQuality, // Low is CRUCIAL for mobile performance!
|
||||
},
|
||||
|
||||
rendering: {},
|
||||
debug,
|
||||
};
|
||||
|
||||
export const IS_MOBILE = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
|
||||
export const IS_MOBILE = navigator.userAgentData.mobile;
|
||||
export const SUPPORT_TOUCH = IS_MOBILE;
|
||||
|
||||
// Automatic calculations
|
||||
globalConfig.minerSpeedItemsPerSecond = globalConfig.beltSpeedItemsPerSecond / 5;
|
||||
|
||||
@ -3,7 +3,6 @@ import { Storage } from "@/platform/storage";
|
||||
/* typehints:end */
|
||||
|
||||
import { FsError } from "@/platform/fs_error";
|
||||
import { IS_DEBUG } from "./config";
|
||||
import { ExplainedResult } from "./explained_result";
|
||||
import { createLogger } from "./logging";
|
||||
|
||||
@ -23,7 +22,7 @@ export class ReadWriteProxy {
|
||||
this.currentData = null;
|
||||
|
||||
// TODO: EXTREMELY HACKY! To verify we need to do this a step later
|
||||
if (G_IS_DEV && IS_DEBUG) {
|
||||
if (G_IS_DEV) {
|
||||
setTimeout(() => {
|
||||
assert(
|
||||
this.verify(this.getDefaultData()).result,
|
||||
|
||||
@ -4,7 +4,6 @@ import "./core/polyfills";
|
||||
import "./mods/modloader";
|
||||
|
||||
import { Application } from "./application";
|
||||
import { IS_DEBUG } from "./core/config";
|
||||
import { createLogger, logSection } from "./core/logging";
|
||||
import { initComponentRegistry } from "./game/component_registry";
|
||||
import { initGameModeRegistry } from "./game/game_mode_registry";
|
||||
@ -27,7 +26,7 @@ console.log(
|
||||
|
||||
console.log("Environment: %c" + G_APP_ENVIRONMENT, "color: #fff");
|
||||
|
||||
if (G_IS_DEV && IS_DEBUG) {
|
||||
if (G_IS_DEV) {
|
||||
console.log("\n%c🛑 DEBUG ENVIRONMENT 🛑\n", "color: #f77");
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user