This commit is contained in:
+24
-47
@@ -2,7 +2,7 @@ import type { Game, User } from "./interfaces";
|
|||||||
|
|
||||||
export function subscribe(endpoint: string) {
|
export function subscribe(endpoint: string) {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
const evtSource = new EventSource(new URL(endpoint, config.public.endpoint), {
|
const evtSource = new EventSource(config.public.endpoint + endpoint, {
|
||||||
withCredentials: true,
|
withCredentials: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -11,12 +11,9 @@ export function subscribe(endpoint: string) {
|
|||||||
|
|
||||||
export async function getLobby() {
|
export async function getLobby() {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
const req = await useFetch<Array<Game>>(
|
const req = await useFetch<Array<Game>>(config.public.endpoint + "/games", {
|
||||||
new URL("/games", config.public.endpoint).href,
|
credentials: "include",
|
||||||
{
|
});
|
||||||
credentials: "include",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
if (req.data.value == null) {
|
if (req.data.value == null) {
|
||||||
throw new Error("Lobby answer is empty");
|
throw new Error("Lobby answer is empty");
|
||||||
}
|
}
|
||||||
@@ -26,7 +23,7 @@ export async function getLobby() {
|
|||||||
export async function whoami() {
|
export async function whoami() {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
const { data, pending, error, refresh } = await useFetch<User>(
|
const { data, pending, error, refresh } = await useFetch<User>(
|
||||||
new URL("/whoami", config.public.endpoint).href,
|
config.public.endpoint + "/whoami",
|
||||||
{
|
{
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
}
|
}
|
||||||
@@ -48,13 +45,10 @@ export async function whoami() {
|
|||||||
|
|
||||||
export async function createGame() {
|
export async function createGame() {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
const res = await $fetch<Game>(
|
const res = await $fetch<Game>(config.public.endpoint + "/games", {
|
||||||
new URL("/games", config.public.endpoint).href,
|
method: "POST",
|
||||||
{
|
credentials: "include",
|
||||||
method: "POST",
|
});
|
||||||
credentials: "include",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
console.log(res);
|
console.log(res);
|
||||||
navigateTo("/game/" + res._id);
|
navigateTo("/game/" + res._id);
|
||||||
}
|
}
|
||||||
@@ -62,7 +56,7 @@ export async function createGame() {
|
|||||||
export async function startGame(game: string) {
|
export async function startGame(game: string) {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
const res = await $fetch<Game>(
|
const res = await $fetch<Game>(
|
||||||
new URL(`games/${game}/start`, config.public.endpoint).href,
|
config.public.endpoint + `games/${game}/start`,
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
@@ -73,7 +67,7 @@ export async function startGame(game: string) {
|
|||||||
export async function joinGame(game: string) {
|
export async function joinGame(game: string) {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
const res = await $fetch<Game>(
|
const res = await $fetch<Game>(
|
||||||
new URL(`games/${game}/join`, config.public.endpoint).href,
|
config.public.endpoint + `games/${game}/join`,
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
@@ -83,7 +77,7 @@ export async function joinGame(game: string) {
|
|||||||
|
|
||||||
export async function endTurn(game: string) {
|
export async function endTurn(game: string) {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
await $fetch(new URL(`games/${game}/endTurn`, config.public.endpoint).href, {
|
await $fetch(config.public.endpoint + `games/${game}/endTurn`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
});
|
});
|
||||||
@@ -92,8 +86,7 @@ export async function endTurn(game: string) {
|
|||||||
export async function lockCard(game: string, cardId: string) {
|
export async function lockCard(game: string, cardId: string) {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
await $fetch(
|
await $fetch(
|
||||||
new URL(`games/${game}/turn/lockCard/${cardId}`, config.public.endpoint)
|
config.public.endpoint + `games/${game}/turn/lockCard/${cardId}`,
|
||||||
.href,
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
@@ -104,8 +97,7 @@ export async function lockCard(game: string, cardId: string) {
|
|||||||
export async function buyCard(game: string, cardId: string) {
|
export async function buyCard(game: string, cardId: string) {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
await $fetch(
|
await $fetch(
|
||||||
new URL(`games/${game}/turn/buyCard/${cardId}`, config.public.endpoint)
|
config.public.endpoint + `games/${game}/turn/buyCard/${cardId}`,
|
||||||
.href,
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
@@ -115,13 +107,10 @@ export async function buyCard(game: string, cardId: string) {
|
|||||||
|
|
||||||
export async function buyGem(game: string) {
|
export async function buyGem(game: string) {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
await $fetch(
|
await $fetch(config.public.endpoint + `games/${game}/turn/buyGem`, {
|
||||||
new URL(`games/${game}/turn/buyGem`, config.public.endpoint).href,
|
method: "POST",
|
||||||
{
|
credentials: "include",
|
||||||
method: "POST",
|
});
|
||||||
credentials: "include",
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function useToken(
|
export async function useToken(
|
||||||
@@ -132,8 +121,7 @@ export async function useToken(
|
|||||||
) {
|
) {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
await $fetch(
|
await $fetch(
|
||||||
new URL(`games/${game}/turn/useToken/${tokenId}`, config.public.endpoint)
|
config.public.endpoint + `games/${game}/turn/useToken/${tokenId}`,
|
||||||
.href,
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
@@ -145,8 +133,7 @@ export async function useToken(
|
|||||||
export async function lockEffect(game: string, effectId: string) {
|
export async function lockEffect(game: string, effectId: string) {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
await $fetch(
|
await $fetch(
|
||||||
new URL(`games/${game}/turn/lockEffect/${effectId}`, config.public.endpoint)
|
config.public.endpoint + `games/${game}/turn/lockEffect/${effectId}`,
|
||||||
.href,
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
@@ -161,10 +148,7 @@ export async function makeDiscard(
|
|||||||
) {
|
) {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
await $fetch(
|
await $fetch(
|
||||||
new URL(
|
config.public.endpoint + `games/${game}/turn/makeDiscard/${playerId}`,
|
||||||
`games/${game}/turn/makeDiscard/${playerId}`,
|
|
||||||
config.public.endpoint
|
|
||||||
).href,
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
@@ -179,10 +163,7 @@ export async function damagePlayer(
|
|||||||
) {
|
) {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
await $fetch(
|
await $fetch(
|
||||||
new URL(
|
config.public.endpoint + `games/${game}/turn/damagePlayer/${playerId}`,
|
||||||
`games/${game}/turn/damagePlayer/${playerId}`,
|
|
||||||
config.public.endpoint
|
|
||||||
).href,
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
@@ -198,10 +179,7 @@ export async function damageChampion(
|
|||||||
) {
|
) {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
await $fetch(
|
await $fetch(
|
||||||
new URL(
|
config.public.endpoint + `games/${game}/turn/damageChampion/${cardId}`,
|
||||||
`games/${game}/turn/damageChampion/${cardId}`,
|
|
||||||
config.public.endpoint
|
|
||||||
).href,
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
@@ -213,8 +191,7 @@ export async function damageChampion(
|
|||||||
export async function discardCard(game: string, cardId: string) {
|
export async function discardCard(game: string, cardId: string) {
|
||||||
const config = useRuntimeConfig();
|
const config = useRuntimeConfig();
|
||||||
await $fetch(
|
await $fetch(
|
||||||
new URL(`games/${game}/turn/discardCard/${cardId}`, config.public.endpoint)
|
config.public.endpoint + `games/${game}/turn/discardCard/${cardId}`,
|
||||||
.href,
|
|
||||||
{
|
{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
|
|||||||
Reference in New Issue
Block a user