mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-05 14:26:06 +02:00
refactor coordinators
This commit is contained in:
@@ -1,49 +1,45 @@
|
||||
import { useAvatarStore } from '../stores/avatar';
|
||||
import { useGameLogStore } from '../stores/gameLog';
|
||||
import { useGameStore } from '../stores/game';
|
||||
import { useInstanceStore } from '../stores/instance';
|
||||
import { useLocationStore } from '../stores/location';
|
||||
import { useUpdateLoopStore } from '../stores/updateLoop';
|
||||
import { useUserStore } from '../stores/user';
|
||||
import { useVrStore } from '../stores/vr';
|
||||
|
||||
import configRepository from '../service/config';
|
||||
|
||||
import * as workerTimers from 'worker-timers';
|
||||
|
||||
/**
|
||||
* @param {object} deps Coordinator dependencies.
|
||||
* @returns {object} Game flow coordinator methods.
|
||||
* Runs shared side effects when game running state changes.
|
||||
* @param {boolean} isGameRunning Whether VRChat is running.
|
||||
*/
|
||||
export function createGameCoordinator(deps) {
|
||||
const {
|
||||
userStore,
|
||||
instanceStore,
|
||||
updateLoopStore,
|
||||
locationStore,
|
||||
gameLogStore,
|
||||
vrStore,
|
||||
avatarStore,
|
||||
configRepository,
|
||||
workerTimers,
|
||||
checkVRChatDebugLogging,
|
||||
autoVRChatCacheManagement,
|
||||
checkIfGameCrashed,
|
||||
getIsGameNoVR
|
||||
} = deps;
|
||||
export async function runGameRunningChangedFlow(isGameRunning) {
|
||||
const userStore = useUserStore();
|
||||
const instanceStore = useInstanceStore();
|
||||
const updateLoopStore = useUpdateLoopStore();
|
||||
const locationStore = useLocationStore();
|
||||
const gameLogStore = useGameLogStore();
|
||||
const vrStore = useVrStore();
|
||||
const avatarStore = useAvatarStore();
|
||||
const gameStore = useGameStore();
|
||||
|
||||
/**
|
||||
* Runs shared side effects when game running state changes.
|
||||
* @param {boolean} isGameRunning Whether VRChat is running.
|
||||
*/
|
||||
async function runGameRunningChangedFlow(isGameRunning) {
|
||||
if (isGameRunning) {
|
||||
userStore.markCurrentUserGameStarted();
|
||||
} else {
|
||||
await configRepository.setBool('isGameNoVR', getIsGameNoVR());
|
||||
userStore.markCurrentUserGameStopped();
|
||||
instanceStore.removeAllQueuedInstances();
|
||||
autoVRChatCacheManagement();
|
||||
checkIfGameCrashed();
|
||||
updateLoopStore.setIpcTimeout(0);
|
||||
avatarStore.addAvatarWearTime(userStore.currentUser.currentAvatar);
|
||||
}
|
||||
|
||||
locationStore.lastLocationReset();
|
||||
gameLogStore.clearNowPlaying();
|
||||
vrStore.updateVRLastLocation();
|
||||
workerTimers.setTimeout(() => checkVRChatDebugLogging(), 60000);
|
||||
updateLoopStore.setNextDiscordUpdate(0);
|
||||
if (isGameRunning) {
|
||||
userStore.markCurrentUserGameStarted();
|
||||
} else {
|
||||
await configRepository.setBool('isGameNoVR', gameStore.isGameNoVR);
|
||||
userStore.markCurrentUserGameStopped();
|
||||
instanceStore.removeAllQueuedInstances();
|
||||
gameStore.autoVRChatCacheManagement();
|
||||
gameStore.checkIfGameCrashed();
|
||||
updateLoopStore.setIpcTimeout(0);
|
||||
avatarStore.addAvatarWearTime(userStore.currentUser.currentAvatar);
|
||||
}
|
||||
|
||||
return {
|
||||
runGameRunningChangedFlow
|
||||
};
|
||||
locationStore.lastLocationReset();
|
||||
gameLogStore.clearNowPlaying();
|
||||
vrStore.updateVRLastLocation();
|
||||
workerTimers.setTimeout(() => gameStore.checkVRChatDebugLogging(), 60000);
|
||||
updateLoopStore.setNextDiscordUpdate(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user