refactor coordinators

This commit is contained in:
pa
2026-03-10 11:54:09 +09:00
parent 648fcde085
commit 2fffadfbcf
16 changed files with 1068 additions and 1257 deletions
+39 -43
View File
@@ -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);
}