From a943334ba0bf13bf3ba8c0f2b3d8c7ae58737c25 Mon Sep 17 00:00:00 2001 From: Giga Date: Tue, 5 Sep 2023 13:46:35 +1200 Subject: [PATCH] Merge Places module into the Metaverse module To consolidate metaverse API methods. --- src/components/overlays/explore/Explore.vue | 7 +-- src/modules/metaverse/API.ts | 33 +++++++++++- src/modules/metaverse/APIPlaces.ts | 8 +++ src/modules/places/index.ts | 56 --------------------- src/pages/FirstTimeSetup.vue | 7 +-- 5 files changed, 48 insertions(+), 63 deletions(-) delete mode 100644 src/modules/places/index.ts diff --git a/src/components/overlays/explore/Explore.vue b/src/components/overlays/explore/Explore.vue index 3ca2f7d5..9073fd74 100644 --- a/src/components/overlays/explore/Explore.vue +++ b/src/components/overlays/explore/Explore.vue @@ -479,7 +479,8 @@ import { Vector3, Vector4 } from "@babylonjs/core"; import { applicationStore, userStore } from "@Stores/index"; import { Utility } from "@Modules/utility"; import { Location } from "@Modules/domain/location"; -import { Places, PlaceEntry } from "@Modules/places"; +import { API } from "@Modules/metaverse/API"; +import type { PlaceEntry } from "@Modules/metaverse/APIPlaces"; import { Renderer } from "@Modules/scene"; import Log from "@Modules/debugging/log"; import OverlayShell from "../OverlayShell.vue"; @@ -515,7 +516,7 @@ export default defineComponent({ data() { return { - placesList: [] as PlaceEntry[], + placesList: new Array(), loading: false, filterText: "", locationInput: "", @@ -598,7 +599,7 @@ export default defineComponent({ methods: { async loadPlacesList(): Promise { this.loading = true; - this.placesList = await Places.getActiveList(); + this.placesList = await API.getActivePlaceList(); this.loading = false; }, diff --git a/src/modules/metaverse/API.ts b/src/modules/metaverse/API.ts index 16e2efe0..cd5e0a66 100644 --- a/src/modules/metaverse/API.ts +++ b/src/modules/metaverse/API.ts @@ -13,8 +13,9 @@ import { MetaverseManager } from "@Modules/metaverse"; import { Account } from "../account"; import { GetAccountAPI, PostUsersAPI } from "@Modules/metaverse/APIAccount"; import { MetaverseInfoAPI } from "@Modules/metaverse/APIInfo"; -import { GetPlacesAPI } from "@Modules/metaverse/APIPlaces"; +import { GetPlacesAPI, type GetPlacesResponse, type PlaceEntry } from "@Modules/metaverse/APIPlaces"; import { OAuthTokenAPI } from "@Modules/metaverse/APIToken"; +import Log, { findErrorMessage } from "@Modules/debugging/log"; /** * Standard response from Metaverse server API requests. @@ -124,4 +125,34 @@ export class API { } throw new Error(`Vircadia API POST request to ${path} failed: ${response.status}: ${response.statusText}`); } + + /** + * @returns A list of the places (worlds) available in the connected Metaverse. + */ + public static async getActivePlaceList(): Promise { + const places: PlaceEntry[] = []; + + if (!MetaverseManager.activeMetaverse?.isConnected) { + Log.error(Log.types.PLACES, "Attempted to get places when not connected to a Metaverse server."); + } + + try { + const placesResponse = await this.get(this.endpoints.places + "?status=online") as GetPlacesResponse; + + for (const place of placesResponse.places) { + places.push({ + name: place.name, + placeId: place.placeId, + address: place.address, + description: place.description, + thumbnail: place.thumbnail ?? "", + currentAttendance: place.current_attendance ?? 0 + }); + } + } catch (error) { + Log.error(Log.types.PLACES, `Exception while attempting to get places: ${findErrorMessage(error)}`); + } + + return places; + } } diff --git a/src/modules/metaverse/APIPlaces.ts b/src/modules/metaverse/APIPlaces.ts index 3009a41a..c1259cdb 100644 --- a/src/modules/metaverse/APIPlaces.ts +++ b/src/modules/metaverse/APIPlaces.ts @@ -18,3 +18,11 @@ export interface GetPlacesResponse { "places": PlaceInfo[], "maturity-categories": string[] } +export interface PlaceEntry { + name: string; + placeId: string; + address: string; + description: string; + thumbnail: string; + currentAttendance: number; +} diff --git a/src/modules/places/index.ts b/src/modules/places/index.ts deleted file mode 100644 index 75e08e70..00000000 --- a/src/modules/places/index.ts +++ /dev/null @@ -1,56 +0,0 @@ -// -// Copyright 2021 Vircadia contributors. -// Copyright 2022 DigiSomni LLC. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -import { MetaverseManager } from "@Modules/metaverse"; -import { API } from "@Modules/metaverse/API"; -import type { GetPlacesResponse } from "@Modules/metaverse/APIPlaces"; -import Log, { findErrorMessage } from "@Modules/debugging/log"; - -export interface PlaceEntry { - name: string; - placeId: string; - address: string; - description: string; - thumbnail: string; - currentAttendance: number; -} - -/** - * Static methods for interacting with places/worlds in the connected Metaverse. - */ -export class Places { - /** - * @returns A list of the places (worlds) available in the connected Metaverse. - */ - public static async getActiveList(): Promise { - const places: PlaceEntry[] = []; - - if (!MetaverseManager.activeMetaverse?.isConnected) { - Log.error(Log.types.PLACES, "Attempted to get places when not connected to a Metaverse server."); - } - - try { - const placesResponse = await API.get(API.endpoints.places + "?status=online") as GetPlacesResponse; - - for (const place of placesResponse.places) { - places.push({ - name: place.name, - placeId: place.placeId, - address: place.address, - description: place.description, - thumbnail: place.thumbnail ?? "", - currentAttendance: place.current_attendance ?? 0 - }); - } - } catch (error) { - Log.error(Log.types.PLACES, `Exception while attempting to get places: ${findErrorMessage(error)}`); - } - - return places; - } -} diff --git a/src/pages/FirstTimeSetup.vue b/src/pages/FirstTimeSetup.vue index 2619e597..be95ab1b 100644 --- a/src/pages/FirstTimeSetup.vue +++ b/src/pages/FirstTimeSetup.vue @@ -498,7 +498,8 @@ import { defineComponent } from "vue"; import { uniqueNamesGenerator, adjectives, colors, animals } from "unique-names-generator"; import { AvatarStoreInterface } from "@Modules/avatar/StoreInterface"; import { Utility } from "@Modules/utility"; -import { Places, PlaceEntry } from "@Modules/places"; +import { API } from "@Modules/metaverse/API"; +import type { PlaceEntry } from "@Modules/metaverse/APIPlaces"; export default defineComponent({ name: "FirstTimeSetup", @@ -509,7 +510,7 @@ export default defineComponent({ transition: false, step: 1, AvatarStoreInterface, - placesList: [] as PlaceEntry[], + placesList: new Array(), selectedPlace: {} as PlaceEntry }; }, @@ -629,7 +630,7 @@ export default defineComponent({ */ async loadPlaces(): Promise { await Utility.metaverseConnectionSetup(applicationStore.defaultConnectionConfig.DEFAULT_METAVERSE_URL ?? ""); - this.placesList = await Places.getActiveList(); + this.placesList = await API.getActivePlaceList(); }, /** * Register the first-time-setup process as complete, and redirect to any pending location.