diff --git a/src/pages/game/galaxyView.astro b/src/pages/game/galaxyView.astro index 859bf58..4b2ede8 100644 --- a/src/pages/game/galaxyView.astro +++ b/src/pages/game/galaxyView.astro @@ -2,7 +2,6 @@ import Layout from '../../layouts/Layout.astro'; import NavBar from '../../components/NavBar.astro'; import { getUserByAccessToken } from '../../lib/db/users'; -import { getAllPlanets } from '../../lib/db/planets'; import locationManager from '../../lib/classes/managers/LocationManager'; import ResourceBar from '../../components/ResourceBar.astro'; @@ -13,89 +12,157 @@ if(loggedToken === null || username === "") return Astro.redirect('/logout'); const checkUser = await getUserByAccessToken(loggedToken); if(checkUser === null || checkUser.username !== username) return Astro.redirect('/logout'); -const allPlanets = await getAllPlanets(); +const allGalaxies = locationManager.galaxies; -const formattedPlanets = allPlanets.map(planet => { +let i = 0; +const galaxies = allGalaxies.map(galaxy => { return { - name: planet.name, - owner: locationManager.getUser(planet.owner)?.username ?? "Unowned" + numericId: i++, + name: galaxy.name, + style: { + left: 0, + top: 0, + color: "red" + }, + sectors: galaxy.sectors.map(sector => { + return { + id: sector._id.toString(), + name: sector.name + }; + }) }; }) + +for(const galaxy of galaxies) { + for(let i = 0; i < 100; i++) { + galaxy.style.left = Math.random() * 1200 + 20; + galaxy.style.top = Math.random() * 380 + 20; + const overlap = galaxies.slice(0, galaxy.numericId).some(otherGalaxy => { + const dx = galaxy.style.left - otherGalaxy.style.left; + const dy = galaxy.style.top - otherGalaxy.style.top; + const distance = Math.sqrt(dx * dx + dy * dy); + return distance < 100; + }); + if(!overlap) { + galaxy.style.color = "white" + break; + } + } +} --- - - {formattedPlanets.map(planet => {planet.name} ({planet.owner}))} - + + + {galaxies.map(galaxy => <> + + + {galaxy.name} + + + >)} + + + + + + + + - + \ No newline at end of file