1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-11 09:11:50 +00:00

Remove all references of "G_IS_STANDALONE"

This commit is contained in:
cody-ferguson 2024-06-19 13:47:50 -05:00
parent 60b2727b42
commit 6662cb2694
15 changed files with 114 additions and 257 deletions

View File

@ -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",
};

View File

@ -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",
};

View File

@ -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

View File

@ -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 + "<br>" + err,
["retry"]
)
.retry.add(() => window.location.reload());
} else {
dialogs
.showWarning(
T.dialogs.resourceLoadFailed.title,
T.dialogs.resourceLoadFailed.descWeb.replace(
"<demoOnSteamLinkText>",
`<a href="https://get.shapez.io/resource_timeout" target="_blank">${T.dialogs.resourceLoadFailed.demoLinkText}</a>`
) +
"<br>" +
err,
["retry"]
)
.retry.add(() => window.location.reload());
}
dialogs
.showWarning(
T.dialogs.resourceLoadFailed.title,
T.dialogs.resourceLoadFailed.descSteamDemo + "<br>" + err,
["retry"]
)
.retry.add(() => window.location.reload());
}
preloadWithProgress(src, progressHandler) {

View File

@ -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,

View File

@ -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;
}
/**

View File

@ -27,7 +27,7 @@ export class HUDUnlockNotification extends BaseHUDPart {
}
shouldPauseGame() {
return !G_IS_STANDALONE && this.visible;
return false;
}
createElements(parent) {

167
src/js/globals.d.ts vendored
View File

@ -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<any>;
// Debugging
activeClickDetectors: Array<any>;
// 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<string>;
keys(): Array<string>;
}
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<T = unknown> = 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<T> {
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<T extends Props> = {
(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<T extends Props> = {
(props: T): Element;
};
/**
* A child of a JSX element.
*/
type Node = Element | string | boolean | null | undefined;
}

View File

@ -63,8 +63,4 @@ function bootApp() {
app.boot();
}
if (G_IS_STANDALONE) {
window.addEventListener("load", bootApp);
} else {
bootApp();
}
window.addEventListener("load", bootApp);

View File

@ -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

View File

@ -99,11 +99,6 @@ export class SteamAchievementProvider extends AchievementProviderInterface {
/** @returns {Promise<void>} */
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;

View File

@ -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) {

View File

@ -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;

View File

@ -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 {
<div class="actions">
${
this.modsSupported && MODS.mods.length > 0
MODS.mods.length > 0
? `<button class="styledButton browseMods">${T.mods.browseMods}</button>`
: ""
}
${
this.modsSupported
? `<button class="styledButton openModsFolder">${T.mods.openFolder}</button>`
: ""
}
<button class="styledButton openModsFolder">${T.mods.openFolder}</button>
</div>
</div>`;
@ -45,18 +41,6 @@ export class ModsState extends TextualGameState {
}
getMainContentHTML() {
if (!this.modsSupported) {
return `
<div class="noModSupport">
<p>${T.mods.noModSupport}</p>
<br>
<button class="styledButton browseMods">${T.mods.browseMods}</button>
</div>
`;
}
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");
}

View File

@ -172,10 +172,6 @@ export class PreloadState extends GameState {
return;
}
if (!G_IS_STANDALONE) {
return;
}
return this.app.storage
.readFileAsync("lastversion.bin")
.catch(err => {