Further crazygames sdk integration
This commit is contained in:
parent
a39195c972
commit
8454a782b4
|
@ -134,6 +134,9 @@ export class Application {
|
|||
/** @type {TypedTrackedState<boolean>} */
|
||||
this.trackedIsRenderable = new TrackedState(this.onAppRenderableStateChanged, this);
|
||||
|
||||
/** @type {TypedTrackedState<boolean>} */
|
||||
this.trackedIsPlaying = new TrackedState(this.onAppPlayingStateChanged, this);
|
||||
|
||||
// Dimensions
|
||||
this.screenWidth = 0;
|
||||
this.screenHeight = 0;
|
||||
|
@ -330,6 +333,14 @@ export class Application {
|
|||
this.sound.onPageRenderableStateChanged(renderable);
|
||||
}
|
||||
|
||||
onAppPlayingStateChanged(playing) {
|
||||
try {
|
||||
this.adProvider.setPlayStatus(playing);
|
||||
} catch (ex) {
|
||||
console.warn("Play status changed");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal before-unload handler
|
||||
*/
|
||||
|
@ -386,6 +397,7 @@ export class Application {
|
|||
}
|
||||
|
||||
const currentState = this.stateMgr.getCurrentState();
|
||||
this.trackedIsPlaying.set(currentState && currentState.getIsIngame());
|
||||
if (currentState) {
|
||||
currentState.onRender(dt);
|
||||
}
|
||||
|
|
|
@ -229,6 +229,14 @@ export class GameState {
|
|||
return MUSIC.menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should return true if the player is currently ingame
|
||||
* @returns {boolean}
|
||||
*/
|
||||
getIsIngame() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should return whether to clear the whole body content before entering the state.
|
||||
* @returns {boolean}
|
||||
|
|
|
@ -28,6 +28,10 @@ export class HUDUnlockNotification extends BaseHUDPart {
|
|||
this.root.app.gameAnalytics.noteMinor("game.started");
|
||||
}
|
||||
|
||||
shouldPauseGame() {
|
||||
return !G_IS_STANDALONE && this.visible;
|
||||
}
|
||||
|
||||
createElements(parent) {
|
||||
this.inputReciever = new InputReceiver("unlock-notification");
|
||||
|
||||
|
|
|
@ -44,4 +44,6 @@ export class AdProviderInterface {
|
|||
showVideoAd() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
setPlayStatus(playing) {}
|
||||
}
|
||||
|
|
|
@ -88,4 +88,12 @@ export class CrazygamesAdProvider extends AdProviderInterface {
|
|||
this.app.sound.setSoundVolume(this.app.settings.getSetting("soundVolume"));
|
||||
});
|
||||
}
|
||||
setPlayStatus(playing) {
|
||||
console.log("crazygames::playing:", playing);
|
||||
if (playing) {
|
||||
this.sdkInstance.gameplayStart();
|
||||
} else {
|
||||
this.sdkInstance.gameplayStop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,6 +203,14 @@ export class InGameState extends GameState {
|
|||
// do nothing
|
||||
}
|
||||
|
||||
getIsIngame() {
|
||||
return (
|
||||
this.stage === GAME_LOADING_STATES.s10_gameRunning &&
|
||||
this.core &&
|
||||
!this.core.root.hud.shouldPauseGame()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the game somehow failed to initialize. Resets everything to basic state and
|
||||
* then goes to the main menu, showing the error
|
||||
|
|
|
@ -68,19 +68,27 @@ export class PreloadState extends GameState {
|
|||
if (G_IS_STANDALONE && !G_IS_STEAM_DEMO) {
|
||||
return;
|
||||
}
|
||||
if (!queryParamOptions.campaign) {
|
||||
return;
|
||||
if (queryParamOptions.campaign) {
|
||||
fetch(
|
||||
"https://analytics.shapez.io/campaign/" +
|
||||
queryParamOptions.campaign +
|
||||
"?lpurl=nocontent&fbclid=" +
|
||||
queryParamOptions.fbclid +
|
||||
"&gclid=" +
|
||||
queryParamOptions.gclid
|
||||
).catch(err => {
|
||||
console.warn("Failed to send beacon:", err);
|
||||
});
|
||||
}
|
||||
if (queryParamOptions.embedProvider) {
|
||||
fetch(
|
||||
"https://analytics.shapez.io/campaign/embed_" +
|
||||
queryParamOptions.embedProvider +
|
||||
"?lpurl=nocontent"
|
||||
).catch(err => {
|
||||
console.warn("Failed to send beacon:", err);
|
||||
});
|
||||
}
|
||||
fetch(
|
||||
"https://analytics.shapez.io/campaign/" +
|
||||
queryParamOptions.campaign +
|
||||
"?lpurl=nocontent&fbclid=" +
|
||||
queryParamOptions.fbclid +
|
||||
"&gclid=" +
|
||||
queryParamOptions.gclid
|
||||
).catch(err => {
|
||||
console.warn("Failed to send beacon:", err);
|
||||
});
|
||||
}
|
||||
|
||||
onLeave() {
|
||||
|
|
Loading…
Reference in New Issue