File tree Expand file tree Collapse file tree 7 files changed +62
-12
lines changed Expand file tree Collapse file tree 7 files changed +62
-12
lines changed Original file line number Diff line number Diff line change @@ -134,6 +134,9 @@ export class Application {
134134 /** @type {TypedTrackedState<boolean> } */
135135 this . trackedIsRenderable = new TrackedState ( this . onAppRenderableStateChanged , this ) ;
136136
137+ /** @type {TypedTrackedState<boolean> } */
138+ this . trackedIsPlaying = new TrackedState ( this . onAppPlayingStateChanged , this ) ;
139+
137140 // Dimensions
138141 this . screenWidth = 0 ;
139142 this . screenHeight = 0 ;
@@ -330,6 +333,14 @@ export class Application {
330333 this . sound . onPageRenderableStateChanged ( renderable ) ;
331334 }
332335
336+ onAppPlayingStateChanged ( playing ) {
337+ try {
338+ this . adProvider . setPlayStatus ( playing ) ;
339+ } catch ( ex ) {
340+ console . warn ( "Play status changed" ) ;
341+ }
342+ }
343+
333344 /**
334345 * Internal before-unload handler
335346 */
@@ -386,6 +397,7 @@ export class Application {
386397 }
387398
388399 const currentState = this . stateMgr . getCurrentState ( ) ;
400+ this . trackedIsPlaying . set ( currentState && currentState . getIsIngame ( ) ) ;
389401 if ( currentState ) {
390402 currentState . onRender ( dt ) ;
391403 }
Original file line number Diff line number Diff line change @@ -229,6 +229,14 @@ export class GameState {
229229 return MUSIC . menu ;
230230 }
231231
232+ /**
233+ * Should return true if the player is currently ingame
234+ * @returns {boolean }
235+ */
236+ getIsIngame ( ) {
237+ return false ;
238+ }
239+
232240 /**
233241 * Should return whether to clear the whole body content before entering the state.
234242 * @returns {boolean }
Original file line number Diff line number Diff line change @@ -28,6 +28,10 @@ export class HUDUnlockNotification extends BaseHUDPart {
2828 this . root . app . gameAnalytics . noteMinor ( "game.started" ) ;
2929 }
3030
31+ shouldPauseGame ( ) {
32+ return ! G_IS_STANDALONE && this . visible ;
33+ }
34+
3135 createElements ( parent ) {
3236 this . inputReciever = new InputReceiver ( "unlock-notification" ) ;
3337
Original file line number Diff line number Diff line change @@ -44,4 +44,6 @@ export class AdProviderInterface {
4444 showVideoAd ( ) {
4545 return Promise . resolve ( ) ;
4646 }
47+
48+ setPlayStatus ( playing ) { }
4749}
Original file line number Diff line number Diff line change @@ -88,4 +88,12 @@ export class CrazygamesAdProvider extends AdProviderInterface {
8888 this . app . sound . setSoundVolume ( this . app . settings . getSetting ( "soundVolume" ) ) ;
8989 } ) ;
9090 }
91+ setPlayStatus ( playing ) {
92+ console . log ( "crazygames::playing:" , playing ) ;
93+ if ( playing ) {
94+ this . sdkInstance . gameplayStart ( ) ;
95+ } else {
96+ this . sdkInstance . gameplayStop ( ) ;
97+ }
98+ }
9199}
Original file line number Diff line number Diff line change @@ -203,6 +203,14 @@ export class InGameState extends GameState {
203203 // do nothing
204204 }
205205
206+ getIsIngame ( ) {
207+ return (
208+ this . stage === GAME_LOADING_STATES . s10_gameRunning &&
209+ this . core &&
210+ ! this . core . root . hud . shouldPauseGame ( )
211+ ) ;
212+ }
213+
206214 /**
207215 * Called when the game somehow failed to initialize. Resets everything to basic state and
208216 * then goes to the main menu, showing the error
Original file line number Diff line number Diff line change @@ -68,19 +68,27 @@ export class PreloadState extends GameState {
6868 if ( G_IS_STANDALONE && ! G_IS_STEAM_DEMO ) {
6969 return ;
7070 }
71- if ( ! queryParamOptions . campaign ) {
72- return ;
71+ if ( queryParamOptions . campaign ) {
72+ fetch (
73+ "https://analytics.shapez.io/campaign/" +
74+ queryParamOptions . campaign +
75+ "?lpurl=nocontent&fbclid=" +
76+ queryParamOptions . fbclid +
77+ "&gclid=" +
78+ queryParamOptions . gclid
79+ ) . catch ( err => {
80+ console . warn ( "Failed to send beacon:" , err ) ;
81+ } ) ;
82+ }
83+ if ( queryParamOptions . embedProvider ) {
84+ fetch (
85+ "https://analytics.shapez.io/campaign/embed_" +
86+ queryParamOptions . embedProvider +
87+ "?lpurl=nocontent"
88+ ) . catch ( err => {
89+ console . warn ( "Failed to send beacon:" , err ) ;
90+ } ) ;
7391 }
74- fetch (
75- "https://analytics.shapez.io/campaign/" +
76- queryParamOptions . campaign +
77- "?lpurl=nocontent&fbclid=" +
78- queryParamOptions . fbclid +
79- "&gclid=" +
80- queryParamOptions . gclid
81- ) . catch ( err => {
82- console . warn ( "Failed to send beacon:" , err ) ;
83- } ) ;
8492 }
8593
8694 onLeave ( ) {
You can’t perform that action at this time.
0 commit comments