This repository has been archived by the owner on Jan 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/gameFeature' into develop
- Loading branch information
Showing
4 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<script lang="ts"> | ||
import { GameFacade, type GameKey } from "$lib/components/Game/GameFacade"; | ||
import GameLoader from "./GameLoader.svelte"; | ||
const gameUrls: Record<GameKey, string> = { | ||
"Flappy Package": "https://niravanaa.github.io/FlappyPackage/", | ||
"Package Clicker": "https://niravanaa.github.io/PackageClicker/", | ||
"Package Climber": "https://niravanaa.github.io/PackageClimber/", | ||
}; | ||
const gameFacade = new GameFacade(gameUrls); | ||
let selectedGame: GameKey | null = null; | ||
// Update gameUrl reactively based on selectedGame | ||
$: gameUrl = selectedGame ? gameFacade.getGameUrl(selectedGame) : ""; | ||
// Handle radio selection to update selectedGame and gameUrl instantly | ||
const onGameSelect = (gameKey: GameKey) => { | ||
selectedGame = gameKey; | ||
}; | ||
</script> | ||
|
||
<div class="card flex flex-col items-center justify-center space-y-4 p-4"> | ||
{#if gameUrl} | ||
<GameLoader bind:url={gameUrl} /> | ||
{/if} | ||
|
||
<div class="flex space-x-4"> | ||
{#each gameFacade.getAvailableGames() as gameKey} | ||
<label class="flex items-center space-x-2"> | ||
<input | ||
class="radio" | ||
type="radio" | ||
bind:group={selectedGame} | ||
value={gameKey} | ||
on:change={() => onGameSelect(gameKey)} /> | ||
<p>{gameKey}</p> | ||
</label> | ||
{/each} | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export type GameKey = "Flappy Package" | "Package Clicker" | "Package Climber"; | ||
|
||
export class GameFacade { | ||
private gameUrls: Record<GameKey, string>; | ||
|
||
constructor(gameUrls: Record<GameKey, string>) { | ||
this.gameUrls = gameUrls; | ||
} | ||
|
||
getGameUrl(gameKey: GameKey): string { | ||
return this.gameUrls[gameKey] || ""; | ||
} | ||
|
||
getAvailableGames(): GameKey[] { | ||
return Object.keys(this.gameUrls) as GameKey[]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<script lang="ts"> | ||
import { onMount } from "svelte"; | ||
export let url: string; | ||
let iframe: HTMLIFrameElement | null = null; | ||
const keepIframeActive = () => { | ||
if (iframe) { | ||
iframe.contentWindow?.focus(); | ||
} | ||
}; | ||
onMount(() => { | ||
document.addEventListener("click", keepIframeActive); | ||
return () => { | ||
document.removeEventListener("click", keepIframeActive); | ||
}; | ||
}); | ||
</script> | ||
|
||
<iframe | ||
title="Game by SvelteShip Solutions" | ||
bind:this={iframe} | ||
src={url} | ||
class="h-[640px] w-[640px] resize overflow-auto" | ||
scrolling="no" | ||
allow="autoplay"> | ||
</iframe> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters