diff --git a/index.html b/index.html index 7c22c1357..42e38e91a 100644 --- a/index.html +++ b/index.html @@ -269,6 +269,7 @@
{ + const slots = window.ramp?.settings?.slots; + console.log("InGameFooterAd: checking slots=", slots); + const filled = + slots && + Object.values(slots).some( + (slot: any) => + slot?.type === FOOTER_AD_TYPE && slot?.element?.offsetHeight > 0, + ); + if (filled) { + const hud = document.getElementById("bottom-hud"); + if (hud) hud.style.paddingBottom = `${AD_HEIGHT_PX}px`; + console.log("In-game footer ad slot filled"); + return; + } + if (Date.now() - start < 5000) { + setTimeout(check, 200); + } else { + console.log("In-game footer ad did not fill after 5s, slots=", slots); + } + }; + setTimeout(check, 200); + } + + private hideFooterAd(): void { + const hud = document.getElementById("bottom-hud"); + if (hud) hud.style.paddingBottom = ""; + try { + window.ramp.destroyUnits(FOOTER_AD_TYPE); + console.log("successfully destroyed in-game footer ad"); + } catch (e) { + console.error("error destroying in-game footer ad", e); + } + } + + public tick() { + if (this.isHidden) { + return; + } + + const gameTicks = + this.game.ticks() - this.game.config().numSpawnPhaseTurns(); + if (gameTicks > AD_SHOW_TICKS) { + console.log("destroying in-game footer ad and refreshing PageOS"); + this.hideFooterAd(); + this.isHidden = true; + + if (window.PageOS?.session?.newPageView) { + window.PageOS.session.newPageView(); + } + return; + } + } + + shouldTransform(): boolean { + return false; + } + + render() { + return nothing; + } +}