This commit is contained in:
parent
dd7f78b662
commit
7e2c4cf972
@ -16,16 +16,8 @@ type Player = {
|
||||
};
|
||||
|
||||
interface ScoreSaberScoresStore {
|
||||
lastUpdated: number;
|
||||
players: Player[];
|
||||
|
||||
/**
|
||||
* Sets when the player scores were last updated
|
||||
*
|
||||
* @param lastUpdated when the player scores were last updated
|
||||
*/
|
||||
setLastUpdated: (lastUpdated: number) => void;
|
||||
|
||||
/**
|
||||
* Checks if the player exists
|
||||
*
|
||||
@ -78,10 +70,6 @@ export const useScoresaberScoresStore = create<ScoreSaberScoresStore>()(
|
||||
lastUpdated: 0,
|
||||
players: [],
|
||||
|
||||
setLastUpdated: (lastUpdated: number) => {
|
||||
set({ lastUpdated });
|
||||
},
|
||||
|
||||
exists: (playerId: string) => {
|
||||
const players: Player[] = get().players;
|
||||
return players.some((player) => player.id == playerId);
|
||||
@ -238,10 +226,6 @@ export const useScoresaberScoresStore = create<ScoreSaberScoresStore>()(
|
||||
|
||||
// add local player and friends if they don't exist
|
||||
for (const player of allPlayers) {
|
||||
if (get().lastUpdated == 0) {
|
||||
set({ lastUpdated: Date.now() });
|
||||
}
|
||||
|
||||
if (get().get(player.id) == undefined) {
|
||||
toast.info(
|
||||
`${
|
||||
@ -261,20 +245,20 @@ export const useScoresaberScoresStore = create<ScoreSaberScoresStore>()(
|
||||
}
|
||||
}
|
||||
|
||||
// loop through all of the players and update their scores
|
||||
for (const player of players) {
|
||||
// Skip if we refreshed the scores recently
|
||||
const timeUntilRefreshMs =
|
||||
UPDATE_INTERVAL - (Date.now() - get().lastUpdated);
|
||||
UPDATE_INTERVAL - (Date.now() - player.lastUpdated);
|
||||
if (timeUntilRefreshMs > 0) {
|
||||
console.log(
|
||||
"Waiting",
|
||||
timeUntilRefreshMs / 1000,
|
||||
"seconds to refresh scores for players",
|
||||
"seconds to refresh scores for " + player.id,
|
||||
);
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
|
||||
// loop through all of the players and update their scores
|
||||
for (const player of players) {
|
||||
get().addOrUpdatePlayer(player.id);
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user