add bgs and rooms stuff

This commit is contained in:
not-nullptr 2024-03-16 21:26:27 +00:00
parent 188e38c6ec
commit 7ad700c83d
11 changed files with 100 additions and 64 deletions

View file

@ -1,36 +1,54 @@
<script lang="ts"> <script lang="ts">
import type { IRoom } from "$types/rooms"; import type { IRoom } from "$types/rooms";
export let icon: string | undefined;
export let room: IRoom; export let room: IRoom;
</script> </script>
<div class="relative flex h-fit items-center gap-6 rounded-[2.25rem] bg-[#110d10] p-6"> <div
{#if icon} class="relative flex h-full w-full overflow-hidden rounded-[2.25rem] border-2 border-solid border-[#ffffff34] bg-[#110d10] p-6 shadow-lg shadow-[#00000028]"
<img src={icon} alt="Icon for '{room.preferredGameName}'" class="h-[100px] rounded-2xl" /> >
{/if} <div
<div> class="absolute left-0 top-0 z-20 h-full w-full opacity-25 blur-sm"
<h2 class="mb-2 text-[20px] leading-[1.41] md:text-[28px] md:leading-[1.1]"> style="background-image: url({room.game
{room.name} ?.bannerUrl}); background-size: cover; background-position: center center;
<span class="ml-1 text-base font-normal text-gray-500" --mask-image: linear-gradient(
>({room.preferredGameName || "No preferred game"})</span to right,
> rgba(0, 0, 0, 0.1) 50%,
</h2> rgba(0, 0, 0, 1) 100%
<p>{room.description}</p> ); mask-image: var(--mask-image); -webkit-mask-image: var(--mask-image);
<div class="mt-2 text-sm text-gray-600"> "
{room.players.length} / {room.maxPlayers} | {#if room.players.length > 4} />
{#each room.players.slice(0, 4) as player} <div class="relative z-30 flex items-stretch gap-6">
{player.nickname}{#if player !== room.players[3]},{" "} {#if room.game?.iconUrl}
{/if} <img
{/each} src={room.game.iconUrl}
and {room.players.length - 4} alt="Icon for '{room.preferredGameName}'"
{room.players.length - 4 === 1 ? "other" : "others"} class="w-[100px] rounded-2xl object-cover"
{:else} />
{#each room.players as player} {/if}
{player.nickname}{#if player !== room.players[room.players.length - 1]},{" "} <div class="flex flex-col">
{/if} <h2 class="mb-2 text-[20px] leading-[1.41] md:text-[28px] md:leading-[1.1]">
{/each} {room.name}
{/if} | {room.hasPassword ? "Private" : "Public"} | {room.address}:{room.port} <span class="ml-1 text-base font-normal text-gray-300"
>({room.game?.name || "No preferred game"})</span
>
</h2>
<p class="flex-grow">{room.description}</p>
<div class="mt-2 text-sm text-gray-300">
{room.players.length} / {room.maxPlayers} | {#if room.players.length > 4}
{#each room.players.slice(0, 4) as player}
{player.nickname}{#if player !== room.players[3]},{" "}
{/if}
{/each}
and {room.players.length - 4}
{room.players.length - 4 === 1 ? "other" : "others"}
{:else}
{#each room.players as player}
{player.nickname}{#if player !== room.players[room.players.length - 1]},{" "}
{/if}
{/each}
{/if} | {room.hasPassword ? "Private" : "Public"} | {room.address}:{room.port}
</div>
</div> </div>
</div> </div>
</div> </div>

View file

@ -4,6 +4,7 @@ import { building } from "$app/environment";
import type { Handle } from "@sveltejs/kit"; import type { Handle } from "@sveltejs/kit";
import { WebSocketServer } from "ws"; import { WebSocketServer } from "ws";
import { userRepo } from "$lib/server/repo"; import { userRepo } from "$lib/server/repo";
import { globalData } from "$lib/server/other";
let server: WebSocketServer; let server: WebSocketServer;
@ -22,6 +23,20 @@ function initServer() {
} catch {} } catch {}
} }
async function fetchGames() {
console.log("Fetching game data");
const res = await fetch("https://raw.githubusercontent.com/blawar/titledb/master/US.en.json");
let gamesText = await res.text();
gamesText = gamesText.replaceAll(/\\u[0-9a-fA-F]{4}/gm, "");
globalData.games = Object.values(JSON.parse(gamesText));
console.log("Fetched game data");
}
async function setupGames() {
await fetchGames();
setInterval(fetchGames, 1000 * 60 * 60 * 12);
}
const runAllTheInitFunctions = async () => { const runAllTheInitFunctions = async () => {
if (!db.isInitialized) await db.initialize(); if (!db.isInitialized) await db.initialize();
// sigh. // sigh.
@ -34,6 +49,9 @@ const runAllTheInitFunctions = async () => {
} catch { } catch {
console.error("Could not initialize WebSocket server"); console.error("Could not initialize WebSocket server");
} }
if (globalData.games.length === 0) {
await setupGames();
}
}; };
if (!building) { if (!building) {

View file

@ -1,4 +1,5 @@
import type { IRoom, IRoomConfig, RoomPlayer } from "$types/rooms"; import type { IRoom, IRoomConfig, RoomPlayer } from "$types/rooms";
import { globalData, type SwitchGame } from "../other";
import type { SuyuUser } from "../schema"; import type { SuyuUser } from "../schema";
import { v4 } from "uuid"; import { v4 } from "uuid";
@ -52,6 +53,9 @@ export class Room {
netVersion: 1, netVersion: 1,
owner: this.host.username, owner: this.host.username,
port: parseInt(parsed[1]), port: parseInt(parsed[1]),
game: globalData.games.find(
(g) => g.name.toUpperCase().trim() === config.gameName.toUpperCase().trim(),
),
}; };
} }

View file

@ -1,14 +1,14 @@
interface SwitchGame { export interface SwitchGame {
bannerUrl: string; bannerUrl: string;
category: string[]; category: string[];
description: string; description: string;
developer: null; // developer: null;
frontBoxArt: null; // frontBoxArt: null;
iconUrl: string; iconUrl: string;
id: string; id: string;
intro: null | string; intro: null | string;
isDemo: boolean; isDemo: boolean;
key: null; // key: null;
languages: string[]; languages: string[];
name: string; name: string;
nsuId: number; nsuId: number;
@ -16,12 +16,12 @@ interface SwitchGame {
publisher: string; publisher: string;
rating: number; rating: number;
ratingContent: string[]; ratingContent: string[];
region: null; // region: null;
releaseDate: number; releaseDate: number;
rightsId: string; rightsId: string;
screenshots: string[]; screenshots: string[];
size: number; size: number;
version: null; // version: null;
} }
export const globalData: { export const globalData: {
games: SwitchGame[]; games: SwitchGame[];

View file

@ -130,7 +130,7 @@
$: navItems = [ $: navItems = [
{ {
name: "Blog", name: "Blog",
href: "/blog", href: "/coming-soon",
}, },
{ {
name: "Docs", name: "Docs",
@ -264,7 +264,7 @@
<div <div
class="flex w-full flex-row items-center justify-center gap-2 text-sm font-medium text-[#A6A5A7] max-[625px]:hidden" class="flex w-full flex-row items-center justify-center gap-2 text-sm font-medium text-[#A6A5A7] max-[625px]:hidden"
> >
<a href="/blog" class="px-5 py-3 transition hover:text-white">Blog</a> <a href="/coming-soon" class="px-5 py-3 transition hover:text-white">Blog</a>
<a href="/coming-soon" class="px-5 py-3 transition hover:text-white">Docs</a> <a href="/coming-soon" class="px-5 py-3 transition hover:text-white">Docs</a>
<a href="/coming-soon" class="px-5 py-3 transition hover:text-white">FAQ</a> <a href="/coming-soon" class="px-5 py-3 transition hover:text-white">FAQ</a>
</div> </div>

View file

@ -1,6 +1,5 @@
import { building } from "$app/environment"; import { building } from "$app/environment";
import { DISCORD_USER_TOKEN, GITLAB_API_TOKEN } from "$env/static/private"; import { DISCORD_USER_TOKEN, GITLAB_API_TOKEN } from "$env/static/private";
import { globalData } from "$lib/server/other";
let memberCount = 0; let memberCount = 0;
let starCount = 0; let starCount = 0;
@ -41,19 +40,9 @@ async function fetchServerSideData() {
console.log("Stars count:", starCount); console.log("Stars count:", starCount);
} }
async function fetchSlowServerSideData() {
console.log("Fetching game data");
const res = await fetch("https://raw.githubusercontent.com/blawar/titledb/master/US.en.json");
let gamesText = await res.text();
gamesText = gamesText.replaceAll(/\\u[0-9a-fA-F]{4}/gm, "");
globalData.games = Object.values(JSON.parse(gamesText));
console.log("Fetched game data");
}
if (!building) { if (!building) {
await Promise.all([await fetchServerSideData(), await fetchSlowServerSideData()]); await fetchServerSideData();
setInterval(fetchServerSideData, 1000 * 60 * 10); setInterval(fetchServerSideData, 1000 * 60 * 10);
setInterval(fetchSlowServerSideData, 1000 * 60 * 60 * 12);
} }
export async function load({ cookies }) { export async function load({ cookies }) {

View file

@ -168,13 +168,13 @@
{#key data.url} {#key data.url}
<div <div
class={`navbar ${data.url} relative z-50 mb-4 flex w-max gap-1 overflow-hidden rounded-full bg-[#110d10] p-1`} class={`navbar ${data.url} relative z-50 mb-4 ml-auto mr-auto flex w-max gap-1 overflow-hidden rounded-full bg-[#110d10] p-1`}
bind:this={navBar} bind:this={navBar}
> >
<div <div
bind:this={indicator} bind:this={indicator}
style="transition: 360ms {transition}" style="transition: 360ms {transition}"
class="pointer-events-none absolute left-0 top-[4px] z-10 h-[calc(100%-8px)] translate-x-0 transform rounded-full bg-gradient-to-b from-slate-50 to-[#a9a9a9] mix-blend-difference motion-reduce:!transition-none" class="pointer-events-none absolute left-0 top-[4px] z-10 h-[calc(100%-8px)] translate-x-0 transform rounded-full bg-gradient-to-b from-[#fafafa] to-[#d1d1d1] mix-blend-difference motion-reduce:!transition-none"
></div> ></div>
{#each navItems as item, i} {#each navItems as item, i}
<a <a

View file

@ -1,14 +1,8 @@
import { building } from "$app/environment";
import { RoomManager } from "$lib/server/class/Room.js"; import { RoomManager } from "$lib/server/class/Room.js";
import { globalData } from "$lib/server/other/index.js";
export function load({ request }) { export function load({ request }) {
const rooms = RoomManager.getRooms().map((r) => r.toJSON()) || []; const rooms = RoomManager.getRooms().map((r) => r.toJSON()) || [];
const requiredGames = rooms
.map((r) => r.preferredGameName.toUpperCase().trim())
.map((r) => globalData.games.find((g) => g.name.toUpperCase().trim() === r));
return { return {
rooms: rooms, rooms: rooms,
games: requiredGames,
}; };
} }

View file

@ -51,11 +51,26 @@
</script> </script>
<div class="relative h-[calc(100vh-200px)]"> <div class="relative h-[calc(100vh-200px)]">
<div class="relative flex w-full flex-col gap-4 pb-6"> <div class="room-grid relative flex w-full gap-4 pb-6">
{#each data.rooms as room, i} {#each data.rooms as room, i}
<div class="room opacity-0" data-index={i}> <div class="room opacity-0" data-index={i}>
<Room icon={data.games[i]?.iconUrl} {room} /> <Room {room} />
</div> </div>
{/each} {/each}
</div> </div>
</div> </div>
<style>
.room-grid {
display: grid;
grid-template-columns: repeat(1, 1fr);
grid-auto-rows: auto;
align-items: stretch;
}
@media (min-width: 750px) {
.room-grid {
grid-template-columns: repeat(2, 1fr);
}
}
</style>

View file

@ -1,4 +1,4 @@
<script lang="ts"> <!-- <script lang="ts">
import { page } from "$app/stores"; import { page } from "$app/stores";
import { onDestroy, onMount } from "svelte"; import { onDestroy, onMount } from "svelte";
import type { PageData } from "./$types"; import type { PageData } from "./$types";
@ -57,10 +57,6 @@
<h1 class="mb-8 text-[40px] leading-[1.41] md:text-[60px] md:leading-[1.1]">Blog Posts</h1> <h1 class="mb-8 text-[40px] leading-[1.41] md:text-[60px] md:leading-[1.1]">Blog Posts</h1>
{#if data.userInfo.isModerator} {#if data.userInfo.isModerator}
<!-- <p class="mb-8 text-[24px] leading-[1.41] md:text-[36px] md:leading-[1.1]">
<a href="/blog/new">Create a new post</a>
</p> -->
<!-- wh, wha r -->
<div class="mb-4 ml-1 flex gap-4"> <div class="mb-4 ml-1 flex gap-4">
<a href="/blog/new" class="cta-button">Create a new post</a> <a href="/blog/new" class="cta-button">Create a new post</a>
<a href="/blog/edit" class="cta-button">Edit a post</a> <a href="/blog/edit" class="cta-button">Edit a post</a>
@ -104,4 +100,4 @@
font-family: "DM Sans", sans-serif; font-family: "DM Sans", sans-serif;
font-weight: 500; font-weight: 500;
} }
</style> </style> -->

View file

@ -1,3 +1,4 @@
import type { SwitchGame } from "$lib/server/other";
import type { SuyuUser } from "$lib/server/schema"; import type { SuyuUser } from "$lib/server/schema";
export interface IRoom { export interface IRoom {
@ -14,6 +15,7 @@ export interface IRoom {
port: number; port: number;
preferredGameId: number; preferredGameId: number;
preferredGameName: string; preferredGameName: string;
game?: SwitchGame;
} }
export interface IRoomConfig { export interface IRoomConfig {