mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-04-28 03:03:47 +02:00
refactor: app.js (#1291)
* refactor: frontend * Fix avatar gallery sort * Update .NET dependencies * Update npm dependencies electron v37.1.0 * bulkRefreshFriends * fix dark theme * Remove crowdin * Fix config.json dialog not updating * VRCX log file fixes & add Cef log * Remove SharedVariable, fix startup * Revert init theme change * Logging date not working? Fix WinformThemer designer error * Add Cef request hander, no more escaping main page * clean * fix * fix * clean * uh * Apply thememode at startup, fixes random user colours * Split database into files * Instance info remove empty lines * Open external VRC links with VRCX * Electron fixes * fix userdialog style * ohhhh * fix store * fix store * fix: load all group members after kicking a user * fix: world dialog favorite button style * fix: Clear VRCX Cache Timer input value * clean * Fix VR overlay * Fix VR overlay 2 * Fix Discord discord rich presence for RPC worlds * Clean up age verified user tags * Fix playerList being occupied after program reload * no `this` * Fix login stuck loading * writable: false * Hide dialogs on logout * add flush sync option * rm LOGIN event * rm LOGOUT event * remove duplicate event listeners * remove duplicate event listeners * clean * remove duplicate event listeners * clean * fix theme style * fix t * clearable * clean * fix ipcEvent * Small changes * Popcorn Palace support * Remove checkActiveFriends * Clean up * Fix dragEnterCef * Block API requests when not logged in * Clear state on login & logout * Fix worldDialog instances not updating * use <script setup> * Fix avatar change event, CheckGameRunning at startup * Fix image dragging * fix * Remove PWI * fix updateLoop * add webpack-dev-server to dev environment * rm unnecessary chunks * use <script setup> * webpack-dev-server changes * use <script setup> * use <script setup> * Fix UGC text size * Split login event * t * use <script setup> * fix * Update .gitignore and enable checkJs in jsconfig * fix i18n t * use <script setup> * use <script setup> * clean * global types * fix * use checkJs for debugging * Add watchState for login watchers * fix .vue template * type fixes * rm Vue.filter * Cef v138.0.170, VC++ 2022 * Settings fixes * Remove 'USER:CURRENT' * clean up 2FA callbacks * remove userApply * rm i18n import * notification handling to use notification store methods * refactor favorite handling to use favorite store methods and clean up event emissions * refactor moderation handling to use dedicated functions for player moderation events * refactor friend handling to use dedicated functions for friend events * Fix program startup, move lang init * Fix friend state * Fix status change error * Fix user notes diff * fix * rm group event * rm auth event * rm avatar event * clean * clean * getUser * getFriends * getFavoriteWorlds, getFavoriteAvatars * AvatarGalleryUpload btn style & package.json update * Fix friend requests * Apply user * Apply world * Fix note diff * Fix VR overlay * Fixes * Update build scripts * Apply avatar * Apply instance * Apply group * update hidden VRC+ badge * Fix sameInstance "private" * fix 502/504 API errors * fix 502/504 API errors * clean * Fix friend in same instance on orange showing twice in friends list * Add back in broken friend state repair methods * add types --------- Co-authored-by: Natsumi <cmcooper123@hotmail.com>
This commit is contained in:
258
src/stores/location.js
Normal file
258
src/stores/location.js
Normal file
@@ -0,0 +1,258 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { computed, reactive } from 'vue';
|
||||
import { database } from '../service/database';
|
||||
import {
|
||||
getGroupName,
|
||||
getWorldName,
|
||||
isRealInstance,
|
||||
parseLocation
|
||||
} from '../shared/utils';
|
||||
import { useGameStore } from './game';
|
||||
import { useGameLogStore } from './gameLog';
|
||||
import { useInstanceStore } from './instance';
|
||||
import { useNotificationStore } from './notification';
|
||||
import { usePhotonStore } from './photon';
|
||||
import { useAdvancedSettingsStore } from './settings/advanced';
|
||||
import { useUserStore } from './user';
|
||||
import { useVrStore } from './vr';
|
||||
|
||||
export const useLocationStore = defineStore('Location', () => {
|
||||
const advancedSettingsStore = useAdvancedSettingsStore();
|
||||
const userStore = useUserStore();
|
||||
const instanceStore = useInstanceStore();
|
||||
const notificationStore = useNotificationStore();
|
||||
const gameStore = useGameStore();
|
||||
const vrStore = useVrStore();
|
||||
const photonStore = usePhotonStore();
|
||||
const gameLogStore = useGameLogStore();
|
||||
|
||||
const state = reactive({
|
||||
lastLocation: {
|
||||
date: 0,
|
||||
location: '',
|
||||
name: '',
|
||||
playerList: new Map(),
|
||||
friendList: new Map()
|
||||
},
|
||||
lastLocation$: {
|
||||
tag: '',
|
||||
instanceId: '',
|
||||
accessType: '',
|
||||
worldName: '',
|
||||
worldCapacity: 0,
|
||||
joinUrl: '',
|
||||
statusName: '',
|
||||
statusImage: ''
|
||||
},
|
||||
lastLocationDestination: '',
|
||||
lastLocationDestinationTime: 0
|
||||
});
|
||||
|
||||
const lastLocation = computed({
|
||||
get: () => state.lastLocation,
|
||||
set: (value) => {
|
||||
state.lastLocation = value;
|
||||
}
|
||||
});
|
||||
|
||||
const lastLocation$ = computed({
|
||||
get: () => state.lastLocation$,
|
||||
set: (value) => {
|
||||
state.lastLocation$ = value;
|
||||
}
|
||||
});
|
||||
|
||||
const lastLocationDestination = computed({
|
||||
get: () => state.lastLocationDestination,
|
||||
set: (value) => {
|
||||
state.lastLocationDestination = value;
|
||||
}
|
||||
});
|
||||
|
||||
const lastLocationDestinationTime = computed({
|
||||
get: () => state.lastLocationDestinationTime,
|
||||
set: (value) => {
|
||||
state.lastLocationDestinationTime = value;
|
||||
}
|
||||
});
|
||||
|
||||
function updateCurrentUserLocation() {
|
||||
const ref = userStore.cachedUsers.get(userStore.currentUser.id);
|
||||
if (typeof ref === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
// update cached user with both gameLog and API locations
|
||||
let currentLocation = userStore.currentUser.$locationTag;
|
||||
const L = parseLocation(currentLocation);
|
||||
if (L.isTraveling) {
|
||||
currentLocation = userStore.currentUser.$travelingToLocation;
|
||||
}
|
||||
ref.location = userStore.currentUser.$locationTag;
|
||||
ref.travelingToLocation = userStore.currentUser.$travelingToLocation;
|
||||
|
||||
if (
|
||||
gameStore.isGameRunning &&
|
||||
!advancedSettingsStore.gameLogDisabled &&
|
||||
state.lastLocation.location !== ''
|
||||
) {
|
||||
// use gameLog instead of API when game is running
|
||||
currentLocation = state.lastLocation.location;
|
||||
if (state.lastLocation.location === 'traveling') {
|
||||
currentLocation = state.lastLocationDestination;
|
||||
}
|
||||
ref.location = state.lastLocation.location;
|
||||
ref.travelingToLocation = state.lastLocationDestination;
|
||||
}
|
||||
|
||||
ref.$online_for = userStore.currentUser.$online_for;
|
||||
ref.$offline_for = userStore.currentUser.$offline_for;
|
||||
ref.$location = parseLocation(currentLocation);
|
||||
if (!gameStore.isGameRunning || advancedSettingsStore.gameLogDisabled) {
|
||||
ref.$location_at = userStore.currentUser.$location_at;
|
||||
ref.$travelingToTime = userStore.currentUser.$travelingToTime;
|
||||
userStore.applyUserDialogLocation();
|
||||
instanceStore.applyWorldDialogInstances();
|
||||
instanceStore.applyGroupDialogInstances();
|
||||
} else {
|
||||
ref.$location_at = state.lastLocation.date;
|
||||
ref.$travelingToTime = state.lastLocationDestinationTime;
|
||||
userStore.currentUser.$travelingToTime =
|
||||
state.lastLocationDestinationTime;
|
||||
}
|
||||
}
|
||||
|
||||
async function setCurrentUserLocation(location, travelingToLocation) {
|
||||
userStore.currentUser.$location_at = Date.now();
|
||||
userStore.currentUser.$travelingToTime = Date.now();
|
||||
userStore.currentUser.$locationTag = location;
|
||||
userStore.currentUser.$travelingToLocation = travelingToLocation;
|
||||
updateCurrentUserLocation();
|
||||
|
||||
// janky gameLog support for Quest
|
||||
if (gameStore.isGameRunning) {
|
||||
// with the current state of things, lets not run this if we don't need to
|
||||
return;
|
||||
}
|
||||
let lastLocation = '';
|
||||
for (let i = gameLogStore.gameLogSessionTable.length - 1; i > -1; i--) {
|
||||
const item = gameLogStore.gameLogSessionTable[i];
|
||||
if (item.type === 'Location') {
|
||||
lastLocation = item.location;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lastLocation === location) {
|
||||
return;
|
||||
}
|
||||
state.lastLocationDestination = '';
|
||||
state.lastLocationDestinationTime = 0;
|
||||
|
||||
if (isRealInstance(location)) {
|
||||
const dt = new Date().toJSON();
|
||||
const L = parseLocation(location);
|
||||
|
||||
state.lastLocation.location = location;
|
||||
state.lastLocation.date = dt;
|
||||
|
||||
const entry = {
|
||||
created_at: dt,
|
||||
type: 'Location',
|
||||
location,
|
||||
worldId: L.worldId,
|
||||
worldName: await getWorldName(L.worldId),
|
||||
groupName: await getGroupName(L.groupId),
|
||||
time: 0
|
||||
};
|
||||
database.addGamelogLocationToDatabase(entry);
|
||||
notificationStore.queueGameLogNoty(entry);
|
||||
gameLogStore.addGameLog(entry);
|
||||
instanceStore.addInstanceJoinHistory(location, dt);
|
||||
|
||||
userStore.applyUserDialogLocation();
|
||||
instanceStore.applyWorldDialogInstances();
|
||||
instanceStore.applyGroupDialogInstances();
|
||||
} else {
|
||||
state.lastLocation.location = '';
|
||||
state.lastLocation.date = '';
|
||||
}
|
||||
}
|
||||
|
||||
function lastLocationReset(gameLogDate) {
|
||||
let dateTime = gameLogDate;
|
||||
if (!gameLogDate) {
|
||||
dateTime = new Date().toJSON();
|
||||
}
|
||||
const dateTimeStamp = Date.parse(dateTime);
|
||||
photonStore.photonLobby = new Map();
|
||||
photonStore.photonLobbyCurrent = new Map();
|
||||
photonStore.photonLobbyMaster = 0;
|
||||
photonStore.photonLobbyCurrentUser = 0;
|
||||
photonStore.photonLobbyUserData = new Map();
|
||||
photonStore.photonLobbyWatcherLoopStop();
|
||||
photonStore.photonLobbyAvatars = new Map();
|
||||
photonStore.photonLobbyLastModeration = new Map();
|
||||
photonStore.photonLobbyJointime = new Map();
|
||||
photonStore.photonLobbyActivePortals = new Map();
|
||||
photonStore.photonEvent7List = new Map();
|
||||
photonStore.photonLastEvent7List = '';
|
||||
photonStore.photonLastChatBoxMsg = new Map();
|
||||
photonStore.moderationEventQueue = new Map();
|
||||
if (photonStore.photonEventTable.data.length > 0) {
|
||||
photonStore.photonEventTablePrevious.data =
|
||||
photonStore.photonEventTable.data;
|
||||
photonStore.photonEventTable.data = [];
|
||||
}
|
||||
const playerList = Array.from(state.lastLocation.playerList.values());
|
||||
const dataBaseEntries = [];
|
||||
for (const ref of playerList) {
|
||||
const entry = {
|
||||
created_at: dateTime,
|
||||
type: 'OnPlayerLeft',
|
||||
displayName: ref.displayName,
|
||||
location: state.lastLocation.location,
|
||||
userId: ref.userId,
|
||||
time: dateTimeStamp - ref.joinTime
|
||||
};
|
||||
dataBaseEntries.unshift(entry);
|
||||
gameLogStore.addGameLog(entry);
|
||||
}
|
||||
database.addGamelogJoinLeaveBulk(dataBaseEntries);
|
||||
if (state.lastLocation.date !== 0) {
|
||||
const update = {
|
||||
time: dateTimeStamp - state.lastLocation.date,
|
||||
created_at: new Date(state.lastLocation.date).toJSON()
|
||||
};
|
||||
database.updateGamelogLocationTimeToDatabase(update);
|
||||
}
|
||||
state.lastLocationDestination = '';
|
||||
state.lastLocationDestinationTime = 0;
|
||||
state.lastLocation = {
|
||||
date: 0,
|
||||
location: '',
|
||||
name: '',
|
||||
playerList: new Map(),
|
||||
friendList: new Map()
|
||||
};
|
||||
updateCurrentUserLocation();
|
||||
instanceStore.updateCurrentInstanceWorld();
|
||||
vrStore.updateVRLastLocation();
|
||||
instanceStore.getCurrentInstanceUserList();
|
||||
gameLogStore.lastVideoUrl = '';
|
||||
gameLogStore.lastResourceloadUrl = '';
|
||||
userStore.applyUserDialogLocation();
|
||||
instanceStore.applyWorldDialogInstances();
|
||||
instanceStore.applyGroupDialogInstances();
|
||||
}
|
||||
|
||||
return {
|
||||
state,
|
||||
lastLocation,
|
||||
lastLocation$,
|
||||
lastLocationDestination,
|
||||
lastLocationDestinationTime,
|
||||
updateCurrentUserLocation,
|
||||
setCurrentUserLocation,
|
||||
lastLocationReset
|
||||
};
|
||||
});
|
||||
Reference in New Issue
Block a user