From 6662cb26940ed4c9b563da787af8facffe8325e7 Mon Sep 17 00:00:00 2001 From: cody-ferguson Date: Wed, 19 Jun 2024 13:47:50 -0500 Subject: [PATCH] Remove all references of "G_IS_STANDALONE" --- gulp/webpack.config.js | 2 - gulp/webpack.production.config.js | 2 - src/js/application.js | 45 +---- src/js/core/background_resources_loader.js | 35 +--- src/js/core/globals.js | 2 - src/js/core/utils.js | 45 +---- src/js/game/hud/parts/unlock_notification.js | 2 +- src/js/globals.d.ts | 167 +++++++++--------- src/js/main.js | 6 +- src/js/mods/modloader.js | 16 +- .../electron/steam_achievement_provider.js | 5 - src/js/platform/sound.js | 10 +- src/js/profile/application_settings.js | 4 +- src/js/states/mods.js | 26 +-- src/js/states/preload.js | 4 - 15 files changed, 114 insertions(+), 257 deletions(-) diff --git a/gulp/webpack.config.js b/gulp/webpack.config.js index 596680e2..cac0161b 100644 --- a/gulp/webpack.config.js +++ b/gulp/webpack.config.js @@ -17,8 +17,6 @@ const globalDefs = { G_ALL_UI_IMAGES: JSON.stringify(getAllResourceImages()), G_IS_RELEASE: "false", - G_IS_STANDALONE: "true", - G_IS_BROWSER: "false", G_HAVE_ASSERT: "true", }; diff --git a/gulp/webpack.production.config.js b/gulp/webpack.production.config.js index c10b4dae..4962843a 100644 --- a/gulp/webpack.production.config.js +++ b/gulp/webpack.production.config.js @@ -18,8 +18,6 @@ const globalDefs = { "G_ALL_UI_IMAGES": JSON.stringify(getAllResourceImages()), "G_IS_RELEASE": "true", - "G_IS_STANDALONE": "true", - "G_IS_BROWSER": "false", "G_HAVE_ASSERT": "false", }; diff --git a/src/js/application.js b/src/js/application.js index 68dbc100..90b197b5 100644 --- a/src/js/application.js +++ b/src/js/application.js @@ -5,16 +5,14 @@ import { GameState } from "./core/game_state"; import { GLOBAL_APP, setGlobalApp } from "./core/globals"; import { InputDistributor } from "./core/input_distributor"; import { Loader } from "./core/loader"; -import { createLogger, logSection } from "./core/logging"; +import { createLogger } from "./core/logging"; import { StateManager } from "./core/state_manager"; import { TrackedState } from "./core/tracked_state"; import { getPlatformName, waitNextFrame } from "./core/utils"; import { Vector } from "./core/vector"; import { NoAchievementProvider } from "./platform/browser/no_achievement_provider"; import { SoundImplBrowser } from "./platform/browser/sound"; -import { PlatformWrapperImplBrowser } from "./platform/browser/wrapper"; import { PlatformWrapperImplElectron } from "./platform/electron/wrapper"; -import { PlatformWrapperInterface } from "./platform/wrapper"; import { ApplicationSettings } from "./profile/application_settings"; import { SavegameManager } from "./savegame/savegame_manager"; import { AboutState } from "./states/about"; @@ -92,16 +90,10 @@ export class Application { /** @type {StorageInterface} */ this.storage = null; - /** @type {SoundInterface} */ - this.sound = null; + this.platformWrapper = new PlatformWrapperImplElectron(this); - /** @type {PlatformWrapperInterface} */ - this.platformWrapper = null; - - /** @type {AchievementProviderInterface} */ - this.achievementProvider = null; - - this.initPlatformDependentInstances(); + this.sound = new SoundImplBrowser(this); + this.achievementProvider = new NoAchievementProvider(this); // Track if the window is focused (only relevant for browser) this.focused = true; @@ -151,22 +143,6 @@ export class Application { MOD_SIGNALS.appBooted.dispatch(); } - /** - * Initializes all platform instances - */ - initPlatformDependentInstances() { - logger.log("Creating platform dependent instances (standalone=", G_IS_STANDALONE, ")"); - - if (G_IS_STANDALONE) { - this.platformWrapper = new PlatformWrapperImplElectron(this); - } else { - this.platformWrapper = new PlatformWrapperImplBrowser(this); - } - - this.sound = new SoundImplBrowser(this); - this.achievementProvider = new NoAchievementProvider(this); - } - /** * Registers all game states */ @@ -312,18 +288,7 @@ export class Application { /** * Internal before-unload handler */ - onBeforeUnload(event) { - logSection("BEFORE UNLOAD HANDLER", "#f77"); - const currentState = this.stateMgr.getCurrentState(); - - if (!G_IS_DEV && currentState && currentState.getHasUnloadConfirmation()) { - if (!G_IS_STANDALONE) { - // Need to show a "Are you sure you want to exit" - event.preventDefault(); - event.returnValue = "Are you sure you want to exit?"; - } - } - } + onBeforeUnload(event) {} /** * Deinitializes the application diff --git a/src/js/core/background_resources_loader.js b/src/js/core/background_resources_loader.js index d967a04a..38584d56 100644 --- a/src/js/core/background_resources_loader.js +++ b/src/js/core/background_resources_loader.js @@ -30,10 +30,8 @@ const INGAME_ASSETS = { css: ["async-resources.css"], }; -if (G_IS_STANDALONE) { - MAIN_MENU_ASSETS.sounds = [...Array.from(Object.values(MUSIC)), ...Array.from(Object.values(SOUNDS))]; - INGAME_ASSETS.sounds = []; -} +MAIN_MENU_ASSETS.sounds = [...Array.from(Object.values(MUSIC)), ...Array.from(Object.values(SOUNDS))]; +INGAME_ASSETS.sounds = []; const LOADER_TIMEOUT_PER_RESOURCE = 180000; @@ -170,28 +168,13 @@ export class BackgroundResourcesLoader { * Shows an error when a resource failed to load and allows to reload the game */ showLoaderError(dialogs, err) { - if (G_IS_STANDALONE) { - dialogs - .showWarning( - T.dialogs.resourceLoadFailed.title, - T.dialogs.resourceLoadFailed.descSteamDemo + "
" + err, - ["retry"] - ) - .retry.add(() => window.location.reload()); - } else { - dialogs - .showWarning( - T.dialogs.resourceLoadFailed.title, - T.dialogs.resourceLoadFailed.descWeb.replace( - "", - `${T.dialogs.resourceLoadFailed.demoLinkText}` - ) + - "
" + - err, - ["retry"] - ) - .retry.add(() => window.location.reload()); - } + dialogs + .showWarning( + T.dialogs.resourceLoadFailed.title, + T.dialogs.resourceLoadFailed.descSteamDemo + "
" + err, + ["retry"] + ) + .retry.add(() => window.location.reload()); } preloadWithProgress(src, progressHandler) { diff --git a/src/js/core/globals.js b/src/js/core/globals.js index 71871b17..4e046824 100644 --- a/src/js/core/globals.js +++ b/src/js/core/globals.js @@ -21,8 +21,6 @@ export const BUILD_OPTIONS = { APP_ENVIRONMENT: G_APP_ENVIRONMENT, IS_DEV: G_IS_DEV, IS_RELEASE: G_IS_RELEASE, - IS_BROWSER: G_IS_BROWSER, - IS_STANDALONE: G_IS_STANDALONE, BUILD_TIME: G_BUILD_TIME, BUILD_COMMIT_HASH: G_BUILD_COMMIT_HASH, BUILD_VERSION: G_BUILD_VERSION, diff --git a/src/js/core/utils.js b/src/js/core/utils.js index aff10781..34213b7d 100644 --- a/src/js/core/utils.js +++ b/src/js/core/utils.js @@ -4,15 +4,10 @@ const bigNumberSuffixTranslationKeys = ["thousands", "millions", "billions", "tr /** * Returns a platform name - * @returns {"android" | "browser" | "ios" | "standalone" | "unknown"} + * @returns {"standalone"} */ export function getPlatformName() { - if (G_IS_STANDALONE) { - return "standalone"; - } else if (G_IS_BROWSER) { - return "browser"; - } - return "unknown"; + return "standalone"; } /** @@ -421,41 +416,7 @@ export function removeAllChildren(elem) { * Returns if the game supports this browser */ export function isSupportedBrowser() { - // please note, - // that IE11 now returns undefined again for window.chrome - // and new Opera 30 outputs true for window.chrome - // but needs to check if window.opr is not undefined - // and new IE Edge outputs to true now for window.chrome - // and if not iOS Chrome check - // so use the below updated condition - - if (G_IS_STANDALONE) { - return true; - } - - // @ts-ignore - var isChromium = window.chrome; - var winNav = window.navigator; - var vendorName = winNav.vendor; - // @ts-ignore - var isIEedge = winNav.userAgent.indexOf("Edge") > -1; - var isIOSChrome = winNav.userAgent.match("CriOS"); - - if (isIOSChrome) { - // is Google Chrome on IOS - return false; - } else if ( - isChromium !== null && - typeof isChromium !== "undefined" && - vendorName === "Google Inc." && - isIEedge === false - ) { - // is Google Chrome - return true; - } else { - // not Google Chrome - return false; - } + return true; } /** diff --git a/src/js/game/hud/parts/unlock_notification.js b/src/js/game/hud/parts/unlock_notification.js index 305a4813..851412e3 100644 --- a/src/js/game/hud/parts/unlock_notification.js +++ b/src/js/game/hud/parts/unlock_notification.js @@ -27,7 +27,7 @@ export class HUDUnlockNotification extends BaseHUDPart { } shouldPauseGame() { - return !G_IS_STANDALONE && this.visible; + return false; } createElements(parent) { diff --git a/src/js/globals.d.ts b/src/js/globals.d.ts index 41c2db95..13e9f3cf 100644 --- a/src/js/globals.d.ts +++ b/src/js/globals.d.ts @@ -1,10 +1,13 @@ // Globals defined by webpack declare const G_IS_DEV: boolean; -declare function assert(condition: boolean | object | string, ...errorMessage: string[]): asserts condition; +declare function assert( + condition: boolean | object | string, + ...errorMessage: string[] +): asserts condition; declare function assertAlways( - condition: boolean | object | string, - ...errorMessage: string[] + condition: boolean | object | string, + ...errorMessage: string[] ): asserts condition; declare const abstract: void; @@ -12,8 +15,6 @@ declare const abstract: void; declare const G_APP_ENVIRONMENT: string; declare const G_HAVE_ASSERT: boolean; declare const G_BUILD_TIME: number; -declare const G_IS_STANDALONE: boolean; -declare const G_IS_BROWSER: boolean; declare const G_BUILD_COMMIT_HASH: string; declare const G_BUILD_VERSION: string; @@ -26,146 +27,146 @@ declare const ipcRenderer: any; // Polyfills declare interface String { - replaceAll(search: string, replacement: string): string; + replaceAll(search: string, replacement: string): string; } declare interface CanvasRenderingContext2D { - beginRoundedRect(x: number, y: number, w: number, h: number, r: number): void; - beginCircle(x: number, y: number, r: number): void; + beginRoundedRect(x: number, y: number, w: number, h: number, r: number): void; + beginCircle(x: number, y: number, r: number): void; - msImageSmoothingEnabled: boolean; - mozImageSmoothingEnabled: boolean; - webkitImageSmoothingEnabled: boolean; + msImageSmoothingEnabled: boolean; + mozImageSmoothingEnabled: boolean; + webkitImageSmoothingEnabled: boolean; } // Just for compatibility with the shared code declare interface Logger { - log(...args); - warn(...args); - info(...args); - error(...args); + log(...args); + warn(...args); + info(...args); + error(...args); } declare interface MobileAccessibility { - usePreferredTextZoom(boolean); + usePreferredTextZoom(boolean); } declare interface Window { - // Debugging - activeClickDetectors: Array; + // Debugging + activeClickDetectors: Array; - // Mods - $shapez_registerMod: any; - anyModLoaded: any; + // Mods + $shapez_registerMod: any; + anyModLoaded: any; - shapez: any; + shapez: any; - APP_ERROR_OCCURED?: boolean; + APP_ERROR_OCCURED?: boolean; - webkitRequestAnimationFrame(); + webkitRequestAnimationFrame(); - assert(condition: boolean, failureMessage: string); + assert(condition: boolean, failureMessage: string); - coreThreadLoadedCb(); + coreThreadLoadedCb(); } declare interface Navigator { - app: any; - device: any; - splashscreen: any; + app: any; + device: any; + splashscreen: any; } // Webpack declare interface WebpackContext { - keys(): Array; + keys(): Array; } declare interface NodeRequire { - context(src: string, flag: boolean, regexp: RegExp): WebpackContext; + context(src: string, flag: boolean, regexp: RegExp): WebpackContext; } declare interface Object { - entries(obj: object): Array<[string, any]>; + entries(obj: object): Array<[string, any]>; } declare interface Math { - radians(number): number; - degrees(number): number; + radians(number): number; + degrees(number): number; } declare type Class = new (...args: any[]) => T; declare interface String { - padStart(size: number, fill?: string): string; - padEnd(size: number, fill: string): string; + padStart(size: number, fill?: string): string; + padEnd(size: number, fill: string): string; } declare interface SignalTemplate0 { - add(receiver: () => string | void, scope: null | any); - dispatch(): string | void; - remove(receiver: () => string | void); - removeAll(); + add(receiver: () => string | void, scope: null | any); + dispatch(): string | void; + remove(receiver: () => string | void); + removeAll(); } declare class TypedTrackedState { - constructor(callbackMethod?: (value: T) => void, callbackScope?: any); + constructor(callbackMethod?: (value: T) => void, callbackScope?: any); - set(value: T, changeHandler?: (value: T) => void, changeScope?: any): void; + set(value: T, changeHandler?: (value: T) => void, changeScope?: any): void; - setSilent(value: any): void; - get(): T; + setSilent(value: any): void; + get(): T; } declare type Layer = "regular" | "wires"; declare type ItemType = "shape" | "color" | "boolean"; declare module "worker-loader?inline=true&fallback=false!*" { - class WebpackWorker extends Worker { - constructor(); - } + class WebpackWorker extends Worker { + constructor(); + } - export default WebpackWorker; + export default WebpackWorker; } // JSX type support - https://www.typescriptlang.org/docs/handbook/jsx.html // modified from https://stackoverflow.com/a/68238924 declare namespace JSX { - /** - * The return type of a JSX expression. - * - * In reality, Fragments can return arbitrary values, but we ignore this for convenience. - */ - type Element = HTMLElement; - /** - * Key-value list of intrinsic element names and their allowed properties. - * - * Because children are treated as a property, the Node type cannot be excluded from the index signature. - */ - type IntrinsicElements = { - [K in keyof HTMLElementTagNameMap]: { - children?: Node | Node[]; - [k: string]: Node | Node[] | string | number | boolean; - }; + /** + * The return type of a JSX expression. + * + * In reality, Fragments can return arbitrary values, but we ignore this for convenience. + */ + type Element = HTMLElement; + /** + * Key-value list of intrinsic element names and their allowed properties. + * + * Because children are treated as a property, the Node type cannot be excluded from the index signature. + */ + type IntrinsicElements = { + [K in keyof HTMLElementTagNameMap]: { + children?: Node | Node[]; + [k: string]: Node | Node[] | string | number | boolean; }; - /** - * The property of the attributes object storing the children. - */ - type ElementChildrenAttribute = { children: unknown }; + }; + /** + * The property of the attributes object storing the children. + */ + type ElementChildrenAttribute = { children: unknown }; - // The following do not have special meaning to TypeScript. + // The following do not have special meaning to TypeScript. - /** - * An attributes object. - */ - type Props = { [k: string]: unknown }; - /** - * A functional component requiring attributes to match `T`. - */ - type Component = { - (props: T): Element; - }; - /** - * A child of a JSX element. - */ - type Node = Element | string | boolean | null | undefined; + /** + * An attributes object. + */ + type Props = { [k: string]: unknown }; + /** + * A functional component requiring attributes to match `T`. + */ + type Component = { + (props: T): Element; + }; + /** + * A child of a JSX element. + */ + type Node = Element | string | boolean | null | undefined; } diff --git a/src/js/main.js b/src/js/main.js index 17c971ee..acade03b 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -63,8 +63,4 @@ function bootApp() { app.boot(); } -if (G_IS_STANDALONE) { - window.addEventListener("load", bootApp); -} else { - bootApp(); -} +window.addEventListener("load", bootApp); diff --git a/src/js/mods/modloader.js b/src/js/mods/modloader.js index 3104bca3..b5d375a5 100644 --- a/src/js/mods/modloader.js +++ b/src/js/mods/modloader.js @@ -105,7 +105,7 @@ export class ModLoader { } exposeExports() { - if (G_IS_DEV || G_IS_STANDALONE) { + if (G_IS_DEV) { let exports = {}; const modules = import.meta.webpackContext("../", { recursive: true, @@ -140,24 +140,14 @@ export class ModLoader { } async initMods() { - if (!G_IS_STANDALONE && !G_IS_DEV) { - this.initialized = true; - return; - } - // Create a storage for reading mod settings - const storage = G_IS_STANDALONE - ? new StorageImplElectron(this.app) - : new StorageImplBrowserIndexedDB(this.app); + const storage = new StorageImplElectron(this.app); await storage.initialize(); LOG.log("hook:init", this.app, this.app.storage); this.exposeExports(); - let mods = []; - if (G_IS_STANDALONE) { - mods = await ipcRenderer.invoke("get-mods"); - } + let mods = await ipcRenderer.invoke("get-mods"); if (G_IS_DEV && globalConfig.debug.externalModUrl) { const modURLs = Array.isArray(globalConfig.debug.externalModUrl) ? globalConfig.debug.externalModUrl diff --git a/src/js/platform/electron/steam_achievement_provider.js b/src/js/platform/electron/steam_achievement_provider.js index 291bd926..ae470f9c 100644 --- a/src/js/platform/electron/steam_achievement_provider.js +++ b/src/js/platform/electron/steam_achievement_provider.js @@ -99,11 +99,6 @@ export class SteamAchievementProvider extends AchievementProviderInterface { /** @returns {Promise} */ initialize() { - if (!G_IS_STANDALONE) { - logger.warn("Steam unavailable. Achievements won't sync."); - return Promise.resolve(); - } - return ipcRenderer.invoke("steam:is-initialized").then(initialized => { this.initialized = initialized; diff --git a/src/js/platform/sound.js b/src/js/platform/sound.js index 28274111..8f8fae87 100644 --- a/src/js/platform/sound.js +++ b/src/js/platform/sound.js @@ -33,16 +33,12 @@ export const SOUNDS = { export const MUSIC = { // The theme always depends on the standalone only, even if running the full // version in the browser - theme: G_IS_STANDALONE ? "theme-full" : "theme-short", + theme: "theme-full", }; -if (G_IS_STANDALONE) { - MUSIC.menu = "menu"; -} +MUSIC.menu = "menu"; -if (G_IS_STANDALONE) { - MUSIC.puzzle = "puzzle-full"; -} +MUSIC.puzzle = "puzzle-full"; export class SoundInstanceInterface { constructor(key, url) { diff --git a/src/js/profile/application_settings.js b/src/js/profile/application_settings.js index e31dab9e..b454c163 100644 --- a/src/js/profile/application_settings.js +++ b/src/js/profile/application_settings.js @@ -189,7 +189,7 @@ function initializeSettings() { }, /** * @param {Application} app - */ app => G_IS_STANDALONE + */ app => true ), new BoolSetting( @@ -288,7 +288,7 @@ function initializeSettings() { class SettingsStorage { constructor() { this.uiScale = "regular"; - this.fullscreen = G_IS_STANDALONE; + this.fullscreen = true; this.soundVolume = 1.0; this.musicVolume = 1.0; diff --git a/src/js/states/mods.js b/src/js/states/mods.js index 80bcb4b5..2cb41109 100644 --- a/src/js/states/mods.js +++ b/src/js/states/mods.js @@ -13,7 +13,7 @@ export class ModsState extends TextualGameState { } get modsSupported() { - return G_IS_STANDALONE || G_IS_DEV; + return true; } internalGetFullHtml() { @@ -23,15 +23,11 @@ export class ModsState extends TextualGameState {
${ - this.modsSupported && MODS.mods.length > 0 + MODS.mods.length > 0 ? `` : "" } - ${ - this.modsSupported - ? `` - : "" - } +
`; @@ -45,18 +41,6 @@ export class ModsState extends TextualGameState { } getMainContentHTML() { - if (!this.modsSupported) { - return ` -
- -

${T.mods.noModSupport}

-
- - -
- `; - } - if (MODS.mods.length === 0) { return ` @@ -121,10 +105,6 @@ export class ModsState extends TextualGameState { } openModsFolder() { - if (!G_IS_STANDALONE) { - this.dialogs.showWarning(T.global.error, T.mods.folderOnlyStandalone); - return; - } ipcRenderer.invoke("open-mods-folder"); } diff --git a/src/js/states/preload.js b/src/js/states/preload.js index 5b170dfd..37144612 100644 --- a/src/js/states/preload.js +++ b/src/js/states/preload.js @@ -172,10 +172,6 @@ export class PreloadState extends GameState { return; } - if (!G_IS_STANDALONE) { - return; - } - return this.app.storage .readFileAsync("lastversion.bin") .catch(err => {