136 lines
3.4 KiB
Plaintext
136 lines
3.4 KiB
Plaintext
---
|
|
import Layout from '../../layouts/Layout.astro';
|
|
import NavBar from '../../components/NavBar.astro';
|
|
import { getUserByAccessToken, getUserResources } from '../../lib/db/users';
|
|
import { getHighestWeightedLanguage, getLocales } from '../../lib/lang/langDriver';
|
|
import ResourceBar from '../../components/ResourceBar.astro';
|
|
|
|
const buildingsList = (await import('../../lib/data/buildings.json')).default;
|
|
|
|
const loggedToken = Astro.cookies.get('sessionToken')?.value ?? null;
|
|
const username = Astro.cookies.get('username')?.value ?? "";
|
|
if(loggedToken === null || username === "") return Astro.redirect('/logout');
|
|
|
|
const checkUser = await getUserByAccessToken(loggedToken);
|
|
if(checkUser === null || checkUser.username !== username) return Astro.redirect('/logout');
|
|
|
|
const resources = await getUserResources(checkUser._id);
|
|
|
|
const locale = getHighestWeightedLanguage(Astro.request.headers.get('accept-language'));
|
|
|
|
const langResources = await getLocales(locale, 'resources');
|
|
const langGame = await getLocales(locale, 'game');
|
|
const langBuildings = await getLocales(locale, 'buildings');
|
|
---
|
|
|
|
<Layout title="Buildings">
|
|
<NavBar loggedIn="true" active="buildings" />
|
|
<ResourceBar />
|
|
|
|
{buildingsList.map(cat => (
|
|
<div class="building-card">
|
|
<h3>{langBuildings[`Label_${cat.category}`]}</h3>
|
|
{cat.buildings.map(building => (
|
|
<div>{langBuildings[`Label_${building.id}`]} - {langResources['Label_iron']}: {building.cost['iron']}, {langResources['Label_gold']}: {building.cost['gold']}, {langResources['Label_coal']}: {building.cost['coal']} | <a id={`build_${building.id}`} href="#" class="a-button">{langGame['Link_build']}</a></div>
|
|
))}
|
|
</div>
|
|
))}
|
|
</Layout>
|
|
|
|
<style>
|
|
* {
|
|
color: white;
|
|
}
|
|
|
|
main {
|
|
margin: auto;
|
|
padding: 1rem;
|
|
width: 800px;
|
|
max-width: calc(100% - 2rem);
|
|
color: white;
|
|
font-size: 20px;
|
|
line-height: 1.6;
|
|
}
|
|
|
|
.astro-a {
|
|
position: absolute;
|
|
top: -32px;
|
|
left: 50%;
|
|
transform: translatex(-50%);
|
|
width: 220px;
|
|
height: auto;
|
|
z-index: -1;
|
|
}
|
|
|
|
h3 {
|
|
font-size: 2rem;
|
|
font-weight: 700;
|
|
line-height: 1;
|
|
text-align: center;
|
|
margin-bottom: 1em;
|
|
}
|
|
|
|
.text-gradient {
|
|
background-image: var(--accent-gradient);
|
|
-webkit-background-clip: text;
|
|
-webkit-text-fill-color: transparent;
|
|
background-size: 400%;
|
|
background-position: 0%;
|
|
}
|
|
|
|
.instructions {
|
|
margin-bottom: 2rem;
|
|
border: 1px solid rgba(var(--accent-light), 25%);
|
|
background: linear-gradient(rgba(var(--accent-dark), 66%), rgba(var(--accent-dark), 33%));
|
|
padding: 1.5rem;
|
|
border-radius: 8px;
|
|
}
|
|
|
|
.instructions code {
|
|
font-size: 0.8em;
|
|
font-weight: bold;
|
|
background: rgba(var(--accent-light), 12%);
|
|
color: rgb(var(--accent-light));
|
|
border-radius: 4px;
|
|
padding: 0.3em 0.4em;
|
|
}
|
|
|
|
.instructions strong {
|
|
color: rgb(var(--accent-light));
|
|
}
|
|
|
|
.link-card-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(24ch, 1fr));
|
|
gap: 2rem;
|
|
padding: 0;
|
|
}
|
|
|
|
.a-button {
|
|
text-decoration: none;
|
|
color: green;
|
|
}
|
|
|
|
.a-button:hover {
|
|
color: lime;
|
|
}
|
|
</style>
|
|
<script>
|
|
const allButtons = document.getElementsByClassName("a-button");
|
|
|
|
for(const buildingButton of allButtons) {
|
|
buildingButton.addEventListener("click", async () => {
|
|
const id = buildingButton.id.split("_")[1];
|
|
|
|
await fetch('/api/build/createBuilding', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
building: id
|
|
})
|
|
});
|
|
});
|
|
}
|
|
</script> |