Skip to content

Commit

Permalink
Merge Places module into the Metaverse module
Browse files Browse the repository at this point in the history
To consolidate metaverse API methods.
  • Loading branch information
Gigabyte5671 committed Sep 5, 2023
1 parent e7f313a commit a943334
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 63 deletions.
7 changes: 4 additions & 3 deletions src/components/overlays/explore/Explore.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -515,7 +516,7 @@ export default defineComponent({

data() {
return {
placesList: [] as PlaceEntry[],
placesList: new Array<PlaceEntry>(),
loading: false,
filterText: "",
locationInput: "",
Expand Down Expand Up @@ -598,7 +599,7 @@ export default defineComponent({
methods: {
async loadPlacesList(): Promise<void> {
this.loading = true;
this.placesList = await Places.getActiveList();
this.placesList = await API.getActivePlaceList();
this.loading = false;
},

Expand Down
33 changes: 32 additions & 1 deletion src/modules/metaverse/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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<PlaceEntry[]> {
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;
}
}
8 changes: 8 additions & 0 deletions src/modules/metaverse/APIPlaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
56 changes: 0 additions & 56 deletions src/modules/places/index.ts

This file was deleted.

7 changes: 4 additions & 3 deletions src/pages/FirstTimeSetup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -509,7 +510,7 @@ export default defineComponent({
transition: false,
step: 1,
AvatarStoreInterface,
placesList: [] as PlaceEntry[],
placesList: new Array<PlaceEntry>(),
selectedPlace: {} as PlaceEntry
};
},
Expand Down Expand Up @@ -629,7 +630,7 @@ export default defineComponent({
*/
async loadPlaces(): Promise<void> {
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.
Expand Down

0 comments on commit a943334

Please sign in to comment.