Add player onboarding and tactical viewer updates
This commit is contained in:
@@ -2,12 +2,15 @@ import type { WorldDelta, WorldSnapshot } from "./contracts";
|
||||
import type { TelemetrySnapshot } from "./contractsTelemetry";
|
||||
import type { BalanceSettings } from "./contractsBalance";
|
||||
import type { PlayerFactionSnapshot } from "./contractsPlayerFaction";
|
||||
import type { AuthSessionResponse, ForgotPasswordResponse } from "./contractsAuth";
|
||||
import type { RaceSnapshot } from "./contractsRaces";
|
||||
import type { AuthSessionResponse, ForgotPasswordResponse, RegisterResponse } from "./contractsAuth";
|
||||
import type { PlayerIdentitySummary } from "./contractsIdentity";
|
||||
import type { ShipAutomationCatalogSnapshot } from "./contractsShipAutomation";
|
||||
import type { FactionSnapshot } from "./contractsFactions";
|
||||
import type { ShipSnapshot } from "./contractsShips";
|
||||
import type { StationSnapshot } from "./contractsInfrastructure";
|
||||
import { clearAuthSession, getAuthSession, setAuthSession } from "./authSession";
|
||||
import { getEffectivePlayerIdentityId } from "./effectiveIdentitySession";
|
||||
import type {
|
||||
PlayerAssetAssignmentCommandRequest,
|
||||
PlayerAutomationPolicyCommandRequest,
|
||||
@@ -35,6 +38,12 @@ async function fetchJson<T>(input: RequestInfo | URL, init?: RequestInit, option
|
||||
if (session?.accessToken) {
|
||||
headers.set("Authorization", `Bearer ${session.accessToken}`);
|
||||
}
|
||||
if (session?.roles.some((role) => role === "gm" || role === "admin")) {
|
||||
const effectivePlayerId = getEffectivePlayerIdentityId();
|
||||
if (effectivePlayerId) {
|
||||
headers.set("X-Act-As-Player-Id", effectivePlayerId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const response = await fetch(input, {
|
||||
@@ -160,13 +169,11 @@ export async function resetWorld() {
|
||||
}
|
||||
|
||||
export async function register(request: { email: string; password: string }) {
|
||||
const session = await fetchJson<AuthSessionResponse>("/api/auth/register", {
|
||||
return fetchJson<RegisterResponse>("/api/auth/register", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(request),
|
||||
}, { skipAuth: true, skipRefresh: true });
|
||||
setAuthSession(session);
|
||||
return session;
|
||||
}
|
||||
|
||||
export async function login(request: { email: string; password: string }) {
|
||||
@@ -199,6 +206,22 @@ export async function fetchPlayerFaction(signal?: AbortSignal) {
|
||||
return fetchJson<PlayerFactionSnapshot>("/api/player-faction", { signal });
|
||||
}
|
||||
|
||||
export async function fetchRaces(signal?: AbortSignal) {
|
||||
return fetchJson<RaceSnapshot[]>("/api/auth/races", { signal }, { skipAuth: true });
|
||||
}
|
||||
|
||||
export async function completePlayerOnboarding(request: { name: string; raceId: string }) {
|
||||
return fetchJson<PlayerFactionSnapshot>("/api/player-faction/onboarding", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
}
|
||||
|
||||
export async function fetchPlayerIdentities(signal?: AbortSignal) {
|
||||
return fetchJson<PlayerIdentitySummary[]>("/api/player-faction/identities", { signal });
|
||||
}
|
||||
|
||||
export async function fetchShipAutomationCatalog(signal?: AbortSignal) {
|
||||
return fetchJson<ShipAutomationCatalogSnapshot>("/api/ships/catalog", { signal }, { skipAuth: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user