Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improvements over backend mock #74

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 22 additions & 25 deletions backend/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ impl Data {
fuels,
asteria: Asteria {
id: ID::from(uuid::Uuid::new_v4().to_string()),
position: Position {
x: (rand::random::<f32>() * 100.0).floor() as i32,
y: (rand::random::<f32>() * 100.0).floor() as i32,
},
position: Position { x: 0, y: 0 },
total_rewards: 1235431230,
class: "Asteria".to_string(),
},
Expand All @@ -61,19 +58,17 @@ impl Data {

pub fn objects_in_radius(self, center: Position, radius: i32) -> Vec<MapObject> {
let mut retval = Vec::new();
let _ = self
.ships
.clone()
.into_iter()
.filter(|ship| (ship.position.x - center.x) + (ship.position.y - center.y) < radius)
.map(|ship| retval.push(MapObject::Ship(ship.clone())));
let _ = self
.fuels
.clone()
.into_iter()
.filter(|fuel| (fuel.position.x - center.x) + (fuel.position.y - center.y) < radius)
.map(|fuel| retval.push(MapObject::Fuel(fuel.clone())));

for ship in self.ships {
if (ship.position.x - center.x) + (ship.position.y - center.y) < radius {
retval.push(MapObject::Ship(ship.clone()));
}
}
for fuel in self.fuels {
if (fuel.position.x - center.x) + (fuel.position.y - center.y) < radius {
retval.push(MapObject::Fuel(fuel.clone()));
}
}
if (self.asteria.position.x - center.x) + (self.asteria.position.y - center.y) < radius {
retval.push(MapObject::Asteria(self.asteria.clone()))
}
Expand All @@ -97,10 +92,7 @@ impl Ship {
Self {
id: ID::from(uuid::Uuid::new_v4().to_string()),
fuel: (rand::random::<f32>() * 100.0).floor() as i32,
position: Position {
x: (rand::random::<f32>() * 100.0).floor() as i32,
y: (rand::random::<f32>() * 100.0).floor() as i32,
},
position: Position::random(),
shipyard_policy: PolicyId {
id: ID::from(uuid::Uuid::new_v4().to_string()),
},
Expand Down Expand Up @@ -129,10 +121,7 @@ impl Fuel {
Self {
id: ID::from(uuid::Uuid::new_v4().to_string()),
fuel: (rand::random::<f32>() * 100.0).floor() as i32,
position: Position {
x: (rand::random::<f32>() * 100.0).floor() as i32,
y: (rand::random::<f32>() * 100.0).floor() as i32,
},
position: Position::random(),
shipyard_policy: PolicyId {
id: ID::from(uuid::Uuid::new_v4().to_string()),
},
Expand Down Expand Up @@ -161,6 +150,14 @@ pub struct Position {
x: i32,
y: i32,
}
impl Position {
pub fn random() -> Self {
Self {
x: (rand::random::<f32>() * 200.0 - 100.0).floor() as i32,
y: (rand::random::<f32>() * 200.0 - 100.0).floor() as i32,
}
}
}

#[derive(Clone, SimpleObject)]
pub struct PolicyId {
Expand Down Expand Up @@ -375,7 +372,7 @@ async fn rocket() -> _ {
let schema = Schema::build(QueryRoot, EmptyMutation, EmptySubscription)
.register_output_type::<PositionalInterface>()
.data(shipyard_policy_id)
.data(Data::new(20, 50))
.data(Data::new(200, 100))
.finish();

rocket::build()
Expand Down
Loading