From 2304ff48a3186eb29fd87e068c3adb1a44f7c039 Mon Sep 17 00:00:00 2001 From: Aelita4 Date: Tue, 18 Jun 2024 15:19:52 +0200 Subject: [PATCH] Add planet support --- src/components/PlanetView.astro | 36 +++++++++++ src/components/ResourceBar.astro | 4 +- src/layouts/Layout.astro | 3 + src/lib/db/planets.ts | 48 +++++++++++++++ src/lib/db/users.ts | 60 ------------------- src/lib/utils/resourceManager.ts | 38 ++++++------ src/pages/api/planets/getAllPlanets.ts | 22 +++++++ src/pages/api/planets/getPlanet/[planetId].ts | 44 ++++++++++++++ src/pages/game/galaxyView.astro | 13 ++-- src/pages/game/index.astro | 4 +- src/pages/login.astro | 13 +++- src/pages/logout.astro | 4 ++ src/types/Planet.ts | 15 +++++ src/types/User.ts | 11 ++-- 14 files changed, 214 insertions(+), 101 deletions(-) create mode 100644 src/components/PlanetView.astro create mode 100644 src/lib/db/planets.ts create mode 100644 src/pages/api/planets/getAllPlanets.ts create mode 100644 src/pages/api/planets/getPlanet/[planetId].ts create mode 100644 src/types/Planet.ts diff --git a/src/components/PlanetView.astro b/src/components/PlanetView.astro new file mode 100644 index 0000000..3eaffa1 --- /dev/null +++ b/src/components/PlanetView.astro @@ -0,0 +1,36 @@ +--- +import { ObjectId } from 'mongodb'; +import { getHighestWeightedLanguage, getLocales } from '../lib/utils/langDriver'; +import { getUserWithPlanets } from '../lib/db/users'; +import { createPlanet } from '../lib/db/planets'; + +// await createPlanet({ +// name: "BiałePodNapletem2", +// ownerId: new ObjectId(Astro.cookies.get('userid')?.value ?? ""), +// fields: 69 +// }) + +if(!Astro.cookies.get('userid')?.value) return; +const planets = (await getUserWithPlanets(new ObjectId(Astro.cookies.get('userid')?.value ?? "")))?.planets.data; +if(!planets) return; + +// console.log(planets); + +// const resourceLang = await getLocales(await getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resources'); +// const resBarLang = await getLocales(await getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resourcebar'); + + +--- +
+ {planets.map(planet =>
+ {planet.name}
+

{planet.fields}

+
)} +
+ + \ No newline at end of file diff --git a/src/components/ResourceBar.astro b/src/components/ResourceBar.astro index e0616e8..e051905 100644 --- a/src/components/ResourceBar.astro +++ b/src/components/ResourceBar.astro @@ -1,6 +1,6 @@ --- import { ObjectId } from 'mongodb'; -import { calculateCurrentAvailableResources, getUserResources } from '../lib/utils/resourceManager'; +import { calculateCurrentAvailableResources } from '../lib/utils/resourceManager'; import { getHighestWeightedLanguage, getLocales } from '../lib/utils/langDriver'; import resourceTypes from '../lib/data/resources.json'; @@ -8,7 +8,7 @@ import resourceTypes from '../lib/data/resources.json'; const resourceLang = await getLocales(await getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resources'); const resBarLang = await getLocales(await getHighestWeightedLanguage(Astro.request.headers.get('accept-language')), 'resourcebar'); -const resources = await calculateCurrentAvailableResources(new ObjectId(Astro.cookies.get('userid')?.value ?? '')); +const resources = await calculateCurrentAvailableResources(new ObjectId(Astro.cookies.get('planetid')?.value ?? '')); const resourceArray = []; for(const key in resources) { diff --git a/src/layouts/Layout.astro b/src/layouts/Layout.astro index 7b552be..0018557 100644 --- a/src/layouts/Layout.astro +++ b/src/layouts/Layout.astro @@ -1,4 +1,6 @@ --- +import PlanetView from '../components/PlanetView.astro'; + interface Props { title: string; } @@ -18,6 +20,7 @@ const { title } = Astro.props; +