Jofthomas commited on
Commit
8989235
·
1 Parent(s): 6b307e5

useffect on join lobby number

Browse files
Files changed (1) hide show
  1. src/components/Game.tsx +13 -2
src/components/Game.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import { useRef, useState } from 'react';
2
  import PixiGame from './PixiGame.tsx';
3
 
4
  import { useElementSize } from 'usehooks-ts';
@@ -24,7 +24,18 @@ import { LOBBY_SIZE } from '../../convex/constants';
24
  export const SHOW_DEBUG_UI = !!import.meta.env.VITE_SHOW_DEBUG_UI;
25
 
26
  export function GameStateLabel(game: GameObj, me: PlayerDescription | undefined) {
27
- const humans = [...game.world.playersInit.values()].filter(player => player.human).length
 
 
 
 
 
 
 
 
 
 
 
28
  switch (game.world.gameCycle.cycleState) {
29
  case 'Day':
30
  return {
 
1
+ import { useRef, useState,useEffect } from 'react';
2
  import PixiGame from './PixiGame.tsx';
3
 
4
  import { useElementSize } from 'usehooks-ts';
 
24
  export const SHOW_DEBUG_UI = !!import.meta.env.VITE_SHOW_DEBUG_UI;
25
 
26
  export function GameStateLabel(game: GameObj, me: PlayerDescription | undefined) {
27
+ const [humans, setHumans] = useState(0);
28
+
29
+ useEffect(() => {
30
+ const updateHumanPlayers = () => {
31
+ const humanCount = [...game.world.players.values()].filter(player => player.human).length;
32
+ setHumans(humanCount);
33
+ };
34
+
35
+ // Update the count of human players when the component mounts and when game.world.players changes
36
+ updateHumanPlayers();
37
+ }, [game.world.players]);
38
+
39
  switch (game.world.gameCycle.cycleState) {
40
  case 'Day':
41
  return {