1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-12-14 10:41:52 +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_ALL_UI_IMAGES: JSON.stringify(getAllResourceImages()),
G_IS_RELEASE: "false", G_IS_RELEASE: "false",
G_IS_STANDALONE: "true",
G_IS_BROWSER: "false",
G_HAVE_ASSERT: "true", G_HAVE_ASSERT: "true",
}; };

View File

@ -18,8 +18,6 @@ const globalDefs = {
"G_ALL_UI_IMAGES": JSON.stringify(getAllResourceImages()), "G_ALL_UI_IMAGES": JSON.stringify(getAllResourceImages()),
"G_IS_RELEASE": "true", "G_IS_RELEASE": "true",
"G_IS_STANDALONE": "true",
"G_IS_BROWSER": "false",
"G_HAVE_ASSERT": "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 { GLOBAL_APP, setGlobalApp } from "./core/globals";
import { InputDistributor } from "./core/input_distributor"; import { InputDistributor } from "./core/input_distributor";
import { Loader } from "./core/loader"; import { Loader } from "./core/loader";
import { createLogger, logSection } from "./core/logging"; import { createLogger } from "./core/logging";
import { StateManager } from "./core/state_manager"; import { StateManager } from "./core/state_manager";
import { TrackedState } from "./core/tracked_state"; import { TrackedState } from "./core/tracked_state";
import { getPlatformName, waitNextFrame } from "./core/utils"; import { getPlatformName, waitNextFrame } from "./core/utils";
import { Vector } from "./core/vector"; import { Vector } from "./core/vector";
import { NoAchievementProvider } from "./platform/browser/no_achievement_provider"; import { NoAchievementProvider } from "./platform/browser/no_achievement_provider";
import { SoundImplBrowser } from "./platform/browser/sound"; import { SoundImplBrowser } from "./platform/browser/sound";
import { PlatformWrapperImplBrowser } from "./platform/browser/wrapper";
import { PlatformWrapperImplElectron } from "./platform/electron/wrapper"; import { PlatformWrapperImplElectron } from "./platform/electron/wrapper";
import { PlatformWrapperInterface } from "./platform/wrapper";
import { ApplicationSettings } from "./profile/application_settings"; import { ApplicationSettings } from "./profile/application_settings";
import { SavegameManager } from "./savegame/savegame_manager"; import { SavegameManager } from "./savegame/savegame_manager";
import { AboutState } from "./states/about"; import { AboutState } from "./states/about";
@ -92,16 +90,10 @@ export class Application {
/** @type {StorageInterface} */ /** @type {StorageInterface} */
this.storage = null; this.storage = null;
/** @type {SoundInterface} */ this.platformWrapper = new PlatformWrapperImplElectron(this);
this.sound = null;
/** @type {PlatformWrapperInterface} */ this.sound = new SoundImplBrowser(this);
this.platformWrapper = null; this.achievementProvider = new NoAchievementProvider(this);
/** @type {AchievementProviderInterface} */
this.achievementProvider = null;
this.initPlatformDependentInstances();
// Track if the window is focused (only relevant for browser) // Track if the window is focused (only relevant for browser)
this.focused = true; this.focused = true;
@ -151,22 +143,6 @@ export class Application {
MOD_SIGNALS.appBooted.dispatch(); 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 * Registers all game states
*/ */
@ -312,18 +288,7 @@ export class Application {
/** /**
* Internal before-unload handler * Internal before-unload handler
*/ */
onBeforeUnload(event) { 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?";
}
}
}
/** /**
* Deinitializes the application * Deinitializes the application

View File

@ -30,10 +30,8 @@ const INGAME_ASSETS = {
css: ["async-resources.css"], css: ["async-resources.css"],
}; };
if (G_IS_STANDALONE) { MAIN_MENU_ASSETS.sounds = [...Array.from(Object.values(MUSIC)), ...Array.from(Object.values(SOUNDS))];
MAIN_MENU_ASSETS.sounds = [...Array.from(Object.values(MUSIC)), ...Array.from(Object.values(SOUNDS))]; INGAME_ASSETS.sounds = [];
INGAME_ASSETS.sounds = [];
}
const LOADER_TIMEOUT_PER_RESOURCE = 180000; const LOADER_TIMEOUT_PER_RESOURCE = 180000;
@ -170,7 +168,6 @@ export class BackgroundResourcesLoader {
* Shows an error when a resource failed to load and allows to reload the game * Shows an error when a resource failed to load and allows to reload the game
*/ */
showLoaderError(dialogs, err) { showLoaderError(dialogs, err) {
if (G_IS_STANDALONE) {
dialogs dialogs
.showWarning( .showWarning(
T.dialogs.resourceLoadFailed.title, T.dialogs.resourceLoadFailed.title,
@ -178,20 +175,6 @@ export class BackgroundResourcesLoader {
["retry"] ["retry"]
) )
.retry.add(() => window.location.reload()); .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());
}
} }
preloadWithProgress(src, progressHandler) { preloadWithProgress(src, progressHandler) {

View File

@ -21,8 +21,6 @@ export const BUILD_OPTIONS = {
APP_ENVIRONMENT: G_APP_ENVIRONMENT, APP_ENVIRONMENT: G_APP_ENVIRONMENT,
IS_DEV: G_IS_DEV, IS_DEV: G_IS_DEV,
IS_RELEASE: G_IS_RELEASE, IS_RELEASE: G_IS_RELEASE,
IS_BROWSER: G_IS_BROWSER,
IS_STANDALONE: G_IS_STANDALONE,
BUILD_TIME: G_BUILD_TIME, BUILD_TIME: G_BUILD_TIME,
BUILD_COMMIT_HASH: G_BUILD_COMMIT_HASH, BUILD_COMMIT_HASH: G_BUILD_COMMIT_HASH,
BUILD_VERSION: G_BUILD_VERSION, BUILD_VERSION: G_BUILD_VERSION,

View File

@ -4,15 +4,10 @@ const bigNumberSuffixTranslationKeys = ["thousands", "millions", "billions", "tr
/** /**
* Returns a platform name * Returns a platform name
* @returns {"android" | "browser" | "ios" | "standalone" | "unknown"} * @returns {"standalone"}
*/ */
export function getPlatformName() { export function getPlatformName() {
if (G_IS_STANDALONE) {
return "standalone"; return "standalone";
} else if (G_IS_BROWSER) {
return "browser";
}
return "unknown";
} }
/** /**
@ -421,41 +416,7 @@ export function removeAllChildren(elem) {
* Returns if the game supports this browser * Returns if the game supports this browser
*/ */
export function isSupportedBrowser() { 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; 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;
}
} }
/** /**

View File

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

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

@ -1,7 +1,10 @@
// Globals defined by webpack // Globals defined by webpack
declare const G_IS_DEV: boolean; 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( declare function assertAlways(
condition: boolean | object | string, condition: boolean | object | string,
...errorMessage: string[] ...errorMessage: string[]
@ -12,8 +15,6 @@ declare const abstract: void;
declare const G_APP_ENVIRONMENT: string; declare const G_APP_ENVIRONMENT: string;
declare const G_HAVE_ASSERT: boolean; declare const G_HAVE_ASSERT: boolean;
declare const G_BUILD_TIME: number; 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_COMMIT_HASH: string;
declare const G_BUILD_VERSION: string; declare const G_BUILD_VERSION: string;

View File

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

View File

@ -105,7 +105,7 @@ export class ModLoader {
} }
exposeExports() { exposeExports() {
if (G_IS_DEV || G_IS_STANDALONE) { if (G_IS_DEV) {
let exports = {}; let exports = {};
const modules = import.meta.webpackContext("../", { const modules = import.meta.webpackContext("../", {
recursive: true, recursive: true,
@ -140,24 +140,14 @@ export class ModLoader {
} }
async initMods() { async initMods() {
if (!G_IS_STANDALONE && !G_IS_DEV) {
this.initialized = true;
return;
}
// Create a storage for reading mod settings // Create a storage for reading mod settings
const storage = G_IS_STANDALONE const storage = new StorageImplElectron(this.app);
? new StorageImplElectron(this.app)
: new StorageImplBrowserIndexedDB(this.app);
await storage.initialize(); await storage.initialize();
LOG.log("hook:init", this.app, this.app.storage); LOG.log("hook:init", this.app, this.app.storage);
this.exposeExports(); this.exposeExports();
let mods = []; let mods = await ipcRenderer.invoke("get-mods");
if (G_IS_STANDALONE) {
mods = await ipcRenderer.invoke("get-mods");
}
if (G_IS_DEV && globalConfig.debug.externalModUrl) { if (G_IS_DEV && globalConfig.debug.externalModUrl) {
const modURLs = Array.isArray(globalConfig.debug.externalModUrl) const modURLs = Array.isArray(globalConfig.debug.externalModUrl)
? globalConfig.debug.externalModUrl ? globalConfig.debug.externalModUrl

View File

@ -99,11 +99,6 @@ export class SteamAchievementProvider extends AchievementProviderInterface {
/** @returns {Promise<void>} */ /** @returns {Promise<void>} */
initialize() { initialize() {
if (!G_IS_STANDALONE) {
logger.warn("Steam unavailable. Achievements won't sync.");
return Promise.resolve();
}
return ipcRenderer.invoke("steam:is-initialized").then(initialized => { return ipcRenderer.invoke("steam:is-initialized").then(initialized => {
this.initialized = initialized; this.initialized = initialized;

View File

@ -33,16 +33,12 @@ export const SOUNDS = {
export const MUSIC = { export const MUSIC = {
// The theme always depends on the standalone only, even if running the full // The theme always depends on the standalone only, even if running the full
// version in the browser // 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 { export class SoundInstanceInterface {
constructor(key, url) { constructor(key, url) {

View File

@ -189,7 +189,7 @@ function initializeSettings() {
}, },
/** /**
* @param {Application} app * @param {Application} app
*/ app => G_IS_STANDALONE */ app => true
), ),
new BoolSetting( new BoolSetting(
@ -288,7 +288,7 @@ function initializeSettings() {
class SettingsStorage { class SettingsStorage {
constructor() { constructor() {
this.uiScale = "regular"; this.uiScale = "regular";
this.fullscreen = G_IS_STANDALONE; this.fullscreen = true;
this.soundVolume = 1.0; this.soundVolume = 1.0;
this.musicVolume = 1.0; this.musicVolume = 1.0;

View File

@ -13,7 +13,7 @@ export class ModsState extends TextualGameState {
} }
get modsSupported() { get modsSupported() {
return G_IS_STANDALONE || G_IS_DEV; return true;
} }
internalGetFullHtml() { internalGetFullHtml() {
@ -23,15 +23,11 @@ export class ModsState extends TextualGameState {
<div class="actions"> <div class="actions">
${ ${
this.modsSupported && MODS.mods.length > 0 MODS.mods.length > 0
? `<button class="styledButton browseMods">${T.mods.browseMods}</button>` ? `<button class="styledButton browseMods">${T.mods.browseMods}</button>`
: "" : ""
} }
${ <button class="styledButton openModsFolder">${T.mods.openFolder}</button>
this.modsSupported
? `<button class="styledButton openModsFolder">${T.mods.openFolder}</button>`
: ""
}
</div> </div>
</div>`; </div>`;
@ -45,18 +41,6 @@ export class ModsState extends TextualGameState {
} }
getMainContentHTML() { 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) { if (MODS.mods.length === 0) {
return ` return `
@ -121,10 +105,6 @@ export class ModsState extends TextualGameState {
} }
openModsFolder() { openModsFolder() {
if (!G_IS_STANDALONE) {
this.dialogs.showWarning(T.global.error, T.mods.folderOnlyStandalone);
return;
}
ipcRenderer.invoke("open-mods-folder"); ipcRenderer.invoke("open-mods-folder");
} }

View File

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