Skip to content

Commit

Permalink
♻️ [useDebugManager] Start listening to the play event
Browse files Browse the repository at this point in the history
  • Loading branch information
beefchimi committed Jan 23, 2024
1 parent a9458f0 commit abfe58e
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions app/website/src/store/useDebugManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ const {manager, activeStacks} = useEarwurmStore();

const stateHistoryRef = ref([manager.state]);
const errorHistoryRef = ref<ErrorResponse[]>([]);

// TODO: Update these to be more accurate.
// Currently, these do not update on the right events.
const unlockHistoryRef = ref([manager.unlocked]);
const playHistoryRef = ref([manager.playing]);

Expand All @@ -28,28 +25,20 @@ function updateUnlockHistory() {
unlockHistoryRef.value = newHistory.slice(MAX_HISTORY_LENGTH * -1);
}

function updatePlayHistory() {
const currentLength = playHistoryRef.value.length;

if (manager.playing === playHistoryRef.value[currentLength - 1]) {
return;
}

const newHistory = [...playHistoryRef.value, manager.playing];
playHistoryRef.value = newHistory.slice(MAX_HISTORY_LENGTH * -1);
}

manager.on('state', (current) => {
const newState = [...stateHistoryRef.value, current];
stateHistoryRef.value = newState.slice(MAX_HISTORY_LENGTH * -1);
const newStateHistory = [...stateHistoryRef.value, current];
stateHistoryRef.value = newStateHistory.slice(MAX_HISTORY_LENGTH * -1);

updateUnlockHistory();
updatePlayHistory();
});

manager.on('play', (active) => {
const newPlayHistory = [...playHistoryRef.value, active];
playHistoryRef.value = newPlayHistory.slice(MAX_HISTORY_LENGTH * -1);
});

manager.on('library', () => {
updateUnlockHistory();
updatePlayHistory();
});

manager.on('error', (response) => {
Expand Down

0 comments on commit abfe58e

Please sign in to comment.