Add static coordinates of galaxies

This commit is contained in:
Aelita4 2024-09-30 13:45:03 +02:00
parent b51200f3e8
commit 2f96c08da3
Signed by: Aelita4
GPG Key ID: E44490C2025906C1
3 changed files with 13 additions and 21 deletions

View File

@ -10,6 +10,10 @@ export type Galaxy = {
_id: ObjectId,
name: string,
sectors: Array<Sector>
coords: {
x: number,
y: number
}
}
export type Sector = {
@ -56,7 +60,8 @@ class LocationManager {
const galaxyObject: Galaxy = {
_id: galaxy._id,
name: galaxy.name,
sectors: []
sectors: [],
coords: galaxy.coords
};
for(const sectorId of galaxy.sectors) {

View File

@ -20,9 +20,9 @@ const galaxies = allGalaxies.map(galaxy => {
numericId: i++,
name: galaxy.name,
style: {
left: 0,
top: 0,
color: "red"
left: galaxy.coords.x,
top: galaxy.coords.y,
color: "white"
},
sectors: galaxy.sectors.map(sector => {
return {
@ -32,23 +32,6 @@ const galaxies = allGalaxies.map(galaxy => {
})
};
})
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;
}
}
}
---
<Layout title="Galaxy view">

View File

@ -4,4 +4,8 @@ export default interface DBGalaxy {
_id: ObjectId;
name: string;
sectors: Array<ObjectId>;
coords: {
x: number;
y: number;
}
}