Spaces:
Sleeping
Sleeping
pray
Browse files- src/components/Game.tsx +2 -1
- src/components/PlayerDetails.tsx +14 -13
src/components/Game.tsx
CHANGED
@@ -144,13 +144,14 @@ https://github.com/michalochman/react-pixi-fiber/issues/145#issuecomment-5315492
|
|
144 |
<p className="text-lg text-center">{GameStateLabel(game as GameObj, meDescription).desc}</p>
|
145 |
</div>
|
146 |
{playerId && !isEndGame(game) && canVote(game, meDescription) && <GameVote engineId={engineId} game={game} playerId={playerId} />}
|
147 |
-
{!isEndGame(game) && !canVote(game, meDescription) &&
|
148 |
worldId={worldId}
|
149 |
engineId={engineId}
|
150 |
game={game}
|
151 |
playerId={selectedElement?.id}
|
152 |
setSelectedElement={setSelectedElement}
|
153 |
scrollViewRef={scrollViewRef}
|
|
|
154 |
/>}
|
155 |
{playerId && isEndGame(game) && <EndGame game={game} playerId={playerId} />}
|
156 |
</div>
|
|
|
144 |
<p className="text-lg text-center">{GameStateLabel(game as GameObj, meDescription).desc}</p>
|
145 |
</div>
|
146 |
{playerId && !isEndGame(game) && canVote(game, meDescription) && <GameVote engineId={engineId} game={game} playerId={playerId} />}
|
147 |
+
{!isEndGame(game) && !canVote(game, meDescription) && playerId &&<PlayerDetails
|
148 |
worldId={worldId}
|
149 |
engineId={engineId}
|
150 |
game={game}
|
151 |
playerId={selectedElement?.id}
|
152 |
setSelectedElement={setSelectedElement}
|
153 |
scrollViewRef={scrollViewRef}
|
154 |
+
currentPlayerId={playerId}
|
155 |
/>}
|
156 |
{playerId && isEndGame(game) && <EndGame game={game} playerId={playerId} />}
|
157 |
</div>
|
src/components/PlayerDetails.tsx
CHANGED
@@ -14,9 +14,10 @@ export default function PlayerDetails({
|
|
14 |
worldId,
|
15 |
engineId,
|
16 |
game,
|
17 |
-
playerId,
|
18 |
setSelectedElement,
|
19 |
scrollViewRef,
|
|
|
20 |
}: {
|
21 |
worldId: Id<'worlds'>;
|
22 |
engineId: Id<'engines'>;
|
@@ -24,12 +25,12 @@ export default function PlayerDetails({
|
|
24 |
playerId?: GameId<'players'>;
|
25 |
setSelectedElement: SelectElement;
|
26 |
scrollViewRef: React.RefObject<HTMLDivElement>;
|
|
|
27 |
}) {
|
28 |
const oauth = JSON.parse(localStorage.getItem('oauth'));
|
29 |
const oauthToken = oauth ? oauth.userInfo.fullname : undefined;
|
30 |
const humanTokenIdentifier = useQuery(api.world.userStatus, { worldId, oauthToken });
|
31 |
|
32 |
-
const players = [...game.world.players.values()];
|
33 |
const humanPlayer = [...game.world.players.values()].find(
|
34 |
(p) => game.playerDescriptions.get(p.id)?.name === humanTokenIdentifier,
|
35 |
);
|
@@ -39,25 +40,25 @@ export default function PlayerDetails({
|
|
39 |
const otherPlayerIds = [...humanConversation.participants.keys()].filter(
|
40 |
(p) => !!p && p !== humanPlayer.id,
|
41 |
);
|
42 |
-
|
43 |
}
|
44 |
|
45 |
-
const player =
|
46 |
const playerConversation = player && game.world.playerConversation(player);
|
47 |
|
48 |
const previousConversation = useQuery(
|
49 |
api.world.previousConversation,
|
50 |
-
|
51 |
);
|
52 |
|
53 |
-
const playerDescription =
|
54 |
|
55 |
const startConversation = useSendInput(engineId, 'startConversation');
|
56 |
const acceptInvite = useSendInput(engineId, 'acceptInvite');
|
57 |
const rejectInvite = useSendInput(engineId, 'rejectInvite');
|
58 |
const leaveConversation = useSendInput(engineId, 'leaveConversation');
|
59 |
|
60 |
-
if (!
|
61 |
return (
|
62 |
<div className="h-full text-xl flex text-center items-center p-4">
|
63 |
Click on an agent on the map to see chat history.
|
@@ -67,7 +68,7 @@ export default function PlayerDetails({
|
|
67 |
if (!player) {
|
68 |
return null;
|
69 |
}
|
70 |
-
const isMe = humanPlayer &&
|
71 |
const canInvite = !isMe && !playerConversation && humanPlayer && !humanConversation;
|
72 |
const sameConversation =
|
73 |
!isMe &&
|
@@ -78,10 +79,10 @@ export default function PlayerDetails({
|
|
78 |
|
79 |
const humanStatus =
|
80 |
humanPlayer && humanConversation && humanConversation.participants.get(humanPlayer.id)?.status;
|
81 |
-
const playerStatus = playerConversation && playerConversation.participants.get(
|
82 |
const haveInvite = sameConversation && humanStatus?.kind === 'invited';
|
83 |
const waitingForAccept =
|
84 |
-
sameConversation && playerConversation.participants.get(
|
85 |
const waitingForNearby =
|
86 |
sameConversation && playerStatus?.kind === 'walkingOver' && humanStatus?.kind === 'walkingOver';
|
87 |
|
@@ -91,14 +92,14 @@ export default function PlayerDetails({
|
|
91 |
humanStatus?.kind === 'participating';
|
92 |
|
93 |
const onStartConversation = async () => {
|
94 |
-
if (!humanPlayer || !
|
95 |
return;
|
96 |
}
|
97 |
console.log(`Starting conversation`);
|
98 |
-
await toastOnError(startConversation({ playerId: humanPlayer.id, invitee:
|
99 |
};
|
100 |
const onAcceptInvite = async () => {
|
101 |
-
if (!humanPlayer || !humanConversation || !
|
102 |
return;
|
103 |
}
|
104 |
await toastOnError(
|
|
|
14 |
worldId,
|
15 |
engineId,
|
16 |
game,
|
17 |
+
playerId: SelectedPlayerId,
|
18 |
setSelectedElement,
|
19 |
scrollViewRef,
|
20 |
+
currentPlayerId,
|
21 |
}: {
|
22 |
worldId: Id<'worlds'>;
|
23 |
engineId: Id<'engines'>;
|
|
|
25 |
playerId?: GameId<'players'>;
|
26 |
setSelectedElement: SelectElement;
|
27 |
scrollViewRef: React.RefObject<HTMLDivElement>;
|
28 |
+
currentPlayerId:GameId<'players'>;
|
29 |
}) {
|
30 |
const oauth = JSON.parse(localStorage.getItem('oauth'));
|
31 |
const oauthToken = oauth ? oauth.userInfo.fullname : undefined;
|
32 |
const humanTokenIdentifier = useQuery(api.world.userStatus, { worldId, oauthToken });
|
33 |
|
|
|
34 |
const humanPlayer = [...game.world.players.values()].find(
|
35 |
(p) => game.playerDescriptions.get(p.id)?.name === humanTokenIdentifier,
|
36 |
);
|
|
|
40 |
const otherPlayerIds = [...humanConversation.participants.keys()].filter(
|
41 |
(p) => !!p && p !== humanPlayer.id,
|
42 |
);
|
43 |
+
SelectedPlayerId = otherPlayerIds[0];
|
44 |
}
|
45 |
|
46 |
+
const player = SelectedPlayerId && game.world.players.get(SelectedPlayerId);
|
47 |
const playerConversation = player && game.world.playerConversation(player);
|
48 |
|
49 |
const previousConversation = useQuery(
|
50 |
api.world.previousConversation,
|
51 |
+
SelectedPlayerId ? { worldId, playerId: SelectedPlayerId } : 'skip',
|
52 |
);
|
53 |
|
54 |
+
const playerDescription = SelectedPlayerId && game.playerDescriptions.get(SelectedPlayerId);
|
55 |
|
56 |
const startConversation = useSendInput(engineId, 'startConversation');
|
57 |
const acceptInvite = useSendInput(engineId, 'acceptInvite');
|
58 |
const rejectInvite = useSendInput(engineId, 'rejectInvite');
|
59 |
const leaveConversation = useSendInput(engineId, 'leaveConversation');
|
60 |
|
61 |
+
if (!SelectedPlayerId) {
|
62 |
return (
|
63 |
<div className="h-full text-xl flex text-center items-center p-4">
|
64 |
Click on an agent on the map to see chat history.
|
|
|
68 |
if (!player) {
|
69 |
return null;
|
70 |
}
|
71 |
+
const isMe = humanPlayer && SelectedPlayerId === currentPlayerId;
|
72 |
const canInvite = !isMe && !playerConversation && humanPlayer && !humanConversation;
|
73 |
const sameConversation =
|
74 |
!isMe &&
|
|
|
79 |
|
80 |
const humanStatus =
|
81 |
humanPlayer && humanConversation && humanConversation.participants.get(humanPlayer.id)?.status;
|
82 |
+
const playerStatus = playerConversation && playerConversation.participants.get(SelectedPlayerId)?.status;
|
83 |
const haveInvite = sameConversation && humanStatus?.kind === 'invited';
|
84 |
const waitingForAccept =
|
85 |
+
sameConversation && playerConversation.participants.get(SelectedPlayerId)?.status.kind === 'invited';
|
86 |
const waitingForNearby =
|
87 |
sameConversation && playerStatus?.kind === 'walkingOver' && humanStatus?.kind === 'walkingOver';
|
88 |
|
|
|
92 |
humanStatus?.kind === 'participating';
|
93 |
|
94 |
const onStartConversation = async () => {
|
95 |
+
if (!humanPlayer || !SelectedPlayerId) {
|
96 |
return;
|
97 |
}
|
98 |
console.log(`Starting conversation`);
|
99 |
+
await toastOnError(startConversation({ playerId: humanPlayer.id, invitee: SelectedPlayerId }));
|
100 |
};
|
101 |
const onAcceptInvite = async () => {
|
102 |
+
if (!humanPlayer || !humanConversation || !SelectedPlayerId) {
|
103 |
return;
|
104 |
}
|
105 |
await toastOnError(
|