From add005d96397f053a349b52fe2f13561c8f801bd Mon Sep 17 00:00:00 2001 From: Sheldan <5037282+Sheldan@users.noreply.github.com> Date: Mon, 8 Sep 2025 22:52:10 +0200 Subject: [PATCH] survivors: only displaying the controls if we are on mobile adding method to detect if mobile --- absurd-survivors/src/ui.ts | 24 +++++++++++++++++------- absurd-survivors/src/utils.ts | 4 ++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/absurd-survivors/src/ui.ts b/absurd-survivors/src/ui.ts index 8aa7cbf..a168932 100644 --- a/absurd-survivors/src/ui.ts +++ b/absurd-survivors/src/ui.ts @@ -1,34 +1,44 @@ import type {Drawable, DrawContainer, MouseInteracting, MouseInterActingContainer} from "./interfaces.ts"; import {World} from "./World.ts"; import {Vector} from "./base.ts"; -import {drawDot, fillDot, rectPointIntersection} from "./utils.ts"; +import {drawDot, fillDot, isMobile, rectPointIntersection} from "./utils.ts"; export class HUD implements DrawContainer { private health: PlayerInfo; - private controls: Controls; + private controls: Controls | undefined; private world: World; constructor(world: World, keys: any) { this.world = world; this.health = new PlayerInfo(world); - this.controls = new Controls(world, keys); + if (isMobile()) { + this.controls = new Controls(world, keys); + } } draw(ctx: CanvasRenderingContext2D) { this.health.draw(ctx) - this.controls.draw(ctx) + if(this.controls) { + this.controls.draw(ctx) + } } mouseDown(pos: Vector) { - this.controls.mouseDown(pos) + if(this.controls) { + this.controls.mouseDown(pos) + } } mouseUp(pos: Vector) { - this.controls.mouseUp(pos) + if(this.controls) { + this.controls.mouseUp(pos) + } } mouseMove(pos: Vector) { - this.controls.mouseMove(pos) + if(this.controls) { + this.controls.mouseMove(pos) + } } } diff --git a/absurd-survivors/src/utils.ts b/absurd-survivors/src/utils.ts index 8981277..0add926 100644 --- a/absurd-survivors/src/utils.ts +++ b/absurd-survivors/src/utils.ts @@ -7,6 +7,10 @@ export function fillDot(position: Vector, size: number, color: string, ctx: Canv ctx.fill(); } +export function isMobile() { + return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); +} + export function drawDot(position: Vector, size: number, color: string, ctx: CanvasRenderingContext2D) { ctx.beginPath(); ctx.strokeStyle = color;