Spaces:
Sleeping
Sleeping
test
Browse files- convex/aiTown/gameCycle.ts +9 -2
- convex/init.ts +1 -0
- src/components/Game.tsx +1 -1
convex/aiTown/gameCycle.ts
CHANGED
@@ -79,6 +79,8 @@ export const gameCycleSchema = {
|
|
79 |
v.literal('LobbyState'),
|
80 |
),
|
81 |
cycleIndex: v.number(),
|
|
|
|
|
82 |
};
|
83 |
|
84 |
export type SerializedGameCycle = ObjectType<typeof gameCycleSchema>;
|
@@ -160,12 +162,14 @@ export class GameCycle {
|
|
160 |
currentTime: number;
|
161 |
cycleState: CycleState;
|
162 |
cycleIndex: number;
|
|
|
163 |
|
164 |
constructor(serialized: SerializedGameCycle) {
|
165 |
-
const { currentTime, cycleState, cycleIndex
|
166 |
this.currentTime = currentTime;
|
167 |
this.cycleState = cycleState;
|
168 |
this.cycleIndex = cycleIndex;
|
|
|
169 |
}
|
170 |
|
171 |
startGame(game: Game) {
|
@@ -173,6 +177,7 @@ export class GameCycle {
|
|
173 |
onStateChange(this.cycleState, 'Day', game, 0);
|
174 |
this.cycleState = 'Day';
|
175 |
this.cycleIndex = 0;
|
|
|
176 |
console.log('Game started')
|
177 |
}
|
178 |
|
@@ -193,16 +198,18 @@ export class GameCycle {
|
|
193 |
const prevState = this.cycleState;
|
194 |
this.currentTime = 0;
|
195 |
this.cycleIndex = (this.cycleIndex + 1) % normalCycle.length;
|
|
|
196 |
this.cycleState = normalCycle[this.cycleIndex];
|
197 |
onStateChange(prevState, this.cycleState, game, tickDuration);
|
198 |
}
|
199 |
}
|
200 |
serialize(): SerializedGameCycle {
|
201 |
-
const { currentTime, cycleState, cycleIndex } = this;
|
202 |
return {
|
203 |
currentTime,
|
204 |
cycleState,
|
205 |
cycleIndex,
|
|
|
206 |
};
|
207 |
}
|
208 |
}
|
|
|
79 |
v.literal('LobbyState'),
|
80 |
),
|
81 |
cycleIndex: v.number(),
|
82 |
+
cycleNumber: v.number(),
|
83 |
+
|
84 |
};
|
85 |
|
86 |
export type SerializedGameCycle = ObjectType<typeof gameCycleSchema>;
|
|
|
162 |
currentTime: number;
|
163 |
cycleState: CycleState;
|
164 |
cycleIndex: number;
|
165 |
+
cycleNumber:number,
|
166 |
|
167 |
constructor(serialized: SerializedGameCycle) {
|
168 |
+
const { currentTime, cycleState, cycleIndex,cycleNumber} = serialized;
|
169 |
this.currentTime = currentTime;
|
170 |
this.cycleState = cycleState;
|
171 |
this.cycleIndex = cycleIndex;
|
172 |
+
this.cycleNumber=cycleNumber;
|
173 |
}
|
174 |
|
175 |
startGame(game: Game) {
|
|
|
177 |
onStateChange(this.cycleState, 'Day', game, 0);
|
178 |
this.cycleState = 'Day';
|
179 |
this.cycleIndex = 0;
|
180 |
+
this.cycleNumber=0
|
181 |
console.log('Game started')
|
182 |
}
|
183 |
|
|
|
198 |
const prevState = this.cycleState;
|
199 |
this.currentTime = 0;
|
200 |
this.cycleIndex = (this.cycleIndex + 1) % normalCycle.length;
|
201 |
+
this.cycleNumber = this.cycleNumber + 1;
|
202 |
this.cycleState = normalCycle[this.cycleIndex];
|
203 |
onStateChange(prevState, this.cycleState, game, tickDuration);
|
204 |
}
|
205 |
}
|
206 |
serialize(): SerializedGameCycle {
|
207 |
+
const { currentTime, cycleState, cycleIndex , cycleNumber} = this;
|
208 |
return {
|
209 |
currentTime,
|
210 |
cycleState,
|
211 |
cycleIndex,
|
212 |
+
cycleNumber,
|
213 |
};
|
214 |
}
|
215 |
}
|
convex/init.ts
CHANGED
@@ -65,6 +65,7 @@ async function getOrCreateDefaultWorld(ctx: MutationCtx) {
|
|
65 |
currentTime: 0,
|
66 |
cycleState: 'LobbyState',
|
67 |
cycleIndex: -1,
|
|
|
68 |
},
|
69 |
gameVotes: [],
|
70 |
llmVotes: []
|
|
|
65 |
currentTime: 0,
|
66 |
cycleState: 'LobbyState',
|
67 |
cycleIndex: -1,
|
68 |
+
cycleNumber:0,
|
69 |
},
|
70 |
gameVotes: [],
|
71 |
llmVotes: []
|
src/components/Game.tsx
CHANGED
@@ -24,7 +24,7 @@ import { LOBBY_SIZE } from '../../convex/constants';
|
|
24 |
export const SHOW_DEBUG_UI = !!import.meta.env.VITE_SHOW_DEBUG_UI;
|
25 |
export function GameStateLabel(game: GameObj, me: PlayerDescription | undefined) {
|
26 |
let humans = [...game.world.players.values()].filter(player => player.human).length
|
27 |
-
let cycle_num=game.world.gameCycle.
|
28 |
|
29 |
switch (game.world.gameCycle.cycleState) {
|
30 |
case 'Day':
|
|
|
24 |
export const SHOW_DEBUG_UI = !!import.meta.env.VITE_SHOW_DEBUG_UI;
|
25 |
export function GameStateLabel(game: GameObj, me: PlayerDescription | undefined) {
|
26 |
let humans = [...game.world.players.values()].filter(player => player.human).length
|
27 |
+
let cycle_num=game.world.gameCycle.cycleNumber
|
28 |
|
29 |
switch (game.world.gameCycle.cycleState) {
|
30 |
case 'Day':
|