Spaces:
Sleeping
Sleeping
freeze game while in lobby + properly delete players
Browse files- convex/aiTown/game.ts +21 -0
- convex/world.ts +1 -0
- src/App.tsx +1 -1
convex/aiTown/game.ts
CHANGED
|
@@ -26,6 +26,17 @@ import { HistoricalObject } from '../engine/historicalObject';
|
|
| 26 |
import { AgentDescription, serializedAgentDescription } from './agentDescription';
|
| 27 |
import { parseMap, serializeMap } from '../util/object';
|
| 28 |
import { LOBBY_SIZE } from '../constants';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
type WerewolfLookupTable = {
|
| 31 |
[key: number]: number;
|
|
@@ -258,6 +269,16 @@ export class Game extends AbstractGame {
|
|
| 258 |
// Quit LobbyState to start the game once we have at least 3 players
|
| 259 |
if (this.world.gameCycle.cycleState === 'LobbyState' && humans.length >= LOBBY_SIZE) {
|
| 260 |
this.world.gameCycle.startGame(this)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
}
|
| 262 |
|
| 263 |
// debug
|
|
|
|
| 26 |
import { AgentDescription, serializedAgentDescription } from './agentDescription';
|
| 27 |
import { parseMap, serializeMap } from '../util/object';
|
| 28 |
import { LOBBY_SIZE } from '../constants';
|
| 29 |
+
import { useMutation, useQuery } from 'convex/react';
|
| 30 |
+
import { api } from '../_generated/api';
|
| 31 |
+
|
| 32 |
+
const stopAllowed = useQuery(api.testing.stopAllowed) ?? false;
|
| 33 |
+
const defaultWorld = useQuery(api.world.defaultWorldStatus);
|
| 34 |
+
|
| 35 |
+
const frozen = defaultWorld?.status === 'stoppedByDeveloper';
|
| 36 |
+
|
| 37 |
+
const unfreeze = useMutation(api.testing.resume);
|
| 38 |
+
const freeze = useMutation(api.testing.stop);
|
| 39 |
+
|
| 40 |
|
| 41 |
type WerewolfLookupTable = {
|
| 42 |
[key: number]: number;
|
|
|
|
| 269 |
// Quit LobbyState to start the game once we have at least 3 players
|
| 270 |
if (this.world.gameCycle.cycleState === 'LobbyState' && humans.length >= LOBBY_SIZE) {
|
| 271 |
this.world.gameCycle.startGame(this)
|
| 272 |
+
if (frozen) {
|
| 273 |
+
console.log('Unfreezing');
|
| 274 |
+
unfreeze();
|
| 275 |
+
}
|
| 276 |
+
}
|
| 277 |
+
if (this.world.gameCycle.cycleState === 'LobbyState' && humans.length < LOBBY_SIZE) {
|
| 278 |
+
|
| 279 |
+
console.log('Freezing');
|
| 280 |
+
freeze();
|
| 281 |
+
|
| 282 |
}
|
| 283 |
|
| 284 |
// debug
|
convex/world.ts
CHANGED
|
@@ -193,6 +193,7 @@ export const leaveWorld = mutation({
|
|
| 193 |
await insertInput(ctx, world._id, 'leave', {
|
| 194 |
playerId: existingPlayer.id,
|
| 195 |
});
|
|
|
|
| 196 |
},
|
| 197 |
});
|
| 198 |
|
|
|
|
| 193 |
await insertInput(ctx, world._id, 'leave', {
|
| 194 |
playerId: existingPlayer.id,
|
| 195 |
});
|
| 196 |
+
world.players.delete(oauthToken);
|
| 197 |
},
|
| 198 |
});
|
| 199 |
|
src/App.tsx
CHANGED
|
@@ -17,7 +17,7 @@ import OAuthLogin from './components//buttons/OAuthLogin.tsx';
|
|
| 17 |
import FreezeButton from './components/FreezeButton.tsx';
|
| 18 |
import { MAX_HUMAN_PLAYERS } from '../convex/constants.ts';
|
| 19 |
import PoweredByConvex from './components/PoweredByConvex.tsx';
|
| 20 |
-
|
| 21 |
export default function Home() {
|
| 22 |
const [helpModalOpen, setHelpModalOpen] = useState(false);
|
| 23 |
return (
|
|
|
|
| 17 |
import FreezeButton from './components/FreezeButton.tsx';
|
| 18 |
import { MAX_HUMAN_PLAYERS } from '../convex/constants.ts';
|
| 19 |
import PoweredByConvex from './components/PoweredByConvex.tsx';
|
| 20 |
+
|
| 21 |
export default function Home() {
|
| 22 |
const [helpModalOpen, setHelpModalOpen] = useState(false);
|
| 23 |
return (
|