mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-25 08:42:44 +00:00
f7598369ed
## Description: This PR consolidates ad hoc platform/environment/viewport detection into a single shared utility. It is scoped to this refactor only, and serves as groundwork for the mobile-focused feature work planned for the v31 milestone. ### What changed - Introduced a shared `Platform` utility centralising: - OS detection (with `userAgentData` + UA fallback) - Electron environment detection - Viewport breakpoint helpers (`isMobileWidth`, `isTabletWidth`, `isDesktopWidth`) - Replaced duplicated inline checks across client files with the shared API. - Normalised Mac detection to derive from the consolidated OS logic rather than a separate regex. ### Why - Multiple client files each independently ran `navigator.userAgent` regexes or copy-pasted `isElectron` logic — this unifies all of that. - Puts a stable, tested abstraction in place before v31 mobile work lands, so mobile feature branches have a consistent surface to build against. ## Please complete the following: - [x] I have added screenshots for all UI updates (N/A: refactor only, no visible UI changes) - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file (N/A: no new user-facing strings) - [x] I have added relevant tests to the test directory (N/A: refactor only) - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: skigim
68 lines
1.7 KiB
TypeScript
68 lines
1.7 KiB
TypeScript
import { LitElement, html } from "lit";
|
|
import { customElement, state } from "lit/decorators.js";
|
|
import { crazyGamesSDK } from "src/client/CrazyGamesSDK";
|
|
import { Platform } from "src/client/Platform";
|
|
import { getGamesPlayed } from "src/client/Utils";
|
|
import { GameType } from "src/core/game/Game";
|
|
import { GameView } from "../../../core/game/GameView";
|
|
import "../../components/VideoPromo";
|
|
import { Layer } from "./Layer";
|
|
|
|
@customElement("spawn-video-ad")
|
|
export class SpawnVideoAd extends LitElement implements Layer {
|
|
public game: GameView;
|
|
|
|
@state() private shouldShow = false;
|
|
@state() private adComplete = false;
|
|
|
|
createRenderRoot() {
|
|
return this;
|
|
}
|
|
|
|
init() {
|
|
if (
|
|
!window.adsEnabled ||
|
|
Platform.isMobileWidth ||
|
|
crazyGamesSDK.isOnCrazyGames() ||
|
|
this.game.config().gameConfig().gameType === GameType.Singleplayer ||
|
|
getGamesPlayed() < 3 // Don't show to new players
|
|
) {
|
|
return;
|
|
}
|
|
this.shouldShow = true;
|
|
}
|
|
|
|
tick() {
|
|
if (this.adComplete) return;
|
|
// Hide when spawn phase ends
|
|
if (this.shouldShow && !this.game.inSpawnPhase()) {
|
|
this.shouldShow = false;
|
|
this.requestUpdate();
|
|
}
|
|
}
|
|
|
|
private handleComplete = () => {
|
|
this.adComplete = true;
|
|
this.shouldShow = false;
|
|
};
|
|
|
|
shouldTransform(): boolean {
|
|
return false;
|
|
}
|
|
|
|
render() {
|
|
if (!this.shouldShow || this.adComplete) {
|
|
return html``;
|
|
}
|
|
|
|
return html`
|
|
<div class="fixed bottom-0 left-0 z-[9999] pointer-events-auto">
|
|
<video-ad
|
|
style="width: 400px; max-width: 400px; height: 225px; aspect-ratio: auto;"
|
|
.onComplete="${this.handleComplete}"
|
|
></video-ad>
|
|
</div>
|
|
`;
|
|
}
|
|
}
|