feat: massive AI generation
This commit is contained in:
@@ -1,6 +1,21 @@
|
||||
import type { WorldDelta, WorldSnapshot } from "./contracts";
|
||||
import type { TelemetrySnapshot } from "./contractsTelemetry";
|
||||
import type { BalanceSettings } from "./contractsBalance";
|
||||
import type { PlayerFactionSnapshot } from "./contractsPlayerFaction";
|
||||
import type { ShipSnapshot } from "./contractsShips";
|
||||
import type {
|
||||
PlayerAssetAssignmentCommandRequest,
|
||||
PlayerAutomationPolicyCommandRequest,
|
||||
PlayerDirectiveCommandRequest,
|
||||
PlayerOrganizationCommandRequest,
|
||||
PlayerOrganizationMembershipCommandRequest,
|
||||
PlayerPolicyCommandRequest,
|
||||
PlayerStrategicIntentCommandRequest,
|
||||
} from "./playerFactionCommands";
|
||||
import type {
|
||||
ShipDefaultBehaviorCommandRequest,
|
||||
ShipOrderCommandRequest,
|
||||
} from "./shipCommands";
|
||||
|
||||
export interface WorldStreamScope {
|
||||
scopeKind?: string;
|
||||
@@ -8,12 +23,16 @@ export interface WorldStreamScope {
|
||||
bubbleId?: string | null;
|
||||
}
|
||||
|
||||
export async function fetchWorldSnapshot(signal?: AbortSignal) {
|
||||
const response = await fetch("/api/world", { signal });
|
||||
async function fetchJson<T>(input: RequestInfo | URL, init?: RequestInit): Promise<T> {
|
||||
const response = await fetch(input, init);
|
||||
if (!response.ok) {
|
||||
throw new Error(`World request failed with ${response.status}`);
|
||||
throw new Error(`${init?.method ?? "GET"} ${typeof input === "string" ? input : input.toString()} failed with ${response.status}`);
|
||||
}
|
||||
return response.json() as Promise<WorldSnapshot>;
|
||||
return response.json() as Promise<T>;
|
||||
}
|
||||
|
||||
export async function fetchWorldSnapshot(signal?: AbortSignal) {
|
||||
return fetchJson<WorldSnapshot>("/api/world", { signal });
|
||||
}
|
||||
|
||||
export function openWorldStream(
|
||||
@@ -52,39 +71,114 @@ export function openWorldStream(
|
||||
}
|
||||
|
||||
export async function fetchTelemetry(signal?: AbortSignal) {
|
||||
const response = await fetch("/api/telemetry", { signal });
|
||||
if (!response.ok) {
|
||||
throw new Error(`Telemetry request failed with ${response.status}`);
|
||||
}
|
||||
return response.json() as Promise<TelemetrySnapshot>;
|
||||
return fetchJson<TelemetrySnapshot>("/api/telemetry", { signal });
|
||||
}
|
||||
|
||||
export async function fetchBalance(signal?: AbortSignal) {
|
||||
const response = await fetch("/api/balance", { signal });
|
||||
if (!response.ok) {
|
||||
throw new Error(`Balance request failed with ${response.status}`);
|
||||
}
|
||||
return response.json() as Promise<BalanceSettings>;
|
||||
return fetchJson<BalanceSettings>("/api/balance", { signal });
|
||||
}
|
||||
|
||||
export async function updateBalance(settings: BalanceSettings) {
|
||||
const response = await fetch("/api/balance", {
|
||||
return fetchJson<BalanceSettings>("/api/balance", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(settings),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Balance update failed with ${response.status}`);
|
||||
}
|
||||
return response.json() as Promise<BalanceSettings>;
|
||||
}
|
||||
|
||||
export async function resetWorld() {
|
||||
const response = await fetch("/api/world/reset", {
|
||||
return fetchJson<WorldSnapshot>("/api/world/reset", {
|
||||
method: "POST",
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`Reset request failed with ${response.status}`);
|
||||
}
|
||||
return response.json() as Promise<WorldSnapshot>;
|
||||
}
|
||||
|
||||
export async function fetchPlayerFaction(signal?: AbortSignal) {
|
||||
return fetchJson<PlayerFactionSnapshot>("/api/player-faction", { signal });
|
||||
}
|
||||
|
||||
export async function createPlayerOrganization(request: PlayerOrganizationCommandRequest) {
|
||||
return fetchJson<PlayerFactionSnapshot>("/api/player-faction/organizations", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
}
|
||||
|
||||
export async function deletePlayerOrganization(organizationId: string) {
|
||||
return fetchJson<PlayerFactionSnapshot>(`/api/player-faction/organizations/${organizationId}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
export async function updatePlayerOrganizationMembership(organizationId: string, request: PlayerOrganizationMembershipCommandRequest) {
|
||||
return fetchJson<PlayerFactionSnapshot>(`/api/player-faction/organizations/${organizationId}/membership`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
}
|
||||
|
||||
export async function upsertPlayerDirective(request: PlayerDirectiveCommandRequest, directiveId?: string | null) {
|
||||
const path = directiveId ? `/api/player-faction/directives/${directiveId}` : "/api/player-faction/directives";
|
||||
return fetchJson<PlayerFactionSnapshot>(path, {
|
||||
method: directiveId ? "PUT" : "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
}
|
||||
|
||||
export async function deletePlayerDirective(directiveId: string) {
|
||||
return fetchJson<PlayerFactionSnapshot>(`/api/player-faction/directives/${directiveId}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
export async function upsertPlayerAssignment(assetId: string, request: PlayerAssetAssignmentCommandRequest) {
|
||||
return fetchJson<PlayerFactionSnapshot>(`/api/player-faction/assignments/${assetId}`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
}
|
||||
|
||||
export async function upsertPlayerPolicy(request: PlayerPolicyCommandRequest, policyId?: string | null) {
|
||||
const path = policyId ? `/api/player-faction/policies/${policyId}` : "/api/player-faction/policies";
|
||||
return fetchJson<PlayerFactionSnapshot>(path, {
|
||||
method: policyId ? "PUT" : "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
}
|
||||
|
||||
export async function upsertPlayerAutomationPolicy(request: PlayerAutomationPolicyCommandRequest, automationPolicyId?: string | null) {
|
||||
const path = automationPolicyId ? `/api/player-faction/automation-policies/${automationPolicyId}` : "/api/player-faction/automation-policies";
|
||||
return fetchJson<PlayerFactionSnapshot>(path, {
|
||||
method: automationPolicyId ? "PUT" : "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
}
|
||||
|
||||
export async function updatePlayerStrategicIntent(request: PlayerStrategicIntentCommandRequest) {
|
||||
return fetchJson<PlayerFactionSnapshot>("/api/player-faction/strategic-intent", {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
}
|
||||
|
||||
export async function enqueueShipOrder(shipId: string, request: ShipOrderCommandRequest) {
|
||||
return fetchJson<ShipSnapshot>(`/api/ships/${shipId}/orders`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
}
|
||||
|
||||
export async function updateShipDefaultBehavior(shipId: string, request: ShipDefaultBehaviorCommandRequest) {
|
||||
return fetchJson<ShipSnapshot>(`/api/ships/${shipId}/default-behavior`, {
|
||||
method: "PUT",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(request),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user