diff --git a/src/components/ItemCard.astro b/src/components/ItemCard.astro index b7be9f5..5382d49 100644 --- a/src/components/ItemCard.astro +++ b/src/components/ItemCard.astro @@ -12,15 +12,13 @@ interface Props { } const lang = await getLocales(Astro.cookies.get('language')?.value ?? await getHighestWeightedLanguage(Astro.request.headers.get('accept-language'))); - --- -
{Astro.props.name} | {Astro.props.level}
{Astro.props.description}
- {getName(lang, Astro.props.button_type, Astro.props.button_name)} +
i
diff --git a/src/pages/game/buildings.astro b/src/pages/game/buildings.astro index d27402e..4c7f70e 100644 --- a/src/pages/game/buildings.astro +++ b/src/pages/game/buildings.astro @@ -29,6 +29,24 @@ if(planetId === "") return "No planet selected"; const planet = locationManager.getPlanet(new ObjectId(planetId)); if(!planet) return "Planet not found"; +if(Astro.request.method === "POST") { + const selectedBuildingId = (await Astro.request.formData()).get('id') as string | null; + + const request = await (await fetch(Astro.url.origin + '/api/build/createBuilding', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + loggedToken + }, + body: JSON.stringify({ + planet: planetId, + building: selectedBuildingId + }) + })).json(); + + console.log(request); +} + const modalSet: { [key: string]: { resources: Array, research: Array, buildings: Array, energy: number } } = {}; for(const building of buildingsList) { @@ -246,29 +264,4 @@ const buildingsByCategory = buildingsList.reduce((acc: { [key: string]: Array { - const id = buildingButton.id.split("_")[1]; - - const response = await fetch('/api/build/createBuilding', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - building: id, - planet: planetId - }) - }); - - if(response.status === 200) { - window.location.reload(); - } else { - alert("Failed to build building: " + JSON.stringify(await response.json())); - } - }); - } \ No newline at end of file diff --git a/src/pages/game/research.astro b/src/pages/game/research.astro index 7c0cc35..143d8f1 100644 --- a/src/pages/game/research.astro +++ b/src/pages/game/research.astro @@ -19,6 +19,24 @@ if(checkUser === null || checkUser.username !== username) return Astro.redirect( const planetId = Astro.cookies.get('planetid')?.value ?? ""; if(planetId === "") return Astro.redirect('/logout'); +if(Astro.request.method === "POST") { + const selectedResearchId = (await Astro.request.formData()).get('id') as string | null; + + const request = await (await fetch(Astro.url.origin + '/api/research/performResearch', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': 'Bearer ' + loggedToken + }, + body: JSON.stringify({ + research: selectedResearchId, + planetId + }) + })).json(); + + console.log(request); +} + const locale = Astro.cookies.get('language')?.value ?? await getHighestWeightedLanguage(Astro.request.headers.get('accept-language')); const lang = await getLocales(locale); @@ -226,29 +244,4 @@ for(const research of researchList) { if(!backgroundDiv) return; backgroundDiv.style.display = 'none'; }); - - const allButtons = document.getElementsByClassName("item-card-build"); - - for(const researchButton of allButtons) { - researchButton.addEventListener("click", async () => { - const id = researchButton.id.split("_")[1]; - - const response = await fetch('/api/research/performResearch', { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - research: id, - planetId - }) - }); - - if(response.status === 200) { - window.location.reload(); - } else { - alert("Failed to build building: " + JSON.stringify(await response.json())); - } - }); - } \ No newline at end of file