diff --git a/src/client/Main.ts b/src/client/Main.ts index 55406ed30..1241fe060 100644 --- a/src/client/Main.ts +++ b/src/client/Main.ts @@ -180,12 +180,17 @@ declare global { ramp: { que: Array<() => void>; passiveMode: boolean; - spaAddAds: (ads: Array<{ type: string; selectorId: string }>) => void; - destroyUnits: (adType: string) => void; + spaAddAds: (ads: Array<{ type: string; selectorId?: string }>) => void; + destroyUnits: (adType: string | string[]) => Promise; settings?: { slots?: any; }; spaNewPage: (url?: string) => void; + spaAds: (config?: { + ads?: Array<{ type: string; selectorId?: string }>; + countPageview?: boolean; + path?: string; + }) => void; // Video ad methods onPlayerReady: (() => void) | null; addUnits: (units: Array<{ type: string }>) => Promise; diff --git a/src/client/graphics/layers/InGamePromo.ts b/src/client/graphics/layers/InGamePromo.ts index a160e5924..097bf5bd6 100644 --- a/src/client/graphics/layers/InGamePromo.ts +++ b/src/client/graphics/layers/InGamePromo.ts @@ -5,19 +5,71 @@ import { Layer } from "./Layer"; const AD_TYPE = "standard_iab_left1"; const AD_CONTAINER_ID = "in-game-bottom-left-ad"; +const BOTTOM_RAIL_TYPE = "bottom_rail"; @customElement("in-game-promo") export class InGamePromo extends LitElement implements Layer { public game: GameView; private shouldShow: boolean = false; + private bottomRailActive: boolean = false; + private cornerAdShown: boolean = false; createRenderRoot() { return this; } init() { - this.showAd(); + this.showBottomRail(); + } + + tick() { + if (!this.game.inSpawnPhase()) { + if (this.bottomRailActive) { + this.destroyBottomRail(); + } + if (!this.cornerAdShown) { + this.cornerAdShown = true; + this.showAd(); + } + } + } + + private showBottomRail(): void { + if (!window.adsEnabled) return; + if (!this.game.inSpawnPhase()) return; + if (!window.ramp) { + console.warn("Playwire RAMP not available for bottom_rail ad"); + return; + } + + this.bottomRailActive = true; + try { + window.ramp.que.push(() => { + try { + window.ramp.spaAddAds([{ type: BOTTOM_RAIL_TYPE }]); + console.log("Bottom rail ad loaded during spawn phase"); + } catch (e) { + console.error("Failed to add bottom_rail ad:", e); + } + }); + } catch (error) { + console.error("Failed to load bottom_rail ad:", error); + } + } + + private destroyBottomRail(): void { + if (!this.bottomRailActive) return; + this.bottomRailActive = false; + + if (!window.ramp) return; + + try { + window.ramp.spaAds({ ads: [], countPageview: false }); + console.log("Bottom rail ad destroyed via spaAds after spawn phase"); + } catch (e) { + console.error("Error destroying bottom_rail ad:", e); + } } private showAd(): void { @@ -59,6 +111,7 @@ export class InGamePromo extends LitElement implements Layer { } public hideAd(): void { + this.destroyBottomRail(); if (!window.ramp) { console.warn("Playwire RAMP not available for in-game ad"); return;