|
@@ -1,9 +1,10 @@
|
|
|
import { useEffect } from "react";
|
|
|
-import { useLastRound } from "../../../domain/gameStore";
|
|
|
+import { useLastRound, usePlayerName } from "../../../domain/gameStore";
|
|
|
import useMap from "../../../hooks/useMap";
|
|
|
import usePlayerScores from "../../../hooks/usePlayerScores";
|
|
|
-import usePlayerColors from "./usePlayerColors";
|
|
|
import { makeQuestionMarker, makeFlagMarker, makeLine } from "./markers";
|
|
|
+import getColorGenerator from "./getColorGenerator";
|
|
|
+import { useRef } from "react";
|
|
|
|
|
|
const useMapWithMarkers = (mapDivRef) => {
|
|
|
// get the info about the last round
|
|
@@ -23,15 +24,24 @@ const useMapWithMarkers = (mapDivRef) => {
|
|
|
?.filter(({ guesses }) => guesses[roundNum] && guesses[roundNum].score !== null)
|
|
|
?.map(({ name, totalScore, guesses }) => ({ name, totalScore, guess: guesses[roundNum] }));
|
|
|
|
|
|
+ // get the current player's name
|
|
|
+ const playerName = usePlayerName();
|
|
|
+
|
|
|
// set up the marker colors
|
|
|
- const playerColors = usePlayerColors(players?.map(({ name }) => name));
|
|
|
+ const playerColors = useRef({ [playerName]: "#000000" });
|
|
|
+ const nextColor = useRef(getColorGenerator());
|
|
|
+ if (players) {
|
|
|
+ players
|
|
|
+ .filter(({ name }) => !playerColors.current[name])
|
|
|
+ .forEach(({ name }) => { playerColors.current[name] = nextColor.current() });
|
|
|
+ }
|
|
|
|
|
|
// draw all the player markers and trails
|
|
|
useEffect(() => {
|
|
|
if (!players) return;
|
|
|
const drawings = [];
|
|
|
players.forEach(({ name, guess: { lat, lng, score } }) => {
|
|
|
- const color = playerColors[name];
|
|
|
+ const color = playerColors.current[name];
|
|
|
const selectedPoint = { lat, lng };
|
|
|
|
|
|
const marker = makeQuestionMarker(mapRef.current, selectedPoint, `${name} - ${score} Points`, color);
|