updated friend field to be optional (frontend bug fix, not that I have

no friends)
This commit is contained in:
2026-02-17 21:37:15 +08:00
parent 8578ba3376
commit f1d03fc96a
4 changed files with 31 additions and 24 deletions

View File

@@ -23,8 +23,8 @@
let isInteractive = $derived($sceneInteractive);
function getFriendById(userId: string) {
const friend = $appData?.friends?.find((f) => f.friend.id === userId);
return friend!.friend;
const friend = $appData?.friends?.find((f) => f.friend?.id === userId);
return friend?.friend;
}
function getFriendDoll(userId: string) {
@@ -32,8 +32,8 @@
return $friendsActiveDolls[userId];
}
const friend = $appData?.friends?.find((f) => f.friend.id === userId);
return friend?.friend.activeDoll;
const friend = $appData?.friends?.find((f) => f.friend?.id === userId);
return friend?.friend?.activeDoll;
}
function getFriendStatus(userId: string) {
@@ -109,7 +109,7 @@
{#each Object.entries($friendsCursorPositions) as [userId, position]}
{@const status = getFriendStatus(userId)}
<div class="badge py-3 text-xs text-left flex flex-row gap-2">
<span class="font-bold">{getFriendById(userId).name}</span>
<span class="font-bold">{getFriendById(userId)?.name}</span>
<div class="flex flex-row font-mono gap-2">
<span>
({position.mapped.x.toFixed(3)}, {position.mapped.y.toFixed(
@@ -143,12 +143,13 @@
{#if Object.keys($friendsCursorPositions).length > 0}
{#each Object.entries($friendsCursorPositions) as [userId, position]}
{@const doll = getFriendDoll(userId)}
{#if doll}
{@const friend = getFriendById(userId)}
{#if doll && friend}
<DesktopPet
id={userId}
targetX={position.mapped.x * innerWidth}
targetY={position.mapped.y * innerHeight}
user={getFriendById(userId)}
user={friend}
userStatus={getFriendStatus(userId)}
{doll}
{isInteractive}