committing cus i hit an ICE

This commit is contained in:
Michael Zhang 2023-12-30 23:33:15 -06:00
parent e0fa661845
commit f0bef1a2f3
8 changed files with 86 additions and 23 deletions

View file

@ -44,6 +44,7 @@ pub fn generate_map() -> Result<Map> {
id,
position: (point.x, point.y),
owned_by_empire_id: None,
planets: HashMap::new(),
};
star_systems.insert(id, star_system);
}

View file

@ -7,14 +7,15 @@ use chrono::Utc;
use colourado::{ColorPalette, PaletteType};
use names::Generator as NameGenerator;
use petgraph::algo::k_shortest_path;
use rand::{
rngs::ThreadRng, seq::SliceRandom, thread_rng, RngCore, SeedableRng,
};
use rand::{seq::SliceRandom, thread_rng, RngCore, SeedableRng};
use rand_chacha::ChaCha12Rng;
use crate::{
prisma::PrismaClient,
state::{EmpireCoreState, EmpireId, GameCoreState, StarSystemId, UniverseId},
prisma::{planet, star_system, universe, PrismaClient},
state::{
EmpireCoreState, EmpireId, GameCoreState, PlanetCoreState, PlanetId,
StarSystemId, UniverseId,
},
};
use self::map::generate_map;
@ -74,18 +75,36 @@ pub async fn generate_initial_game_state(
{
let id = EmpireId(idx as i32);
// Set the star system's owner
map
.star_systems
.get_mut(&capital_system_id)
.unwrap()
.owned_by_empire_id = Some(id);
{
let star_system = map.star_systems.get_mut(&capital_system_id).unwrap();
// Set the star system's owner
star_system.owned_by_empire_id = Some(id);
// Generate a planet to put inside the star system
let planet = client
.planet()
.create(
universe::UniqueWhereParam::IdEquals(universe.id),
star_system::UniqueWhereParam::UniverseIdIndexEquals(
universe.id,
star_system.id.0,
),
vec![],
)
.exec()
.await?;
let planet_id = PlanetId(planet.id);
let planet_state = PlanetCoreState {};
star_system.planets.insert(planet_id, planet_state);
}
let empire = EmpireCoreState {
id,
name,
color,
capital_system_id,
resources: HashMap::default(),
};
empires.insert(id, empire);
}

View file

@ -1,3 +1,5 @@
use std::collections::HashMap;
use colourado::Color;
use super::StarSystemId;
@ -10,6 +12,10 @@ pub struct EmpireCoreState {
pub name: String,
pub color: Color,
pub capital_system_id: StarSystemId,
pub resources: HashMap<String, f64>,
}
pub struct EmpireDerivedState {}
pub struct EmpireDerivedState {
pub resources: HashMap<String, f64>,
}

View file

@ -89,6 +89,7 @@ impl GameCoreState {
self.universe_id.0,
empire.name.clone(),
format_color(empire.color),
json!({}),
vec![empire::id::set(empire.id.0)],
)
})
@ -98,7 +99,7 @@ impl GameCoreState {
.exec()
.await?;
// Update the ownership
// Update the star system ownership
for (star_system_id, empire_id) in owned_systems.into_iter() {
client
.star_system()

View file

@ -4,9 +4,11 @@ mod macros;
mod empire;
mod fleet;
mod game;
mod planet;
mod starsystem;
pub use self::empire::*;
pub use self::fleet::*;
pub use self::game::*;
pub use self::planet::*;
pub use self::starsystem::*;

View file

@ -0,0 +1,8 @@
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct PlanetId(pub i32);
#[derive(Debug)]
pub struct PlanetCoreState {}
#[derive(Debug)]
pub struct PlanetDerivedState {}

View file

@ -1,6 +1,7 @@
use super::EmpireId;
use std::collections::HashMap;
use super::{EmpireId, PlanetCoreState, PlanetId};
/// This is only guaranteed to be unique for a specific UniverseId
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct StarSystemId(pub i32);
@ -9,6 +10,7 @@ pub struct StarSystemCoreState {
pub id: StarSystemId,
pub position: (f64, f64),
pub owned_by_empire_id: Option<EmpireId>,
pub planets: HashMap<PlanetId, PlanetCoreState>,
}
pub struct StarSystemDerivedState {}

View file

@ -13,12 +13,13 @@ model Universe {
config Json
players Player[]
empires Empire[]
starSystems StarSystem[]
planets Planet[]
Fleet Fleet[]
StarSystemEdges StarSystemEdges[]
players Player[]
empires Empire[]
starSystems StarSystem[]
planets Planet[]
fleets Fleet[]
hyperlanes StarSystemEdges[]
starbases Starbase[]
}
model User {
@ -58,6 +59,8 @@ model Empire {
starSystems StarSystem[] @relation("owner")
resources Json
@@id([universeId, id])
}
@ -75,6 +78,9 @@ model StarSystem {
ownedByEmpireId Int?
ownedByEmpire Empire? @relation("owner", fields: [universeId, ownedByEmpireId], references: [universeId, id])
planets Planet[]
starbase Starbase?
@@id([universeId, index])
}
@ -91,11 +97,29 @@ model StarSystemEdges {
@@id([universeId, fromSystemId, toSystemId])
}
model Planet {
id String @id @default(uuid())
model Starbase {
id Int @default(autoincrement())
universeId Int
universe Universe @relation(fields: [universeId], references: [id])
starSystemId Int
starSystem StarSystem @relation(fields: [universeId, starSystemId], references: [universeId, index])
@@id([universeId, id])
@@unique([universeId, starSystemId])
}
model Planet {
id Int @default(autoincrement())
universeId Int
universe Universe @relation(fields: [universeId], references: [id])
surroundingStarSystemId Int
surroundingStarSystem StarSystem @relation(fields: [universeId, surroundingStarSystemId], references: [universeId, index])
@@id([universeId, id])
}
model Fleet {