Move isRealInstance

This commit is contained in:
Natsumi
2025-01-25 07:27:40 +13:00
parent 0618ea68a6
commit da4102429e
4 changed files with 51 additions and 52 deletions

View File

@@ -488,12 +488,12 @@ console.log(`isLinux: ${LINUX}`);
API.applyPresenceLocation = function (ref) {
var presence = ref.presence;
if ($app.isRealInstance(presence.world)) {
if ($utils.isRealInstance(presence.world)) {
ref.$locationTag = `${presence.world}:${presence.instance}`;
} else {
ref.$locationTag = presence.world;
}
if ($app.isRealInstance(presence.travelingToWorld)) {
if ($utils.isRealInstance(presence.travelingToWorld)) {
ref.$travelingToLocation = `${presence.travelingToWorld}:${presence.travelingToInstance}`;
} else {
ref.$travelingToLocation = presence.travelingToWorld;
@@ -976,13 +976,13 @@ console.log(`isLinux: ${LINUX}`);
userLocation
);
if ($app.isRealInstance(userLocation)) {
if ($utils.isRealInstance(userLocation)) {
console.warn('PWI: returning user location', userLocation);
const L = $utils.parseLocation(userLocation);
return L.worldId;
}
if ($app.isRealInstance(gameLogLocation)) {
if ($utils.isRealInstance(gameLogLocation)) {
console.warn(`PWI: returning gamelog location: `, gameLogLocation);
const L = $utils.parseLocation(gameLogLocation);
return L.worldId;
@@ -4579,7 +4579,7 @@ console.log(`isLinux: ${LINUX}`);
fromGetCurrentUser &&
ctx.state !== 'online' &&
typeof ref !== 'undefined' &&
this.isRealInstance(ref.location)
$utils.isRealInstance(ref.location)
) {
if (this.debugFriendState) {
console.log(
@@ -4783,17 +4783,15 @@ console.log(`isLinux: ${LINUX}`);
$app.methods.getWorldName = async function (location) {
var worldName = '';
if (this.isRealInstance(location)) {
try {
var L = $utils.parseLocation(location);
if (L.worldId) {
var args = await API.getCachedWorld({
worldId: L.worldId
});
worldName = args.ref.name;
}
} catch (err) {}
}
try {
var L = $utils.parseLocation(location);
if (L.isRealInstance && L.worldId) {
var args = await API.getCachedWorld({
worldId: L.worldId
});
worldName = args.ref.name;
}
} catch (err) {}
return worldName;
};
@@ -10178,7 +10176,7 @@ console.log(`isLinux: ${LINUX}`);
return;
}
var L = $utils.parseLocation(D.ref.$location.tag);
if (updateInstanceOccupants && this.isRealInstance(L.tag)) {
if (updateInstanceOccupants && L.isRealInstance) {
API.getInstance({
worldId: L.worldId,
instanceId: L.instanceId
@@ -10278,7 +10276,7 @@ console.log(`isLinux: ${LINUX}`);
ref: {}
};
}
if (!this.isRealInstance(L.tag)) {
if (!L.isRealInstance) {
D.instance = {
id: L.instanceId,
tag: L.tag,
@@ -10597,7 +10595,7 @@ console.log(`isLinux: ${LINUX}`);
});
});
}
if (this.isRealInstance(instanceId)) {
if ($utils.isRealInstance(instanceId)) {
var ref = API.cachedInstances.get(instanceId);
if (typeof ref !== 'undefined') {
this.currentInstanceWorld.instance = ref;
@@ -11319,7 +11317,7 @@ console.log(`isLinux: ${LINUX}`);
D.stickersDisabled = ref.tags?.includes('feature_stickers_disabled');
$app.applyWorldDialogInstances();
for (var room of D.rooms) {
if ($app.isRealInstance(room.tag)) {
if ($utils.isRealInstance(room.tag)) {
API.getInstance({
worldId: D.id,
instanceId: room.id
@@ -11861,7 +11859,7 @@ console.log(`isLinux: ${LINUX}`);
var ref = API.cachedInstances.get(room.tag);
if (typeof ref !== 'undefined') {
room.ref = ref;
} else if ($app.isRealInstance(room.tag)) {
} else if ($utils.isRealInstance(room.tag)) {
API.getInstance({
worldId: room.$location.worldId,
instanceId: room.$location.instanceId
@@ -12764,7 +12762,7 @@ console.log(`isLinux: ${LINUX}`);
};
$app.methods.showInviteDialog = function (tag) {
if (!this.isRealInstance(tag)) {
if (!$utils.isRealInstance(tag)) {
return;
}
this.$nextTick(() => $app.adjustDialogZ(this.$refs.inviteDialog.$el));
@@ -13176,10 +13174,10 @@ console.log(`isLinux: ${LINUX}`);
};
$app.methods.selfInvite = function (location, shortName) {
if (!this.isRealInstance(location)) {
var L = $utils.parseLocation(location);
if (!L.isRealInstance) {
return;
}
var L = $utils.parseLocation(location);
API.selfInvite({
instanceId: L.instanceId,
worldId: L.worldId,
@@ -13249,7 +13247,7 @@ console.log(`isLinux: ${LINUX}`);
};
$app.methods.showNewInstanceDialog = async function (tag) {
if (!this.isRealInstance(tag)) {
if (!$utils.isRealInstance(tag)) {
return;
}
this.$nextTick(() =>
@@ -13872,7 +13870,7 @@ console.log(`isLinux: ${LINUX}`);
};
$app.methods.showLaunchDialog = function (tag, shortName) {
if (!this.isRealInstance(tag)) {
if (!$utils.isRealInstance(tag)) {
return;
}
this.$nextTick(() => $app.adjustDialogZ(this.$refs.launchDialog.$el));
@@ -17358,7 +17356,7 @@ console.log(`isLinux: ${LINUX}`);
}
var { location } = this.lastLocation;
AppApi.VrcClosedGracefully().then((result) => {
if (result || !this.isRealInstance(location)) {
if (result || !$utils.isRealInstance(location)) {
return;
}
// wait a bit for SteamVR to potentially close before deciding to relaunch
@@ -19736,23 +19734,6 @@ console.log(`isLinux: ${LINUX}`);
return false;
};
$app.methods.isRealInstance = function (instanceId) {
if (!instanceId) {
return false;
}
switch (instanceId) {
case 'offline':
case 'offline:offline':
case 'private':
case 'private:private':
case 'traveling':
case 'traveling:traveling':
case instanceId.startsWith('local'):
return false;
}
return true;
};
$app.methods.onPlayerTraveling = function (ref) {
if (
!this.isGameRunning ||
@@ -19842,7 +19823,7 @@ console.log(`isLinux: ${LINUX}`);
this.lastLocationDestination = '';
this.lastLocationDestinationTime = 0;
if (this.isRealInstance(location)) {
if ($utils.isRealInstance(location)) {
var dt = new Date().toJSON();
var L = $utils.parseLocation(location);
@@ -23171,11 +23152,10 @@ console.log(`isLinux: ${LINUX}`);
$app.computed.friendsInSameInstance = function () {
const friendsList = {};
const allFriends = [...this.vipFriends, ...this.onlineFriends];
this.friends.forEach((friend) => {
if (!friend.ref?.$location.isRealInstance) return;
allFriends.forEach((friend) => {
const key = friend.ref?.$location.tag;
if (!key || key === 'private' || key === 'offline') return;
const key = friend.ref.$location.tag;
if (!friendsList[key]) {
friendsList[key] = [];
}

View File

@@ -94,7 +94,7 @@ export default class extends baseClass {
var travelingToWorld = $travelingLocation.worldId;
var travelingToInstance = $travelingLocation.instanceId;
if (!$app.isGameRunning && json.presence) {
if ($app.isRealInstance(json.presence.world)) {
if ($utils.isRealInstance(json.presence.world)) {
location = `${json.presence.world}:${json.presence.instance}`;
travelingToLocation = `${json.presence.travelingToWorld}:${json.presence.travelingToInstance}`;
} else {

View File

@@ -84,6 +84,23 @@ export default {
return s.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
},
isRealInstance(instanceId) {
if (!instanceId) {
return false;
}
switch (instanceId) {
case 'offline':
case 'offline:offline':
case 'private':
case 'private:private':
case 'traveling':
case 'traveling:traveling':
case instanceId.startsWith('local'):
return false;
}
return true;
},
parseLocation(tag) {
var _tag = String(tag || '');
var ctx = {
@@ -91,6 +108,7 @@ export default {
isOffline: false,
isPrivate: false,
isTraveling: false,
isRealInstance: false,
worldId: '',
instanceId: '',
instanceName: '',
@@ -114,7 +132,8 @@ export default {
ctx.isPrivate = true;
} else if (_tag === 'traveling' || _tag === 'traveling:traveling') {
ctx.isTraveling = true;
} else if (_tag.startsWith('local') === false) {
} else if (!_tag.startsWith('local')) {
ctx.isRealInstance = true;
var sep = _tag.indexOf(':');
// technically not part of instance id, but might be there when coping id from url so why not support it
var shortNameQualifier = '&shortName=';

View File

@@ -110,7 +110,7 @@ mixin friendsListSidebar
i.el-icon-arrow-right(:class='{ rotate: isSidebarGroupByInstanceCollapsed }')
span(style='margin-left: 5px') {{ $t('side_panel.same_instance') }} ― {{ friendsInSameInstance.length }}
div(v-show='!isSidebarGroupByInstanceCollapsed')
div(v-for='friendArr in friendsInSameInstance' :key='friendArr[0].ref?.location.tag')
div(v-for='friendArr in friendsInSameInstance' :key='friendArr[0].ref?.$location.tag')
div(style='margin-bottom: 3px')
location.extra(:location='getFriendsLocations(friendArr)' style='color: #c7c7c7')
span(style='margin-left: 5px') {{ `(${friendArr.length})` }}