diff --git a/src/components/ResourceBar.astro b/src/components/ResourceBar.astro
index bc6850e..065f296 100644
--- a/src/components/ResourceBar.astro
+++ b/src/components/ResourceBar.astro
@@ -1,32 +1,174 @@
---
+import { ObjectId } from 'mongodb';
+import { getUserResources } from '../lib/db/users';
import { getHighestWeightedLanguage, getLocales } from '../lib/lang/langDriver';
-interface Props {
- loggedIn: string;
+
+import resourceTypes from '../lib/data/resources.json';
+
+const resourceLang = await getLocales(getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resources');
+
+const resources = await getUserResources(new ObjectId(Astro.cookies.get('userid')?.value ?? ''));
+
+const resourceArray = [];
+for(const key in resources) {
+ resourceArray.push({
+ name: key,
+ amount: resources[key as never]
+ });
}
-
-const lang = await getLocales(getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resourcebar');
-
-// const { loggedIn } = Astro.props;
---
-
-
-
-
coal
+
+
+ {resourceArray.map(res =>
+
x.name === res.name)?.type ?? "solid"} style={(resourceTypes.find(x => x.name === res.name)?.type ?? "solid") === "solid" ? "" : "display: none;"}>
+
+
x.name === res.name)?.icon ?? "#"} alt={res.name} />
+
+
+
{resourceLang[`Label_${res.name}`]}
+
{res.amount}
+
+
+ )}
\ No newline at end of file
+}
+
+.resourcebar-item-icon {
+ width: 50px;
+ height: 50px;
+ margin-right: 8px;
+ margin-top: 8px;
+ margin-bottom: 8px;
+}
+
+.resourcebar-item-icon img {
+ width: 100%;
+}
+
+.resourcebar-item-text-wrapper {
+ display: flex;
+ flex-direction: column;
+ justify-content: center;
+}
+
+.resourcebar-item-text {
+ font-size: 1.5em;
+}
+
+.resourcebar-item-amount {
+ font-size: 1.2em;
+}
+
+
+
\ No newline at end of file
diff --git a/src/lib/data/resources.json b/src/lib/data/resources.json
new file mode 100644
index 0000000..41f9e94
--- /dev/null
+++ b/src/lib/data/resources.json
@@ -0,0 +1,49 @@
+[
+ {
+ "name": "coal",
+ "type": "solid",
+ "icon": "https://gamepedia.cursecdn.com/minecraft_gamepedia/5/58/Coal_JE4_BE3.png"
+ },
+ {
+ "name": "iron",
+ "type": "solid",
+ "icon": "https://vignette.wikia.nocookie.net/minecraft/images/e/e8/New_Iron_IngotB.png/revision/latest?cb=20190520101024"
+ },
+ {
+ "name": "gold",
+ "type": "solid",
+ "icon": "https://gamepedia.cursecdn.com/minecraft_gamepedia/5/57/Gold_Ingot_JE3_BE2.png"
+ },
+
+ {
+ "name": "water",
+ "type": "liquid",
+ "icon": "https://ael.ovh/uranium.png"
+ },
+ {
+ "name": "sulfuricAcid",
+ "type": "liquid",
+ "icon": "https://ael.ovh/uranium.png"
+ },
+ {
+ "name": "liquidNitrogen",
+ "type": "liquid",
+ "icon": "https://ael.ovh/uranium.png"
+ },
+
+ {
+ "name": "hydrogen",
+ "type": "gas",
+ "icon": "https://ael.ovh/uranium.png"
+ },
+ {
+ "name": "oxygen",
+ "type": "gas",
+ "icon": "https://ael.ovh/uranium.png"
+ },
+ {
+ "name": "helium3",
+ "type": "gas",
+ "icon": "https://ael.ovh/uranium.png"
+ }
+]
\ No newline at end of file
diff --git a/src/lib/db/users.ts b/src/lib/db/users.ts
index bd0d938..56d3043 100644
--- a/src/lib/db/users.ts
+++ b/src/lib/db/users.ts
@@ -39,9 +39,9 @@ export const getUserByAccessToken = async(accessToken: string | AccessToken): Pr
} else return getUserById(accessToken.user as ObjectId)
}
-export const getUserResources = async (username: string): Promise
=> {
+export const getUserResources = async (id: ObjectId): Promise => {
const users = await Users();
- const user = await users.findOne({ username });
+ const user = await users.findOne({ _id: id });
const defaultResources: Resources = {
coal: 0,
diff --git a/src/lib/lang/en/resources.json b/src/lib/lang/en/resources.json
index eddd436..2768675 100644
--- a/src/lib/lang/en/resources.json
+++ b/src/lib/lang/en/resources.json
@@ -1,7 +1,15 @@
{
"Label": {
- "coal": "Coal",
- "iron": "Iron",
- "gold": "Gold"
+ "coal": "Coal (C)",
+ "iron": "Iron (Fe)",
+ "gold": "Gold (Au)",
+
+ "water": "Water (H₂O)",
+ "sulfuricAcid": "Sulfuric Acid (H₂SO₄)",
+ "liquidNitrogen": "Liquid Nitrogen (N₂)",
+
+ "hydrogen": "Hydrogen (H₂)",
+ "oxygen": "Oxygen (O₂)",
+ "helium3": "Helium-3 (³He)"
}
}
\ No newline at end of file
diff --git a/src/pages/game/buildings.astro b/src/pages/game/buildings.astro
index 56b48c3..6aece36 100644
--- a/src/pages/game/buildings.astro
+++ b/src/pages/game/buildings.astro
@@ -1,7 +1,7 @@
---
import Layout from '../../layouts/Layout.astro';
import NavBar from '../../components/NavBar.astro';
-import { getUserResources } from '../../lib/db/users';
+import { getUserByAccessToken, getUserResources } from '../../lib/db/users';
import { getHighestWeightedLanguage, getLocales } from '../../lib/lang/langDriver';
import ResourceBar from '../../components/ResourceBar.astro';
@@ -9,10 +9,12 @@ 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');
-if(loggedToken === null || username === "") return Astro.redirect('/');
+const checkUser = await getUserByAccessToken(loggedToken);
+if(checkUser === null || checkUser.username !== username) return Astro.redirect('/logout');
-const resources = await getUserResources(username);
+const resources = await getUserResources(checkUser._id);
const locale = getHighestWeightedLanguage(Astro.request.headers.get('accept-language'));
@@ -23,12 +25,7 @@ const langBuildings = await getLocales(locale, 'buildings');
-
-
- - {langResources['Label_coal']}: {resources.coal * 2}
- - {langResources['Label_iron']}: {resources.iron * 3}
- - {langResources['Label_gold']}: {resources.gold * 4}
-
+
{buildingsList.map(cat => (
@@ -119,18 +116,6 @@ const langBuildings = await getLocales(locale, 'buildings');
}
\ No newline at end of file
+
\ No newline at end of file
diff --git a/src/pages/game/profile.astro b/src/pages/game/profile.astro
index 8eebe32..4c647d3 100644
--- a/src/pages/game/profile.astro
+++ b/src/pages/game/profile.astro
@@ -1,15 +1,17 @@
---
import Layout from '../../layouts/Layout.astro';
import NavBar from '../../components/NavBar.astro';
-import { getUserByNickOrEmail, getUserResources, updateUserResources } from '../../lib/db/users';
+import { getUserByAccessToken, getUserByNickOrEmail } from '../../lib/db/users';
import { getHighestWeightedLanguage, getLocales } from '../../lib/lang/langDriver';
import ResourceBar from '../../components/ResourceBar.astro';
import format from '../../lib/utils/format';
const loggedToken = Astro.cookies.get('sessionToken')?.value ?? null;
const username = Astro.cookies.get('username')?.value ?? "";
+if(loggedToken === null || username === "") return Astro.redirect('/logout');
-if(loggedToken === null || username === "") return Astro.redirect('/');
+const checkUser = await getUserByAccessToken(loggedToken);
+if(checkUser === null || checkUser.username !== username) return Astro.redirect('/logout');
const locale = getHighestWeightedLanguage(Astro.request.headers.get('accept-language'));
diff --git a/src/pages/login.astro b/src/pages/login.astro
index 6518faa..8a59aee 100644
--- a/src/pages/login.astro
+++ b/src/pages/login.astro
@@ -57,6 +57,13 @@ if(Astro.request.method === "POST") {
secure: true
});
+ Astro.cookies.set("userid", user._id?.toString() as string, {
+ path: "/",
+ maxAge: sessionTime,
+ sameSite: "lax",
+ secure: true
+ });
+
return Astro.redirect("/game");
} else {
error = "invalid username or password";
@@ -66,7 +73,7 @@ if(Astro.request.method === "POST") {
---
-
+