From a18ee0c1c37b6aa37ce94355109352544eb73a51 Mon Sep 17 00:00:00 2001 From: neki-dev Date: Wed, 22 Nov 2023 11:39:49 +0300 Subject: [PATCH] Removed SDK --- package.json | 2 - src/assets/sprites/hud/ads.png | Bin 603 -> 0 bytes src/const/ads.ts | 9 -- src/const/game.ts | 30 ---- src/game/game.ts | 54 ++----- .../interface/content/save-game/index.tsx | 3 +- .../scenes/menu/interface/copyright/index.tsx | 10 +- .../screen/interface/ads-reward/index.tsx | 50 ------ .../interface/ads-reward/modal/index.tsx | 61 -------- .../interface/ads-reward/modal/styles.ts | 109 ------------- src/game/scenes/screen/interface/index.tsx | 2 - .../scenes/screen/interface/skills/index.tsx | 20 +-- .../screen/interface/unlocks/modal/index.tsx | 45 +----- .../unlocks/modal/item-ads/index.tsx | 34 ---- .../unlocks/modal/item-ads/styles.ts | 58 ------- src/game/scenes/screen/screen.ts | 3 +- src/game/scenes/system/system.ts | 3 - src/game/scenes/world/builder.ts | 3 +- src/game/scenes/world/effects/fx-manager.ts | 12 +- src/game/scenes/world/effects/particles.ts | 3 +- .../world/entities/building/building.ts | 3 +- .../entities/building/variants/generator.ts | 3 +- .../entities/building/variants/tower/tower.ts | 3 +- src/game/scenes/world/entities/npc/npc.ts | 3 +- .../world/entities/npc/variants/assistant.ts | 3 +- .../entities/npc/variants/enemy/enemy.ts | 3 +- .../npc/variants/enemy/variants/berserk.ts | 3 +- .../npc/variants/enemy/variants/ghost.ts | 3 +- .../npc/variants/enemy/variants/telepath.ts | 3 +- src/game/scenes/world/entities/player.ts | 3 +- .../scenes/world/entities/shot/ball/ball.ts | 5 +- src/game/scenes/world/entities/shot/lazer.ts | 3 +- src/game/scenes/world/entities/sprite.ts | 5 +- src/game/scenes/world/wave.ts | 8 +- src/game/scenes/world/world.ts | 5 +- src/index.ts | 38 ++--- src/lib/analytics.ts | 111 -------------- src/lib/environment.ts | 30 ---- src/lib/sdk.ts | 145 ------------------ src/lib/shader.ts | 11 +- src/types/game.ts | 16 +- src/types/sdk.ts | 11 -- vite.config.js | 2 +- 43 files changed, 67 insertions(+), 864 deletions(-) delete mode 100644 src/assets/sprites/hud/ads.png delete mode 100644 src/const/ads.ts delete mode 100644 src/game/scenes/screen/interface/ads-reward/index.tsx delete mode 100644 src/game/scenes/screen/interface/ads-reward/modal/index.tsx delete mode 100644 src/game/scenes/screen/interface/ads-reward/modal/styles.ts delete mode 100644 src/game/scenes/screen/interface/unlocks/modal/item-ads/index.tsx delete mode 100644 src/game/scenes/screen/interface/unlocks/modal/item-ads/styles.ts delete mode 100644 src/lib/analytics.ts delete mode 100644 src/lib/environment.ts delete mode 100644 src/lib/sdk.ts delete mode 100644 src/types/sdk.ts diff --git a/package.json b/package.json index 3283640c..365e4bdd 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,6 @@ "scripts": { "start": "vite --host", "build": "vite build --mode vanilla", - "build:crazy_games": "vite build --mode crazy_games", - "build:poki": "vite build --mode poki", "test": "jest", "lint": "eslint \"./**/*.{js,ts,tsx}\" --ignore-path .gitignore --fix" }, diff --git a/src/assets/sprites/hud/ads.png b/src/assets/sprites/hud/ads.png deleted file mode 100644 index 935bc4e1f86a53913829ca417cb305b1fbe47cba..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 603 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+ru!+5>z-T!HleK>)HQ{ucx~MW-al zFPOn){;Q6oezJewNlt8F|F%C&P2gd?`|Wd^Ejd5z+3u~Y$aUF3^y!8fRXN99JGR`p z$iToD?&;zf5^?zL)SG#S36Xv`?}t|k9SaLxnDWPA<&OO8 zllsr4PCWW`vFeR2{m(M&UcbJ4G%Agw;N5C|8&3IOc6%e5Z(Z?XaIKp;S;gvl`W}P7 zd(EU?dv?nIinR2p&wiE2TfnwLqO)p7-IN(tmCQ^cQ!Q7zzdX*x@nPQLe{~c7r7yo< z=6l1xeq!HMcZQep>@QD?yUQ~^{*tSDAajdd825oElkKF}oZQeQ_+R0{OzQ{w%-;fE zvTBq$=`3MaII#alU?qdWdSicvcL~gV9w(HKva+nUeEWb=p;!3UK_&(r^)1cJ1`B0l z8a6j`7L = { - [GamePlatform.POKI]: { - sdk: 'https://game-cdn.poki.com/scripts/v2/poki-sdk.js', - flags: { - [GameFlag.ADS]: true, - [GameFlag.AUTO_ORIENTATION]: true, - }, - }, - [GamePlatform.CRAZY_GAMES]: { - sdk: 'https://sdk.crazygames.com/crazygames-sdk-v2.js', - flags: { - [GameFlag.ADS]: true, - [GameFlag.COPYRIGHT]: true, - }, - }, - [GamePlatform.VANILLA]: { - flags: { - [GameFlag.BLOOD]: true, - [GameFlag.COPYRIGHT]: true, - }, - }, - [GamePlatform.DEVELOPMENT]: { - flags: { - [GameFlag.BLOOD]: true, - }, - }, -}; diff --git a/src/game/game.ts b/src/game/game.ts index b139d2b6..7a1ce932 100644 --- a/src/game/game.ts +++ b/src/game/game.ts @@ -3,9 +3,6 @@ import Phaser from 'phaser'; import { AUDIO_VOLUME, CONTAINER_ID, DEBUG_MODS, } from '~const/game'; -import { Analytics } from '~lib/analytics'; -import { Environment } from '~lib/environment'; -import { SDK } from '~lib/sdk'; import { registerShaders } from '~lib/shader'; import { Storage } from '~lib/storage'; import { Tutorial } from '~lib/tutorial'; @@ -27,7 +24,6 @@ import { } from '~type/game'; import { MenuPage } from '~type/menu'; import { IScreen } from '~type/screen'; -import { SDKAdsType } from '~type/sdk'; import { StorageSave } from '~type/storage'; import { IWorld } from '~type/world'; @@ -89,10 +85,6 @@ export class Game extends Phaser.Game implements IGame { }, }); - Analytics.Register(); - - SDK.ToggleLoadState(true); - this.readSettings(); if (!this.isSettingEnabled(GameSettings.TUTORIAL)) { @@ -127,7 +119,7 @@ export class Game extends Phaser.Game implements IGame { || (this.state === GameState.PAUSED && !this.isSaved) ); - if (needConfirm && Environment.Platform !== 'development') { + if (needConfirm && ENV_MODE !== 'development') { event.preventDefault(); // @ts-ignore // eslint-disable-next-line no-param-reassign @@ -138,12 +130,6 @@ export class Game extends Phaser.Game implements IGame { window.addEventListener('contextmenu', (event: Event) => { event.preventDefault(); }); - - window.addEventListener('error', (event: ErrorEvent) => { - Analytics.TrackError( - event.error ?? new Error(event.message ?? 'Undefined error'), - ); - }); } public pauseGame() { @@ -168,16 +154,14 @@ export class Game extends Phaser.Game implements IGame { return; } - SDK.ShowAds(SDKAdsType.MIDGAME).then(() => { - this.setState(GameState.STARTED); + this.setState(GameState.STARTED); - this.scene.systemScene.scene.stop(GameScene.MENU); + this.scene.systemScene.scene.stop(GameScene.MENU); - this.world.scene.resume(); - this.screen.scene.resume(); + this.world.scene.resume(); + this.screen.scene.resume(); - this.isSaved = false; - }); + this.isSaved = false; } public continueGame(save: StorageSave) { @@ -187,9 +171,7 @@ export class Game extends Phaser.Game implements IGame { this.usedSave = save; - SDK.ShowAds(SDKAdsType.MIDGAME).then(() => { - this.startGame(); - }); + this.startGame(); } public startNewGame() { @@ -199,13 +181,7 @@ export class Game extends Phaser.Game implements IGame { this.usedSave = null; - if (this.sessionsCount === 0) { - this.startGame(); - } else { - SDK.ShowAds(SDKAdsType.MIDGAME).then(() => { - this.startGame(); - }); - } + this.startGame(); } private startGame() { @@ -262,10 +238,7 @@ export class Game extends Phaser.Game implements IGame { } this.stopGame(false); - - SDK.ShowAds(SDKAdsType.MIDGAME).then(() => { - this.startGame(); - }); + this.startGame(); } public finishGame() { @@ -284,15 +257,9 @@ export class Game extends Phaser.Game implements IGame { this.scene.systemScene.scene.stop(GameScene.SCREEN); this.scene.systemScene.scene.launch(GameScene.GAMEOVER, { stat, record }); - - Analytics.TrackEvent({ - world: this.world, - success: false, - }); } public toggleSystemPause(state: boolean) { - SDK.TogglePlayState(!state); this.events.emit(GameEvents.TOGGLE_PAUSE, state); if (state) { @@ -313,7 +280,6 @@ export class Game extends Phaser.Game implements IGame { this.state = state; if (prevPauseState !== nextPauseState) { - SDK.TogglePlayState(!nextPauseState); this.events.emit(GameEvents.TOGGLE_PAUSE, nextPauseState); } } @@ -359,7 +325,7 @@ export class Game extends Phaser.Game implements IGame { if ( this.scale.isFullscreen || this.isDesktop() - || Environment.Platform === 'development' + || ENV_MODE === 'development' ) { return; } diff --git a/src/game/scenes/menu/interface/content/save-game/index.tsx b/src/game/scenes/menu/interface/content/save-game/index.tsx index c25efacc..547c263f 100644 --- a/src/game/scenes/menu/interface/content/save-game/index.tsx +++ b/src/game/scenes/menu/interface/content/save-game/index.tsx @@ -4,7 +4,6 @@ import React, { } from 'react'; import { MAX_GAME_SAVES } from '~const/game'; -import { Environment } from '~lib/environment'; import { phrase } from '~lib/lang'; import { Storage } from '~lib/storage'; import { Button } from '~scene/system/interface/button'; @@ -30,7 +29,7 @@ export const SaveGame: React.FC = () => { const reachedLimit = ( saves.length >= MAX_GAME_SAVES - && Environment.Platform !== 'development' + && ENV_MODE !== 'development' ); const onSelectSave = (save: StorageSave) => { diff --git a/src/game/scenes/menu/interface/copyright/index.tsx b/src/game/scenes/menu/interface/copyright/index.tsx index 3a84dacb..656efac4 100644 --- a/src/game/scenes/menu/interface/copyright/index.tsx +++ b/src/game/scenes/menu/interface/copyright/index.tsx @@ -1,8 +1,6 @@ import React from 'react'; import pkg from '../../../../../../package.json'; -import { Environment } from '~lib/environment'; -import { GameFlag } from '~type/game'; import { Wrapper, Icon, About, Discord, Author, Link, @@ -13,11 +11,9 @@ export const Copyright: React.FC = () => ( Created by{' '} - {Environment.GetFlag(GameFlag.COPYRIGHT) ? ( - - {pkg.author.name} - - ) : pkg.author.name} + + {pkg.author.name} + Version {pkg.version} diff --git a/src/game/scenes/screen/interface/ads-reward/index.tsx b/src/game/scenes/screen/interface/ads-reward/index.tsx deleted file mode 100644 index d971a0bd..00000000 --- a/src/game/scenes/screen/interface/ads-reward/index.tsx +++ /dev/null @@ -1,50 +0,0 @@ -import { useScene } from 'phaser-react-ui'; -import React, { useState, useEffect } from 'react'; - -import { ADS_REWARD_WAVE_FREQUENCY, ADS_REWARD_EXPERIENCE, ADS_REWARD_RESOURCES } from '~const/ads'; -import { Environment } from '~lib/environment'; -import { GameScene, GameFlag } from '~type/game'; -import { IWorld } from '~type/world'; -import { WaveEvents } from '~type/world/wave'; - -import { Modal } from './modal'; - -export const AdsReward: React.FC = () => { - const world = useScene(GameScene.WORLD); - - const [isAdsOfferOpen, setAdsOfferOpen] = useState(false); - const [adsReward, setAdsReward] = useState({ - experience: 0, - resources: 0, - }); - - const onClose = () => { - setAdsOfferOpen(false); - }; - - const onWaveComplete = (number: number) => { - if (number % ADS_REWARD_WAVE_FREQUENCY === 0) { - setAdsOfferOpen(true); - setAdsReward({ - experience: ADS_REWARD_EXPERIENCE * number, - resources: ADS_REWARD_RESOURCES * number, - }); - } - }; - - useEffect(() => { - if (!Environment.GetFlag(GameFlag.ADS)) { - return; - } - - world.wave.on(WaveEvents.COMPLETE, onWaveComplete); - - return () => { - world.wave.off(WaveEvents.COMPLETE, onWaveComplete); - }; - }, []); - - return ( - isAdsOfferOpen && - ); -}; diff --git a/src/game/scenes/screen/interface/ads-reward/modal/index.tsx b/src/game/scenes/screen/interface/ads-reward/modal/index.tsx deleted file mode 100644 index 511aec30..00000000 --- a/src/game/scenes/screen/interface/ads-reward/modal/index.tsx +++ /dev/null @@ -1,61 +0,0 @@ -import { useClick, useGame, useScene } from 'phaser-react-ui'; -import React, { useRef } from 'react'; - -import { phrase } from '~lib/lang'; -import { SDK } from '~lib/sdk'; -import { IGame, GameScene } from '~type/game'; -import { SDKAdsType } from '~type/sdk'; -import { IWorld } from '~type/world'; - -import { - Container, Label, Amounts, Amount, IconPlay, Content, Close, Group, -} from './styles'; - -type Props = { - experience: number - resources: number - onClose: () => void -}; - -export const Modal: React.FC = ({ experience, resources, onClose }) => { - const game = useGame(); - const world = useScene(GameScene.WORLD); - - const refContent = useRef(null); - - useClick(refContent, 'down', () => { - onClose(); - game.toggleSystemPause(true); - SDK.ShowAds(SDKAdsType.REWARDED).then((reward) => { - game.toggleSystemPause(false); - if (reward) { - world.player.giveExperience(experience); - world.player.giveResources(resources); - } - }); - }, [experience, resources]); - - return ( - - - - - - - - - {resources} - - - - {experience} - - - - - X - - ); -}; diff --git a/src/game/scenes/screen/interface/ads-reward/modal/styles.ts b/src/game/scenes/screen/interface/ads-reward/modal/styles.ts deleted file mode 100644 index 4aa52c01..00000000 --- a/src/game/scenes/screen/interface/ads-reward/modal/styles.ts +++ /dev/null @@ -1,109 +0,0 @@ -import styled from 'styled-components'; - -import { INTERFACE_MOBILE_BREAKPOINT } from '~const/interface'; -import { InterfaceBackgroundColor, InterfaceFont } from '~type/interface'; - -export const Container = styled.div` - color: #fff; - background: rgba(67, 0, 143, 0.75); - border-radius: 5px; - display: flex; - align-items: center; - pointer-events: all; - overflow: hidden; -`; - -export const Content = styled.div` - display: flex; - align-items: center; - padding: 16px 18px; - flex: 1; - &:hover { - cursor: pointer; - background: ${InterfaceBackgroundColor.BLACK_TRANSPARENT_25}; - } - @media ${INTERFACE_MOBILE_BREAKPOINT} { - padding: 14px 16px; - } -`; - -export const Group = styled.div` -`; - -export const IconPlay = styled.img` - width: 40px; - margin-right: 18px; - @media ${INTERFACE_MOBILE_BREAKPOINT} { - width: 28px; - margin-right: 12px; - } -`; - -export const Label = styled.div` - color: #fff; - font-family: ${InterfaceFont.PIXEL_LABEL}; - font-size: 10px; - line-height: 10px; - margin-top: -1px; - white-space: nowrap; - @media ${INTERFACE_MOBILE_BREAKPOINT} { - font-size: 9px; - line-height: 9px; - } -`; - -export const Close = styled.div` - color: #fff; - font-family: ${InterfaceFont.PIXEL_LABEL}; - font-size: 13px; - line-height: 13px; - padding: 0 24px; - background: ${InterfaceBackgroundColor.BLACK_TRANSPARENT_50}; - height: 100%; - display: flex; - align-items: center; - &:hover { - cursor: pointer; - background: ${InterfaceBackgroundColor.ERROR_DARK}; - } - @media ${INTERFACE_MOBILE_BREAKPOINT} { - padding: 0 20px; - } -`; - -export const Amounts = styled.div` - display: flex; - align-items: center; - gap: 16px; - margin-top: 10px; - @media ${INTERFACE_MOBILE_BREAKPOINT} { - gap: 10px; - margin-top: 6px; - } -`; - -export const Amount: any = styled.div` - display: flex; - align-items: center; -`; - -Amount.Icon = styled.img` - margin-right: 8px; - width: 16px; - @media ${INTERFACE_MOBILE_BREAKPOINT} { - width: 12px; - } -`; - -Amount.Value = styled.div` - color: #fff; - font-family: ${InterfaceFont.PIXEL_LABEL}; - font-size: 15px; - line-height: 15px; - margin-top: -2px; - @media ${INTERFACE_MOBILE_BREAKPOINT} { - font-size: 14px; - line-height: 14px; - margin-top: -3px; - } -`; diff --git a/src/game/scenes/screen/interface/index.tsx b/src/game/scenes/screen/interface/index.tsx index 48b43dbd..4fbd6d4e 100644 --- a/src/game/scenes/screen/interface/index.tsx +++ b/src/game/scenes/screen/interface/index.tsx @@ -4,7 +4,6 @@ import React from 'react'; import { INTERFACE_SCALE } from '~const/interface'; import { Section } from '~scene/system/interface/section'; -import { AdsReward } from './ads-reward'; import { Builder } from './builder'; import { Debug } from './debug'; import { Modes } from './modes'; @@ -33,7 +32,6 @@ export const ScreenUI: React.FC = () => { - diff --git a/src/game/scenes/screen/interface/skills/index.tsx b/src/game/scenes/screen/interface/skills/index.tsx index b9e99674..7407e33e 100644 --- a/src/game/scenes/screen/interface/skills/index.tsx +++ b/src/game/scenes/screen/interface/skills/index.tsx @@ -1,22 +1,18 @@ -import { useGame, useScene } from 'phaser-react-ui'; +import { useGame } from 'phaser-react-ui'; import React, { useEffect, useState } from 'react'; import { phrase } from '~lib/lang'; -import { SDK } from '~lib/sdk'; import { Tutorial } from '~lib/tutorial'; import { Button } from '~scene/system/interface/button'; import { Hint } from '~scene/system/interface/hint'; -import { GameScene, IGame } from '~type/game'; -import { SDKAdsType } from '~type/sdk'; +import { IGame } from '~type/game'; import { TutorialStep } from '~type/tutorial'; -import { IWorld } from '~type/world'; import { Modal } from './modal'; import { Wrapper } from './styles'; export const Skills: React.FC = () => { const game = useGame(); - const world = useScene(GameScene.WORLD); const [isOpened, setOpened] = useState(false); const [hint, setHint] = useState(false); @@ -28,16 +24,8 @@ export const Skills: React.FC = () => { }; const onClose = () => { - const close = () => { - setOpened(false); - game.toggleSystemPause(false); - }; - - if (world.wave.number >= 4) { - SDK.ShowAds(SDKAdsType.MIDGAME).then(close); - } else { - close(); - } + setOpened(false); + game.toggleSystemPause(false); }; useEffect(() => ( diff --git a/src/game/scenes/screen/interface/unlocks/modal/index.tsx b/src/game/scenes/screen/interface/unlocks/modal/index.tsx index 16ae7691..bf86741b 100644 --- a/src/game/scenes/screen/interface/unlocks/modal/index.tsx +++ b/src/game/scenes/screen/interface/unlocks/modal/index.tsx @@ -1,23 +1,11 @@ -import { - useClick, useCurrentScene, useEvent, useScene, -} from 'phaser-react-ui'; -import React, { - useEffect, useMemo, useRef, useState, -} from 'react'; +import { useClick, useCurrentScene, useEvent } from 'phaser-react-ui'; +import React, { useEffect, useRef, useState } from 'react'; import { Feature } from '..'; -import { ADS_MIDGAMES_WAVES, ADS_UNLOCK_SUPERSKILL_MIN_WAVE } from '~const/ads'; -import { Environment } from '~lib/environment'; import { phrase } from '~lib/lang'; -import { SDK } from '~lib/sdk'; import { Tutorial } from '~lib/tutorial'; -import { GameFlag, GameScene } from '~type/game'; -import { SDKAdsType } from '~type/sdk'; -import { IWorld } from '~type/world'; -import { PlayerSuperskill } from '~type/world/entities/player'; import { Item } from './item'; -import { ItemAds } from './item-ads'; import { Button, Container, Label, List, Overlay, } from './styles'; @@ -29,38 +17,14 @@ type Props = { export const Modal: React.FC = ({ features, onClose }) => { const scene = useCurrentScene(); - const world = useScene(GameScene.WORLD); const [unlocks, setUnlocks] = useState(features); - const [isAllowAds, setAllowAds] = useState(() => ( - Environment.GetFlag(GameFlag.ADS) - && Object.keys(world.player.unlockedSuperskills).length < Object.keys(PlayerSuperskill).length - && world.wave.number >= ADS_UNLOCK_SUPERSKILL_MIN_WAVE - )); const refOverlay = useRef(null); const refButton = useRef(null); - const hasSuperskill = useMemo(() => ( - features.some((feature) => feature.type === 'SUPERSKILL') - ), [features]); - const handleClose = () => { - if ( - Environment.GetFlag(GameFlag.ADS) - && ADS_MIDGAMES_WAVES.includes(world.wave.number) - ) { - SDK.ShowAds(SDKAdsType.MIDGAME).then(onClose); - } else { - onClose(); - } - }; - - const onAdsComplete = (rewarded: boolean) => { - setAllowAds(false); - if (rewarded) { - world.player.unlockSuperskill(); - } + onClose(); }; useClick(refOverlay, 'down', () => {}, []); @@ -88,9 +52,6 @@ export const Modal: React.FC = ({ features, onClose }) => { {unlocks.map((feature, i) => ( ))} - {(isAllowAds && hasSuperskill) && ( - - )} diff --git a/src/game/scenes/screen/interface/unlocks/modal/item-ads/index.tsx b/src/game/scenes/screen/interface/unlocks/modal/item-ads/index.tsx deleted file mode 100644 index 613e6070..00000000 --- a/src/game/scenes/screen/interface/unlocks/modal/item-ads/index.tsx +++ /dev/null @@ -1,34 +0,0 @@ -import { useClick } from 'phaser-react-ui'; -import React, { useRef } from 'react'; - -import { phrase } from '~lib/lang'; -import { SDK } from '~lib/sdk'; -import { SDKAdsType } from '~type/sdk'; - -import { - Container, IconPlay, Text, Body, IconAdd, -} from './styles'; - -type Props = { - onComplete: (rewarded: boolean) => void -}; - -export const ItemAds: React.FC = ({ onComplete }) => { - const refContainer = useRef(null); - - useClick(refContainer, 'down', () => { - SDK.ShowAds(SDKAdsType.REWARDED).then(onComplete); - }, []); - - return ( - - - - - - - {phrase('ADS_UNLOCK')} - - - ); -}; diff --git a/src/game/scenes/screen/interface/unlocks/modal/item-ads/styles.ts b/src/game/scenes/screen/interface/unlocks/modal/item-ads/styles.ts deleted file mode 100644 index 7f6222b3..00000000 --- a/src/game/scenes/screen/interface/unlocks/modal/item-ads/styles.ts +++ /dev/null @@ -1,58 +0,0 @@ -import styled from 'styled-components'; - -import { INTERFACE_MOBILE_BREAKPOINT } from '~const/interface'; -import { InterfaceBackgroundColor, InterfaceFont } from '~type/interface'; - -export const Container = styled.div` - width: 220px; - border-radius: 10px; - display: flex; - flex-direction: column; - pointer-events: all; - backdrop-filter: blur(10px); - -webkit-backdrop-filter: blur(10px); - transform: translateZ(0); - -webkit-transform: translateZ(0); - overflow: hidden; - &:hover { - cursor: pointer; - background: ${InterfaceBackgroundColor.BLACK_TRANSPARENT_50}; - } -`; - -export const Body = styled.div` - background: rgba(67, 0, 143, 0.25); - display: flex; - justify-content: center; - align-items: center; - height: 140px; - @media ${INTERFACE_MOBILE_BREAKPOINT} { - height: 100px; - } -`; - -export const IconPlay = styled.img` - width: 32px; - margin-right: 10px; -`; - -export const IconAdd = styled.img` - width: 40px; - margin: 10px 0; - opacity: 0.5; - @media ${INTERFACE_MOBILE_BREAKPOINT} { - width: 30px; - } -`; - -export const Text = styled.div` - background: rgba(67, 0, 143, 0.5); - padding: 20px 30px; - color: #fff; - font-family: ${InterfaceFont.PIXEL_TEXT}; - font-size: 11px; - line-height: 11px; - flex: 1; - display: flex; - align-items: center; -`; diff --git a/src/game/scenes/screen/screen.ts b/src/game/scenes/screen/screen.ts index 9337535c..a568e3c4 100644 --- a/src/game/scenes/screen/screen.ts +++ b/src/game/scenes/screen/screen.ts @@ -3,7 +3,6 @@ import VirtualJoystick from 'phaser3-rex-plugins/plugins/virtualjoystick'; import { INTERFACE_SCALE } from '~const/interface'; import { Scene } from '~game/scenes'; -import { Analytics } from '~lib/analytics'; import { Assets } from '~lib/assets'; import { GameScene } from '~type/game'; import { LangPhrase } from '~type/lang'; @@ -38,7 +37,7 @@ export class Screen extends Scene implements IScreen { try { this.handleJoystick(); } catch (error) { - Analytics.TrackWarn('Failed to update screen', error as TypeError); + console.warn('Failed to update screen', error as TypeError); } } diff --git a/src/game/scenes/system/system.ts b/src/game/scenes/system/system.ts index 93bb5a6e..2b50c3cd 100644 --- a/src/game/scenes/system/system.ts +++ b/src/game/scenes/system/system.ts @@ -1,7 +1,6 @@ import { CONTROL_KEY } from '~const/controls'; import { Scene } from '~game/scenes'; import { Assets } from '~lib/assets'; -import { SDK } from '~lib/sdk'; import { removeLoading, setLoadingStatus } from '~lib/state'; import { Storage } from '~lib/storage'; import { GameScene, GameState } from '~type/game'; @@ -43,8 +42,6 @@ export class System extends Scene { this.scene.bringToTop(); - SDK.ToggleLoadState(false); - removeLoading(); if (!this.game.isDesktop()) { diff --git a/src/game/scenes/world/builder.ts b/src/game/scenes/world/builder.ts index ed729aa9..a8d9a401 100644 --- a/src/game/scenes/world/builder.ts +++ b/src/game/scenes/world/builder.ts @@ -5,7 +5,6 @@ import { DIFFICULTY } from '~const/world/difficulty'; import { BUILDING_TILE } from '~const/world/entities/building'; import { BUILDINGS } from '~const/world/entities/buildings'; import { LEVEL_MAP_PERSPECTIVE, LEVEL_MAP_TILE } from '~const/world/level'; -import { Analytics } from '~lib/analytics'; import { isPositionsEqual } from '~lib/dimension'; import { phrase } from '~lib/lang'; import { progressionLinear } from '~lib/progression'; @@ -87,7 +86,7 @@ export class Builder extends Phaser.Events.EventEmitter implements IBuilder { this.close(); } } catch (error) { - Analytics.TrackWarn('Failed to update builder', error as TypeError); + console.warn('Failed to update builder', error as TypeError); } } diff --git a/src/game/scenes/world/effects/fx-manager.ts b/src/game/scenes/world/effects/fx-manager.ts index b6e2dd18..600184ab 100644 --- a/src/game/scenes/world/effects/fx-manager.ts +++ b/src/game/scenes/world/effects/fx-manager.ts @@ -1,6 +1,4 @@ -import { Analytics } from '~lib/analytics'; -import { Environment } from '~lib/environment'; -import { GameFlag, GameSettings } from '~type/game'; +import { GameSettings } from '~type/game'; import { IWorld } from '~type/world'; import { EffectTexture, IParticlesParent, ParticlesTexture } from '~type/world/effects'; import { IFXManager, SoundParams } from '~type/world/effects/fx-manager'; @@ -29,7 +27,7 @@ export class FXManager implements IFXManager { this.scene.sound.play(sound, params); } } catch (error) { - Analytics.TrackWarn('Failed to play sound', error as TypeError); + console.warn('Failed to play sound', error as TypeError); } } @@ -61,7 +59,6 @@ export class FXManager implements IFXManager { public createBloodEffect(parent: ISprite) { if ( !parent.active - || !Environment.GetFlag(GameFlag.BLOOD) || !this.isEffectsEnabled() || FXManager.IsExist(parent, 'blood') ) { @@ -346,10 +343,7 @@ export class FXManager implements IFXManager { } public createBloodStainEffect(position: PositionAtWorld) { - if ( - !this.isEffectsEnabled() - || !Environment.GetFlag(GameFlag.BLOOD) - ) { + if (!this.isEffectsEnabled()) { return null; } diff --git a/src/game/scenes/world/effects/particles.ts b/src/game/scenes/world/effects/particles.ts index ebaf1d3c..a369667a 100644 --- a/src/game/scenes/world/effects/particles.ts +++ b/src/game/scenes/world/effects/particles.ts @@ -1,4 +1,3 @@ -import { Analytics } from '~lib/analytics'; import { Assets } from '~lib/assets'; import { IWorld } from '~type/world'; import { @@ -74,7 +73,7 @@ export class Particles implements IParticles { try { this.emitter.setDepth(this.parent.depth + 1); } catch (error) { - Analytics.TrackWarn('Failed to update particles', error as TypeError); + console.warn('Failed to update particles', error as TypeError); } } } diff --git a/src/game/scenes/world/entities/building/building.ts b/src/game/scenes/world/entities/building/building.ts index 13d7db7f..44f8478d 100644 --- a/src/game/scenes/world/entities/building/building.ts +++ b/src/game/scenes/world/entities/building/building.ts @@ -7,7 +7,6 @@ import { BUILDING_TILE } from '~const/world/entities/building'; import { LEVEL_MAP_PERSPECTIVE } from '~const/world/level'; import { Indicator } from '~entity/addons/indicator'; import { Live } from '~entity/addons/live'; -import { Analytics } from '~lib/analytics'; import { Assets } from '~lib/assets'; import { progressionQuadratic, progressionLinear } from '~lib/progression'; import { Tutorial } from '~lib/tutorial'; @@ -167,7 +166,7 @@ export class Building extends Phaser.GameObjects.Image implements IBuilding, ITi this.focus(); } } catch (error) { - Analytics.TrackWarn('Failed building update', error as TypeError); + console.warn('Failed building update', error as TypeError); } } diff --git a/src/game/scenes/world/entities/building/variants/generator.ts b/src/game/scenes/world/entities/building/variants/generator.ts index 4a61b077..5a80f04f 100644 --- a/src/game/scenes/world/entities/building/variants/generator.ts +++ b/src/game/scenes/world/entities/building/variants/generator.ts @@ -1,6 +1,5 @@ import { DIFFICULTY } from '~const/world/difficulty'; import { Building } from '~entity/building'; -import { Analytics } from '~lib/analytics'; import { Tutorial } from '~lib/tutorial'; import { TutorialStep } from '~type/tutorial'; import { IWorld } from '~type/world'; @@ -54,7 +53,7 @@ export class BuildingGenerator extends Building { this.pauseActions(); } } catch (error) { - Analytics.TrackWarn('Failed to update generator generator', error as TypeError); + console.warn('Failed to update generator generator', error as TypeError); } } diff --git a/src/game/scenes/world/entities/building/variants/tower/tower.ts b/src/game/scenes/world/entities/building/variants/tower/tower.ts index 69ef8de2..0a7c72e5 100644 --- a/src/game/scenes/world/entities/building/variants/tower/tower.ts +++ b/src/game/scenes/world/entities/building/variants/tower/tower.ts @@ -1,6 +1,5 @@ import { DIFFICULTY } from '~const/world/difficulty'; import { Building } from '~entity/building'; -import { Analytics } from '~lib/analytics'; import { getClosestByIsometricDistance } from '~lib/dimension'; import { progressionLinear } from '~lib/progression'; import { Tutorial } from '~lib/tutorial'; @@ -67,7 +66,7 @@ export class BuildingTower extends Building implements IBuildingTower { this.attack(); } } catch (error) { - Analytics.TrackWarn('Failed to update tower building', error as TypeError); + console.warn('Failed to update tower building', error as TypeError); } } diff --git a/src/game/scenes/world/entities/npc/npc.ts b/src/game/scenes/world/entities/npc/npc.ts index 98b81027..32fc449d 100644 --- a/src/game/scenes/world/entities/npc/npc.ts +++ b/src/game/scenes/world/entities/npc/npc.ts @@ -5,7 +5,6 @@ import { WORLD_DEPTH_GRAPHIC } from '~const/world'; import { NPC_PATH_FIND_RATE } from '~const/world/entities/npc'; import { LEVEL_MAP_PERSPECTIVE } from '~const/world/level'; import { Sprite } from '~entity/sprite'; -import { Analytics } from '~lib/analytics'; import { isPositionsEqual, getIsometricAngle, getIsometricDistance } from '~lib/dimension'; import { Level } from '~scene/world/level'; import { IWorld } from '~type/world'; @@ -82,7 +81,7 @@ export class NPC extends Sprite implements INPC { this.isPathPassed = false; } } catch (error) { - Analytics.TrackWarn('Failed to update NPC', error as TypeError); + console.warn('Failed to update NPC', error as TypeError); } } diff --git a/src/game/scenes/world/entities/npc/variants/assistant.ts b/src/game/scenes/world/entities/npc/variants/assistant.ts index 464d8706..d940eae8 100644 --- a/src/game/scenes/world/entities/npc/variants/assistant.ts +++ b/src/game/scenes/world/entities/npc/variants/assistant.ts @@ -3,7 +3,6 @@ import { ASSISTANT_PATH_BREAKPOINT, ASSISTANT_TILE_SIZE, ASSISTANT_WEAPON } from import { NPC } from '~entity/npc'; import { ShotBallFire } from '~entity/shot/ball/variants/fire'; import { ShotLazer } from '~entity/shot/lazer'; -import { Analytics } from '~lib/analytics'; import { Assets } from '~lib/assets'; import { getClosestByIsometricDistance, getIsometricDistance } from '~lib/dimension'; import { progressionQuadratic } from '~lib/progression'; @@ -73,7 +72,7 @@ export class Assistant extends NPC implements IAssistant { this.attack(); } } catch (error) { - Analytics.TrackWarn('Failed to update assistant', error as TypeError); + console.warn('Failed to update assistant', error as TypeError); } } diff --git a/src/game/scenes/world/entities/npc/variants/enemy/enemy.ts b/src/game/scenes/world/entities/npc/variants/enemy/enemy.ts index 14bce859..c6e00221 100644 --- a/src/game/scenes/world/entities/npc/variants/enemy/enemy.ts +++ b/src/game/scenes/world/entities/npc/variants/enemy/enemy.ts @@ -7,7 +7,6 @@ import { } from '~const/world/entities/enemy'; import { Building } from '~entity/building'; import { NPC } from '~entity/npc'; -import { Analytics } from '~lib/analytics'; import { Assets } from '~lib/assets'; import { progressionLinear, progressionQuadratic } from '~lib/progression'; import { GameSettings } from '~type/game'; @@ -127,7 +126,7 @@ export class Enemy extends NPC implements IEnemy { this.isOverlapTarget = false; } catch (error) { - Analytics.TrackWarn('Failed to update enemy', error as TypeError); + console.warn('Failed to update enemy', error as TypeError); } } diff --git a/src/game/scenes/world/entities/npc/variants/enemy/variants/berserk.ts b/src/game/scenes/world/entities/npc/variants/enemy/variants/berserk.ts index 7ac2f917..f22cb76d 100644 --- a/src/game/scenes/world/entities/npc/variants/enemy/variants/berserk.ts +++ b/src/game/scenes/world/entities/npc/variants/enemy/variants/berserk.ts @@ -1,5 +1,4 @@ import { ENEMY_HEAL_MULTIPLIER, ENEMY_HEAL_TIMESTAMP_PAUSE } from '~const/world/entities/enemy'; -import { Analytics } from '~lib/analytics'; import { IWorld } from '~type/world'; import { EnemyVariantData, EnemyTexture } from '~type/world/entities/npc/enemy'; @@ -33,7 +32,7 @@ export class EnemyBerserk extends Enemy { try { this.heal(); } catch (error) { - Analytics.TrackWarn('Failed to update berserk enemy', error as TypeError); + console.warn('Failed to update berserk enemy', error as TypeError); } } diff --git a/src/game/scenes/world/entities/npc/variants/enemy/variants/ghost.ts b/src/game/scenes/world/entities/npc/variants/enemy/variants/ghost.ts index 84ab520a..432e6191 100644 --- a/src/game/scenes/world/entities/npc/variants/enemy/variants/ghost.ts +++ b/src/game/scenes/world/entities/npc/variants/enemy/variants/ghost.ts @@ -1,4 +1,3 @@ -import { Analytics } from '~lib/analytics'; import { IWorld } from '~type/world'; import { BuildingVariant } from '~type/world/entities/building'; import { EnemyVariantData, EnemyTexture } from '~type/world/entities/npc/enemy'; @@ -29,7 +28,7 @@ export class EnemyGhost extends Enemy { try { this.updateVisible(); } catch (error) { - Analytics.TrackWarn('Failed to update ghost enemy', error as TypeError); + console.warn('Failed to update ghost enemy', error as TypeError); } } diff --git a/src/game/scenes/world/entities/npc/variants/enemy/variants/telepath.ts b/src/game/scenes/world/entities/npc/variants/enemy/variants/telepath.ts index 3c8ee21a..5080c024 100644 --- a/src/game/scenes/world/entities/npc/variants/enemy/variants/telepath.ts +++ b/src/game/scenes/world/entities/npc/variants/enemy/variants/telepath.ts @@ -2,7 +2,6 @@ import { ENEMY_REGENERATION_EFFECT_COLOR, ENEMY_REGENERATION_EFFECT_DURATION, ENEMY_REGENERATION_RADIUS, } from '~const/world/entities/enemy'; import { LEVEL_MAP_PERSPECTIVE } from '~const/world/level'; -import { Analytics } from '~lib/analytics'; import { getIsometricDistance } from '~lib/dimension'; import { IWorld } from '~type/world'; import { EntityType } from '~type/world/entities'; @@ -45,7 +44,7 @@ export class EnemyTelepath extends Enemy { try { this.updateArea(); } catch (error) { - Analytics.TrackWarn('Failed to update telepth enemy', error as TypeError); + console.warn('Failed to update telepth enemy', error as TypeError); } } diff --git a/src/game/scenes/world/entities/player.ts b/src/game/scenes/world/entities/player.ts index a5d1ca81..04a54450 100644 --- a/src/game/scenes/world/entities/player.ts +++ b/src/game/scenes/world/entities/player.ts @@ -10,7 +10,6 @@ import { import { LEVEL_MAP_PERSPECTIVE } from '~const/world/level'; import { Crystal } from '~entity/crystal'; import { Sprite } from '~entity/sprite'; -import { Analytics } from '~lib/analytics'; import { Assets } from '~lib/assets'; import { getClosestByIsometricDistance, isPositionsEqual } from '~lib/dimension'; import { progressionLinear, progressionQuadratic } from '~lib/progression'; @@ -197,7 +196,7 @@ export class Player extends Sprite implements IPlayer { this.updateStamina(); } } catch (error) { - Analytics.TrackWarn('Failed to update player', error as TypeError); + console.warn('Failed to update player', error as TypeError); } } diff --git a/src/game/scenes/world/entities/shot/ball/ball.ts b/src/game/scenes/world/entities/shot/ball/ball.ts index 99b346cd..2dcfb7cd 100644 --- a/src/game/scenes/world/entities/shot/ball/ball.ts +++ b/src/game/scenes/world/entities/shot/ball/ball.ts @@ -1,6 +1,5 @@ import Phaser from 'phaser'; -import { Analytics } from '~lib/analytics'; import { Assets } from '~lib/assets'; import { getIsometricDistance } from '~lib/dimension'; import { IWorld } from '~type/world'; @@ -62,7 +61,7 @@ export class ShotBall extends Phaser.Physics.Arcade.Image implements IShotBall { try { this.hit(enemy as IEnemy); } catch (error) { - Analytics.TrackWarn('Failed to handle ball shot collider', error as TypeError); + console.warn('Failed to handle ball shot collider', error as TypeError); } }, ); @@ -85,7 +84,7 @@ export class ShotBall extends Phaser.Physics.Arcade.Image implements IShotBall { try { this.updateFlyDistance(); } catch (error) { - Analytics.TrackWarn('Failed to update ball shot', error as TypeError); + console.warn('Failed to update ball shot', error as TypeError); } } diff --git a/src/game/scenes/world/entities/shot/lazer.ts b/src/game/scenes/world/entities/shot/lazer.ts index c5e2deb8..463f72e8 100644 --- a/src/game/scenes/world/entities/shot/lazer.ts +++ b/src/game/scenes/world/entities/shot/lazer.ts @@ -2,7 +2,6 @@ import Phaser from 'phaser'; import { WORLD_DEPTH_GRAPHIC } from '~const/world'; import { SHOT_LAZER_DELAY, SHOT_LAZER_REPEAT } from '~const/world/entities/shot'; -import { Analytics } from '~lib/analytics'; import { Assets } from '~lib/assets'; import { getIsometricDistance } from '~lib/dimension'; import { IWorld } from '~type/world'; @@ -61,7 +60,7 @@ export class ShotLazer extends Phaser.GameObjects.Line implements IShotLazer { this.updateLine(); this.processing(); } catch (error) { - Analytics.TrackWarn('Failed to update lazer shot', error as TypeError); + console.warn('Failed to update lazer shot', error as TypeError); } } diff --git a/src/game/scenes/world/entities/sprite.ts b/src/game/scenes/world/entities/sprite.ts index f8bfdefd..fb3be57d 100644 --- a/src/game/scenes/world/entities/sprite.ts +++ b/src/game/scenes/world/entities/sprite.ts @@ -4,7 +4,6 @@ import { DEBUG_MODS } from '~const/game'; import { WORLD_COLLIDE_SPEED_FACTOR, WORLD_DEPTH_GRAPHIC } from '~const/world'; import { Indicator } from '~entity/addons/indicator'; import { Live } from '~entity/addons/live'; -import { Analytics } from '~lib/analytics'; import { isPositionsEqual } from '~lib/dimension'; import { Level } from '~scene/world/level'; import { ILive, LiveEvents } from '~type/live'; @@ -97,7 +96,7 @@ export class Sprite extends Phaser.Physics.Arcade.Sprite implements ISprite { this.drawDebugGroundPosition(); } catch (error) { - Analytics.TrackWarn('Failed to update sprite', error as TypeError); + console.warn('Failed to update sprite', error as TypeError); } } @@ -152,7 +151,7 @@ export class Sprite extends Phaser.Physics.Arcade.Sprite implements ISprite { try { callback(sprite); } catch (error) { - Analytics.TrackWarn(`Failed to handle sprite ${mode} with ${target.toLowerCase()}`, error as TypeError); + console.warn(`Failed to handle sprite ${mode} with ${target.toLowerCase()}`, error as TypeError); } }, ); diff --git a/src/game/scenes/world/wave.ts b/src/game/scenes/world/wave.ts index 5ba436bc..919f6beb 100644 --- a/src/game/scenes/world/wave.ts +++ b/src/game/scenes/world/wave.ts @@ -4,7 +4,6 @@ import { DIFFICULTY } from '~const/world/difficulty'; import { ENEMIES } from '~const/world/entities/enemies'; import { ENEMY_BOSS_SPAWN_WAVE_RATE } from '~const/world/entities/enemy'; import { WAVE_INCREASED_TIME_SCALE, WAVE_TIMELEFT_ALARM } from '~const/world/wave'; -import { Analytics } from '~lib/analytics'; import { Assets } from '~lib/assets'; import { progressionLinear, progressionQuadraticMixed } from '~lib/progression'; import { Tutorial } from '~lib/tutorial'; @@ -76,7 +75,7 @@ export class Wave extends Phaser.Events.EventEmitter implements IWave { this.handleTimeleft(); this.handleProcessing(); } catch (error) { - Analytics.TrackWarn('Failed to update wave', error as TypeError); + console.warn('Failed to update wave', error as TypeError); } } @@ -224,11 +223,6 @@ export class Wave extends Phaser.Events.EventEmitter implements IWave { break; } } - - Analytics.TrackEvent({ - world: this.scene, - success: true, - }); } private spawnEnemy() { diff --git a/src/game/scenes/world/world.ts b/src/game/scenes/world/world.ts index bdb9a7dd..34f2f5b7 100644 --- a/src/game/scenes/world/world.ts +++ b/src/game/scenes/world/world.ts @@ -8,7 +8,6 @@ import { Crystal } from '~entity/crystal'; import { Assistant } from '~entity/npc/variants/assistant'; import { Player } from '~entity/player'; import { Scene } from '~game/scenes'; -import { Analytics } from '~lib/analytics'; import { Assets } from '~lib/assets'; import { aroundPosition } from '~lib/dimension'; import { progressionLinear } from '~lib/progression'; @@ -162,7 +161,7 @@ export class World extends Scene implements IWorld { this.builder.update(); this.wave.update(); } catch (error) { - Analytics.TrackWarn('Failed to update world', error as TypeError); + console.warn('Failed to update world', error as TypeError); } } @@ -450,7 +449,7 @@ export class World extends Scene implements IWorld { building.loadSavePayload(buildingData); } catch (error) { - Analytics.TrackWarn(`Failed to load '${buildingData.variant}' building`, error as TypeError); + console.warn(`Failed to load '${buildingData.variant}' building`, error as TypeError); } }); } diff --git a/src/index.ts b/src/index.ts index 3b9222ef..40e3ac1b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,40 +1,32 @@ -import { Environment } from '~lib/environment'; -import { SDK } from '~lib/sdk'; import { removeFailure, throwFailure } from '~lib/state'; -import { GameFlag, GamePlatform } from '~type/game'; +import { GamePlatform } from '~type/game'; import { FailureType } from '~type/state'; import pkg from '../package.json'; import { Game } from '~game'; -Environment.Register(); +const game = new Game(); -SDK.Register().then(() => { - const game = new Game(); +if (ENV_MODE === GamePlatform.DEVELOPMENT) { + window.GAME = game; +} - if (Environment.Platform === GamePlatform.DEVELOPMENT) { - window.GAME = game; +const checkScreenOrientation = (event?: MediaQueryListEvent) => { + if (event ? event.matches : window.innerWidth >= window.innerHeight) { + removeFailure(FailureType.BAD_SCREEN_SIZE); + } else { + throwFailure(FailureType.BAD_SCREEN_SIZE); } +}; - if (!Environment.GetFlag(GameFlag.AUTO_ORIENTATION)) { - const checkScreenOrientation = (event?: MediaQueryListEvent) => { - if (event ? event.matches : window.innerWidth >= window.innerHeight) { - removeFailure(FailureType.BAD_SCREEN_SIZE); - } else { - throwFailure(FailureType.BAD_SCREEN_SIZE); - } - }; - - checkScreenOrientation(); - window.matchMedia('(orientation: landscape)') - .addEventListener('change', checkScreenOrientation); - } -}); +checkScreenOrientation(); +window.matchMedia('(orientation: landscape)') + .addEventListener('change', checkScreenOrientation); console.clear(); console.log([ `Created by ${pkg.author.name} / ${pkg.author.url}`, - `Build v${pkg.version}-${Environment.Platform}`, + `Build v${pkg.version}-${ENV_MODE}`, `Open-Source at ${pkg.repository.url.replace('git+', '')}`, ].join('\n')); diff --git a/src/lib/analytics.ts b/src/lib/analytics.ts deleted file mode 100644 index 668de297..00000000 --- a/src/lib/analytics.ts +++ /dev/null @@ -1,111 +0,0 @@ -import { v4 as uuidv4 } from 'uuid'; - -import pkg from '../../package.json'; -import { ANALYTICS_SERVER } from '~const/analytics'; -import { Environment } from '~lib/environment'; -import { AnalyticEventData } from '~type/analytics'; - -export class Analytics { - private static UserId: string; - - private static Host: string; - - static Register() { - const userId = localStorage.getItem('USER_ID'); - - if (userId) { - this.UserId = userId; - } else { - this.UserId = uuidv4(); - localStorage.setItem('USER_ID', this.UserId); - } - - if (document.referrer) { - this.Host = document.referrer.replace(/(https?:\/\/)?([^/?]+).*/, '$2'); - } else { - this.Host = window.location.host; - } - } - - static TrackEvent(data: AnalyticEventData) { - if (Environment.Platform === 'development') { - return; - } - - this.FetchRequest('create-event', this.GetEventPayload(data)); - } - - static TrackError(data: Error) { - if (Environment.Platform === 'development') { - return; - } - - this.FetchRequest('create-error', this.GetErrorPayload(data)); - } - - static TrackWarn(message: string, originError?: TypeError) { - let fullMessage = message; - - if (originError) { - fullMessage += `. Error: ${originError.message}`; - } - - console.warn(fullMessage); - - if (Environment.Platform === 'development') { - return; - } - - this.FetchRequest('create-error', this.GetWarnPayload(fullMessage)); - } - - private static FetchRequest(endpoint: string, payload: any) { - fetch(`${ANALYTICS_SERVER}/api/${endpoint}.php`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(payload), - }).catch((e) => { - console.warn('Failed analytics', endpoint, 'request:', payload, e); - }); - } - - private static GetEventPayload(data: AnalyticEventData) { - return { - // Game progress - success: data.success, - difficulty: data.world.game.difficulty, - planet: data.world.level.planet, - waveNumber: data.world.wave.number, - resources: data.world.player.resources, - // System info - userId: this.UserId, - host: this.Host, - version: pkg.version, - }; - } - - private static GetErrorPayload(data: Error) { - return { - // Error info - type: 'error', - message: data.message, - stack: data.stack, - // System info - userId: this.UserId, - version: pkg.version, - userAgent: window.navigator.userAgent, - }; - } - - private static GetWarnPayload(message: string) { - return { - // Warn info - type: 'warn', - message, - // System info - userId: this.UserId, - version: pkg.version, - userAgent: window.navigator.userAgent, - }; - } -} diff --git a/src/lib/environment.ts b/src/lib/environment.ts deleted file mode 100644 index 4dc16681..00000000 --- a/src/lib/environment.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { ENVIRONMENTS } from '~const/game'; -import { GameFlag, GamePlatform } from '~type/game'; - -export class Environment { - public static Platform: GamePlatform; - - public static Register() { - this.Platform = this.GetCustomPlatform() ?? PLATFORM; - - if (!this.Platform) { - throw Error('Invalid environment platform'); - } - } - - public static GetFlag(flag: GameFlag) { - return ENVIRONMENTS[this.Platform].flags[flag]; - } - - public static GetSDK() { - return ENVIRONMENTS[this.Platform].sdk; - } - - private static GetCustomPlatform() { - const customPlatform = new URLSearchParams(window.location.search).get('sdk')?.toLowerCase(); - - if (customPlatform && customPlatform in ENVIRONMENTS) { - return customPlatform as GamePlatform; - } - } -} diff --git a/src/lib/sdk.ts b/src/lib/sdk.ts deleted file mode 100644 index 2ad99d41..00000000 --- a/src/lib/sdk.ts +++ /dev/null @@ -1,145 +0,0 @@ -import { Environment } from '~lib/environment'; -import { GameFlag, GamePlatform } from '~type/game'; -import { SDKAdsType } from '~type/sdk'; - -export class SDK { - private static IsPlaying: boolean = false; - - public static async Register() { - const sdk = Environment.GetSDK(); - - if (!sdk) { - return; - } - - return new Promise((resolve, reject) => { - const script = document.createElement('script'); - - script.setAttribute('src', sdk); - script.addEventListener('load', resolve); - script.addEventListener('error', reject); - - document.body.appendChild(script); - }) - .then(() => { - switch (Environment.Platform) { - case GamePlatform.POKI: { - window.PokiSDK?.init(); - } - } - }) - .catch((error) => { - console.error('SDK initialization error:', error); - }); - } - - public static ShowAds(type: SDKAdsType) { - if (!Environment.GetFlag(GameFlag.ADS)) { - return Promise.resolve(false); - } - - return new Promise((resolve) => { - try { - switch (Environment.Platform) { - case GamePlatform.CRAZY_GAMES: { - window.CrazyGames.SDK.ad.requestAd(type, { - adFinished: () => { - const rewarded = (type === SDKAdsType.REWARDED); - - resolve(rewarded); - }, - adError: () => { - resolve(false); - }, - }); - break; - } - case GamePlatform.POKI: { - const method = type === SDKAdsType.REWARDED - ? 'rewardedBreak' - : 'commercialBreak'; - - window.PokiSDK[method]().then((success: boolean) => { - const rewarded = (type === SDKAdsType.REWARDED && success); - - resolve(rewarded); - }); - break; - } - default: { - console.error('Undefined ads platform handler'); - resolve(false); - break; - } - } - } catch (error) { - console.error('SDK show ads error:', error); - resolve(false); - } - }); - } - - public static ToggleLoadState(state: boolean) { - try { - switch (Environment.Platform) { - case GamePlatform.DEVELOPMENT: { - // console.log('Toggle load state to', state); - break; - } - case GamePlatform.CRAZY_GAMES: { - if (state) { - window.CrazyGames?.SDK.game.sdkGameLoadingStart(); - } else { - window.CrazyGames?.SDK.game.sdkGameLoadingStop(); - } - break; - } - case GamePlatform.POKI: { - if (!state) { - window.PokiSDK?.gameLoadingFinished(); - } - break; - } - } - } catch (error) { - console.error('SDK load state error:', error); - } - } - - public static TogglePlayState(state: boolean) { - if (this.IsPlaying === state) { - console.warn('Unnecessary changing play state to', state); - - return; - } - - try { - this.IsPlaying = state; - - switch (Environment.Platform) { - case GamePlatform.DEVELOPMENT: { - // console.log('Toggle play state to', state); - break; - } - case GamePlatform.CRAZY_GAMES: { - if (state) { - window.CrazyGames?.SDK.game.gameplayStart(); - } else { - window.CrazyGames?.SDK.game.gameplayStop(); - } - break; - } - case GamePlatform.POKI: { - if (state) { - window.PokiSDK?.gameplayStart(); - } else { - window.PokiSDK?.gameplayStop(); - } - break; - } - } - } catch (error) { - console.error('SDK play state error:', error); - } - } -} diff --git a/src/lib/shader.ts b/src/lib/shader.ts index 502a0132..4ec44fc3 100644 --- a/src/lib/shader.ts +++ b/src/lib/shader.ts @@ -1,4 +1,3 @@ -import { Analytics } from '~lib/analytics'; import { eachEntries } from '~lib/utils'; import { ShaderType } from '~type/shader'; @@ -6,7 +5,7 @@ import { SHADERS } from '../shaders'; export function registerShaders(renderer: Phaser.Renderer.WebGL.WebGLRenderer | Phaser.Renderer.Canvas.CanvasRenderer) { if (renderer instanceof Phaser.Renderer.Canvas.CanvasRenderer) { - Analytics.TrackWarn('WebGL renderer is not supported'); + console.warn('WebGL renderer is not supported'); return; } @@ -15,7 +14,7 @@ export function registerShaders(renderer: Phaser.Renderer.WebGL.WebGLRenderer | try { renderer.pipelines.addPostPipeline(name, Shader); } catch (error) { - Analytics.TrackWarn(`Failed to register '${name}' shader`, error as TypeError); + console.warn(`Failed to register '${name}' shader`, error as TypeError); } }); } @@ -27,7 +26,7 @@ Phaser.GameObjects.Image.prototype.addShader = function (shader: ShaderType, con this.updateShader(shader, config); } } catch (error) { - Analytics.TrackWarn(`Failed to add '${shader}' shader`, error as TypeError); + console.warn(`Failed to add '${shader}' shader`, error as TypeError); } }; @@ -39,7 +38,7 @@ Phaser.GameObjects.Image.prototype.updateShader = function (shader: ShaderType, pipeline.setConfig(config); } } catch (error) { - Analytics.TrackWarn(`Failed to update '${shader}' shader`, error as TypeError); + console.warn(`Failed to update '${shader}' shader`, error as TypeError); } }; @@ -47,6 +46,6 @@ Phaser.GameObjects.Image.prototype.removeShader = function (shader: ShaderType) try { this.removePostPipeline(shader); } catch (error) { - Analytics.TrackWarn(`Failed to remove '${shader}' shader`, error as TypeError); + console.warn(`Failed to remove '${shader}' shader`, error as TypeError); } }; diff --git a/src/types/game.ts b/src/types/game.ts index 718ea90a..4f57d998 100644 --- a/src/types/game.ts +++ b/src/types/game.ts @@ -151,17 +151,8 @@ export enum GameDifficulty { HARD = 'HARD', } -export enum GameFlag { - BLOOD = 'BLOOD', - ADS = 'ADS', - AUTO_ORIENTATION = 'AUTO_ORIENTATION', - COPYRIGHT = 'COPYRIGHT', -} - export enum GamePlatform { DEVELOPMENT = 'development', - POKI = 'poki', - CRAZY_GAMES = 'crazy_games', VANILLA = 'vanilla', } @@ -177,13 +168,8 @@ export type GameStat = { lived: number }; -export type GameEnvironment = { - flags: Partial> - sdk?: string -}; - declare global { - const PLATFORM: GamePlatform; + const ENV_MODE: GamePlatform; interface Window { GAME?: IGame diff --git a/src/types/sdk.ts b/src/types/sdk.ts deleted file mode 100644 index a5badef7..00000000 --- a/src/types/sdk.ts +++ /dev/null @@ -1,11 +0,0 @@ -export enum SDKAdsType { - MIDGAME = 'midgame', - REWARDED = 'rewarded', -} - -declare global { - interface Window { - PokiSDK?: any - CrazyGames?: any - } -} diff --git a/vite.config.js b/vite.config.js index dfef682e..f9b2c429 100644 --- a/vite.config.js +++ b/vite.config.js @@ -38,7 +38,7 @@ export default defineConfig(({ mode }) => ({ port: 9999, }, define: { - PLATFORM: JSON.stringify(mode), + ENV_MODE: JSON.stringify(mode), }, resolve: { alias: alias