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, id,
position: (point.x, point.y), position: (point.x, point.y),
owned_by_empire_id: None, owned_by_empire_id: None,
planets: HashMap::new(),
}; };
star_systems.insert(id, star_system); star_systems.insert(id, star_system);
} }

View file

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

View file

@ -1,3 +1,5 @@
use std::collections::HashMap;
use colourado::Color; use colourado::Color;
use super::StarSystemId; use super::StarSystemId;
@ -10,6 +12,10 @@ pub struct EmpireCoreState {
pub name: String, pub name: String,
pub color: Color, pub color: Color,
pub capital_system_id: StarSystemId, 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, self.universe_id.0,
empire.name.clone(), empire.name.clone(),
format_color(empire.color), format_color(empire.color),
json!({}),
vec![empire::id::set(empire.id.0)], vec![empire::id::set(empire.id.0)],
) )
}) })
@ -98,7 +99,7 @@ impl GameCoreState {
.exec() .exec()
.await?; .await?;
// Update the ownership // Update the star system ownership
for (star_system_id, empire_id) in owned_systems.into_iter() { for (star_system_id, empire_id) in owned_systems.into_iter() {
client client
.star_system() .star_system()

View file

@ -4,9 +4,11 @@ mod macros;
mod empire; mod empire;
mod fleet; mod fleet;
mod game; mod game;
mod planet;
mod starsystem; mod starsystem;
pub use self::empire::*; pub use self::empire::*;
pub use self::fleet::*; pub use self::fleet::*;
pub use self::game::*; pub use self::game::*;
pub use self::planet::*;
pub use self::starsystem::*; 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)] #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct StarSystemId(pub i32); pub struct StarSystemId(pub i32);
@ -9,6 +10,7 @@ pub struct StarSystemCoreState {
pub id: StarSystemId, pub id: StarSystemId,
pub position: (f64, f64), pub position: (f64, f64),
pub owned_by_empire_id: Option<EmpireId>, pub owned_by_empire_id: Option<EmpireId>,
pub planets: HashMap<PlanetId, PlanetCoreState>,
} }
pub struct StarSystemDerivedState {} pub struct StarSystemDerivedState {}

View file

@ -17,8 +17,9 @@ model Universe {
empires Empire[] empires Empire[]
starSystems StarSystem[] starSystems StarSystem[]
planets Planet[] planets Planet[]
Fleet Fleet[] fleets Fleet[]
StarSystemEdges StarSystemEdges[] hyperlanes StarSystemEdges[]
starbases Starbase[]
} }
model User { model User {
@ -58,6 +59,8 @@ model Empire {
starSystems StarSystem[] @relation("owner") starSystems StarSystem[] @relation("owner")
resources Json
@@id([universeId, id]) @@id([universeId, id])
} }
@ -75,6 +78,9 @@ model StarSystem {
ownedByEmpireId Int? ownedByEmpireId Int?
ownedByEmpire Empire? @relation("owner", fields: [universeId, ownedByEmpireId], references: [universeId, id]) ownedByEmpire Empire? @relation("owner", fields: [universeId, ownedByEmpireId], references: [universeId, id])
planets Planet[]
starbase Starbase?
@@id([universeId, index]) @@id([universeId, index])
} }
@ -91,11 +97,29 @@ model StarSystemEdges {
@@id([universeId, fromSystemId, toSystemId]) @@id([universeId, fromSystemId, toSystemId])
} }
model Planet { model Starbase {
id String @id @default(uuid()) id Int @default(autoincrement())
universeId Int universeId Int
universe Universe @relation(fields: [universeId], references: [id]) 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 { model Fleet {