refactor: enhance player data handling to include label and default timestamp for improved tracking
This commit is contained in:
@@ -35,8 +35,15 @@ export const useTurtleStore = create((set, get) => ({
|
|||||||
data.turtles.forEach(turtle => {
|
data.turtles.forEach(turtle => {
|
||||||
turtlesMap[turtle.turtleID] = turtle;
|
turtlesMap[turtle.turtleID] = turtle;
|
||||||
});
|
});
|
||||||
|
const playersMap = {};
|
||||||
|
if (data.players && Array.isArray(data.players)) {
|
||||||
|
data.players.forEach(player => {
|
||||||
|
playersMap[player.playerID] = player;
|
||||||
|
});
|
||||||
|
}
|
||||||
set({
|
set({
|
||||||
turtles: turtlesMap,
|
turtles: turtlesMap,
|
||||||
|
players: playersMap,
|
||||||
worldBlocks: data.blocks || []
|
worldBlocks: data.blocks || []
|
||||||
});
|
});
|
||||||
} else if (data.type === 'turtle_update') {
|
} else if (data.type === 'turtle_update') {
|
||||||
@@ -74,7 +81,8 @@ export const useTurtleStore = create((set, get) => ({
|
|||||||
[data.playerID]: {
|
[data.playerID]: {
|
||||||
playerID: data.playerID,
|
playerID: data.playerID,
|
||||||
position: data.position,
|
position: data.position,
|
||||||
timestamp: data.timestamp
|
label: data.label || null,
|
||||||
|
timestamp: data.timestamp || Date.now()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|||||||
Reference in New Issue
Block a user