From c6be289134c1f749884d269f955b39d39b604469 Mon Sep 17 00:00:00 2001 From: tom barrett Date: Wed, 20 Feb 2019 13:09:11 -0600 Subject: new naming scheme --- src/client/construction.rs | 6 +++--- src/client/engines.rs | 4 ++-- src/client/mining.rs | 6 +++--- src/client/navigation.rs | 4 ++-- src/client/refinery.rs | 6 +++--- src/client/tractorbeam.rs | 12 ++++++------ src/modules/construction.rs | 26 ++++++++++++------------ src/modules/engines.rs | 10 +++++----- src/modules/mining.rs | 28 +++++++++++++------------- src/modules/navigation.rs | 22 ++++++++++----------- src/modules/refinery.rs | 28 +++++++++++++------------- src/modules/tractorbeam.rs | 48 ++++++++++++++++++++++----------------------- 12 files changed, 100 insertions(+), 100 deletions(-) (limited to 'src') diff --git a/src/client/construction.rs b/src/client/construction.rs index 8549c09..28a91be 100644 --- a/src/client/construction.rs +++ b/src/client/construction.rs @@ -8,7 +8,7 @@ use std::io::{BufRead, BufReader}; use std::net::TcpStream; use crate::constants; -use crate::modules::construction::{ConstructionClientData, ConstructionStatus}; +use crate::modules::construction; pub fn client_construction(mut stream: TcpStream, mut buff_r: BufReader) { let stdout = stdout(); @@ -18,7 +18,7 @@ pub fn client_construction(mut stream: TcpStream, mut buff_r: BufReader { + construction::Status::None => { write!(stdout, "{}Press c to create a refinery.", clear).unwrap() } _ => write!(stdout, "{}Press c to cancel..", clear).unwrap(), diff --git a/src/client/engines.rs b/src/client/engines.rs index dc3799b..52af206 100644 --- a/src/client/engines.rs +++ b/src/client/engines.rs @@ -9,7 +9,7 @@ use std::net::TcpStream; use std::thread::sleep; use std::time::Duration; -use crate::modules::engines::EnginesClientData; +use crate::modules::engines; pub fn client_engines(mut stream: TcpStream, mut buff_r: BufReader) { let stdout = stdout(); @@ -19,7 +19,7 @@ pub fn client_engines(mut stream: TcpStream, mut buff_r: BufReader) { loop { let mut recv = String::new(); buff_r.read_line(&mut recv).unwrap(); - let engines_data: EnginesClientData = + let engines_data: engines::ClientData = serde_json::from_str(&recv.replace("\n", "")).unwrap(); writeln!( diff --git a/src/client/mining.rs b/src/client/mining.rs index 84dfcb6..c9ad3dc 100644 --- a/src/client/mining.rs +++ b/src/client/mining.rs @@ -7,7 +7,7 @@ use std::io::{stdout, Read, Write}; use std::io::{BufRead, BufReader}; use std::net::TcpStream; -use crate::modules::mining::{MiningClientData, MiningStatus}; +use crate::modules::mining; pub fn client_mining(mut stream: TcpStream, mut buff_r: BufReader) { let stdout = stdout(); @@ -17,7 +17,7 @@ pub fn client_mining(mut stream: TcpStream, mut buff_r: BufReader) { loop { let mut recv = String::new(); buff_r.read_line(&mut recv).unwrap(); - let data: MiningClientData = serde_json::from_str(&recv.replace("\n", "")).unwrap(); + let data: mining::ClientData = serde_json::from_str(&recv.replace("\n", "")).unwrap(); write!(stdout, "{}", termion::clear::All).unwrap(); @@ -27,7 +27,7 @@ pub fn client_mining(mut stream: TcpStream, mut buff_r: BufReader) { if data.is_within_range { if data.astroid_has_minerals { match data.status { - MiningStatus::None => { + mining::Status::None => { write!(stdout, "{}Press F to begin mining.", clear).unwrap() } _ => write!(stdout, "{}Press F to stop mining.", clear).unwrap(), diff --git a/src/client/navigation.rs b/src/client/navigation.rs index 586ac9e..7e6959b 100644 --- a/src/client/navigation.rs +++ b/src/client/navigation.rs @@ -7,7 +7,7 @@ use std::io::{stdout, Read, Write}; use std::io::{BufRead, BufReader}; use std::net::TcpStream; -use crate::modules::navigation::NavigationClientData; +use crate::modules::navigation; pub fn client_navigation(mut stream: TcpStream, mut buff_r: BufReader) { let stdout = stdout(); @@ -17,7 +17,7 @@ pub fn client_navigation(mut stream: TcpStream, mut buff_r: BufReader loop { let mut recv = String::new(); buff_r.read_line(&mut recv).unwrap(); - let navigation_data: NavigationClientData = serde_json::from_str(&recv).unwrap(); + let navigation_data: navigation::ClientData = serde_json::from_str(&recv).unwrap(); write!( stdout, diff --git a/src/client/refinery.rs b/src/client/refinery.rs index a977e04..99d4be7 100644 --- a/src/client/refinery.rs +++ b/src/client/refinery.rs @@ -7,7 +7,7 @@ use std::io::{stdout, Read, Write}; use std::io::{BufRead, BufReader}; use std::net::TcpStream; -use crate::modules::refinery::{RefineryClientData, RefineryStatus}; +use crate::modules::refinery; pub fn client_refinery(mut stream: TcpStream, mut buff_r: BufReader) { let stdout = stdout(); @@ -17,7 +17,7 @@ pub fn client_refinery(mut stream: TcpStream, mut buff_r: BufReader) loop { let mut recv = String::new(); buff_r.read_line(&mut recv).unwrap(); - let data: RefineryClientData = serde_json::from_str(&recv.replace("\n", "")).unwrap(); + let data: refinery::ClientData = serde_json::from_str(&recv.replace("\n", "")).unwrap(); write!(stdout, "{}", termion::clear::All).unwrap(); @@ -25,7 +25,7 @@ pub fn client_refinery(mut stream: TcpStream, mut buff_r: BufReader) if data.has_crude_minerals { match data.status { - RefineryStatus::None => { + refinery::Status::None => { write!(stdout, "{}Press R to begin refining.", clear).unwrap() } _ => write!(stdout, "{}Press R to stop refining.", clear).unwrap(), diff --git a/src/client/tractorbeam.rs b/src/client/tractorbeam.rs index 16508b5..74d912f 100644 --- a/src/client/tractorbeam.rs +++ b/src/client/tractorbeam.rs @@ -7,7 +7,7 @@ use std::io::{stdout, Read, Write}; use std::io::{BufRead, BufReader}; use std::net::TcpStream; -use crate::modules::tractorbeam::{TractorbeamClientData, TractorbeamStatus}; +use crate::modules::tractorbeam; pub fn client_tractorbeam(mut stream: TcpStream, mut buff_r: BufReader) { let stdout = stdout(); @@ -17,7 +17,7 @@ pub fn client_tractorbeam(mut stream: TcpStream, mut buff_r: BufReader write!( + tractorbeam::Status::None => write!( stdout, "{}Press o to pull, p to push, t to bring to 5m.", clear ) .unwrap(), - TractorbeamStatus::Push => write!( + tractorbeam::Status::Push => write!( stdout, "{}Press o to pull, p to stop pushing, t to bring to 5m.", clear ) .unwrap(), - TractorbeamStatus::Pull => write!( + tractorbeam::Status::Pull => write!( stdout, "{}Press o to stop pulling, p to push, t to bring to 5m.", clear ) .unwrap(), - TractorbeamStatus::Bring => write!( + tractorbeam::Status::Bring => write!( stdout, "{}Press o to pulling, p to push, t to stop bringing to 5m.", clear diff --git a/src/modules/construction.rs b/src/modules/construction.rs index ca4dd2d..0eec155 100644 --- a/src/modules/construction.rs +++ b/src/modules/construction.rs @@ -10,7 +10,7 @@ use crate::storage::Storage; #[derive(Serialize, Deserialize, Debug, Clone, Default)] pub struct Construction { - pub status: ConstructionStatus, + pub status: Status, construction: Option, time: u64, start: Option, @@ -19,7 +19,7 @@ pub struct Construction { impl Construction { pub fn new() -> Construction { Construction { - status: ConstructionStatus::None, + status: Status::None, construction: None, time: constants::SHIP_CONSTRUCTION_TIME, start: None, @@ -39,10 +39,10 @@ impl Construction { if let Some(timer) = self.start { if timer.elapsed().unwrap().as_secs() > self.time { self.start = Some(SystemTime::now()); - self.status = ConstructionStatus::Constructed; + self.status = Status::Constructed; } } - if self.status == ConstructionStatus::Constructed { + if self.status == Status::Constructed { storage .take_items(ItemType::Iron, constants::SHIP_CONSTRUCTION_IRON_COST) .unwrap(); @@ -59,7 +59,7 @@ impl Construction { } pub fn get_client_data(&self, storage: &Storage) -> String { - let client_data = ConstructionClientData { + let client_data = ClientData { has_enough: self.has_enough(storage), status: self.status.clone(), }; @@ -83,19 +83,19 @@ impl Construction { fn toggle(&mut self) { match self.status { - ConstructionStatus::None => self.on(), + Status::None => self.on(), _ => self.off(), }; } fn on(&mut self) { self.start = Some(SystemTime::now()); - self.status = ConstructionStatus::Constructing; + self.status = Status::Constructing; } fn off(&mut self) { self.start = None; - self.status = ConstructionStatus::None; + self.status = Status::None; } fn constructed(&mut self) { @@ -104,20 +104,20 @@ impl Construction { } #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct ConstructionClientData { - pub status: ConstructionStatus, +pub struct ClientData { + pub status: Status, pub has_enough: bool, } #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] -pub enum ConstructionStatus { +pub enum Status { None, Constructing, Constructed, } -impl Default for ConstructionStatus { +impl Default for Status { fn default() -> Self { - ConstructionStatus::None + Status::None } } diff --git a/src/modules/engines.rs b/src/modules/engines.rs index 63e1fcd..313346a 100644 --- a/src/modules/engines.rs +++ b/src/modules/engines.rs @@ -1,7 +1,7 @@ use crate::constants; use crate::mass::Mass; use crate::math::Vector; -use crate::modules::navigation::NavigationStatus; +use crate::modules::navigation; #[derive(Serialize, Deserialize, Debug, Clone, Default)] pub struct Engines { @@ -62,9 +62,9 @@ impl Engines { self.acceleration = acceleration; } - pub fn get_client_data(&self, status: NavigationStatus) -> String { - let client_data = EnginesClientData { - has_target: status == NavigationStatus::Targeted, + pub fn get_client_data(&self, status: navigation::Status) -> String { + let client_data = ClientData { + has_target: status == navigation::Status::Targeted, fuel: self.fuel, }; serde_json::to_string(&client_data).unwrap() + "\n" @@ -87,7 +87,7 @@ impl Engines { } #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct EnginesClientData { +pub struct ClientData { pub has_target: bool, pub fuel: f64, } diff --git a/src/modules/mining.rs b/src/modules/mining.rs index 8e5b001..816313e 100644 --- a/src/modules/mining.rs +++ b/src/modules/mining.rs @@ -10,7 +10,7 @@ use std::collections::HashMap; #[derive(Serialize, Deserialize, Debug, Clone, Default)] pub struct Mining { pub range: f64, - pub status: MiningStatus, + pub status: Status, time: u64, start: Option, } @@ -19,7 +19,7 @@ impl Mining { pub fn new() -> Mining { Mining { range: constants::SHIP_MINING_RANGE, - status: MiningStatus::None, + status: Status::None, time: constants::SHIP_MINING_TIME, start: None, } @@ -37,11 +37,11 @@ impl Mining { } if let Some(timer) = self.start { if timer.elapsed().unwrap().as_secs() > self.time { - self.status = MiningStatus::Mined; + self.status = Status::Mined; self.start = None; } } - if self.status == MiningStatus::Mined { + if self.status == Status::Mined { if let MassType::Astroid { ref mut resources, .. } = target.mass_type @@ -89,7 +89,7 @@ impl Mining { None => false, }; - let client_data = MiningClientData { + let client_data = ClientData { has_astroid_target, astroid_has_minerals, is_within_range, @@ -102,45 +102,45 @@ impl Mining { fn toggle(&mut self) { match self.status { - MiningStatus::None => self.on(), + Status::None => self.on(), _ => self.off(), }; } fn on(&mut self) { self.start = Some(SystemTime::now()); - self.status = MiningStatus::Mining; + self.status = Status::Mining; } fn off(&mut self) { self.start = None; - self.status = MiningStatus::None; + self.status = Status::None; } fn mined(&mut self) { - self.status = MiningStatus::Mining; + self.status = Status::Mining; self.start = Some(SystemTime::now()); } } #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct MiningClientData { +pub struct ClientData { pub has_astroid_target: bool, pub astroid_has_minerals: bool, pub is_within_range: bool, - pub status: MiningStatus, + pub status: Status, pub range: f64, } #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] -pub enum MiningStatus { +pub enum Status { None, Mining, Mined, } -impl Default for MiningStatus { +impl Default for Status { fn default() -> Self { - MiningStatus::None + Status::None } } diff --git a/src/modules/navigation.rs b/src/modules/navigation.rs index b15beef..c931338 100644 --- a/src/modules/navigation.rs +++ b/src/modules/navigation.rs @@ -8,7 +8,7 @@ use crate::math::Vector; #[derive(Serialize, Deserialize, Debug, Clone, Default)] pub struct Navigation { pub range: f64, - pub status: NavigationStatus, + pub status: Status, pub target_name: Option, time: u64, start: Option, @@ -19,7 +19,7 @@ impl Navigation { Navigation { target_name: None, range: constants::SHIP_NAVIGATION_RANGE, - status: NavigationStatus::None, + status: Status::None, time: constants::SHIP_NAVIGATION_TIME, start: None, } @@ -29,7 +29,7 @@ impl Navigation { self.verify_target(ship_position, masses); if let Some(timer) = self.start { if timer.elapsed().unwrap().as_secs() > self.time { - self.status = NavigationStatus::Targeted; + self.status = Status::Targeted; self.start = None; } } @@ -38,13 +38,13 @@ impl Navigation { pub fn give_received_data(&mut self, recv: String) { if !recv.is_empty() { self.start = Some(SystemTime::now()); - self.status = NavigationStatus::Targeting; + self.status = Status::Targeting; self.target_name = Some(recv); } } pub fn get_client_data(&self, ship_position: Vector, masses: &HashMap) -> String { - let client_data = NavigationClientData { + let client_data = ClientData { ship_position: ship_position.clone(), status: self.status.clone(), target_name: self.target_name.clone(), @@ -63,29 +63,29 @@ impl Navigation { let target = masses.get(&name).unwrap(); if target.position.distance_from(ship_position) > self.range { self.target_name = None; - self.status = NavigationStatus::None; + self.status = Status::None; } } } } #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct NavigationClientData { +pub struct ClientData { pub ship_position: Vector, pub available_targets: Vec<(String, Vector)>, - pub status: NavigationStatus, + pub status: Status, pub target_name: Option, } #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] -pub enum NavigationStatus { +pub enum Status { None, Targeting, Targeted, } -impl Default for NavigationStatus { +impl Default for Status { fn default() -> Self { - NavigationStatus::None + Status::None } } diff --git a/src/modules/refinery.rs b/src/modules/refinery.rs index a0a401b..0e5e125 100644 --- a/src/modules/refinery.rs +++ b/src/modules/refinery.rs @@ -8,7 +8,7 @@ use crate::storage::Storage; pub struct Refinery { time: u64, start: Option, - pub status: RefineryStatus, + pub status: Status, } impl Refinery { @@ -16,7 +16,7 @@ impl Refinery { Refinery { time: constants::SHIP_REFINERY_TIME, start: None, - status: RefineryStatus::None, + status: Status::None, } } @@ -26,11 +26,11 @@ impl Refinery { } if let Some(timer) = self.start { if timer.elapsed().unwrap().as_secs() > self.time { - self.status = RefineryStatus::Refined; + self.status = Status::Refined; self.start = None } } - if self.status == RefineryStatus::Refined { + if self.status == Status::Refined { storage.take_item(ItemType::CrudeMinerals); storage.give_item(Item::new(ItemType::Iron)); storage.give_item(Item::new(ItemType::Hydrogen)); @@ -39,7 +39,7 @@ impl Refinery { } pub fn get_client_data(&self, storage: &Storage) -> String { - let client_data = RefineryClientData { + let client_data = ClientData { has_crude_minerals: self.has_crude_minerals(storage), status: self.status.clone(), }; @@ -62,42 +62,42 @@ impl Refinery { fn toggle(&mut self) { match self.status { - RefineryStatus::None => self.on(), + Status::None => self.on(), _ => self.off(), }; } fn on(&mut self) { self.start = Some(SystemTime::now()); - self.status = RefineryStatus::Refining; + self.status = Status::Refining; } fn off(&mut self) { self.start = None; - self.status = RefineryStatus::None; + self.status = Status::None; } fn taken(&mut self) { - self.status = RefineryStatus::Refining; + self.status = Status::Refining; self.start = Some(SystemTime::now()); } } #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct RefineryClientData { +pub struct ClientData { pub has_crude_minerals: bool, - pub status: RefineryStatus, + pub status: Status, } #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] -pub enum RefineryStatus { +pub enum Status { None, Refining, Refined, } -impl Default for RefineryStatus { +impl Default for Status { fn default() -> Self { - RefineryStatus::None + Status::None } } diff --git a/src/modules/tractorbeam.rs b/src/modules/tractorbeam.rs index 3bbb32a..4f91292 100644 --- a/src/modules/tractorbeam.rs +++ b/src/modules/tractorbeam.rs @@ -4,7 +4,7 @@ use crate::math::Vector; #[derive(Serialize, Deserialize, Debug, Clone, Default)] pub struct Tractorbeam { - pub status: TractorbeamStatus, + pub status: Status, strength: f64, desired_distance: Option, } @@ -12,7 +12,7 @@ pub struct Tractorbeam { impl Tractorbeam { pub fn new() -> Tractorbeam { Tractorbeam { - status: TractorbeamStatus::None, + status: Status::None, strength: constants::SHIP_TRACTORBEAM_STRENGTH, desired_distance: None, } @@ -21,7 +21,7 @@ impl Tractorbeam { pub fn process(&mut self) {} pub fn get_client_data(&self, target: Option<&Mass>) -> String { - let client_data = TractorbeamClientData { + let client_data = ClientData { has_target: target.is_some(), status: self.status.clone(), }; @@ -41,9 +41,9 @@ impl Tractorbeam { pub fn get_acceleration(&self, ship_position: Vector, target_position: Vector) -> Vector { let acceleration = ship_position.clone() - target_position.clone(); match self.status { - TractorbeamStatus::Push => acceleration.unitize() * -0.05, - TractorbeamStatus::Pull => acceleration.unitize() * 0.05, - TractorbeamStatus::Bring => match self.desired_distance { + Status::Push => acceleration.unitize() * -0.05, + Status::Pull => acceleration.unitize() * 0.05, + Status::Bring => match self.desired_distance { Some(desired_distance) => { if desired_distance > ship_position.distance_from(target_position) { acceleration.unitize() * -0.05 @@ -59,55 +59,55 @@ impl Tractorbeam { } None => Vector::default(), }, - TractorbeamStatus::None => Vector::default(), + Status::None => Vector::default(), } } fn toggle_pull(&mut self) { self.status = match self.status { - TractorbeamStatus::None => TractorbeamStatus::Pull, - TractorbeamStatus::Push => TractorbeamStatus::Pull, - TractorbeamStatus::Bring => TractorbeamStatus::Pull, - TractorbeamStatus::Pull => TractorbeamStatus::None, + Status::None => Status::Pull, + Status::Push => Status::Pull, + Status::Bring => Status::Pull, + Status::Pull => Status::None, } } fn toggle_push(&mut self) { self.status = match self.status { - TractorbeamStatus::None => TractorbeamStatus::Push, - TractorbeamStatus::Pull => TractorbeamStatus::Push, - TractorbeamStatus::Bring => TractorbeamStatus::Push, - TractorbeamStatus::Push => TractorbeamStatus::None, + Status::None => Status::Push, + Status::Pull => Status::Push, + Status::Bring => Status::Push, + Status::Push => Status::None, } } fn toggle_bring(&mut self, desired_distance: f64) { self.desired_distance = Some(desired_distance); self.status = match self.status { - TractorbeamStatus::None => TractorbeamStatus::Bring, - TractorbeamStatus::Pull => TractorbeamStatus::Bring, - TractorbeamStatus::Push => TractorbeamStatus::Bring, - TractorbeamStatus::Bring => TractorbeamStatus::None, + Status::None => Status::Bring, + Status::Pull => Status::Bring, + Status::Push => Status::Bring, + Status::Bring => Status::None, } } } #[derive(Serialize, Deserialize, Debug, Clone)] -pub struct TractorbeamClientData { +pub struct ClientData { pub has_target: bool, - pub status: TractorbeamStatus, + pub status: Status, } #[derive(Serialize, Deserialize, Debug, Clone)] -pub enum TractorbeamStatus { +pub enum Status { None, Push, Pull, Bring, } -impl Default for TractorbeamStatus { +impl Default for Status { fn default() -> Self { - TractorbeamStatus::None + Status::None } } -- cgit v1.2.3