diff --git a/auth/src/common/steam_utils.rs b/auth/src/common/steam_utils.rs index bea8079..1f8ea31 100644 --- a/auth/src/common/steam_utils.rs +++ b/auth/src/common/steam_utils.rs @@ -24,7 +24,7 @@ fn get_steam_id_from_ticket_hex(hex_ticket: &str) -> Result u64 { - get_u64_with_offset(&ticket, 12 /* also at 64 ??? */) // should be 76600000000000000 > number > 76500000000000000 + get_u64_with_offset(ticket, 12 /* also at 64 ??? */) // should be 76600000000000000 > number > 76500000000000000 } #[cfg(all(feature = "steam", feature = "cardlife"))] @@ -61,7 +61,7 @@ pub fn authenticate_steam_ticket(hex_ticket: &str) -> Result { get_steam_id_from_ticket_hex(hex_ticket) .map_err(|e| { log::error!("Failed to parse steamId: {}", e); - () + }) } diff --git a/cdn/src/robocraft/factory/arc.rs b/cdn/src/robocraft/factory/arc.rs index ea80585..ed6baf3 100644 --- a/cdn/src/robocraft/factory/arc.rs +++ b/cdn/src/robocraft/factory/arc.rs @@ -25,26 +25,26 @@ async fn try_find_file(zip_path: std::path::PathBuf, id: u32) -> HttpResponse { match e { zip::result::ZipError::Io(e) => { actix_web::HttpResponseBuilder::new(actix_web::http::StatusCode::INTERNAL_SERVER_ERROR) - .body(format!("zip io error: {}", e.to_string())) + .body(format!("zip io error: {}", e)) }, zip::result::ZipError::InvalidArchive(e) => { actix_web::HttpResponseBuilder::new(actix_web::http::StatusCode::INTERNAL_SERVER_ERROR) - .body(format!("invalid zip file: {}", e.to_string())) + .body(format!("invalid zip file: {}", e)) }, zip::result::ZipError::UnsupportedArchive(e) => { actix_web::HttpResponseBuilder::new(actix_web::http::StatusCode::INTERNAL_SERVER_ERROR) - .body(format!("unsupported zip file: {}", e.to_string())) + .body(format!("unsupported zip file: {}", e)) }, zip::result::ZipError::FileNotFound => { actix_web::HttpResponseBuilder::new(actix_web::http::StatusCode::NOT_FOUND) - .body(format!("file not found in zip archive")) + .body("file not found in zip archive".to_string()) }, zip::result::ZipError::InvalidPassword => { actix_web::HttpResponseBuilder::new(actix_web::http::StatusCode::INTERNAL_SERVER_ERROR) - .body(format!("invalid zip password")) + .body("invalid zip password".to_string()) }, _ => actix_web::HttpResponseBuilder::new(actix_web::http::StatusCode::INTERNAL_SERVER_ERROR) - .body(format!("unknown zip error")), + .body("unknown zip error".to_string()), } } } diff --git a/cdn/src/robocraft/mod.rs b/cdn/src/robocraft/mod.rs index 2fc499a..3c968e2 100644 --- a/cdn/src/robocraft/mod.rs +++ b/cdn/src/robocraft/mod.rs @@ -8,4 +8,4 @@ pub mod favicon; mod internal_auth; pub use internal_auth::{IntercomAuth, IntercomOpError}; -pub(self) const DEFAULT_IMAGE: &str = "default.jpg"; + const DEFAULT_IMAGE: &str = "default.jpg"; diff --git a/clippy.sh b/clippy.sh new file mode 100755 index 0000000..11241e7 --- /dev/null +++ b/clippy.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +cargo clippy --all -- \ + -A clippy::collapsible_if \ + -A clippy::type_complexity \ + -A clippy::wrong_self_convention diff --git a/polariton_auth/src/encryption.rs b/polariton_auth/src/encryption.rs index 96a62fa..197e5aa 100644 --- a/polariton_auth/src/encryption.rs +++ b/polariton_auth/src/encryption.rs @@ -26,18 +26,18 @@ pub fn generate_encryption_details(client_pub_key: &[u8]) -> Keys { let big_0 = BigInt::from(0); let prime_root = BigInt::from(PRIME_ROOT); let my_prime = BigInt::from_bytes_be(num::bigint::Sign::Plus, PRIME_768); - log::debug!("Generating keys for client pub key {}", client_num.to_string()); + log::debug!("Generating keys for client pub key {}", client_num); let mut rng = rand::rng(); let mut bytes = rng.random::<[u8; SECRET_LEN]>(); let mut my_secret = BigInt::from_bytes_be(num::bigint::Sign::Plus, &bytes); while my_secret >= &my_prime - 1 || my_secret == big_0 { bytes = rng.random::<[u8; SECRET_LEN]>(); my_secret = BigInt::from_bytes_be(num::bigint::Sign::Plus, &bytes); - log::debug!("Generated secret {} (prime to beat: {})", my_secret.to_string(), my_prime.to_string()); + log::debug!("Generated secret {} (prime to beat: {})", my_secret, my_prime); } let my_pub_key = prime_root.modpow(&my_secret, &my_prime); let shared_key = client_num.modpow(&my_secret, &my_prime); - log::debug!("Generated shared key {} and pub key {}", shared_key.to_string(), my_pub_key.to_string()); + log::debug!("Generated shared key {} and pub key {}", shared_key, my_pub_key); let shared_key = shared_key.to_bytes_be().1; let enc_key: Vec = ring::digest::digest(&ring::digest::SHA256, &shared_key).as_ref().into(); log::debug!("Encryption key is {:?}", enc_key.as_slice()); diff --git a/polariton_auth/src/handshake.rs b/polariton_auth/src/handshake.rs index 1eb8868..faade7b 100644 --- a/polariton_auth/src/handshake.rs +++ b/polariton_auth/src/handshake.rs @@ -36,7 +36,7 @@ impl <'a> Handshake> { if let Message::Standard(conn) = &packet.message { if let Data::InitStart(info) = &conn.data { if info.app_id != self.state.app_id { - let err = ConnectError::WrongAppId { got: &info.app_id, expected: &self.state.app_id }; + let err = ConnectError::WrongAppId { got: &info.app_id, expected: self.state.app_id }; return Err(HandshakeAnd { handshake: self, extra: err, @@ -75,7 +75,7 @@ pub enum EncryptError { impl Handshake { const PUBLIC_KEY_PARAM_KEY: u8 = 1; - pub fn encrypt<'a>(self, packet: &'a Packet) -> Result, HandshakeAnd> { + pub fn encrypt(self, packet: &Packet) -> Result, HandshakeAnd> { if let Packet::Packet(packet) = &packet { if let Message::Standard(conn) = &packet.message { if let Data::InternalOpReq(req) = &conn.data { @@ -153,7 +153,7 @@ impl , E> Handshake> { const AUTH_REQUEST_CODE: u8 = 230; const USER_ID_KEY: u8 = 225; const NICKNAME_KEY: u8 = 225; - pub fn authenticate<'a>(mut self, packet: &'a Packet, serdes_ctx: &polariton::packet::SerdesContext<(), polariton::serdes::NoCustomSerdes>) -> Result, AuthError>> { + pub fn authenticate(mut self, packet: &Packet, serdes_ctx: &polariton::packet::SerdesContext<(), polariton::serdes::NoCustomSerdes>) -> Result, AuthError>> { if let Packet::Packet(packet) = &packet { if let Message::Standard(conn) = &packet.message { if let Data::OpReq(req) = &conn.data { diff --git a/rc_auth/src/robocraft/mod.rs b/rc_auth/src/robocraft/mod.rs index ff478f7..fe6d800 100644 --- a/rc_auth/src/robocraft/mod.rs +++ b/rc_auth/src/robocraft/mod.rs @@ -20,7 +20,7 @@ impl RcConfig { } } -pub(self) struct ErrorTy { + struct ErrorTy { json: libfj::robocraft::ErrorInfo, } diff --git a/rc_auth/src/robocraft/registration.rs b/rc_auth/src/robocraft/registration.rs index 57acfd8..2a0006b 100644 --- a/rc_auth/src/robocraft/registration.rs +++ b/rc_auth/src/robocraft/registration.rs @@ -78,13 +78,13 @@ fn registration_err(form: RegisterForm, error: String , renderer: &handlebars::H pub async fn form_submit(form: Form, config: Data, handlebars_ref: Data>) -> Result { // password confirmation validation if form.password != form.password_c { - return Ok(registration_err(form.into_inner(), "Passwords do not match".to_owned(), &*handlebars_ref)); + return Ok(registration_err(form.into_inner(), "Passwords do not match".to_owned(), &handlebars_ref)); } if form.password.len() < 8 { - return Ok(registration_err(form.into_inner(), "Password too short (minimum 8 characters)".to_owned(), &*handlebars_ref)); + return Ok(registration_err(form.into_inner(), "Password too short (minimum 8 characters)".to_owned(), &handlebars_ref)); } if form.password.len() > 128 { - return Ok(registration_err(form.into_inner(), "Password too long (maximum 128 characters)".to_owned(), &*handlebars_ref)); + return Ok(registration_err(form.into_inner(), "Password too long (maximum 128 characters)".to_owned(), &handlebars_ref)); } // email validation @@ -94,7 +94,7 @@ pub async fn form_submit(form: Form, config: Data actual_email = None; } else { if !email.contains('@') { - return Ok(registration_err(form.into_inner(), "Email must contain @".to_owned(), &*handlebars_ref)); + return Ok(registration_err(form.into_inner(), "Email must contain @".to_owned(), &handlebars_ref)); } let email_exists = config.account_provider.user_exists(oj_rc_core::persist::user::UserId::Email(email.to_owned())) .await @@ -103,7 +103,7 @@ pub async fn form_submit(form: Form, config: Data actix_web::error::ErrorInternalServerError(e) })?; if email_exists { - return Ok(registration_err(form.into_inner(), "Email already registered".to_owned(), &*handlebars_ref)); + return Ok(registration_err(form.into_inner(), "Email already registered".to_owned(), &handlebars_ref)); } actual_email = Some(email.to_owned()); } @@ -119,10 +119,10 @@ pub async fn form_submit(form: Form, config: Data } else { let steam_id = match steam_id.parse() { Ok(id) => id, - Err(_e) => return Ok(registration_err(form.into_inner(), "Invalid SteamID (not an integer)".to_owned(), &*handlebars_ref)), + Err(_e) => return Ok(registration_err(form.into_inner(), "Invalid SteamID (not an integer)".to_owned(), &handlebars_ref)), }; - if steam_id >= 7656120_0000000000 || steam_id < 7656119_0000000000 { - return Ok(registration_err(form.into_inner(), "Invalid SteamID (should be like 7656119XXXXXXXXXX)".to_owned(), &*handlebars_ref)); + if !(7656119_0000000000..7656120_0000000000).contains(&steam_id) { + return Ok(registration_err(form.into_inner(), "Invalid SteamID (should be like 7656119XXXXXXXXXX)".to_owned(), &handlebars_ref)); } let steam_exists = config.account_provider.user_exists(oj_rc_core::persist::user::UserId::SteamId(steam_id)) .await @@ -131,7 +131,7 @@ pub async fn form_submit(form: Form, config: Data actix_web::error::ErrorInternalServerError(e) })?; if steam_exists { - return Ok(registration_err(form.into_inner(), "SteamID already registered".to_owned(), &*handlebars_ref)); + return Ok(registration_err(form.into_inner(), "SteamID already registered".to_owned(), &handlebars_ref)); } actual_steam_id = Some(steam_id); } @@ -141,13 +141,13 @@ pub async fn form_submit(form: Form, config: Data // username validation if form.display_name.len() < 4 { - return Ok(registration_err(form.into_inner(), "Username too short (minimum 4 characters)".to_owned(), &*handlebars_ref)); + return Ok(registration_err(form.into_inner(), "Username too short (minimum 4 characters)".to_owned(), &handlebars_ref)); } if form.display_name.len() > 32 { - return Ok(registration_err(form.into_inner(), "Username too long (maximum 32 characters)".to_owned(), &*handlebars_ref)); + return Ok(registration_err(form.into_inner(), "Username too long (maximum 32 characters)".to_owned(), &handlebars_ref)); } if !all_valid_chars(&form.display_name.to_lowercase()) { - return Ok(registration_err(form.into_inner(), "Invalid username (only alphanumerics and _ allowed)".to_owned(), &*handlebars_ref)); + return Ok(registration_err(form.into_inner(), "Invalid username (only alphanumerics and _ allowed)".to_owned(), &handlebars_ref)); } let username_exists = config.account_provider.user_exists(oj_rc_core::persist::user::UserId::Username(form.display_name.to_owned())) .await @@ -156,7 +156,7 @@ pub async fn form_submit(form: Form, config: Data actix_web::error::ErrorInternalServerError(e) })?; if username_exists { - return Ok(registration_err(form.into_inner(), "Username already registered".to_owned(), &*handlebars_ref)); + return Ok(registration_err(form.into_inner(), "Username already registered".to_owned(), &handlebars_ref)); } let user_id = match config.account_provider.register(oj_rc_core::persist::user::RegistrationInfo { @@ -167,7 +167,7 @@ pub async fn form_submit(form: Form, config: Data }).await { Ok(id) => id, Err(e) => { - return Ok(registration_err(form.into_inner(), format!("Registration failed: {}", e), &*handlebars_ref)); + return Ok(registration_err(form.into_inner(), format!("Registration failed: {}", e), &handlebars_ref)); } }; @@ -187,7 +187,7 @@ pub async fn form_load(handlebars_ref: Data>) -> Html password_c: "".to_owned(), email: None, steam_id: None, - }, &*handlebars_ref) + }, &handlebars_ref) } #[get("/robocraft/favicon")] diff --git a/rc_auth/src/robocraft/steam.rs b/rc_auth/src/robocraft/steam.rs index c4bdcfa..c76937b 100644 --- a/rc_auth/src/robocraft/steam.rs +++ b/rc_auth/src/robocraft/steam.rs @@ -5,7 +5,7 @@ fn authenticate_steam_ticket(hex_ticket: &str) -> Result { get_steam_id_from_ticket_hex(hex_ticket) .map_err(|e| { log::error!("Failed to parse steamId: {}", e); - () + }) } @@ -19,7 +19,7 @@ fn get_steam_id_from_ticket_hex(hex_ticket: &str) -> Result u64 { - get_u64_with_offset(&ticket, 12 /* also at 64 ??? */) // should be 76600000000000000 > number > 76500000000000000 + get_u64_with_offset(ticket, 12 /* also at 64 ??? */) // should be 76600000000000000 > number > 76500000000000000 } fn get_u64_with_offset(arr: &[u8], start: usize) -> u64 { diff --git a/rc_chat_room/src/events/chat_message.rs b/rc_chat_room/src/events/chat_message.rs index 42daa58..a9e4c4b 100644 --- a/rc_chat_room/src/events/chat_message.rs +++ b/rc_chat_room/src/events/chat_message.rs @@ -34,7 +34,7 @@ impl polariton_server::events::IntoEvent for PublicMessag fn into_event(self) -> polariton::operation::Event { polariton::operation::Event { code: Self::CODE, - params: self.as_event_params().into(), + params: self.as_event_params(), } } } @@ -47,7 +47,7 @@ impl polariton_server::events::IntoEvent for &PublicMessa fn into_event(self) -> polariton::operation::Event { polariton::operation::Event { code: PublicMessage::CODE, - params: self.as_event_params().into(), + params: self.as_event_params(), } } } @@ -84,7 +84,7 @@ impl polariton_server::events::IntoEvent for PrivateMessa fn into_event(self) -> polariton::operation::Event { polariton::operation::Event { code: Self::CODE, - params: self.as_event_params().into(), + params: self.as_event_params(), } } } @@ -97,7 +97,7 @@ impl polariton_server::events::IntoEvent for &PrivateMess fn into_event(self) -> polariton::operation::Event { polariton::operation::Event { code: PrivateMessage::CODE, - params: self.as_event_params().into(), + params: self.as_event_params(), } } } diff --git a/rc_chat_room/src/events/player_update.rs b/rc_chat_room/src/events/player_update.rs index 3660cd6..35cd71b 100644 --- a/rc_chat_room/src/events/player_update.rs +++ b/rc_chat_room/src/events/player_update.rs @@ -25,7 +25,7 @@ impl polariton_server::events::IntoEvent for PlayerUpdate fn into_event(self) -> polariton::operation::Event { polariton::operation::Event { code: Self::CODE, - params: self.as_event_params().into(), + params: self.as_event_params(), } } } @@ -38,7 +38,7 @@ impl polariton_server::events::IntoEvent for &PlayerUpdat fn into_event(self) -> polariton::operation::Event { polariton::operation::Event { code: PlayerUpdated::CODE, - params: self.as_event_params().into(), + params: self.as_event_params(), } } } diff --git a/rc_chat_room/src/events/room_join.rs b/rc_chat_room/src/events/room_join.rs index 0e89821..2f4e609 100644 --- a/rc_chat_room/src/events/room_join.rs +++ b/rc_chat_room/src/events/room_join.rs @@ -34,7 +34,7 @@ impl polariton_server::events::IntoEvent for RoomJoined { fn into_event(self) -> polariton::operation::Event { polariton::operation::Event { code: Self::CODE, - params: self.as_event_params().into(), + params: self.as_event_params(), } } } @@ -47,7 +47,7 @@ impl polariton_server::events::IntoEvent for &RoomJoined fn into_event(self) -> polariton::operation::Event { polariton::operation::Event { code: RoomJoined::CODE, - params: self.as_event_params().into(), + params: self.as_event_params(), } } } diff --git a/rc_chat_room/src/op_handler.rs b/rc_chat_room/src/op_handler.rs index ce926bb..990be1d 100644 --- a/rc_chat_room/src/op_handler.rs +++ b/rc_chat_room/src/op_handler.rs @@ -11,8 +11,8 @@ pub struct SimpleChatFunc, &U, &crate::state::ChatImpl) -> Result, i16>) + Send + Sync> SimpleChatFunc { pub fn new(f: F, chat: crate::state::ChatImpl) -> Self { Self { - _user_ty: std::marker::PhantomData::default(), - _custom_ty: std::marker::PhantomData::default(), + _user_ty: std::marker::PhantomData, + _custom_ty: std::marker::PhantomData, chat, func: f, } diff --git a/rc_chat_room/src/operations/send_message.rs b/rc_chat_room/src/operations/send_message.rs index b0fb514..cb8d6f4 100644 --- a/rc_chat_room/src/operations/send_message.rs +++ b/rc_chat_room/src/operations/send_message.rs @@ -24,7 +24,7 @@ impl SimpleOperation for PublicMessageSender { if let Some(Typed::Str(channel_name)) = params.remove(&CHANNEL_NAME_PARAM_KEY) { if let Some(Typed::Str(message_text)) = params.remove(&MESSAGE_TEXT_PARAM_KEY) { let user = user.user()?; - if message_text.string.bytes().len() > MAX_MESSAGE_LEN { + if message_text.string.len() > MAX_MESSAGE_LEN { log::warn!("Rejecting too long chat message from {}", user.public_id()); return Err((oj_rc_core::data::error_codes::ChatErrorCodes::Flood as i16).into()) } @@ -65,7 +65,7 @@ impl SimpleOperation for PrivateMessageSender { if let Some(Typed::Str(username)) = params.remove(&USERNAME_PARAM_KEY) { if let Some(Typed::Str(message_text)) = params.remove(&MESSAGE_TEXT_PARAM_KEY) { let user = user.user()?; - if message_text.string.bytes().len() > MAX_MESSAGE_LEN { + if message_text.string.len() > MAX_MESSAGE_LEN { log::warn!("Rejecting too long chat message from {}", user.public_id()); return Err((oj_rc_core::data::error_codes::ChatErrorCodes::Flood as i16).into()) } diff --git a/rc_chat_room/src/state/chat/config.rs b/rc_chat_room/src/state/chat/config.rs index 25db472..818cf4f 100644 --- a/rc_chat_room/src/state/chat/config.rs +++ b/rc_chat_room/src/state/chat/config.rs @@ -36,7 +36,7 @@ impl ChatSystemConfig { return result; } } - return "Invalid command".to_owned() + "Invalid command".to_owned() } pub fn is_command_channel(&self, channel: &str) -> bool { @@ -66,11 +66,7 @@ impl ChatCommand { } fn perform_if_match(&self, text: &str, ctx: CommandContext) -> Option { - if let Some(cap) = self.regex.captures(text) { - Some(self.op.perform_command(cap, ctx)) - } else { - None - } + self.regex.captures(text).map(|cap| self.op.perform_command(cap, ctx)) } } @@ -122,7 +118,7 @@ impl BuiltIn { } }, Self::TotalUsers => { - format!("User count is not supported") + "User count is not supported".to_string() }, } } diff --git a/rc_chat_room/src/state/chat/mod.rs b/rc_chat_room/src/state/chat/mod.rs index 0e5cd7c..17bab03 100644 --- a/rc_chat_room/src/state/chat/mod.rs +++ b/rc_chat_room/src/state/chat/mod.rs @@ -1,3 +1,4 @@ +#[allow(clippy::module_inception)] mod chat; pub use chat::{ChatSystem, ChatProvider}; diff --git a/rc_core/src/cubes/locations_of.rs b/rc_core/src/cubes/locations_of.rs index 797cbda..09e1163 100644 --- a/rc_core/src/cubes/locations_of.rs +++ b/rc_core/src/cubes/locations_of.rs @@ -45,7 +45,7 @@ impl CubeLocationsParser { pub fn locations_of_by_distance_to_first(&self, r: &mut dyn std::io::Read, locations_of_id: u32, distance_to_id: u32) -> Vec { match super::parser::Cube::parse_list(r) { Ok(cubes) => { - if let Some(target) = cubes.iter().filter(|x| x.id == distance_to_id).next() { + if let Some(target) = cubes.iter().find(|x| x.id == distance_to_id) { let target_x = target.x as f32; let target_y = target.y as f32; let target_z = target.z as f32; diff --git a/rc_core/src/cubes/mod.rs b/rc_core/src/cubes/mod.rs index d11b66a..9be8683 100644 --- a/rc_core/src/cubes/mod.rs +++ b/rc_core/src/cubes/mod.rs @@ -1,4 +1,4 @@ -pub(self) mod parser; + mod parser; mod weapon_list; pub use weapon_list::WeaponListParser; diff --git a/rc_core/src/data/channel.rs b/rc_core/src/data/channel.rs index 30f76a0..7a4ed41 100644 --- a/rc_core/src/data/channel.rs +++ b/rc_core/src/data/channel.rs @@ -31,7 +31,7 @@ impl ChatChannelMember { pub fn as_transmissible(&self) -> Typed { Typed::HashMap(vec![ (Typed::Str("name".into()), Typed::Str(self.name.clone().into())), - (Typed::Str("useCustomAvatar".into()), Typed::Bool(self.use_custom_avatar.into())), + (Typed::Str("useCustomAvatar".into()), Typed::Bool(self.use_custom_avatar)), (Typed::Str("state".into()), Typed::Int(self.state as _)), if self.use_custom_avatar { (Typed::Str("customAvatar".into()), Typed::Bytes(self.custom_avatar.clone().into())) diff --git a/rc_core/src/data/crf.rs b/rc_core/src/data/crf.rs index ca3e229..7eb9e96 100644 --- a/rc_core/src/data/crf.rs +++ b/rc_core/src/data/crf.rs @@ -1,5 +1,3 @@ -use std::i64; - #[allow(dead_code)] pub struct ShopItemListFilters { pub page: u32, diff --git a/rc_core/src/data/cube_list.rs b/rc_core/src/data/cube_list.rs index 01d491f..6f3d067 100644 --- a/rc_core/src/data/cube_list.rs +++ b/rc_core/src/data/cube_list.rs @@ -30,13 +30,13 @@ impl CubeInfo { (Typed::Str("cpuRating".into()), Typed::Int(self.cpu as i32)), (Typed::Str("health".into()), Typed::Int(self.health as i32)), (Typed::Str("healthBoost".into()), Typed::Float(self.health_boost)), - (Typed::Str("GreyOutInTutorial".into()), Typed::Bool(self.grey_out_in_tutorial.into())), + (Typed::Str("GreyOutInTutorial".into()), Typed::Bool(self.grey_out_in_tutorial)), (Typed::Str("buildVisibility".into()), Typed::Str(self.visibility.as_str().into())), - (Typed::Str("isIndestructible".into()), Typed::Bool(self.indestructible.into())), + (Typed::Str("isIndestructible".into()), Typed::Bool(self.indestructible)), (Typed::Str("ItemCategory".into()), Typed::Int(self.category as i32)), (Typed::Str("PlacementFaces".into()), Typed::Int(self.placements as i32)), - (Typed::Str("protoniumCrystal".into()), Typed::Bool(self.protonium.into())), - (Typed::Str("UnlockedByLeague".into()), Typed::Bool(self.unlocked_by_league.into())), + (Typed::Str("protoniumCrystal".into()), Typed::Bool(self.protonium)), + (Typed::Str("UnlockedByLeague".into()), Typed::Bool(self.unlocked_by_league)), (Typed::Str("LeagueUnlockIndex".into()), Typed::Int(self.league_unlock_index)), (Typed::Str("DisplayStats".into()), { let items: Vec<(Typed, Typed)> = self.stats.iter().map(|(key, val)| (Typed::::Str(key.into()), val.to_owned())).collect(); @@ -51,9 +51,9 @@ impl CubeInfo { (Typed::Str("ItemSize".into()), Typed::Int(self.size as i32)), (Typed::Str("ItemType".into()), Typed::Str(self.type_.as_str().into())), (Typed::Str("robotRanking".into()), Typed::Int(self.ranking)), - (Typed::Str("isCosmetic".into()), Typed::Bool(self.cosmetic.into())), + (Typed::Str("isCosmetic".into()), Typed::Bool(self.cosmetic)), (Typed::Str("variantOf".into()), Typed::Str(self.variant_of.clone().into())), - (Typed::Str("ignoreInWeaponsList".into()), Typed::Bool(self.ignore_in_weapon_list.into())), // optional + (Typed::Str("ignoreInWeaponsList".into()), Typed::Bool(self.ignore_in_weapon_list)), // optional ].into()) } diff --git a/rc_core/src/data/garage_bay.rs b/rc_core/src/data/garage_bay.rs index 34ff165..a9dbc71 100644 --- a/rc_core/src/data/garage_bay.rs +++ b/rc_core/src/data/garage_bay.rs @@ -29,10 +29,10 @@ impl GarageSlotInfo { (Typed::Str("name".into()), Typed::Str(self.name.clone().into())), (Typed::Str("numberCubes".into()), Typed::Int(self.cubes as i32)), (Typed::Str("crfId".into()), Typed::Int(self.crf_id as i32)), - (Typed::Str("wasRated".into()), Typed::Bool(self.was_rated.into())), + (Typed::Str("wasRated".into()), Typed::Bool(self.was_rated)), (Typed::Str("movementCategories".into()), Typed::Arr(Arr { ty: TypePrefix::Int, // int - items: self.movement_categories.iter().map(|x| Typed::Int(x.but_bigger() as i32)).collect(), + items: self.movement_categories.iter().map(|x| Typed::Int(x.but_bigger())).collect(), })), (Typed::Str("uniqueId1".into()), Typed::Int(self.uuid.0 as i32)), (Typed::Str("uniqueId2".into()), Typed::Int(self.uuid.1 as i32)), @@ -41,7 +41,7 @@ impl GarageSlotInfo { (Typed::Str("totalCosmeticCPU".into()), Typed::Int(self.total_cosmetic_cpu as i32)), (Typed::Str("totalRobotRanking".into()), Typed::Int(self.total_robot_ranking as i32)), (Typed::Str("bayCpu".into()), Typed::Int(self.bay_cpu as i32)), - (Typed::Str("tutorialRobot".into()), Typed::Bool(self.tutorial_robot.into())), + (Typed::Str("tutorialRobot".into()), Typed::Bool(self.tutorial_robot)), (Typed::Str("starterRobotIndex".into()), Typed::Int(self.starter_robot_index)), (Typed::Str("controlType".into()), Typed::Int(self.control_type as i32)), (Typed::Str("controlOptions".into()), self.control_options.as_transmissible()), @@ -86,9 +86,9 @@ impl ControlOptions { Typed::Arr(Arr { ty: TypePrefix::Bool, // bool items: vec![ - Typed::Bool(self.vertical_strafing.into()), - Typed::Bool(self.sideways_driving.into()), - Typed::Bool(self.tracks_turn_on_spot.into()), + Typed::Bool(self.vertical_strafing), + Typed::Bool(self.sideways_driving), + Typed::Bool(self.tracks_turn_on_spot), ], }) } diff --git a/rc_core/src/data/mod.rs b/rc_core/src/data/mod.rs index 3356345..c31ccf9 100644 --- a/rc_core/src/data/mod.rs +++ b/rc_core/src/data/mod.rs @@ -24,7 +24,7 @@ pub fn encode_7_bit_i32(mut src: i32) -> Vec { let mut out = Vec::with_capacity(5); while src != 0 { let last_7 = (src & 0x7F) as u8; - src = src >> 7; + src >>= 7; if src != 0 { out.push(last_7 | 0x80); } else { @@ -65,5 +65,5 @@ pub fn read_str_for_binwriter(reader: &mut dyn std::io::Read) -> std::io::Result } pub fn cube_id_to_str(id: u32) -> String { - hex::encode(id.to_be_bytes()).into() + hex::encode(id.to_be_bytes()) } diff --git a/rc_core/src/data/movement_list.rs b/rc_core/src/data/movement_list.rs index 1329c79..b40aea2 100644 --- a/rc_core/src/data/movement_list.rs +++ b/rc_core/src/data/movement_list.rs @@ -21,13 +21,13 @@ pub struct MovementCategoryData { impl MovementCategoryData { pub fn as_transmissible(&self) -> Typed { let mut out = Vec::new(); - self.horizontal_top_speed.map(|x| out.push((Typed::Str("horizontalTopSpeed".into()), Typed::Float(x)))); - self.vertical_top_speed.map(|x| out.push((Typed::Str("verticalTopSpeed".into()), Typed::Float(x)))); - self.min_required_items.map(|x| out.push((Typed::Str("minRequiredItems".into()), Typed::Int(x)))); - self.min_item_modifier.map(|x| out.push((Typed::Str("minItemsModifier".into()), Typed::Float(x)))); - self.max_hover_height.map(|x| out.push((Typed::Str("maxHoverHeight".into()), Typed::Float(x)))); - self.light_machine_mass.map(|x| out.push((Typed::Str("lightMachineMass".into()), Typed::Float(x)))); - self.heavy_machine_mass.map(|x| out.push((Typed::Str("heavyMachineMass".into()), Typed::Float(x)))); + if let Some(x) = self.horizontal_top_speed { out.push((Typed::Str("horizontalTopSpeed".into()), Typed::Float(x))) } + if let Some(x) = self.vertical_top_speed { out.push((Typed::Str("verticalTopSpeed".into()), Typed::Float(x))) } + if let Some(x) = self.min_required_items { out.push((Typed::Str("minRequiredItems".into()), Typed::Int(x))) } + if let Some(x) = self.min_item_modifier { out.push((Typed::Str("minItemsModifier".into()), Typed::Float(x))) } + if let Some(x) = self.max_hover_height { out.push((Typed::Str("maxHoverHeight".into()), Typed::Float(x))) } + if let Some(x) = self.light_machine_mass { out.push((Typed::Str("lightMachineMass".into()), Typed::Float(x))) } + if let Some(x) = self.heavy_machine_mass { out.push((Typed::Str("heavyMachineMass".into()), Typed::Float(x))) } out.append(&mut self.specifics.as_transmissible()); for (tier, mov_data) in self.stats.iter() { out.push((Typed::Str(tier.as_str().into()), mov_data.as_transmissible())); @@ -35,7 +35,7 @@ impl MovementCategoryData { Typed::Dict(Dict { key_ty: TypePrefix::Str, val_ty: TypePrefix::Any, - items: out.into(), + items: out, }) } } @@ -136,15 +136,15 @@ pub struct MovementData { impl MovementData { pub fn as_transmissible(&self) -> Typed { let mut out = Vec::new(); - self.speed_boost.map(|x| out.push((Typed::Str("speedBoost".into()), Typed::Float(x)))); - self.max_carry_mass.map(|x| out.push((Typed::Str("maxCarryMass".into()), Typed::Float(x)))); - self.horizontal_top_speed.map(|x| out.push((Typed::Str("horizontalTopSpeed".into()), Typed::Float(x)))); - self.vertical_top_speed.map(|x| out.push((Typed::Str("verticalTopSpeed".into()), Typed::Float(x)))); + if let Some(x) = self.speed_boost { out.push((Typed::Str("speedBoost".into()), Typed::Float(x))) } + if let Some(x) = self.max_carry_mass { out.push((Typed::Str("maxCarryMass".into()), Typed::Float(x))) } + if let Some(x) = self.horizontal_top_speed { out.push((Typed::Str("horizontalTopSpeed".into()), Typed::Float(x))) } + if let Some(x) = self.vertical_top_speed { out.push((Typed::Str("verticalTopSpeed".into()), Typed::Float(x))) } out.append(&mut self.specifics.as_transmissible()); Typed::Dict(Dict { key_ty: TypePrefix::Str, // str val_ty: TypePrefix::Any, // any - items: out.into(), + items: out, }) } } diff --git a/rc_core/src/data/tech_tree.rs b/rc_core/src/data/tech_tree.rs index 7827f64..49fb2ea 100644 --- a/rc_core/src/data/tech_tree.rs +++ b/rc_core/src/data/tech_tree.rs @@ -16,8 +16,8 @@ impl TechTreeNode { (Typed::Str("mainCubeId".into()), Typed::Str(hex::encode(self.main_cube_id.to_be_bytes()).into())), (Typed::Str("positionX".into()), Typed::Int(self.position_x)), (Typed::Str("positionY".into()), Typed::Int(self.position_y)), - (Typed::Str("isUnlocked".into()), Typed::Bool(self.is_unlocked.into())), - (Typed::Str("isUnlockable".into()), Typed::Bool(self.is_unlockable.into())), + (Typed::Str("isUnlocked".into()), Typed::Bool(self.is_unlocked)), + (Typed::Str("isUnlockable".into()), Typed::Bool(self.is_unlockable)), (Typed::Str("tp".into()), Typed::Int(self.tech_points as i32)), (Typed::Str("neighbours".into()), Typed::Arr(Arr { ty: TypePrefix::Str, // str diff --git a/rc_core/src/data/weapon_list.rs b/rc_core/src/data/weapon_list.rs index ec8953b..a9e37c1 100644 --- a/rc_core/src/data/weapon_list.rs +++ b/rc_core/src/data/weapon_list.rs @@ -71,47 +71,47 @@ impl WeaponData { pub fn as_transmissible(&self) -> Typed { let mut out = Vec::new(); - self.damage_inflicted.map(|x| out.push((Typed::Str("damageInflicted".into()), Typed::Int(x)))); - self.protonium_damage_scale.map(|x| out.push((Typed::Str("protoniumDamageScale".into()), Typed::Float(x)))); - self.projectile_speed.map(|x| out.push((Typed::Str("projectileSpeed".into()), Typed::Float(x)))); - self.projectile_range.map(|x| out.push((Typed::Str("projectileRange".into()), Typed::Float(x)))); - self.base_inaccuracy.map(|x| out.push((Typed::Str("baseInaccuracy".into()), Typed::Float(x)))); - self.base_air_inaccuracy.map(|x| out.push((Typed::Str("baseAirInaccuracy".into()), Typed::Float(x)))); - self.movement_inaccuracy.map(|x| out.push((Typed::Str("movementInaccuracy".into()), Typed::Float(x)))); - self.movement_max_speed.map(|x| out.push((Typed::Str("movementMaxThresholdSpeed".into()), Typed::Float(x)))); - self.movement_min_speed.map(|x| out.push((Typed::Str("movementMinThresholdSpeed".into()), Typed::Float(x)))); - self.gun_rotation_slow.map(|x| out.push((Typed::Str("gunRotationThresholdSlow".into()), Typed::Float(x)))); - self.movement_inaccuracy_decay.map(|x| out.push((Typed::Str("movementInaccuracyDecayTime".into()), Typed::Float(x)))); - self.slow_rotation_decay.map(|x| out.push((Typed::Str("slowRotationInaccuracyDecayTime".into()), Typed::Float(x)))); - self.quick_rotation_decay.map(|x| out.push((Typed::Str("quickRotationInaccuracyDecayTime".into()), Typed::Float(x)))); - self.movement_inaccuracy_recovery.map(|x| out.push((Typed::Str("movementInaccuracyRecoveryTime".into()), Typed::Float(x)))); - self.repeat_fire_inaccuracy_total_degrees.map(|x| out.push((Typed::Str("repeatFireInaccuracyTotalDegrees".into()), Typed::Float(x)))); - self.repeat_fire_inaccuracy_decay.map(|x| out.push((Typed::Str("repeatFireInaccuracyDecayTime".into()), Typed::Float(x)))); - self.repeat_fire_innaccuracy_recovery.map(|x| out.push((Typed::Str("repeatFireInaccuracyRecoveryTime".into()), Typed::Float(x)))); - self.fire_instant_accuracy_decay.map(|x| out.push((Typed::Str("fireInstantAccuracyDecayDegrees".into()), Typed::Float(x)))); // degrees - self.accuracy_non_recover_time.map(|x| out.push((Typed::Str("accuracyNonRecoverTime".into()), Typed::Float(x)))); - self.accuracy_decay.map(|x| out.push((Typed::Str("accuracyDecayTime".into()), Typed::Float(x)))); - self.damage_radius.map(|x| out.push((Typed::Str("damageRadius".into()), Typed::Float(x)))); - self.plasma_time_to_full_damage.map(|x| out.push((Typed::Str("plasmaTimeToFullDamage".into()), Typed::Float(x)))); - self.plasma_starting_radius_scale.map(|x| out.push((Typed::Str("plasmaStartingRadiusScale".into()), Typed::Float(x)))); - self.nano_dps.map(|x| out.push((Typed::Str("nanoDPS".into()), Typed::Float(x)))); - self.nano_hps.map(|x| out.push((Typed::Str("nanoHPS".into()), Typed::Float(x)))); - self.tesla_damage.map(|x| out.push((Typed::Str("teslaDamage".into()), Typed::Float(x)))); - self.tesla_charges.map(|x| out.push((Typed::Str("teslaCharges".into()), Typed::Float(x)))); - self.aeroflak_proximity_damage.map(|x| out.push((Typed::Str("aeroflakProximityDamage".into()), Typed::Float(x)))); - self.aeroflak_damage_radius.map(|x| out.push((Typed::Str("aeroflakDamageRadius".into()), Typed::Float(x)))); - self.aeroflak_explosion_radius.map(|x| out.push((Typed::Str("aeroflakExplosionRadius".into()), Typed::Float(x)))); - self.aeroflak_ground_clearance.map(|x| out.push((Typed::Str("aeroflakGroundClearance".into()), Typed::Float(x)))); - self.aeroflak_max_stacks.map(|x| out.push((Typed::Str("aeroflakBuffMaxStacks".into()), Typed::Int(x)))); - self.aeroflak_damage_per_stack.map(|x| out.push((Typed::Str("aeroflakBuffDamagePerStack".into()), Typed::Int(x)))); - self.aeroflak_stack_expire.map(|x| out.push((Typed::Str("aeroflakBuffTimeToExpire".into()), Typed::Float(x)))); - self.shot_cooldown.map(|x| out.push((Typed::Str("cooldownBetweenShots".into()), Typed::Float(x)))); - self.smart_rotation_cooldown.map(|x| out.push((Typed::Str("smartRotationCooldown".into()), Typed::Float(x)))); - self.smart_rotation_cooldown_extra.map(|x| out.push((Typed::Str("smartRotationExtraCooldownTime".into()), Typed::Float(x)))); - self.smart_rotation_max_stacks.map(|x| out.push((Typed::Str("smartRotationMaxStacks".into()), Typed::Float(x)))); - self.spin_up_time.map(|x| out.push((Typed::Str("spinUpTime".into()), Typed::Float(x)))); - self.spin_down_time.map(|x| out.push((Typed::Str("spinDownTime".into()), Typed::Float(x)))); - self.spin_initial_cooldown.map(|x| out.push((Typed::Str("spinInitialCooldown".into()), Typed::Float(x)))); + if let Some(x) = self.damage_inflicted { out.push((Typed::Str("damageInflicted".into()), Typed::Int(x))) } + if let Some(x) = self.protonium_damage_scale { out.push((Typed::Str("protoniumDamageScale".into()), Typed::Float(x))) } + if let Some(x) = self.projectile_speed { out.push((Typed::Str("projectileSpeed".into()), Typed::Float(x))) } + if let Some(x) = self.projectile_range { out.push((Typed::Str("projectileRange".into()), Typed::Float(x))) } + if let Some(x) = self.base_inaccuracy { out.push((Typed::Str("baseInaccuracy".into()), Typed::Float(x))) } + if let Some(x) = self.base_air_inaccuracy { out.push((Typed::Str("baseAirInaccuracy".into()), Typed::Float(x))) } + if let Some(x) = self.movement_inaccuracy { out.push((Typed::Str("movementInaccuracy".into()), Typed::Float(x))) } + if let Some(x) = self.movement_max_speed { out.push((Typed::Str("movementMaxThresholdSpeed".into()), Typed::Float(x))) } + if let Some(x) = self.movement_min_speed { out.push((Typed::Str("movementMinThresholdSpeed".into()), Typed::Float(x))) } + if let Some(x) = self.gun_rotation_slow { out.push((Typed::Str("gunRotationThresholdSlow".into()), Typed::Float(x))) } + if let Some(x) = self.movement_inaccuracy_decay { out.push((Typed::Str("movementInaccuracyDecayTime".into()), Typed::Float(x))) } + if let Some(x) = self.slow_rotation_decay { out.push((Typed::Str("slowRotationInaccuracyDecayTime".into()), Typed::Float(x))) } + if let Some(x) = self.quick_rotation_decay { out.push((Typed::Str("quickRotationInaccuracyDecayTime".into()), Typed::Float(x))) } + if let Some(x) = self.movement_inaccuracy_recovery { out.push((Typed::Str("movementInaccuracyRecoveryTime".into()), Typed::Float(x))) } + if let Some(x) = self.repeat_fire_inaccuracy_total_degrees { out.push((Typed::Str("repeatFireInaccuracyTotalDegrees".into()), Typed::Float(x))) } + if let Some(x) = self.repeat_fire_inaccuracy_decay { out.push((Typed::Str("repeatFireInaccuracyDecayTime".into()), Typed::Float(x))) } + if let Some(x) = self.repeat_fire_innaccuracy_recovery { out.push((Typed::Str("repeatFireInaccuracyRecoveryTime".into()), Typed::Float(x))) } + if let Some(x) = self.fire_instant_accuracy_decay { out.push((Typed::Str("fireInstantAccuracyDecayDegrees".into()), Typed::Float(x))) } // degrees + if let Some(x) = self.accuracy_non_recover_time { out.push((Typed::Str("accuracyNonRecoverTime".into()), Typed::Float(x))) } + if let Some(x) = self.accuracy_decay { out.push((Typed::Str("accuracyDecayTime".into()), Typed::Float(x))) } + if let Some(x) = self.damage_radius { out.push((Typed::Str("damageRadius".into()), Typed::Float(x))) } + if let Some(x) = self.plasma_time_to_full_damage { out.push((Typed::Str("plasmaTimeToFullDamage".into()), Typed::Float(x))) } + if let Some(x) = self.plasma_starting_radius_scale { out.push((Typed::Str("plasmaStartingRadiusScale".into()), Typed::Float(x))) } + if let Some(x) = self.nano_dps { out.push((Typed::Str("nanoDPS".into()), Typed::Float(x))) } + if let Some(x) = self.nano_hps { out.push((Typed::Str("nanoHPS".into()), Typed::Float(x))) } + if let Some(x) = self.tesla_damage { out.push((Typed::Str("teslaDamage".into()), Typed::Float(x))) } + if let Some(x) = self.tesla_charges { out.push((Typed::Str("teslaCharges".into()), Typed::Float(x))) } + if let Some(x) = self.aeroflak_proximity_damage { out.push((Typed::Str("aeroflakProximityDamage".into()), Typed::Float(x))) } + if let Some(x) = self.aeroflak_damage_radius { out.push((Typed::Str("aeroflakDamageRadius".into()), Typed::Float(x))) } + if let Some(x) = self.aeroflak_explosion_radius { out.push((Typed::Str("aeroflakExplosionRadius".into()), Typed::Float(x))) } + if let Some(x) = self.aeroflak_ground_clearance { out.push((Typed::Str("aeroflakGroundClearance".into()), Typed::Float(x))) } + if let Some(x) = self.aeroflak_max_stacks { out.push((Typed::Str("aeroflakBuffMaxStacks".into()), Typed::Int(x))) } + if let Some(x) = self.aeroflak_damage_per_stack { out.push((Typed::Str("aeroflakBuffDamagePerStack".into()), Typed::Int(x))) } + if let Some(x) = self.aeroflak_stack_expire { out.push((Typed::Str("aeroflakBuffTimeToExpire".into()), Typed::Float(x))) } + if let Some(x) = self.shot_cooldown { out.push((Typed::Str("cooldownBetweenShots".into()), Typed::Float(x))) } + if let Some(x) = self.smart_rotation_cooldown { out.push((Typed::Str("smartRotationCooldown".into()), Typed::Float(x))) } + if let Some(x) = self.smart_rotation_cooldown_extra { out.push((Typed::Str("smartRotationExtraCooldownTime".into()), Typed::Float(x))) } + if let Some(x) = self.smart_rotation_max_stacks { out.push((Typed::Str("smartRotationMaxStacks".into()), Typed::Float(x))) } + if let Some(x) = self.spin_up_time { out.push((Typed::Str("spinUpTime".into()), Typed::Float(x))) } + if let Some(x) = self.spin_down_time { out.push((Typed::Str("spinDownTime".into()), Typed::Float(x))) } + if let Some(x) = self.spin_initial_cooldown { out.push((Typed::Str("spinInitialCooldown".into()), Typed::Float(x))) } if !self.group_fire_scales.is_empty() { let typed_arr: Vec> = self.group_fire_scales.iter().map(|x| Typed::Float(*x)).collect(); @@ -121,26 +121,26 @@ impl WeaponData { }))); } - self.mana_cost.map(|x| out.push((Typed::Str("manaCost".into()), Typed::Float(x)))); - self.lock_time.map(|x| out.push((Typed::Str("lockTime".into()), Typed::Float(x)))); - self.full_lock_release.map(|x| out.push((Typed::Str("fullLockRelease".into()), Typed::Float(x)))); - self.change_lock_time.map(|x| out.push((Typed::Str("changeLockTime".into()), Typed::Float(x)))); - self.max_rotation_speed.map(|x| out.push((Typed::Str("maxRotationSpeed".into()), Typed::Float(x)))); - self.initial_rotation_speed.map(|x| out.push((Typed::Str("initialRotationSpeed".into()), Typed::Float(x)))); - self.rotation_acceleration.map(|x| out.push((Typed::Str("rotationAcceleration".into()), Typed::Float(x)))); - self.nano_healing_priority_time.map(|x| out.push((Typed::Str("nanoHealingPriorityTime".into()), Typed::Float(x)))); - self.module_range.map(|x| out.push((Typed::Str("moduleRange".into()), Typed::Float(x)))); - self.shield_lifetime.map(|x| out.push((Typed::Str("shieldLifetime".into()), Typed::Float(x)))); - self.teleport_time.map(|x| out.push((Typed::Str("teleportTime".into()), Typed::Float(x)))); - self.camera_time.map(|x| out.push((Typed::Str("cameraTime".into()), Typed::Float(x)))); - self.camera_delay.map(|x| out.push((Typed::Str("cameraDelay".into()), Typed::Float(x)))); - self.to_invisible_speed.map(|x| out.push((Typed::Str("toInvisibleSpeed".into()), Typed::Float(x)))); - self.to_invisible_duration.map(|x| out.push((Typed::Str("toInvisibleDuration".into()), Typed::Float(x)))); - self.to_visible_duration.map(|x| out.push((Typed::Str("toVisibleDuration".into()), Typed::Float(x)))); - self.countdown_time.map(|x| out.push((Typed::Str("countdownTime".into()), Typed::Float(x)))); - self.stun_time.map(|x| out.push((Typed::Str("stunTime".into()), Typed::Float(x)))); - self.stun_radius.map(|x| out.push((Typed::Str("stunRadius".into()), Typed::Float(x)))); - self.effect_duration.map(|x| out.push((Typed::Str("effectDuration".into()), Typed::Float(x)))); + if let Some(x) = self.mana_cost { out.push((Typed::Str("manaCost".into()), Typed::Float(x))) } + if let Some(x) = self.lock_time { out.push((Typed::Str("lockTime".into()), Typed::Float(x))) } + if let Some(x) = self.full_lock_release { out.push((Typed::Str("fullLockRelease".into()), Typed::Float(x))) } + if let Some(x) = self.change_lock_time { out.push((Typed::Str("changeLockTime".into()), Typed::Float(x))) } + if let Some(x) = self.max_rotation_speed { out.push((Typed::Str("maxRotationSpeed".into()), Typed::Float(x))) } + if let Some(x) = self.initial_rotation_speed { out.push((Typed::Str("initialRotationSpeed".into()), Typed::Float(x))) } + if let Some(x) = self.rotation_acceleration { out.push((Typed::Str("rotationAcceleration".into()), Typed::Float(x))) } + if let Some(x) = self.nano_healing_priority_time { out.push((Typed::Str("nanoHealingPriorityTime".into()), Typed::Float(x))) } + if let Some(x) = self.module_range { out.push((Typed::Str("moduleRange".into()), Typed::Float(x))) } + if let Some(x) = self.shield_lifetime { out.push((Typed::Str("shieldLifetime".into()), Typed::Float(x))) } + if let Some(x) = self.teleport_time { out.push((Typed::Str("teleportTime".into()), Typed::Float(x))) } + if let Some(x) = self.camera_time { out.push((Typed::Str("cameraTime".into()), Typed::Float(x))) } + if let Some(x) = self.camera_delay { out.push((Typed::Str("cameraDelay".into()), Typed::Float(x))) } + if let Some(x) = self.to_invisible_speed { out.push((Typed::Str("toInvisibleSpeed".into()), Typed::Float(x))) } + if let Some(x) = self.to_invisible_duration { out.push((Typed::Str("toInvisibleDuration".into()), Typed::Float(x))) } + if let Some(x) = self.to_visible_duration { out.push((Typed::Str("toVisibleDuration".into()), Typed::Float(x))) } + if let Some(x) = self.countdown_time { out.push((Typed::Str("countdownTime".into()), Typed::Float(x))) } + if let Some(x) = self.stun_time { out.push((Typed::Str("stunTime".into()), Typed::Float(x))) } + if let Some(x) = self.stun_radius { out.push((Typed::Str("stunRadius".into()), Typed::Float(x))) } + if let Some(x) = self.effect_duration { out.push((Typed::Str("effectDuration".into()), Typed::Float(x))) } Typed::HashMap(out.into()) } } diff --git a/rc_core/src/persist/client_config.rs b/rc_core/src/persist/client_config.rs index f96e835..04b94d1 100644 --- a/rc_core/src/persist/client_config.rs +++ b/rc_core/src/persist/client_config.rs @@ -14,19 +14,19 @@ pub struct GameplaySettings { pub cross_promo_link: String, // url } -impl std::convert::Into for GameplaySettings { - fn into(self) -> crate::data::client_config::GameplaySettings { +impl std::convert::From for crate::data::client_config::GameplaySettings { + fn from(val: GameplaySettings) -> Self { crate::data::client_config::GameplaySettings { - show_tutorial_after_date: self.show_tutorial_after_date, - health_threshold: self.health_threshold, - microbot_sphere: self.microbot_sphere, - misfire_angle: self.misfire_angle, - shield_dps: self.shield_dps, - shield_hps: self.shield_hps, - request_review_level: self.request_review_level, - critical_ratio: self.critical_ratio, - cross_promo_image: self.cross_promo_image, - cross_promo_link: self.cross_promo_link, + show_tutorial_after_date: val.show_tutorial_after_date, + health_threshold: val.health_threshold, + microbot_sphere: val.microbot_sphere, + misfire_angle: val.misfire_angle, + shield_dps: val.shield_dps, + shield_hps: val.shield_hps, + request_review_level: val.request_review_level, + critical_ratio: val.critical_ratio, + cross_promo_image: val.cross_promo_image, + cross_promo_link: val.cross_promo_link, } } } diff --git a/rc_core/src/persist/combat.rs b/rc_core/src/persist/combat.rs index ab424cb..868bd59 100644 --- a/rc_core/src/persist/combat.rs +++ b/rc_core/src/persist/combat.rs @@ -28,13 +28,13 @@ pub struct AutoRegenHealth { pub auto_heal: bool, } -impl std::convert::Into for AutoRegenHealth { - fn into(self) -> crate::data::auto_regen::AutoRegenHealthConfig { +impl std::convert::From for crate::data::auto_regen::AutoRegenHealthConfig { + fn from(val: AutoRegenHealth) -> Self { crate::data::auto_regen::AutoRegenHealthConfig { - seconds_to_wait_for_heal: self.wait_for_heal_s, - seconds_to_full_heal: self.wait_full_heal_s, - threshold_to_start_sound: self.sound_start_s, - enable_auto_heal: self.auto_heal, + seconds_to_wait_for_heal: val.wait_for_heal_s, + seconds_to_full_heal: val.wait_full_heal_s, + threshold_to_start_sound: val.sound_start_s, + enable_auto_heal: val.auto_heal, } } } @@ -47,13 +47,13 @@ pub struct VoteThreshold { pub votes_required: i32, } -impl std::convert::Into for VoteThreshold { - fn into(self) -> crate::data::voting::VoteThresholdData { +impl std::convert::From for crate::data::voting::VoteThresholdData { + fn from(val: VoteThreshold) -> Self { crate::data::voting::VoteThresholdData { - name: self.name, - localised_name: self.localised_name, - color: self.color, - votes_required: self.votes_required, + name: val.name, + localised_name: val.localised_name, + color: val.color, + votes_required: val.votes_required, } } } @@ -64,11 +64,11 @@ pub enum Vote { BestLooking, } -impl std::convert::Into for Vote { - fn into(self) -> crate::data::voting::Vote { - match self { - Self::BestPlayed => crate::data::voting::Vote::BestPlayed, - Self::BestLooking => crate::data::voting::Vote::BestLooking, +impl std::convert::From for crate::data::voting::Vote { + fn from(val: Vote) -> Self { + match val { + Vote::BestPlayed => crate::data::voting::Vote::BestPlayed, + Vote::BestLooking => crate::data::voting::Vote::BestLooking, } } } @@ -81,13 +81,13 @@ pub struct GameMode { pub game_time_m: i32, } -impl std::convert::Into for GameMode { - fn into(self) -> crate::data::game_mode::GameModeConfig { +impl std::convert::From for crate::data::game_mode::GameModeConfig { + fn from(val: GameMode) -> Self { crate::data::game_mode::GameModeConfig { - respawn_heal_duration: self.respawn_heal_duration, - respawn_full_heal_duration: self.respawn_full_heal_duration, - kill_limit: self.kill_limit, - game_time_minutes: self.game_time_m, + respawn_heal_duration: val.respawn_heal_duration, + respawn_full_heal_duration: val.respawn_full_heal_duration, + kill_limit: val.kill_limit, + game_time_minutes: val.game_time_m, } } } @@ -100,13 +100,13 @@ pub struct GameModes { pub team_deathmatch: GameMode, } -impl std::convert::Into for GameModes { - fn into(self) -> crate::data::game_mode::GameModeConfigs { +impl std::convert::From for crate::data::game_mode::GameModeConfigs { + fn from(val: GameModes) -> Self { crate::data::game_mode::GameModeConfigs { - battle_arena: self.battle_arena.into(), - elimination: self.elimination.into(), - the_pit: self.pit.into(), - team_deathmatch: self.team_deathmatch.into(), + battle_arena: val.battle_arena.into(), + elimination: val.elimination.into(), + the_pit: val.pit.into(), + team_deathmatch: val.team_deathmatch.into(), } } } @@ -332,7 +332,7 @@ pub(super) fn default_campaigns() -> super::SingleplayerConfig { ], kill_target: 1, time_min: 1, - time_max: 1 * 60, + time_max: 60, } ], } diff --git a/rc_core/src/persist/config/cubes_json.rs b/rc_core/src/persist/config/cubes_json.rs index 605b608..760ff41 100644 --- a/rc_core/src/persist/config/cubes_json.rs +++ b/rc_core/src/persist/config/cubes_json.rs @@ -64,7 +64,7 @@ impl super::ConfigProvider for CubeConfig { } let mut movement_cat_stats = Vec::with_capacity(self.movement.len()); for (k, v) in self.movement.iter() { - let stats: Vec<_> = if let Some(stats) = movements_stats.get(&k) { + let stats: Vec<_> = if let Some(stats) = movements_stats.get(k) { stats.iter().map(|(k, v)| (k.to_owned(), v.to_owned())).collect() } else { Vec::default() @@ -250,7 +250,7 @@ impl super::ConfigProvider for CubeConfig { val_ty: TypePrefix::HashMap, items: vec![ (Typed::Str("GameplaySettings".into()), conf_data.as_transmissible()), - ].into(), + ], }) } @@ -317,7 +317,7 @@ impl super::ConfigProvider for CubeConfig { } fn gamemodes(&self) -> crate::data::game_mode::GameModeConfigs { - self.battle.games.clone().into() + self.battle.games.into() } fn singleplayer_details(&self) -> super::SingleplayerConfig { diff --git a/rc_core/src/persist/cube_data.rs b/rc_core/src/persist/cube_data.rs index c0ae64a..39cd741 100644 --- a/rc_core/src/persist/cube_data.rs +++ b/rc_core/src/persist/cube_data.rs @@ -67,21 +67,21 @@ fn default_true() -> bool { true } -impl std::convert::Into> for CubeInfo { - fn into(self) -> crate::data::cube_list::CubeInfo { +impl std::convert::From for crate::data::cube_list::CubeInfo { + fn from(val: CubeInfo) -> Self { crate::data::cube_list::CubeInfo { - cpu: self.cpu, - health: self.health, - health_boost: self.health_boost, - grey_out_in_tutorial: self.grey_out_in_tutorial, - visibility: self.visibility.into(), - indestructible: self.indestructible, - category: self.category.into(), - placements: self.placements, // default 63 - protonium: self.protonium, - unlocked_by_league: self.unlocked_by_league, - league_unlock_index: self.league_unlock_index, - stats: self.stats.into_iter().map(|(k, v)| { + cpu: val.cpu, + health: val.health, + health_boost: val.health_boost, + grey_out_in_tutorial: val.grey_out_in_tutorial, + visibility: val.visibility.into(), + indestructible: val.indestructible, + category: val.category.into(), + placements: val.placements, // default 63 + protonium: val.protonium, + unlocked_by_league: val.unlocked_by_league, + league_unlock_index: val.league_unlock_index, + stats: val.stats.into_iter().map(|(k, v)| { let new_v = match v { serde_json::Value::Bool(b) => Typed::Bool(b), serde_json::Value::Number(n) => if let Some(n_i64) = n.as_i64() { @@ -96,13 +96,13 @@ impl std::convert::Into> for Cube }; (k, new_v) }).collect(), - description: self.description, - size: self.size.into(), - type_: self.type_.into(), - ranking: self.ranking, - cosmetic: self.cosmetic, - variant_of: hex::encode(self.variant_of.to_be_bytes()).into(), - ignore_in_weapon_list: self.ignore_in_weapon_list, + description: val.description, + size: val.size.into(), + type_: val.type_.into(), + ranking: val.ranking, + cosmetic: val.cosmetic, + variant_of: hex::encode(val.variant_of.to_be_bytes()), + ignore_in_weapon_list: val.ignore_in_weapon_list, } } } @@ -116,13 +116,13 @@ pub enum VisibilityMode { None, } -impl std::convert::Into for VisibilityMode { - fn into(self) -> crate::data::cube_list::VisibilityMode { - match self { - Self::Mothership => crate::data::cube_list::VisibilityMode::Mothership, - Self::All => crate::data::cube_list::VisibilityMode::All, - Self::Tutorial => crate::data::cube_list::VisibilityMode::Tutorial, - Self::None => crate::data::cube_list::VisibilityMode::None, +impl std::convert::From for crate::data::cube_list::VisibilityMode { + fn from(val: VisibilityMode) -> Self { + match val { + VisibilityMode::Mothership => crate::data::cube_list::VisibilityMode::Mothership, + VisibilityMode::All => crate::data::cube_list::VisibilityMode::All, + VisibilityMode::Tutorial => crate::data::cube_list::VisibilityMode::Tutorial, + VisibilityMode::None => crate::data::cube_list::VisibilityMode::None, } } } @@ -139,16 +139,16 @@ pub enum ItemTier { T5 = 600, } -impl std::convert::Into for ItemTier { - fn into(self) -> crate::data::cube_list::ItemTier { - match self { - Self::NoTier => crate::data::cube_list::ItemTier::NoTier, - Self::T0 => crate::data::cube_list::ItemTier::T0, - Self::T1 => crate::data::cube_list::ItemTier::T1, - Self::T2 => crate::data::cube_list::ItemTier::T2, - Self::T3 => crate::data::cube_list::ItemTier::T3, - Self::T4 => crate::data::cube_list::ItemTier::T4, - Self::T5 => crate::data::cube_list::ItemTier::T5, +impl std::convert::From for crate::data::cube_list::ItemTier { + fn from(val: ItemTier) -> Self { + match val { + ItemTier::NoTier => crate::data::cube_list::ItemTier::NoTier, + ItemTier::T0 => crate::data::cube_list::ItemTier::T0, + ItemTier::T1 => crate::data::cube_list::ItemTier::T1, + ItemTier::T2 => crate::data::cube_list::ItemTier::T2, + ItemTier::T3 => crate::data::cube_list::ItemTier::T3, + ItemTier::T4 => crate::data::cube_list::ItemTier::T4, + ItemTier::T5 => crate::data::cube_list::ItemTier::T5, } } } @@ -163,14 +163,14 @@ pub enum ItemType { Cosmetic, } -impl std::convert::Into for ItemType { - fn into(self) -> crate::data::cube_list::ItemType { - match self { - Self::NotAFunctionalItem => crate::data::cube_list::ItemType::NoFunction, - Self::Weapon => crate::data::cube_list::ItemType::Weapon, - Self::Module => crate::data::cube_list::ItemType::Module, - Self::Movement => crate::data::cube_list::ItemType::Movement, - Self::Cosmetic => crate::data::cube_list::ItemType::Cosmetic, +impl std::convert::From for crate::data::cube_list::ItemType { + fn from(val: ItemType) -> Self { + match val { + ItemType::NotAFunctionalItem => crate::data::cube_list::ItemType::NoFunction, + ItemType::Weapon => crate::data::cube_list::ItemType::Weapon, + ItemType::Module => crate::data::cube_list::ItemType::Module, + ItemType::Movement => crate::data::cube_list::ItemType::Movement, + ItemType::Cosmetic => crate::data::cube_list::ItemType::Cosmetic, } } } @@ -209,38 +209,38 @@ pub enum ItemCategory { EnergyModule = 900, } -impl std::convert::Into for ItemCategory { - fn into(self) -> crate::data::weapon_list::ItemCategory { - match self { - Self::NotAFunctionalItem => crate::data::weapon_list::ItemCategory::NoFunction, - Self::Wheel => crate::data::weapon_list::ItemCategory::Wheel, - Self::Hover => crate::data::weapon_list::ItemCategory::Hover, - Self::Wing => crate::data::weapon_list::ItemCategory::Wing, - Self::Rudder => crate::data::weapon_list::ItemCategory::Rudder, - Self::Thruster => crate::data::weapon_list::ItemCategory::Thruster, - Self::InsectLeg => crate::data::weapon_list::ItemCategory::InsectLeg, - Self::MechLeg => crate::data::weapon_list::ItemCategory::MechLeg, - Self::Ski => crate::data::weapon_list::ItemCategory::Ski, - Self::TankTrack => crate::data::weapon_list::ItemCategory::TankTrack, - Self::Rotor => crate::data::weapon_list::ItemCategory::Rotor, - Self::SprinterLeg => crate::data::weapon_list::ItemCategory::SprinterLeg, - Self::Propeller => crate::data::weapon_list::ItemCategory::Propeller, - Self::Laser => crate::data::weapon_list::ItemCategory::Laser, - Self::Plasma => crate::data::weapon_list::ItemCategory::Plasma, - Self::Mortar => crate::data::weapon_list::ItemCategory::Mortar, - Self::Rail => crate::data::weapon_list::ItemCategory::Rail, - Self::Nano => crate::data::weapon_list::ItemCategory::Nano, - Self::Tesla => crate::data::weapon_list::ItemCategory::Tesla, - Self::Aeroflak => crate::data::weapon_list::ItemCategory::Aeroflak, - Self::Ion => crate::data::weapon_list::ItemCategory::Ion, - Self::Seeker => crate::data::weapon_list::ItemCategory::Seeker, - Self::Chaingun => crate::data::weapon_list::ItemCategory::Chaingun, - Self::ShieldModule => crate::data::weapon_list::ItemCategory::ShieldModule, - Self::GhostModule => crate::data::weapon_list::ItemCategory::GhostModule, - Self::BlinkModule => crate::data::weapon_list::ItemCategory::BlinkModule, - Self::EmpModule => crate::data::weapon_list::ItemCategory::EmpModule, - Self::WindowmakerModule => crate::data::weapon_list::ItemCategory::WindowmakerModule, - Self::EnergyModule => crate::data::weapon_list::ItemCategory::EnergyModule, +impl std::convert::From for crate::data::weapon_list::ItemCategory { + fn from(val: ItemCategory) -> Self { + match val { + ItemCategory::NotAFunctionalItem => crate::data::weapon_list::ItemCategory::NoFunction, + ItemCategory::Wheel => crate::data::weapon_list::ItemCategory::Wheel, + ItemCategory::Hover => crate::data::weapon_list::ItemCategory::Hover, + ItemCategory::Wing => crate::data::weapon_list::ItemCategory::Wing, + ItemCategory::Rudder => crate::data::weapon_list::ItemCategory::Rudder, + ItemCategory::Thruster => crate::data::weapon_list::ItemCategory::Thruster, + ItemCategory::InsectLeg => crate::data::weapon_list::ItemCategory::InsectLeg, + ItemCategory::MechLeg => crate::data::weapon_list::ItemCategory::MechLeg, + ItemCategory::Ski => crate::data::weapon_list::ItemCategory::Ski, + ItemCategory::TankTrack => crate::data::weapon_list::ItemCategory::TankTrack, + ItemCategory::Rotor => crate::data::weapon_list::ItemCategory::Rotor, + ItemCategory::SprinterLeg => crate::data::weapon_list::ItemCategory::SprinterLeg, + ItemCategory::Propeller => crate::data::weapon_list::ItemCategory::Propeller, + ItemCategory::Laser => crate::data::weapon_list::ItemCategory::Laser, + ItemCategory::Plasma => crate::data::weapon_list::ItemCategory::Plasma, + ItemCategory::Mortar => crate::data::weapon_list::ItemCategory::Mortar, + ItemCategory::Rail => crate::data::weapon_list::ItemCategory::Rail, + ItemCategory::Nano => crate::data::weapon_list::ItemCategory::Nano, + ItemCategory::Tesla => crate::data::weapon_list::ItemCategory::Tesla, + ItemCategory::Aeroflak => crate::data::weapon_list::ItemCategory::Aeroflak, + ItemCategory::Ion => crate::data::weapon_list::ItemCategory::Ion, + ItemCategory::Seeker => crate::data::weapon_list::ItemCategory::Seeker, + ItemCategory::Chaingun => crate::data::weapon_list::ItemCategory::Chaingun, + ItemCategory::ShieldModule => crate::data::weapon_list::ItemCategory::ShieldModule, + ItemCategory::GhostModule => crate::data::weapon_list::ItemCategory::GhostModule, + ItemCategory::BlinkModule => crate::data::weapon_list::ItemCategory::BlinkModule, + ItemCategory::EmpModule => crate::data::weapon_list::ItemCategory::EmpModule, + ItemCategory::WindowmakerModule => crate::data::weapon_list::ItemCategory::WindowmakerModule, + ItemCategory::EnergyModule => crate::data::weapon_list::ItemCategory::EnergyModule, } } } diff --git a/rc_core/src/persist/garage.rs b/rc_core/src/persist/garage.rs index 8640358..f68c751 100644 --- a/rc_core/src/persist/garage.rs +++ b/rc_core/src/persist/garage.rs @@ -74,27 +74,27 @@ impl GarageSlot { } } -impl std::convert::Into for GarageSlot { - fn into(self) -> crate::data::garage_bay::GarageSlotInfo { +impl std::convert::From for crate::data::garage_bay::GarageSlotInfo { + fn from(val: GarageSlot) -> Self { crate::data::garage_bay::GarageSlotInfo { - name: self.name, - cubes: self.cubes, - crf_id: self.crf_id as u32, - was_rated: self.was_rated, - movement_categories: self.movement_categories.into_iter().map(|x| x.into()).collect(), - uuid: self.uuid, - thumbnail_version: self.thumbnail_version as u32, - total_robot_cpu: self.total_robot_cpu as u32, - total_cosmetic_cpu: self.total_cosmetic_cpu as u32, - total_robot_ranking: self.total_robot_ranking as u32, - bay_cpu: self.bay_cpu as u32, - tutorial_robot: self.tutorial_robot, - starter_robot_index: self.starter_robot_index, - control_type: self.control_type.into(), - control_options: self.control_options.into(), - mastery_level: self.mastery_level, - bay_skin_id: self.bay_skin_id, - weapon_order: self.weapon_order, + name: val.name, + cubes: val.cubes, + crf_id: val.crf_id as u32, + was_rated: val.was_rated, + movement_categories: val.movement_categories.into_iter().map(|x| x.into()).collect(), + uuid: val.uuid, + thumbnail_version: val.thumbnail_version as u32, + total_robot_cpu: val.total_robot_cpu as u32, + total_cosmetic_cpu: val.total_cosmetic_cpu as u32, + total_robot_ranking: val.total_robot_ranking as u32, + bay_cpu: val.bay_cpu as u32, + tutorial_robot: val.tutorial_robot, + starter_robot_index: val.starter_robot_index, + control_type: val.control_type.into(), + control_options: val.control_options.into(), + mastery_level: val.mastery_level, + bay_skin_id: val.bay_skin_id, + weapon_order: val.weapon_order, } } } @@ -114,14 +114,14 @@ pub fn db_into_data(garage: oj_rc_database::schema::garage::Model) -> crate::dat total_robot_ranking: garage.total_robot_ranking as u32, bay_cpu: garage.bay_cpu as u32, tutorial_robot: garage.tutorial_robot, - starter_robot_index: garage.starter_robot_index.map(|x| x as i32).unwrap_or(-1), + starter_robot_index: garage.starter_robot_index.unwrap_or(-1), control_type: control_ty_into_data(garage.control_type), control_options: crate::data::garage_bay::ControlOptions { vertical_strafing: garage.vertical_strafing, sideways_driving: garage.sideways_driving, tracks_turn_on_spot: garage.tracks_turn_on_spot, }, - mastery_level: garage.mastery_level as i32, + mastery_level: garage.mastery_level, bay_skin_id: garage.bay_skin_id, weapon_order: oj_rc_database::schema::parse_int_csv(&garage.weapon_order).into_iter().map(|x| x as i32).collect(), } @@ -150,12 +150,12 @@ pub enum ControlType { Count, } -impl std::convert::Into for ControlType { - fn into(self) -> crate::data::garage_bay::ControlType { - match self { - Self::Camera => crate::data::garage_bay::ControlType::Camera, - Self::Keyboard => crate::data::garage_bay::ControlType::Keyboard, - Self::Count => crate::data::garage_bay::ControlType::Count, +impl std::convert::From for crate::data::garage_bay::ControlType { + fn from(val: ControlType) -> Self { + match val { + ControlType::Camera => crate::data::garage_bay::ControlType::Camera, + ControlType::Keyboard => crate::data::garage_bay::ControlType::Keyboard, + ControlType::Count => crate::data::garage_bay::ControlType::Count, } } } @@ -167,12 +167,12 @@ pub struct GarageControls { pub tracks_turn_on_spot: bool, } -impl std::convert::Into for GarageControls { - fn into(self) -> crate::data::garage_bay::ControlOptions { +impl std::convert::From for crate::data::garage_bay::ControlOptions { + fn from(val: GarageControls) -> Self { crate::data::garage_bay::ControlOptions { - vertical_strafing: self.vertical_strafing, - sideways_driving: self.sideways_driving, - tracks_turn_on_spot: self.tracks_turn_on_spot, + vertical_strafing: val.vertical_strafing, + sideways_driving: val.sideways_driving, + tracks_turn_on_spot: val.tracks_turn_on_spot, } } } @@ -212,12 +212,12 @@ pub enum PrefabId { // TODO File } -impl std::convert::Into for PrefabId { - fn into(self) -> crate::persist::config::VehicleDescriptor { - match self { - Self::Factory { factory } => crate::persist::config::VehicleDescriptor::Factory { factory }, - Self::Database { garage } => crate::persist::config::VehicleDescriptor::Database { garage }, - Self::Raw { cube_data, colour_data } => crate::persist::config::VehicleDescriptor::Raw { cube_data , colour_data }, +impl std::convert::From for crate::persist::config::VehicleDescriptor { + fn from(val: PrefabId) -> Self { + match val { + PrefabId::Factory { factory } => crate::persist::config::VehicleDescriptor::Factory { factory }, + PrefabId::Database { garage } => crate::persist::config::VehicleDescriptor::Database { garage }, + PrefabId::Raw { cube_data, colour_data } => crate::persist::config::VehicleDescriptor::Raw { cube_data , colour_data }, } } } diff --git a/rc_core/src/persist/maps.rs b/rc_core/src/persist/maps.rs index 69fe43c..6f025f3 100644 --- a/rc_core/src/persist/maps.rs +++ b/rc_core/src/persist/maps.rs @@ -97,6 +97,7 @@ const DEFAULT_BASE_RADIUS: f32 = 20.0; const DEFAULT_CAPTURE_PERCENT_PER_SECOND: f32 = DEFAULT_BASE_PERCENT_PER_SECOND * 1.5; const DEFAULT_CAPTURE_RADIUS: f32 = 14.0; +#[allow(clippy::approx_constant)] pub(super) fn default_map() -> std::collections::HashMap { let mut map = std::collections::HashMap::with_capacity(9); //let coords_t0 = corner_to_center((6.60, 4.09, 20.3), 10.0); diff --git a/rc_core/src/persist/mod.rs b/rc_core/src/persist/mod.rs index 3fd44b7..af7b0c9 100644 --- a/rc_core/src/persist/mod.rs +++ b/rc_core/src/persist/mod.rs @@ -41,7 +41,7 @@ pub use multiplayer::{MultiplayerConfig, NetworkConf}; mod maps; pub use maps::{MapsConfig, MapConfig}; -pub(self) const VALID_ROBOT: &[u8] = &[64, + const VALID_ROBOT: &[u8] = &[64, 0, 0, 0, @@ -558,7 +558,7 @@ pub(self) const VALID_ROBOT: &[u8] = &[64, 15, 6]; -pub(self) const VALID_COLOUR: &[u8] = &[64, + const VALID_COLOUR: &[u8] = &[64, 0, 0, 0, diff --git a/rc_core/src/persist/movement.rs b/rc_core/src/persist/movement.rs index b42fbad..39c937f 100644 --- a/rc_core/src/persist/movement.rs +++ b/rc_core/src/persist/movement.rs @@ -49,21 +49,21 @@ pub enum MovementCategorySpecificData { Ski, } -impl std::convert::Into for MovementCategorySpecificData { - fn into(self) -> crate::data::movement_list::MovementCategorySpecificData { - match self { - Self::Wheel => crate::data::movement_list::MovementCategorySpecificData::Wheel, - Self::Hover(x) => crate::data::movement_list::MovementCategorySpecificData::Hover(x.into()), - Self::Wing => crate::data::movement_list::MovementCategorySpecificData::Wing, - Self::Rudder => crate::data::movement_list::MovementCategorySpecificData::Rudder, - Self::Thruster => crate::data::movement_list::MovementCategorySpecificData::Thruster, - Self::Propeller => crate::data::movement_list::MovementCategorySpecificData::Propeller, - Self::InsectLeg => crate::data::movement_list::MovementCategorySpecificData::InsectLeg, - Self::MechLeg(x) => crate::data::movement_list::MovementCategorySpecificData::MechLeg(x.into()), - Self::SprinterLeg(x) => crate::data::movement_list::MovementCategorySpecificData::SprinterLeg(x.into()), - Self::TankTrack => crate::data::movement_list::MovementCategorySpecificData::TankTrack, - Self::Rotor(x) => crate::data::movement_list::MovementCategorySpecificData::Rotor(x.into()), - Self::Ski => crate::data::movement_list::MovementCategorySpecificData::Ski, +impl std::convert::From for crate::data::movement_list::MovementCategorySpecificData { + fn from(val: MovementCategorySpecificData) -> Self { + match val { + MovementCategorySpecificData::Wheel => crate::data::movement_list::MovementCategorySpecificData::Wheel, + MovementCategorySpecificData::Hover(x) => crate::data::movement_list::MovementCategorySpecificData::Hover(x.into()), + MovementCategorySpecificData::Wing => crate::data::movement_list::MovementCategorySpecificData::Wing, + MovementCategorySpecificData::Rudder => crate::data::movement_list::MovementCategorySpecificData::Rudder, + MovementCategorySpecificData::Thruster => crate::data::movement_list::MovementCategorySpecificData::Thruster, + MovementCategorySpecificData::Propeller => crate::data::movement_list::MovementCategorySpecificData::Propeller, + MovementCategorySpecificData::InsectLeg => crate::data::movement_list::MovementCategorySpecificData::InsectLeg, + MovementCategorySpecificData::MechLeg(x) => crate::data::movement_list::MovementCategorySpecificData::MechLeg(x.into()), + MovementCategorySpecificData::SprinterLeg(x) => crate::data::movement_list::MovementCategorySpecificData::SprinterLeg(x.into()), + MovementCategorySpecificData::TankTrack => crate::data::movement_list::MovementCategorySpecificData::TankTrack, + MovementCategorySpecificData::Rotor(x) => crate::data::movement_list::MovementCategorySpecificData::Rotor(x.into()), + MovementCategorySpecificData::Ski => crate::data::movement_list::MovementCategorySpecificData::Ski, } } } @@ -79,16 +79,16 @@ pub struct HoverCategoryData { pub deceleration_multiplier: f32, } -impl std::convert::Into for HoverCategoryData { - fn into(self) -> crate::data::movement_list::HoverCategoryData { +impl std::convert::From for crate::data::movement_list::HoverCategoryData { + fn from(val: HoverCategoryData) -> Self { crate::data::movement_list::HoverCategoryData { - height_tolerance: self.height_tolerance, - force_y_offset: self.force_y_offset, - turning_scale: self.turning_scale, - small_angle_turning_scale: self.small_angle_turning_scale, - hover_damping: self.hover_damping, - angular_damping: self.angular_damping, - deceleration_multiplier: self.deceleration_multiplier, + height_tolerance: val.height_tolerance, + force_y_offset: val.force_y_offset, + turning_scale: val.turning_scale, + small_angle_turning_scale: val.small_angle_turning_scale, + hover_damping: val.hover_damping, + angular_damping: val.angular_damping, + deceleration_multiplier: val.deceleration_multiplier, } } } @@ -98,10 +98,10 @@ pub struct MechLegCategoryData { pub deceleration_multiplier: f32, } -impl std::convert::Into for MechLegCategoryData { - fn into(self) -> crate::data::movement_list::MechLegCategoryData { +impl std::convert::From for crate::data::movement_list::MechLegCategoryData { + fn from(val: MechLegCategoryData) -> Self { crate::data::movement_list::MechLegCategoryData { - deceleration_multiplier: self.deceleration_multiplier, + deceleration_multiplier: val.deceleration_multiplier, } } } @@ -111,10 +111,10 @@ pub struct RotorCategoryData { pub max_turn_rate: f32, } -impl std::convert::Into for RotorCategoryData { - fn into(self) -> crate::data::movement_list::RotorCategoryData { +impl std::convert::From for crate::data::movement_list::RotorCategoryData { + fn from(val: RotorCategoryData) -> Self { crate::data::movement_list::RotorCategoryData { - max_turn_rate: self.max_turn_rate, + max_turn_rate: val.max_turn_rate, } } } @@ -129,14 +129,14 @@ pub struct MovementData { pub specifics: MovementSpecificData, } -impl std::convert::Into for MovementData { - fn into(self) -> crate::data::movement_list::MovementData { +impl std::convert::From for crate::data::movement_list::MovementData { + fn from(val: MovementData) -> Self { crate::data::movement_list::MovementData { - speed_boost: self.speed_boost, - max_carry_mass: self.max_carry_mass, - horizontal_top_speed: self.horizontal_top_speed, - vertical_top_speed: self.vertical_top_speed, - specifics: self.specifics.into(), + speed_boost: val.speed_boost, + max_carry_mass: val.max_carry_mass, + horizontal_top_speed: val.horizontal_top_speed, + vertical_top_speed: val.vertical_top_speed, + specifics: val.specifics.into(), } } } @@ -158,21 +158,21 @@ pub enum MovementSpecificData { Ski, } -impl std::convert::Into for MovementSpecificData { - fn into(self) -> crate::data::movement_list::MovementSpecificData { - match self { - Self::Wheel(x) => crate::data::movement_list::MovementSpecificData::Wheel(x.into()), - Self::Hover(x) => crate::data::movement_list::MovementSpecificData::Hover(x.into()), - Self::Wing(x) => crate::data::movement_list::MovementSpecificData::Wing(x.into()), - Self::Rudder(x) => crate::data::movement_list::MovementSpecificData::Rudder(x.into()), - Self::Thruster(x) => crate::data::movement_list::MovementSpecificData::Thruster(x.into()), - Self::Propeller(x) => crate::data::movement_list::MovementSpecificData::Propeller(x.into()), - Self::InsectLeg(x) => crate::data::movement_list::MovementSpecificData::InsectLeg(x.into()), - Self::MechLeg(x) => crate::data::movement_list::MovementSpecificData::MechLeg(x.into()), - Self::SprinterLeg(x) => crate::data::movement_list::MovementSpecificData::SprinterLeg(x.into()), - Self::TankTrack(x) => crate::data::movement_list::MovementSpecificData::TankTrack(x.into()), - Self::Rotor(x) => crate::data::movement_list::MovementSpecificData::Rotor(x.into()), - Self::Ski=> crate::data::movement_list::MovementSpecificData::Ski, +impl std::convert::From for crate::data::movement_list::MovementSpecificData { + fn from(val: MovementSpecificData) -> Self { + match val { + MovementSpecificData::Wheel(x) => crate::data::movement_list::MovementSpecificData::Wheel(x.into()), + MovementSpecificData::Hover(x) => crate::data::movement_list::MovementSpecificData::Hover(x.into()), + MovementSpecificData::Wing(x) => crate::data::movement_list::MovementSpecificData::Wing(x.into()), + MovementSpecificData::Rudder(x) => crate::data::movement_list::MovementSpecificData::Rudder(x.into()), + MovementSpecificData::Thruster(x) => crate::data::movement_list::MovementSpecificData::Thruster(x.into()), + MovementSpecificData::Propeller(x) => crate::data::movement_list::MovementSpecificData::Propeller(x.into()), + MovementSpecificData::InsectLeg(x) => crate::data::movement_list::MovementSpecificData::InsectLeg(x.into()), + MovementSpecificData::MechLeg(x) => crate::data::movement_list::MovementSpecificData::MechLeg(x.into()), + MovementSpecificData::SprinterLeg(x) => crate::data::movement_list::MovementSpecificData::SprinterLeg(x.into()), + MovementSpecificData::TankTrack(x) => crate::data::movement_list::MovementSpecificData::TankTrack(x.into()), + MovementSpecificData::Rotor(x) => crate::data::movement_list::MovementSpecificData::Rotor(x.into()), + MovementSpecificData::Ski=> crate::data::movement_list::MovementSpecificData::Ski, } } } @@ -191,19 +191,19 @@ pub struct WheelData { pub brake_force_heavy: f32, } -impl std::convert::Into for WheelData { - fn into(self) -> crate::data::movement_list::WheelData { +impl std::convert::From for crate::data::movement_list::WheelData { + fn from(val: WheelData) -> Self { crate::data::movement_list::WheelData { - steering_speed_light: self.steering_speed_light, - steering_speed_heavy: self.steering_speed_heavy, - steering_force_multiplier_light: self.steering_force_multiplier_light, - steering_force_multiplier_heavy: self.steering_force_multiplier_heavy, - lateral_acceleration_light: self.lateral_acceleration_light, - lateral_acceleration_heavy: self.lateral_acceleration_heavy, - time_to_max_acceleration_light: self.time_to_max_acceleration_light, - time_to_max_acceleration_heavy: self.time_to_max_acceleration_heavy, - brake_force_light: self.brake_force_light, - brake_force_heavy: self.brake_force_heavy, + steering_speed_light: val.steering_speed_light, + steering_speed_heavy: val.steering_speed_heavy, + steering_force_multiplier_light: val.steering_force_multiplier_light, + steering_force_multiplier_heavy: val.steering_force_multiplier_heavy, + lateral_acceleration_light: val.lateral_acceleration_light, + lateral_acceleration_heavy: val.lateral_acceleration_heavy, + time_to_max_acceleration_light: val.time_to_max_acceleration_light, + time_to_max_acceleration_heavy: val.time_to_max_acceleration_heavy, + brake_force_light: val.brake_force_light, + brake_force_heavy: val.brake_force_heavy, } } } @@ -224,21 +224,21 @@ pub struct HoverData { pub lateral_damping_heavy: f32, } -impl std::convert::Into for HoverData { - fn into(self) -> crate::data::movement_list::HoverData { +impl std::convert::From for crate::data::movement_list::HoverData { + fn from(val: HoverData) -> Self { crate::data::movement_list::HoverData { - max_hover_height_light: self.max_hover_height_light, - max_hover_height_heavy: self.max_hover_height_heavy, - height_change_speed_light: self.height_change_speed_light, - height_change_speed_heavy: self.height_change_speed_heavy, - turn_torque_light: self.turn_torque_light, - turn_torque_heavy: self.turn_torque_heavy, - acceleration_light: self.acceleration_light, - acceleration_heavy: self.acceleration_heavy, - max_angular_velocity_light: self.max_angular_velocity_light, - max_angular_velocity_heavy: self.max_angular_velocity_heavy, - lateral_damping_light: self.lateral_damping_light, - lateral_damping_heavy: self.lateral_damping_heavy, + max_hover_height_light: val.max_hover_height_light, + max_hover_height_heavy: val.max_hover_height_heavy, + height_change_speed_light: val.height_change_speed_light, + height_change_speed_heavy: val.height_change_speed_heavy, + turn_torque_light: val.turn_torque_light, + turn_torque_heavy: val.turn_torque_heavy, + acceleration_light: val.acceleration_light, + acceleration_heavy: val.acceleration_heavy, + max_angular_velocity_light: val.max_angular_velocity_light, + max_angular_velocity_heavy: val.max_angular_velocity_heavy, + lateral_damping_light: val.lateral_damping_light, + lateral_damping_heavy: val.lateral_damping_heavy, } } } @@ -259,21 +259,21 @@ pub struct AerofoilData { pub vtol_velocity_heavy: f32, } -impl std::convert::Into for AerofoilData { - fn into(self) -> crate::data::movement_list::AerofoilData { +impl std::convert::From for crate::data::movement_list::AerofoilData { + fn from(val: AerofoilData) -> Self { crate::data::movement_list::AerofoilData { - barrel_speed_light: self.barrel_speed_light, - barrel_speed_heavy: self.barrel_speed_heavy, - bank_speed_light: self.bank_speed_light, - bank_speed_heavy: self.bank_speed_heavy, - elevation_speed_light: self.elevation_speed_light, - elevation_speed_heavy: self.elevation_speed_heavy, - rudder_speed_light: self.rudder_speed_light, - rudder_speed_heavy: self.rudder_speed_heavy, - thrust_light: self.thrust_light, - thrust_heavy: self.thrust_heavy, - vtol_velocity_light: self.vtol_velocity_light, - vtol_velocity_heavy: self.vtol_velocity_heavy, + barrel_speed_light: val.barrel_speed_light, + barrel_speed_heavy: val.barrel_speed_heavy, + bank_speed_light: val.bank_speed_light, + bank_speed_heavy: val.bank_speed_heavy, + elevation_speed_light: val.elevation_speed_light, + elevation_speed_heavy: val.elevation_speed_heavy, + rudder_speed_light: val.rudder_speed_light, + rudder_speed_heavy: val.rudder_speed_heavy, + thrust_light: val.thrust_light, + thrust_heavy: val.thrust_heavy, + vtol_velocity_light: val.vtol_velocity_light, + vtol_velocity_heavy: val.vtol_velocity_heavy, } } } @@ -284,11 +284,11 @@ pub struct ThrusterData { pub acceleration_delay_heavy: f32, } -impl std::convert::Into for ThrusterData { - fn into(self) -> crate::data::movement_list::ThrusterData { +impl std::convert::From for crate::data::movement_list::ThrusterData { + fn from(val: ThrusterData) -> Self { crate::data::movement_list::ThrusterData { - acceleration_delay_light: self.acceleration_delay_light, - acceleration_delay_heavy: self.acceleration_delay_heavy, + acceleration_delay_light: val.acceleration_delay_light, + acceleration_delay_heavy: val.acceleration_delay_heavy, } } } @@ -323,35 +323,35 @@ pub struct InsectLegData { pub swagger_force_heavy: f32, } -impl std::convert::Into for InsectLegData { - fn into(self) -> crate::data::movement_list::InsectLegData { +impl std::convert::From for crate::data::movement_list::InsectLegData { + fn from(val: InsectLegData) -> Self { crate::data::movement_list::InsectLegData { - ideal_height_light: self.ideal_height_light, - ideal_height_heavy: self.ideal_height_heavy, - ideal_crouching_height_light: self.ideal_crouching_height_light, - ideal_crouching_height_heavy: self.ideal_crouching_height_heavy, - ideal_height_range_light: self.ideal_height_range_light, - ideal_height_range_heavy: self.ideal_height_range_heavy, - jump_height_light: self.jump_height_light, - jump_height_heavy: self.jump_height_heavy, - max_upwards_force_light: self.max_upwards_force_light, - max_upwards_force_heavy: self.max_upwards_force_heavy, - max_lateral_force_light: self.max_lateral_force_light, - max_lateral_force_heavy: self.max_lateral_force_heavy, - max_turning_force_light: self.max_turning_force_light, - max_turning_force_heavy: self.max_turning_force_heavy, - max_damping_force_light: self.max_damping_force_light, - max_damping_force_heavy: self.max_damping_force_heavy, - max_stopped_force_light: self.max_stopped_force_light, - max_stopped_force_heavy: self.max_stopped_force_heavy, - max_new_stopped_force_light: self.max_new_stopped_force_light, - max_new_stopped_force_heavy: self.max_new_stopped_force_heavy, - upwards_damping_force_light: self.upwards_damping_force_light, - upwards_damping_force_heavy: self.upwards_damping_force_heavy, - lateral_damp_force_light: self.lateral_damp_force_light, - lateral_damp_force_heavy: self.lateral_damp_force_heavy, - swagger_force_light: self.swagger_force_light, - swagger_force_heavy: self.swagger_force_heavy, + ideal_height_light: val.ideal_height_light, + ideal_height_heavy: val.ideal_height_heavy, + ideal_crouching_height_light: val.ideal_crouching_height_light, + ideal_crouching_height_heavy: val.ideal_crouching_height_heavy, + ideal_height_range_light: val.ideal_height_range_light, + ideal_height_range_heavy: val.ideal_height_range_heavy, + jump_height_light: val.jump_height_light, + jump_height_heavy: val.jump_height_heavy, + max_upwards_force_light: val.max_upwards_force_light, + max_upwards_force_heavy: val.max_upwards_force_heavy, + max_lateral_force_light: val.max_lateral_force_light, + max_lateral_force_heavy: val.max_lateral_force_heavy, + max_turning_force_light: val.max_turning_force_light, + max_turning_force_heavy: val.max_turning_force_heavy, + max_damping_force_light: val.max_damping_force_light, + max_damping_force_heavy: val.max_damping_force_heavy, + max_stopped_force_light: val.max_stopped_force_light, + max_stopped_force_heavy: val.max_stopped_force_heavy, + max_new_stopped_force_light: val.max_new_stopped_force_light, + max_new_stopped_force_heavy: val.max_new_stopped_force_heavy, + upwards_damping_force_light: val.upwards_damping_force_light, + upwards_damping_force_heavy: val.upwards_damping_force_heavy, + lateral_damp_force_light: val.lateral_damp_force_light, + lateral_damp_force_heavy: val.lateral_damp_force_heavy, + swagger_force_light: val.swagger_force_light, + swagger_force_heavy: val.swagger_force_heavy, } } } @@ -374,23 +374,23 @@ pub struct MechLegData { pub max_damping_force_heavy: f32, } -impl std::convert::Into for MechLegData { - fn into(self) -> crate::data::movement_list::MechLegData { +impl std::convert::From for crate::data::movement_list::MechLegData { + fn from(val: MechLegData) -> Self { crate::data::movement_list::MechLegData { - time_grounded_after_jump_light: self.time_grounded_after_jump_light, - time_grounded_after_jump_heavy: self.time_grounded_after_jump_heavy, - jump_height_light: self.jump_height_light, - jump_height_heavy: self.jump_height_heavy, - turn_acceleration_light: self.turn_acceleration_light, - turn_acceleration_heavy: self.turn_acceleration_heavy, - legacy_turn_acceleration_light: self.legacy_turn_acceleration_light, - legacy_turn_acceleration_heavy: self.legacy_turn_acceleration_heavy, - long_jump_speed_scale_light: self.long_jump_speed_scale_light, - long_jump_speed_scale_heavy: self.long_jump_speed_scale_heavy, - max_lateral_force_light: self.max_lateral_force_light, - max_lateral_force_heavy: self.max_lateral_force_heavy, - max_damping_force_light: self.max_damping_force_light, - max_damping_force_heavy: self.max_damping_force_heavy, + time_grounded_after_jump_light: val.time_grounded_after_jump_light, + time_grounded_after_jump_heavy: val.time_grounded_after_jump_heavy, + jump_height_light: val.jump_height_light, + jump_height_heavy: val.jump_height_heavy, + turn_acceleration_light: val.turn_acceleration_light, + turn_acceleration_heavy: val.turn_acceleration_heavy, + legacy_turn_acceleration_light: val.legacy_turn_acceleration_light, + legacy_turn_acceleration_heavy: val.legacy_turn_acceleration_heavy, + long_jump_speed_scale_light: val.long_jump_speed_scale_light, + long_jump_speed_scale_heavy: val.long_jump_speed_scale_heavy, + max_lateral_force_light: val.max_lateral_force_light, + max_lateral_force_heavy: val.max_lateral_force_heavy, + max_damping_force_light: val.max_damping_force_light, + max_damping_force_heavy: val.max_damping_force_heavy, } } } @@ -407,17 +407,17 @@ pub struct TankTrackData { pub lateral_acceleration_heavy: f32, } -impl std::convert::Into for TankTrackData { - fn into(self) -> crate::data::movement_list::TankTrackData { +impl std::convert::From for crate::data::movement_list::TankTrackData { + fn from(val: TankTrackData) -> Self { crate::data::movement_list::TankTrackData { - max_turn_rate_moving_light: self.max_turn_rate_moving_light, - max_turn_rate_moving_heavy: self.max_turn_rate_moving_heavy, - max_turn_rate_stopped_light: self.max_turn_rate_stopped_light, - max_turn_rate_stopped_heavy: self.max_turn_rate_stopped_heavy, - turn_acceleration_light: self.turn_acceleration_light, - turn_acceleration_heavy: self.turn_acceleration_heavy, - lateral_acceleration_light: self.lateral_acceleration_light, - lateral_acceleration_heavy: self.lateral_acceleration_heavy, + max_turn_rate_moving_light: val.max_turn_rate_moving_light, + max_turn_rate_moving_heavy: val.max_turn_rate_moving_heavy, + max_turn_rate_stopped_light: val.max_turn_rate_stopped_light, + max_turn_rate_stopped_heavy: val.max_turn_rate_stopped_heavy, + turn_acceleration_light: val.turn_acceleration_light, + turn_acceleration_heavy: val.turn_acceleration_heavy, + lateral_acceleration_light: val.lateral_acceleration_light, + lateral_acceleration_heavy: val.lateral_acceleration_heavy, } } } @@ -436,19 +436,19 @@ pub struct RotorData { pub level_acceleration_heavy: f32, } -impl std::convert::Into for RotorData { - fn into(self) -> crate::data::movement_list::RotorData { +impl std::convert::From for crate::data::movement_list::RotorData { + fn from(val: RotorData) -> Self { crate::data::movement_list::RotorData { - height_acceleration_light: self.height_acceleration_light, - height_acceleration_heavy: self.height_acceleration_heavy, - strafe_acceleration_light: self.strafe_acceleration_light, - strafe_acceleration_heavy: self.strafe_acceleration_heavy, - turn_acceleration_light: self.turn_acceleration_light, - turn_acceleration_heavy: self.turn_acceleration_heavy, - height_max_change_speed_light: self.height_max_change_speed_light, - height_max_change_speed_heavy: self.height_max_change_speed_heavy, - level_acceleration_light: self.level_acceleration_light, - level_acceleration_heavy: self.level_acceleration_heavy, + height_acceleration_light: val.height_acceleration_light, + height_acceleration_heavy: val.height_acceleration_heavy, + strafe_acceleration_light: val.strafe_acceleration_light, + strafe_acceleration_heavy: val.strafe_acceleration_heavy, + turn_acceleration_light: val.turn_acceleration_light, + turn_acceleration_heavy: val.turn_acceleration_heavy, + height_max_change_speed_light: val.height_max_change_speed_light, + height_max_change_speed_heavy: val.height_max_change_speed_heavy, + level_acceleration_light: val.level_acceleration_light, + level_acceleration_heavy: val.level_acceleration_heavy, } } } diff --git a/rc_core/src/persist/singleplayer.rs b/rc_core/src/persist/singleplayer.rs index c273caa..43d20cf 100644 --- a/rc_core/src/persist/singleplayer.rs +++ b/rc_core/src/persist/singleplayer.rs @@ -86,17 +86,17 @@ pub struct CampaignDifficulty { pub damage_boost_wave_increase: f32, } -impl std::convert::Into for CampaignDifficulty { - fn into(self) -> crate::data::campaign::CampaignDifficultyData { +impl std::convert::From for crate::data::campaign::CampaignDifficultyData { + fn from(val: CampaignDifficulty) -> Self { crate::data::campaign::CampaignDifficultyData { - level: self.level, - lives: self.lives, - auto_heal: self.auto_heal, - single_wave_bonus: self.single_wave_bonus, - initial_health_boost: self.initial_health_boost, - health_boost_wave_increase: self.health_boost_wave_increase, - initial_damage_boost: self.initial_damage_boost, - damage_boost_wave_increase: self.damage_boost_wave_increase, + level: val.level, + lives: val.lives, + auto_heal: val.auto_heal, + single_wave_bonus: val.single_wave_bonus, + initial_health_boost: val.initial_health_boost, + health_boost_wave_increase: val.health_boost_wave_increase, + initial_damage_boost: val.initial_damage_boost, + damage_boost_wave_increase: val.damage_boost_wave_increase, } } } @@ -128,22 +128,22 @@ pub struct Wave { pub time_max: i32, } -impl std::convert::Into for Wave { - fn into(self) -> crate::data::campaign::WaveData { +impl std::convert::From for crate::data::campaign::WaveData { + fn from(val: Wave) -> Self { crate::data::campaign::WaveData { - robots_in_wave: self.robots_in_wave.into_iter().map(|x| x.into()).collect(), + robots_in_wave: val.robots_in_wave.into_iter().map(|x| x.into()).collect(), } } } -impl std::convert::Into for Wave { - fn into(self) -> crate::data::campaign::CompleteWaveData { +impl std::convert::From for crate::data::campaign::CompleteWaveData { + fn from(val: Wave) -> Self { crate::data::campaign::CompleteWaveData { - player_spawn_location: self.player_spawn_location, - robots_in_wave: self.robots_in_wave.into_iter().map(|x| x.into()).collect(), - kill_target: self.kill_target, - time_min: self.time_min, - time_max: self.time_max, + player_spawn_location: val.player_spawn_location, + robots_in_wave: val.robots_in_wave.into_iter().map(|x| x.into()).collect(), + kill_target: val.kill_target, + time_min: val.time_min, + time_max: val.time_max, } } } @@ -185,35 +185,35 @@ fn default_1() -> i32 { 1 } -impl std::convert::Into for WaveRobot { - fn into(self) -> crate::data::campaign::WaveRobotData { +impl std::convert::From for crate::data::campaign::WaveRobotData { + fn from(val: WaveRobot) -> Self { crate::data::campaign::WaveRobotData { - name: self.name, - weapon: self.weapon, - movement: self.movement, - rank: self.rank, - count: self.count, + name: val.name, + weapon: val.weapon, + movement: val.movement, + rank: val.rank, + count: val.count, } } } -impl std::convert::Into for WaveRobot { - fn into(self) -> crate::data::campaign::CompleteWaveRobotData { +impl std::convert::From for crate::data::campaign::CompleteWaveRobotData { + fn from(val: WaveRobot) -> Self { crate::data::campaign::CompleteWaveRobotData { - name: self.name, - robot_data: self.robot_data, - colour_data: self.colour_data, - time_to_spawn: self.time_to_spawn, - kills_to_spawn: self.kills_to_spawn, - time_to_despawn: self.time_to_despawn, - kills_to_despawn: self.kills_to_despawn, - initial_robot_amount: self.initial_robot_amount, - periodic_robot_amount: self.periodic_robot_amount, - spawn_interval: self.spawn_interval, - min_robot_amount: self.min_robot_amount, - max_robot_amount: self.max_robot_amount, - is_boss: self.is_boss, - is_kill_requirement: self.is_kill_requirement, + name: val.name, + robot_data: val.robot_data, + colour_data: val.colour_data, + time_to_spawn: val.time_to_spawn, + kills_to_spawn: val.kills_to_spawn, + time_to_despawn: val.time_to_despawn, + kills_to_despawn: val.kills_to_despawn, + initial_robot_amount: val.initial_robot_amount, + periodic_robot_amount: val.periodic_robot_amount, + spawn_interval: val.spawn_interval, + min_robot_amount: val.min_robot_amount, + max_robot_amount: val.max_robot_amount, + is_boss: val.is_boss, + is_kill_requirement: val.is_kill_requirement, } } } @@ -225,12 +225,12 @@ pub enum CampaignType { Elimination = 2, } -impl std::convert::Into for CampaignType { - fn into(self) -> crate::data::campaign::CampaignType { - match self { - Self::TimedElimination => crate::data::campaign::CampaignType::TimedElimination, - Self::Survival => crate::data::campaign::CampaignType::Survival, - Self::Elimination => crate::data::campaign::CampaignType::Elimination, +impl std::convert::From for crate::data::campaign::CampaignType { + fn from(val: CampaignType) -> Self { + match val { + CampaignType::TimedElimination => crate::data::campaign::CampaignType::TimedElimination, + CampaignType::Survival => crate::data::campaign::CampaignType::Survival, + CampaignType::Elimination => crate::data::campaign::CampaignType::Elimination, } } } diff --git a/rc_core/src/persist/user/account_json.rs b/rc_core/src/persist/user/account_json.rs index ebe21b6..8c4fb5a 100644 --- a/rc_core/src/persist/user/account_json.rs +++ b/rc_core/src/persist/user/account_json.rs @@ -404,7 +404,7 @@ impl UserData { group: None, // no platoon team: 0, has_premium: false, // FIXME - robot_uuid: super::i64_as_uuid_str(current_slot.uuid).into(), + robot_uuid: super::i64_as_uuid_str(current_slot.uuid), cpu: cpu_count, avatar_id: avatar_id.ok(), weapon_order: weapon_orders, @@ -448,17 +448,17 @@ impl UserData { }, Ok(None) => { log::error!("Prefab vehicle {} does not exist in factory", factory_id); - return Err(polariton_server::operations::SimpleOpError::with_message( + Err(polariton_server::operations::SimpleOpError::with_message( crate::data::error_codes::SingleplayerErrorCode::UnexpectedError as i16, format!("Prefab vehicle {} does not exist in factory", factory_id), - )); + )) }, Err(e) => { log::error!("Failed to retrieve prefab vehicle {} from factory: {}", factory_id, e); - return Err(polariton_server::operations::SimpleOpError::with_message( + Err(polariton_server::operations::SimpleOpError::with_message( crate::data::error_codes::SingleplayerErrorCode::DatabaseError as i16, format!("Failed to retrieve prefab vehicle {} from factory: {}", factory_id, e), - )); + )) } } }, @@ -488,17 +488,17 @@ impl UserData { }, Ok(None) => { log::error!("Prefab vehicle {} does not exist in main garage database", garage); - return Err(polariton_server::operations::SimpleOpError::with_message( + Err(polariton_server::operations::SimpleOpError::with_message( crate::data::error_codes::SingleplayerErrorCode::UnexpectedError as i16, format!("Prefab vehicle {} does not exist in main garage database", garage), - )); + )) } Err(e) => { log::error!("Failed to retrieve prefab vehicle {} from main garage database: {}", garage, e); - return Err(polariton_server::operations::SimpleOpError::with_message( + Err(polariton_server::operations::SimpleOpError::with_message( crate::data::error_codes::SingleplayerErrorCode::DatabaseError as i16, format!("Failed to retrieve prefab vehicle {} from main garage database: {}", garage, e), - )); + )) } } }, @@ -507,7 +507,7 @@ impl UserData { colour_data, } => { use sha2::Digest; - let sha_bytes = sha2::Sha256::digest(&cube_data); + let sha_bytes = sha2::Sha256::digest(cube_data); let u32_bytes = [ sha_bytes[0], sha_bytes[1], @@ -518,9 +518,9 @@ impl UserData { let uuid_str = crate::persist::user::i64_as_uuid_str(uuid_i64); let weapons_guess = weapon_order.guess_weapons(&mut std::io::Cursor::new(&cube_data)); let weapons_guess = vec![ - weapons_guess.get(0).map(|x| *x).unwrap_or(0), - weapons_guess.get(1).map(|x| *x).unwrap_or(0), - weapons_guess.get(2).map(|x| *x).unwrap_or(0), + weapons_guess.first().copied().unwrap_or(0), + weapons_guess.get(1).copied().unwrap_or(0), + weapons_guess.get(2).copied().unwrap_or(0), ]; let weapon_ranks = weapons_guess.iter().map(|&x| (x, if x == 0 { 0 } else { 1 })).collect(); let cpu_counts = cpu_counter.calculate_cpu(&mut std::io::Cursor::new(&cube_data)); @@ -546,6 +546,7 @@ impl UserData { let mut players = Vec::with_capacity((singleplayer_config.max_enemies + singleplayer_config.max_teammates + 1) as usize); let mut next_id = 0; let mut seen_usernames = std::collections::HashSet::::new(); + #[allow(clippy::explicit_counter_loop)] // this is really bad to read with this suggested refactor for i in 0..(singleplayer_config.max_enemies + singleplayer_config.max_teammates) { let vehicle = singleplayer_config.vehicles.choose(&mut rand::rng()) .ok_or(crate::data::error_codes::SingleplayerErrorCode::UnexpectedError as i16)?; @@ -723,7 +724,7 @@ impl super::User for UserData { movement_categories: polariton::operation::Typed::IntArr(oj_rc_database::schema::parse_int_csv(&slot.movement_categories).into_iter().map(|x| x as i32).collect::>().into()), control_type: polariton::operation::Typed::Int(control_ty as _), control_options: control_options.as_transmissible(), - mastery_level: polariton::operation::Typed::Int(slot.mastery_level as i32), + mastery_level: polariton::operation::Typed::Int(slot.mastery_level), robot_rank: polariton::operation::Typed::Int(slot.total_robot_ranking as _), cpu: polariton::operation::Typed::Int(slot.total_robot_cpu as _), cosmetic_cpu: polariton::operation::Typed::Int(slot.total_cosmetic_cpu as _), @@ -899,7 +900,7 @@ impl super::User for UserData { log::error!("No selected vehicle slot for user_id {}", self.account.id); DATABASE_ERR })?; - let inc_opt = self.garage_upgrades.increments.iter().enumerate().filter(|(_i, inc)| inc.cpu <= selected_slot.bay_cpu as u32).last(); + let inc_opt = self.garage_upgrades.increments.iter().enumerate().filter(|(_i, inc)| inc.cpu <= selected_slot.bay_cpu as u32).next_back(); if let Some((i, _)) = inc_opt { let max_upgrade = self.garage_upgrades.increments.len() - 1; let upgrade_to = i + (increments as usize); diff --git a/rc_core/src/persist/user/initial_data.rs b/rc_core/src/persist/user/initial_data.rs index 4cc47f4..f4676e0 100644 --- a/rc_core/src/persist/user/initial_data.rs +++ b/rc_core/src/persist/user/initial_data.rs @@ -52,11 +52,7 @@ fn default_user_data(info: &super::RegistrationInfo) -> oj_rc_database::schema:: Ok(password) => password.to_string(), } }; - let steam_id = if let Some(id) = info.steam_id { - Some(id.to_string()) - } else { - None - }; + let steam_id = info.steam_id.map(|id| id.to_string()); oj_rc_database::schema::user::ActiveModel { id: Default::default(), creation_time: oj_rc_database::sea_orm::ActiveValue::Set(current_unix_time()), diff --git a/rc_core/src/persist/weapon.rs b/rc_core/src/persist/weapon.rs index 21b778f..6d6beba 100644 --- a/rc_core/src/persist/weapon.rs +++ b/rc_core/src/persist/weapon.rs @@ -88,71 +88,71 @@ fn group_fire_scales_default() -> Vec { vec![1.0] } -impl std::convert::Into for WeaponData { - fn into(self) -> crate::data::weapon_list::WeaponData { +impl std::convert::From for crate::data::weapon_list::WeaponData { + fn from(val: WeaponData) -> Self { crate::data::weapon_list::WeaponData { - damage_inflicted: self.damage_inflicted, - protonium_damage_scale: self.protonium_damage_scale, - projectile_speed: self.projectile_speed, - projectile_range: self.projectile_range, - base_inaccuracy: self.base_inaccuracy, - base_air_inaccuracy: self.base_air_inaccuracy, - movement_inaccuracy: self.movement_inaccuracy, - movement_max_speed: self.movement_max_speed, - movement_min_speed: self.movement_min_speed, - gun_rotation_slow: self.gun_rotation_slow, - movement_inaccuracy_decay: self.movement_inaccuracy_decay, - slow_rotation_decay: self.slow_rotation_decay, - quick_rotation_decay: self.quick_rotation_decay, - movement_inaccuracy_recovery: self.movement_inaccuracy_recovery, - repeat_fire_inaccuracy_total_degrees: self.repeat_fire_inaccuracy_total_degrees, - repeat_fire_inaccuracy_decay: self.repeat_fire_inaccuracy_decay, - repeat_fire_innaccuracy_recovery: self.repeat_fire_innaccuracy_recovery, - fire_instant_accuracy_decay: self.fire_instant_accuracy_decay, // degrees - accuracy_non_recover_time: self.accuracy_non_recover_time, - accuracy_decay: self.accuracy_decay, - damage_radius: self.damage_radius, - plasma_time_to_full_damage: self.plasma_time_to_full_damage, - plasma_starting_radius_scale: self.plasma_starting_radius_scale, - nano_dps: self.nano_dps, - nano_hps: self.nano_hps, - tesla_damage: self.tesla_damage, - tesla_charges: self.tesla_charges, - aeroflak_proximity_damage: self.aeroflak_proximity_damage, - aeroflak_damage_radius: self.aeroflak_damage_radius, - aeroflak_explosion_radius: self.aeroflak_explosion_radius, - aeroflak_ground_clearance: self.aeroflak_ground_clearance, - aeroflak_max_stacks: self.aeroflak_max_stacks, - aeroflak_damage_per_stack: self.aeroflak_damage_per_stack, - aeroflak_stack_expire: self.aeroflak_stack_expire, - shot_cooldown: self.shot_cooldown, - smart_rotation_cooldown: self.smart_rotation_cooldown, - smart_rotation_cooldown_extra: self.smart_rotation_cooldown_extra, - smart_rotation_max_stacks: self.smart_rotation_max_stacks, - spin_up_time: self.spin_up_time, - spin_down_time: self.spin_down_time, - spin_initial_cooldown: self.spin_initial_cooldown, - group_fire_scales: self.group_fire_scales, - mana_cost: self.mana_cost, - lock_time: self.lock_time, - full_lock_release: self.full_lock_release, - change_lock_time: self.change_lock_time, - max_rotation_speed: self.max_rotation_speed, - initial_rotation_speed: self.initial_rotation_speed, - rotation_acceleration: self.rotation_acceleration, - nano_healing_priority_time: self.nano_healing_priority_time, - module_range: self.module_range, - shield_lifetime: self.shield_lifetime, - teleport_time: self.teleport_time, - camera_time: self.camera_time, - camera_delay: self.camera_delay, - to_invisible_speed: self.to_invisible_speed, - to_invisible_duration: self.to_invisible_duration, - to_visible_duration: self.to_visible_duration, - countdown_time: self.countdown_time, - stun_time: self.stun_time, - stun_radius: self.stun_radius, - effect_duration: self.effect_duration, + damage_inflicted: val.damage_inflicted, + protonium_damage_scale: val.protonium_damage_scale, + projectile_speed: val.projectile_speed, + projectile_range: val.projectile_range, + base_inaccuracy: val.base_inaccuracy, + base_air_inaccuracy: val.base_air_inaccuracy, + movement_inaccuracy: val.movement_inaccuracy, + movement_max_speed: val.movement_max_speed, + movement_min_speed: val.movement_min_speed, + gun_rotation_slow: val.gun_rotation_slow, + movement_inaccuracy_decay: val.movement_inaccuracy_decay, + slow_rotation_decay: val.slow_rotation_decay, + quick_rotation_decay: val.quick_rotation_decay, + movement_inaccuracy_recovery: val.movement_inaccuracy_recovery, + repeat_fire_inaccuracy_total_degrees: val.repeat_fire_inaccuracy_total_degrees, + repeat_fire_inaccuracy_decay: val.repeat_fire_inaccuracy_decay, + repeat_fire_innaccuracy_recovery: val.repeat_fire_innaccuracy_recovery, + fire_instant_accuracy_decay: val.fire_instant_accuracy_decay, // degrees + accuracy_non_recover_time: val.accuracy_non_recover_time, + accuracy_decay: val.accuracy_decay, + damage_radius: val.damage_radius, + plasma_time_to_full_damage: val.plasma_time_to_full_damage, + plasma_starting_radius_scale: val.plasma_starting_radius_scale, + nano_dps: val.nano_dps, + nano_hps: val.nano_hps, + tesla_damage: val.tesla_damage, + tesla_charges: val.tesla_charges, + aeroflak_proximity_damage: val.aeroflak_proximity_damage, + aeroflak_damage_radius: val.aeroflak_damage_radius, + aeroflak_explosion_radius: val.aeroflak_explosion_radius, + aeroflak_ground_clearance: val.aeroflak_ground_clearance, + aeroflak_max_stacks: val.aeroflak_max_stacks, + aeroflak_damage_per_stack: val.aeroflak_damage_per_stack, + aeroflak_stack_expire: val.aeroflak_stack_expire, + shot_cooldown: val.shot_cooldown, + smart_rotation_cooldown: val.smart_rotation_cooldown, + smart_rotation_cooldown_extra: val.smart_rotation_cooldown_extra, + smart_rotation_max_stacks: val.smart_rotation_max_stacks, + spin_up_time: val.spin_up_time, + spin_down_time: val.spin_down_time, + spin_initial_cooldown: val.spin_initial_cooldown, + group_fire_scales: val.group_fire_scales, + mana_cost: val.mana_cost, + lock_time: val.lock_time, + full_lock_release: val.full_lock_release, + change_lock_time: val.change_lock_time, + max_rotation_speed: val.max_rotation_speed, + initial_rotation_speed: val.initial_rotation_speed, + rotation_acceleration: val.rotation_acceleration, + nano_healing_priority_time: val.nano_healing_priority_time, + module_range: val.module_range, + shield_lifetime: val.shield_lifetime, + teleport_time: val.teleport_time, + camera_time: val.camera_time, + camera_delay: val.camera_delay, + to_invisible_speed: val.to_invisible_speed, + to_invisible_duration: val.to_invisible_duration, + to_visible_duration: val.to_visible_duration, + countdown_time: val.countdown_time, + stun_time: val.stun_time, + stun_radius: val.stun_radius, + effect_duration: val.effect_duration, } } } diff --git a/rc_lobby_room/src/lobby.rs b/rc_lobby_room/src/lobby.rs index 9528330..d63667c 100644 --- a/rc_lobby_room/src/lobby.rs +++ b/rc_lobby_room/src/lobby.rs @@ -76,8 +76,8 @@ impl QueueHandler { let game_desc = oj_rc_core::persist::user::GameDescriptor { guid: guid_str.clone(), map: key.map.clone(), - mode: key.mode.clone(), - visibility: key.visibility.clone(), + mode: key.mode, + visibility: key.visibility, auto_heal: key.auto_heal, is_ranked: false, is_custom: false, diff --git a/rc_multiplayer/src/events/validate_game_guid.rs b/rc_multiplayer/src/events/validate_game_guid.rs index 7709868..7603a27 100644 --- a/rc_multiplayer/src/events/validate_game_guid.rs +++ b/rc_multiplayer/src/events/validate_game_guid.rs @@ -38,53 +38,53 @@ impl crate::handlers::RlnlEventCodeHandler for AuthUserGame { log::debug!("Sent NewConnection message to matches handler"); if let Ok(Some(e)) = rx.await { log::error!("Failed {:?} event: {} [disconnecting...]", Self::CODE, e); - super::log_lnl_send_failure(crate::handlers::RlnlSender::new(&sender) + super::log_lnl_send_failure(crate::handlers::RlnlSender::new(sender) .send_data(&rlnl::types::StringCode { ty: rlnl::types::GameServerErrorCodes::StrErrCustomString, custom: Some(rlnl::types::BinaryWriterString(e.message)), }, rlnl::event_code::NetworkEvent::OnFailedToConnectToServer, literustlib::packet::Property::ReliableOrdered, - &peer).await); + peer).await); peer.disconnect(); } else { peer.certify(); } } else { log::error!("Registered game GUID does not match sent GUID (got: {}, expected: {}) [disconnecting...]", game_guid, current_game.guid); - super::log_lnl_send_failure(crate::handlers::RlnlSender::new(&sender) + super::log_lnl_send_failure(crate::handlers::RlnlSender::new(sender) .send_data(&rlnl::types::StringCode { ty: rlnl::types::GameServerErrorCodes::StrErrIncorrectGameGuid, custom: Some(rlnl::types::BinaryWriterString(format!("Send game guid does not equal expected guid; {} != {}", game_guid, current_game.guid))), }, rlnl::event_code::NetworkEvent::OnFailedToConnectToServer, literustlib::packet::Property::ReliableOrdered, - &peer).await); + peer).await); peer.disconnect(); } }, Ok(None) => { log::warn!("Cannot validate game guid for user {} with no ongoing game [disconnecting...]", user_info.user_id()); - super::log_lnl_send_failure(crate::handlers::RlnlSender::new(&sender) + super::log_lnl_send_failure(crate::handlers::RlnlSender::new(sender) .send_data(&rlnl::types::StringCode { ty: rlnl::types::GameServerErrorCodes::StrErrIncorrectGameGuid, custom: None, }, rlnl::event_code::NetworkEvent::OnFailedToConnectToServer, literustlib::packet::Property::ReliableOrdered, - &peer).await); + peer).await); peer.disconnect(); }, Err(e) => { log::error!("Failed to get current game for user {}: {} [disconnecting...]", user_info.user_id(), e.message); - super::log_lnl_send_failure(crate::handlers::RlnlSender::new(&sender) + super::log_lnl_send_failure(crate::handlers::RlnlSender::new(sender) .send_data(&rlnl::types::StringCode { ty: core_to_rlnl_mp_error_code(e.code), custom: Some(rlnl::types::BinaryWriterString(e.message)), }, rlnl::event_code::NetworkEvent::OnFailedToConnectToServer, literustlib::packet::Property::ReliableOrdered, - &peer).await); + peer).await); peer.disconnect(); }, } diff --git a/rc_multiplayer/src/handler.rs b/rc_multiplayer/src/handler.rs index f3cc1a6..2db2550 100644 --- a/rc_multiplayer/src/handler.rs +++ b/rc_multiplayer/src/handler.rs @@ -137,8 +137,8 @@ impl literustlib::packet::PacketData for EventData { use std::io::Write; let mut buf = Vec::new(); buf.write_all(&(self.message_ty as i16).to_le_bytes()).unwrap(); - buf.write_all(&(self.variant as i16).to_le_bytes()).unwrap(); - buf.write_all(&(self.data_size as u16).to_le_bytes()).unwrap(); + buf.write_all(&self.variant.to_le_bytes()).unwrap(); + buf.write_all(&self.data_size.to_le_bytes()).unwrap(); buf.write_all(&self.data).unwrap(); buf.into() } diff --git a/rc_multiplayer/src/handlers/gamemode_specific.rs b/rc_multiplayer/src/handlers/gamemode_specific.rs index 57c29f9..a0c3522 100644 --- a/rc_multiplayer/src/handlers/gamemode_specific.rs +++ b/rc_multiplayer/src/handlers/gamemode_specific.rs @@ -16,7 +16,7 @@ impl + Send, H: RlnlEventCodeHandler> crate::EventCodeHandler for SimpleRlnl { async fn handle(&self, data: &bytes::Bytes, peer: &std::sync::Arc>, user: &crate::UserData, sender: &std::sync::Arc>) { - let mut des = byteserde::des_slice::ByteDeserializerSlice::new(&data); + let mut des = byteserde::des_slice::ByteDeserializerSlice::new(data); match In::byte_deserialize(&mut des) { Ok(rlnl_data) => { //log::info!("Received {:?} message", H::CODE); diff --git a/rc_multiplayer/src/handlers/stub.rs b/rc_multiplayer/src/handlers/stub.rs index af98054..08158dc 100644 --- a/rc_multiplayer/src/handlers/stub.rs +++ b/rc_multiplayer/src/handlers/stub.rs @@ -10,7 +10,7 @@ impl + S fn new(_init_ctx: &crate::InitConfig) -> Self { Self { - _in: std::marker::PhantomData::default(), + _in: std::marker::PhantomData, } } } diff --git a/rc_multiplayer/src/matches/aggregate.rs b/rc_multiplayer/src/matches/aggregate.rs index 82f81f2..879ffa4 100644 --- a/rc_multiplayer/src/matches/aggregate.rs +++ b/rc_multiplayer/src/matches/aggregate.rs @@ -52,7 +52,7 @@ impl GameMatches { fakes } - async fn start_new_match_engine(&self, user: &Box, guid: &str) -> Result, oj_rc_core::persist::user::MultiplayerError> { + async fn start_new_match_engine(&self, user: &(dyn oj_rc_core::persist::user::MultiplayerUser + Send + Sync + 'static), guid: &str) -> Result, oj_rc_core::persist::user::MultiplayerError> { let game_info = user.game_info(guid).await? .ok_or_else(|| oj_rc_core::persist::user::MultiplayerError { code: oj_rc_core::persist::user::MultiplayerErrorCode::CustomString, @@ -89,7 +89,7 @@ impl GameMatches { oj_rc_core::data::game_mode::GameMode::BattleArena => { log::warn!("Game {}: Battle Arena is experimental", guid); let resolved_ba_conf = self.ba_settings.resolve( - user.as_ref(), + user, self.factory.as_ref(), &self.cube_parsers.weapon_order(), &self.cube_parsers.cpu_counter(), @@ -127,7 +127,7 @@ impl GameMatches { sender: std::sync::Arc>, ) { log::info!("Creating new game {}", game_guid); - let tx = match self.start_new_match_engine(&user, &game_guid).await { + let tx = match self.start_new_match_engine(user.as_ref().as_ref(), &game_guid).await { Ok(tx) => tx, Err(e) => { if response.send(Some(crate::matches::messages::ErrorMessage { @@ -190,10 +190,8 @@ impl GameMatches { if let Some(tx) = self.matches.get(guid) { if tx.is_closed() { to_clean = Some(guid.to_owned()); - } else { - if tx.send(msg).await.is_err() { - log::error!("Failed to route game message from user {} to match {}", user_id, guid); - } + } else if tx.send(msg).await.is_err() { + log::error!("Failed to route game message from user {} to match {}", user_id, guid); } } else { self.routing.remove(&user_id); diff --git a/rc_multiplayer/src/matches/engine.rs b/rc_multiplayer/src/matches/engine.rs index 5b9599b..2daa3ec 100644 --- a/rc_multiplayer/src/matches/engine.rs +++ b/rc_multiplayer/src/matches/engine.rs @@ -25,6 +25,7 @@ pub trait CustomGameLogic: Sized + Send + Sync + 'static { /// Called when the game is marked as complete async fn on_game_completed(&self, generic: &super::GenericGamemodeEngine) -> bool; /// Called when various network events are broadcast from one client but before they are sent to the rest of the clients + #[allow(clippy::too_many_arguments)] async fn on_broadcast(&self, generic: &super::GenericGamemodeEngine, user_id: i32, event_out: rlnl::event_code::NetworkEvent, event_in: rlnl::event_code::NetworkEvent, property: literustlib::packet::Property, data: &Option>, skip_user: bool) -> bool; /// Called when a vehicle motion event is received from a client async fn on_motion(&self, generic: &super::GenericGamemodeEngine, motion: &rlnl::machine_motion::MachineMotion, location: (f32, f32, f32)) -> bool; diff --git a/rc_multiplayer/src/matches/fake/experimental.rs b/rc_multiplayer/src/matches/fake/experimental.rs index c0baeb0..a7da8e3 100644 --- a/rc_multiplayer/src/matches/fake/experimental.rs +++ b/rc_multiplayer/src/matches/fake/experimental.rs @@ -17,8 +17,8 @@ impl ExperimentalPlayer { #[async_trait::async_trait] impl super::FakeUser for ExperimentalPlayer { - async fn on_init(&self, descriptors: &Vec, player_id: u8) { - if let Some(my_desc) = descriptors.iter().filter(|x| x.player_id == player_id).next() { + async fn on_init(&self, descriptors: &[oj_rc_core::persist::user::PlayerDescriptor], player_id: u8) { + if let Some(my_desc) = descriptors.iter().find(|x| x.player_id == player_id) { *self.me.write().await = Some(my_desc.to_owned()); } } diff --git a/rc_multiplayer/src/matches/fake/traits.rs b/rc_multiplayer/src/matches/fake/traits.rs index a387cde..a02fb0e 100644 --- a/rc_multiplayer/src/matches/fake/traits.rs +++ b/rc_multiplayer/src/matches/fake/traits.rs @@ -1,6 +1,6 @@ #[async_trait::async_trait] pub trait FakeUser: Send + Sync { - async fn on_init(&self, descriptors: &Vec, player_id: u8); + async fn on_init(&self, descriptors: &[oj_rc_core::persist::user::PlayerDescriptor], player_id: u8); async fn on_ready(&self, real_players: &std::collections::HashMap); //fn on_damage(&self, data: &rlnl::events::ingame::DestroyCubesFull); async fn on_end(&self); diff --git a/rc_multiplayer/src/matches/generic.rs b/rc_multiplayer/src/matches/generic.rs index b29de1e..19bae60 100644 --- a/rc_multiplayer/src/matches/generic.rs +++ b/rc_multiplayer/src/matches/generic.rs @@ -233,7 +233,7 @@ impl GenericGamemodeEngine { } pub(super) async fn user_key_by_user_id(&self, user_id: i32) -> Option { - self.user_id_map.read().await.get(&user_id).map(|x| *x) + self.user_id_map.read().await.get(&user_id).copied() } pub(super) async fn rebroadcast(&self, user_id: i32, code: rlnl::event_code::NetworkEvent, property: literustlib::packet::Property, data: &T, in_game: bool) { @@ -335,7 +335,7 @@ impl GenericGamemodeEngine { //tokio::time::sleep(std::time::Duration::from_secs(1)).await; //let id = users.len() as u8; let user_id = user.user_id(); - let player_info = self.players_info.iter().filter(|p| p.user_id == Some(user_id)).next().unwrap(); + let player_info = self.players_info.iter().find(|p| p.user_id == Some(user_id)).unwrap(); let id = player_info.player_id; let new_user = UserConnection { user, @@ -535,10 +535,8 @@ impl GenericGamemodeEngine { log::info!("User {} is awaiting sync", user_id); user.state.mode.store(ConnectionMode::WaitingForSync.to_u8(), std::sync::atomic::Ordering::Relaxed); ready_count += 1; - } else { - if matches!(ConnectionMode::from_u8(user.state.mode.load(std::sync::atomic::Ordering::Relaxed)), ConnectionMode::WaitingForSync) { - ready_count += 1; - } + } else if matches!(ConnectionMode::from_u8(user.state.mode.load(std::sync::atomic::Ordering::Relaxed)), ConnectionMode::WaitingForSync) { + ready_count += 1; } } let player_count = self.players_info.iter().filter(|x| x.user_id.is_some()).count(); @@ -675,7 +673,7 @@ impl GenericGamemodeEngine { }, super::GameMessage::MapPing { user_id: _, ping } => { for (id, conn) in self.users.read().await.iter() { - if (*id as i32) != ping.sender && (conn.descriptor.team as i32) == ping.team_id { + if (*id as i32) != ping.sender && conn.descriptor.team == ping.team_id { crate::events::log_lnl_send_failure(conn.connection.rlnl().send_data( &ping, rlnl::event_code::NetworkEvent::MapPingEvent, @@ -931,7 +929,7 @@ impl GenericGamemodeEngine { sender.send_data( &rlnl::events::sync::InitialiseGameStats { num_players, - stats: (0..num_players).into_iter() + stats: (0..num_players) .map(|i| rlnl::types::IngamePlayerStats { player_name: i, num_stats: 0, diff --git a/rc_multiplayer/src/matches/mod.rs b/rc_multiplayer/src/matches/mod.rs index 72c5820..fc45b90 100644 --- a/rc_multiplayer/src/matches/mod.rs +++ b/rc_multiplayer/src/matches/mod.rs @@ -1,11 +1,11 @@ mod engine; -pub(self) use engine::{CustomGameLogic, RlnlPacket}; + use engine::{CustomGameLogic, RlnlPacket}; mod messages; pub use messages::GameMessage; mod generic; -pub(self) use generic::GenericGamemodeEngine; + use generic::GenericGamemodeEngine; mod aggregate; pub use aggregate::GameMatches; @@ -16,6 +16,6 @@ pub mod modes; mod timer; -pub(self) mod fake; + mod fake; pub const CHANNEL_BOUND: usize = 16; diff --git a/rc_multiplayer/src/matches/modes/battle_arena.rs b/rc_multiplayer/src/matches/modes/battle_arena.rs index e936305..d188041 100644 --- a/rc_multiplayer/src/matches/modes/battle_arena.rs +++ b/rc_multiplayer/src/matches/modes/battle_arena.rs @@ -112,12 +112,10 @@ impl PointInfo { let team = self.team.load(std::sync::atomic::Ordering::SeqCst); if team < 0 { 0 + } else if let Some(counter) = self.on_point.read().await.get(&(team as u8)) { + counter.load(std::sync::atomic::Ordering::SeqCst) } else { - if let Some(counter) = self.on_point.read().await.get(&(team as u8)) { - counter.load(std::sync::atomic::Ordering::SeqCst) - } else { - 0 - } + 0 } } @@ -212,7 +210,7 @@ impl PointTracker { notification: rlnl::types::CapturePointNotificationType::CaptureLocked, id: point_i, defending_team: point_team, - attacking_team: player_team as i8, + attacking_team: player_team, }, true, ).await; @@ -228,7 +226,7 @@ impl PointTracker { notification: rlnl::types::CapturePointNotificationType::CaptureStarted, id: point_i, defending_team: point_team, - attacking_team: player_team as i8, + attacking_team: player_team, }, true, ).await; @@ -240,7 +238,7 @@ impl PointTracker { notification: rlnl::types::CapturePointNotificationType::CaptureLocked, id: point_i, defending_team: point_team, - attacking_team: player_team as i8, + attacking_team: player_team, }, true, ).await; @@ -267,20 +265,18 @@ impl PointTracker { // something is out of sync, let's just ignore it and try to undo any underflow log::warn!("Team {} players on point {} counting error", player_team, point_i); point.on_point.read().await[&player_team_u8].store(0, std::sync::atomic::Ordering::SeqCst); - } else { - if old_friendlies == 1 && current_enemies != 0 { - generic.broadcast( - rlnl::event_code::NetworkEvent::CapturePointNotification, - literustlib::packet::Property::ReliableOrdered, - &rlnl::events::ingame::CapturePointNotification { - notification: rlnl::types::CapturePointNotificationType::CaptureUnlocked, - id: point_i, - defending_team: point_team, - attacking_team: player_team as i8, - }, - true, - ).await; - } + } else if old_friendlies == 1 && current_enemies != 0 { + generic.broadcast( + rlnl::event_code::NetworkEvent::CapturePointNotification, + literustlib::packet::Property::ReliableOrdered, + &rlnl::events::ingame::CapturePointNotification { + notification: rlnl::types::CapturePointNotificationType::CaptureUnlocked, + id: point_i, + defending_team: point_team, + attacking_team: player_team, + }, + true, + ).await; } } else { let old_enemies = point.on_point.read().await[&player_team_u8].fetch_sub(1, std::sync::atomic::Ordering::SeqCst); @@ -289,34 +285,32 @@ impl PointTracker { // something is out of sync, let's just ignore it and try to undo any underflow log::warn!("Team {} players on point {} counting error", player_team, point_i); point.on_point.read().await[&player_team_u8].store(0, std::sync::atomic::Ordering::SeqCst); - } else { - if old_enemies == 1 { - //log::info!("Enemy has left the capture point"); - generic.broadcast( - rlnl::event_code::NetworkEvent::CapturePointNotification, - literustlib::packet::Property::ReliableOrdered, - &rlnl::events::ingame::CapturePointNotification { - notification: rlnl::types::CapturePointNotificationType::CaptureStoppedNoAttackers, - id: point_i, - defending_team: point_team, - attacking_team: player_team as i8, - }, - true, - ).await; - let progress_now = point.capture.load(std::sync::atomic::Ordering::SeqCst).floor(); - point.capture.store(progress_now, std::sync::atomic::Ordering::SeqCst); - let data = rlnl::events::ingame::TeamBaseState { - base_team_or_mining_point_index: point_i, - current_progress: rlnl::types::ByteFloat::from(progress_now), - max_progress: rlnl::types::ByteFloat::from(max_progress), - }; - generic.broadcast( - rlnl::event_code::NetworkEvent::CapturePointProgress, - literustlib::packet::Property::ReliableOrdered, - &data, - true - ).await; - } + } else if old_enemies == 1 { + //log::info!("Enemy has left the capture point"); + generic.broadcast( + rlnl::event_code::NetworkEvent::CapturePointNotification, + literustlib::packet::Property::ReliableOrdered, + &rlnl::events::ingame::CapturePointNotification { + notification: rlnl::types::CapturePointNotificationType::CaptureStoppedNoAttackers, + id: point_i, + defending_team: point_team, + attacking_team: player_team, + }, + true, + ).await; + let progress_now = point.capture.load(std::sync::atomic::Ordering::SeqCst).floor(); + point.capture.store(progress_now, std::sync::atomic::Ordering::SeqCst); + let data = rlnl::events::ingame::TeamBaseState { + base_team_or_mining_point_index: point_i, + current_progress: rlnl::types::ByteFloat::from(progress_now), + max_progress: rlnl::types::ByteFloat::from(max_progress), + }; + generic.broadcast( + rlnl::event_code::NetworkEvent::CapturePointProgress, + literustlib::packet::Property::ReliableOrdered, + &data, + true + ).await; } } } @@ -364,7 +358,7 @@ impl PointTracker { log::info!("Point {} was captured by team {} in game {}", i, new_team, generic.game_guid()); cap_point.capture.store(0.0, std::sync::atomic::Ordering::SeqCst); cap_point.team.store(new_team, std::sync::atomic::Ordering::SeqCst); - if owned_points.get(&(new_team as u8)).map(|x| *x).unwrap_or(0) == 0 { + if owned_points.get(&(new_team as u8)).copied().unwrap_or(0) == 0 { captured_firsts.insert(new_team as u8); } if point_owner >= 0 && *owned_points.get(&(point_owner as u8)).unwrap() == 1 { @@ -738,7 +732,7 @@ impl CustomGameLogic for BattleArenaLogic { property: literustlib::packet::Property::ReliableOrdered, data: Box::new(rlnl::events::sync::GetCapturePoints { points: [ - generic.map_config.capture_points.get(0).map(|(s, _)| Self::sphere_to_capture_point(s, self.config.num_segments as f32)).unwrap_or_else(|| Self::default_capture_point(self.config.num_segments as f32)), + generic.map_config.capture_points.first().map(|(s, _)| Self::sphere_to_capture_point(s, self.config.num_segments as f32)).unwrap_or_else(|| Self::default_capture_point(self.config.num_segments as f32)), generic.map_config.capture_points.get(1).map(|(s, _)| Self::sphere_to_capture_point(s, self.config.num_segments as f32)).unwrap_or_else(|| Self::default_capture_point(self.config.num_segments as f32)), generic.map_config.capture_points.get(2).map(|(s, _)| Self::sphere_to_capture_point(s, self.config.num_segments as f32)).unwrap_or_else(|| Self::default_capture_point(self.config.num_segments as f32)), ] @@ -758,7 +752,7 @@ impl CustomGameLogic for BattleArenaLogic { }), }), // SetShieldState - if generic.map_config.bases.get(&0).is_some() { + if generic.map_config.bases.contains_key(&0) { Some(crate::matches::RlnlPacket { event: rlnl::event_code::NetworkEvent::SetShieldState, property: literustlib::packet::Property::ReliableOrdered, @@ -770,7 +764,7 @@ impl CustomGameLogic for BattleArenaLogic { } else { None }, - if generic.map_config.bases.get(&1).is_some() { + if generic.map_config.bases.contains_key(&1) { Some(crate::matches::RlnlPacket { event: rlnl::event_code::NetworkEvent::SetShieldState, property: literustlib::packet::Property::ReliableOrdered, @@ -852,7 +846,7 @@ impl CustomGameLogic for BattleArenaLogic { health: 7, }), },*/ - ].into_iter().filter_map(|x| x).collect() + ].into_iter().flatten().collect() } async fn on_countdown_start(&self, generic: &crate::matches::GenericGamemodeEngine, game_start: chrono::DateTime) -> bool { diff --git a/rc_multiplayer/src/matches/modes/elimination.rs b/rc_multiplayer/src/matches/modes/elimination.rs index 7a92b97..d09b029 100644 --- a/rc_multiplayer/src/matches/modes/elimination.rs +++ b/rc_multiplayer/src/matches/modes/elimination.rs @@ -332,7 +332,7 @@ impl BaseTracker { } fn teams(&self) -> std::collections::HashSet { - self.bases.keys().map(|x| *x).collect() + self.bases.keys().copied().collect() } } diff --git a/rc_multiplayer/src/vehicle_motion.rs b/rc_multiplayer/src/vehicle_motion.rs index 6237bdf..a58c104 100644 --- a/rc_multiplayer/src/vehicle_motion.rs +++ b/rc_multiplayer/src/vehicle_motion.rs @@ -20,7 +20,7 @@ impl VehicleMotionHandler { impl crate::RobotMotionHandler for VehicleMotionHandler { async fn handle(&self, data: &bytes::Bytes, user: &crate::UserData) { if let Some(user_info) = user.user().await { - let mut des = byteserde::des_slice::ByteDeserializerSlice::new(&data); + let mut des = byteserde::des_slice::ByteDeserializerSlice::new(data); match rlnl::machine_motion::MachineMotion::byte_deserialize(&mut des) { Ok(motion_data) => { crate::events::log_channel_send_failure(self.msg_router.send(crate::matches::GameMessage::Motion { diff --git a/rc_services_room/src/data/customisation_info.rs b/rc_services_room/src/data/customisation_info.rs index ebfdc58..7355c50 100644 --- a/rc_services_room/src/data/customisation_info.rs +++ b/rc_services_room/src/data/customisation_info.rs @@ -17,7 +17,7 @@ impl CustomisationData { (Typed::Str("skinsceneName".into()), Typed::Str(self.skin_scene_name.clone().into())), (Typed::Str("simulationPrefab".into()), Typed::Str(self.simulation_prefab.clone().into())), (Typed::Str("previewImageName".into()), Typed::Str(self.preview_image_name.clone().into())), - (Typed::Str("isDefault".into()), Typed::Bool(self.is_default.into())), + (Typed::Str("isDefault".into()), Typed::Bool(self.is_default)), ].into()) } } diff --git a/rc_services_room/src/data/item_shop_bundle.rs b/rc_services_room/src/data/item_shop_bundle.rs index 102aaa8..a3d5816 100644 --- a/rc_services_room/src/data/item_shop_bundle.rs +++ b/rc_services_room/src/data/item_shop_bundle.rs @@ -67,7 +67,7 @@ impl ItemShopBundle { pub fn as_transmissible_vec(items: Vec) -> Typed { let mut buf = Vec::new(); let mut writer = std::io::Cursor::new(&mut buf); - writer.write(&(items.len() as i32).to_le_bytes()).unwrap(); + writer.write_all(&(items.len() as i32).to_le_bytes()).unwrap(); for item in items.iter() { item.dump(&mut writer).unwrap(); } diff --git a/rc_services_room/src/data/palette.rs b/rc_services_room/src/data/palette.rs index 7c141e2..d94e8f9 100644 --- a/rc_services_room/src/data/palette.rs +++ b/rc_services_room/src/data/palette.rs @@ -9,11 +9,11 @@ pub struct ColourValue { impl ColourValue { fn read_no_alpha(reader: &mut R) -> std::io::Result { let mut buf = [0u8; 1]; - reader.read(&mut buf)?; + reader.read_exact(&mut buf)?; let r = buf[0]; - reader.read(&mut buf)?; + reader.read_exact(&mut buf)?; let g = buf[0]; - reader.read(&mut buf)?; + reader.read_exact(&mut buf)?; let b = buf[0]; Ok(Self { r, g, b, a: u8::MAX, @@ -39,7 +39,7 @@ impl Colour { let specular = ColourValue::read_no_alpha(reader)?; let overlay = ColourValue::read_no_alpha(reader)?; let mut buf = [0u8; 1]; - reader.read(&mut buf)?; + reader.read_exact(&mut buf)?; let premium = buf[0] != 0; Ok(Self { index, diffuse, specular, overlay, premium, @@ -48,7 +48,7 @@ impl Colour { pub fn read_many(reader: &mut R) -> std::io::Result> { let mut buf = [0u8; 4]; - reader.read(&mut buf)?; + reader.read_exact(&mut buf)?; let count = i32::from_le_bytes(buf); let mut results = Vec::with_capacity(count as _); for i in 0..count { diff --git a/rc_services_room/src/data/player_robopass_season.rs b/rc_services_room/src/data/player_robopass_season.rs index 0413a82..3749b23 100644 --- a/rc_services_room/src/data/player_robopass_season.rs +++ b/rc_services_room/src/data/player_robopass_season.rs @@ -17,7 +17,7 @@ impl PlayerRoboPassSeasonInfo { items: vec![ (Typed::Str("deltaXpToShow".into()), Typed::Int(self.delta_xp_to_show)), (Typed::Str("grade".into()), Typed::Int(self.grade)), - (Typed::Str("hasDeluxe".into()), Typed::Bool(self.has_deluxe.into())), + (Typed::Str("hasDeluxe".into()), Typed::Bool(self.has_deluxe)), (Typed::Str("progressInGrade".into()), Typed::Float(self.progress_in_grade)), (Typed::Str("xpFromSeasonStart".into()), Typed::Int(self.xp_from_start)), ], diff --git a/rc_services_room/src/operations/balance_info.rs b/rc_services_room/src/operations/balance_info.rs index 303134e..e7fbe95 100644 --- a/rc_services_room/src/operations/balance_info.rs +++ b/rc_services_room/src/operations/balance_info.rs @@ -7,7 +7,7 @@ const PAID_BALANCE_PARAM_KEY: u8 = 87; pub(super) fn balance_wallet_provider() -> SimpleFunc<66, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result) + Sync + Sync> { SimpleFunc::new(|params, _| { let mut params = params.to_dict(); - params.insert(FREE_BALANCE_PARAM_KEY, Typed::Long(31337_000)); + params.insert(FREE_BALANCE_PARAM_KEY, Typed::Long(31_337_000)); params.insert(PAID_BALANCE_PARAM_KEY, Typed::Long(1)); Ok(params.into()) }) diff --git a/rc_services_room/src/operations/chat_settings.rs b/rc_services_room/src/operations/chat_settings.rs index bf73a22..488dc92 100644 --- a/rc_services_room/src/operations/chat_settings.rs +++ b/rc_services_room/src/operations/chat_settings.rs @@ -7,7 +7,7 @@ pub(super) fn chat_settings_provider() -> SimpleFunc<18, crate::UserTy, impl (Fn SimpleFunc::new(|params, _| { let mut params = params.to_dict(); params.insert(PARAM_KEY, Typed::HashMap(vec![ - (Typed::Str("chatEnabled".into()), Typed::Bool(true.into())), + (Typed::Str("chatEnabled".into()), Typed::Bool(true)), ].into())); Ok(params.into()) }) diff --git a/rc_services_room/src/operations/crf_list_query.rs b/rc_services_room/src/operations/crf_list_query.rs index d55242b..831c9b4 100644 --- a/rc_services_room/src/operations/crf_list_query.rs +++ b/rc_services_room/src/operations/crf_list_query.rs @@ -19,7 +19,7 @@ async fn do_handling(params: ParameterTable<()>, _user: &crate::UserTy, factory: log::error!("Failed to retrieve vehicles from factory: {}", e); oj_rc_core::data::error_codes::WebServicesError::DatabaseError as i16 })?; - let vehicles: Vec<_> = vehicles.into_iter().map(|x| crate::data::crf::ItemResult::from(x)).collect(); + let vehicles: Vec<_> = vehicles.into_iter().map(crate::data::crf::ItemResult::from).collect(); params.insert(ITEMS_PARAM_KEY, crate::data::crf::ItemResult::as_transmissible(&vehicles)); } Ok(params.into()) diff --git a/rc_services_room/src/operations/cube_inventory.rs b/rc_services_room/src/operations/cube_inventory.rs index 9b3d2fa..5ced69e 100644 --- a/rc_services_room/src/operations/cube_inventory.rs +++ b/rc_services_room/src/operations/cube_inventory.rs @@ -32,7 +32,7 @@ impl OperationCode for CubeInventoryProvider { } } -pub(super) fn cube_inv_provider<'a>(cubes: &'a oj_rc_core::ConfigImpl) -> CubeInventoryProvider { +pub(super) fn cube_inv_provider(cubes: &oj_rc_core::ConfigImpl) -> CubeInventoryProvider { let cube_ids = >::ids(cubes); CubeInventoryProvider { cube_ids } } diff --git a/rc_services_room/src/operations/game_event_params.rs b/rc_services_room/src/operations/game_event_params.rs index 9c9cebb..4c071fd 100644 --- a/rc_services_room/src/operations/game_event_params.rs +++ b/rc_services_room/src/operations/game_event_params.rs @@ -50,7 +50,7 @@ impl Operation<()> for GameEventsParamsProvider { code: Self::op_code(), return_code: e, message: polariton::operation::Typed::Null, - params: params.into(), + params, } } } diff --git a/rc_services_room/src/operations/last_completed_campaign.rs b/rc_services_room/src/operations/last_completed_campaign.rs index cf3f0b3..5c3289c 100644 --- a/rc_services_room/src/operations/last_completed_campaign.rs +++ b/rc_services_room/src/operations/last_completed_campaign.rs @@ -8,7 +8,7 @@ const AVAILABLE_PARAM_KEY: u8 = 89; // bool pub(super) fn completed_campaign_provider() -> SimpleFunc<77, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result) + Sync + Sync> { SimpleFunc::new(|params, _| { let mut params = params.to_dict(); - params.insert(AVAILABLE_PARAM_KEY, Typed::Bool(false.into())); + params.insert(AVAILABLE_PARAM_KEY, Typed::Bool(false)); Ok(params.into()) }) } diff --git a/rc_services_room/src/operations/login_flags.rs b/rc_services_room/src/operations/login_flags.rs index 821a8e3..c84e2cb 100644 --- a/rc_services_room/src/operations/login_flags.rs +++ b/rc_services_room/src/operations/login_flags.rs @@ -19,13 +19,13 @@ impl Operation for UserFlagsTeller { fn handle(&self, _: polariton::operation::ParameterTable, _: &Self::User) -> polariton::operation::OperationResponse { let mut resp_params = std::collections::HashMap::new(); - resp_params.insert(Self::REMOVE_OBSOLETE_CUBES_KEY, polariton::operation::Typed::Bool(false.into())); - resp_params.insert(Self::REMOVE_UNOWNED_CUBES_KEY, polariton::operation::Typed::Bool(false.into())); + resp_params.insert(Self::REMOVE_OBSOLETE_CUBES_KEY, polariton::operation::Typed::Bool(false)); + resp_params.insert(Self::REMOVE_UNOWNED_CUBES_KEY, polariton::operation::Typed::Bool(false)); resp_params.insert(Self::REWARD_TITLE_KEY, polariton::operation::Typed::Str("".into())); resp_params.insert(Self::REWARD_BODY_KEY, polariton::operation::Typed::Str("".into())); // set this to non-empty to display pop-up at login - resp_params.insert(Self::REFUND_OBSOLETE_CUBES_KEY, polariton::operation::Typed::Bool(false.into())); - resp_params.insert(Self::CUBES_ARE_REPLACED_KEY, polariton::operation::Typed::Bool(false.into())); - resp_params.insert(Self::NEW_USER_KEY, polariton::operation::Typed::Bool(false.into())); + resp_params.insert(Self::REFUND_OBSOLETE_CUBES_KEY, polariton::operation::Typed::Bool(false)); + resp_params.insert(Self::CUBES_ARE_REPLACED_KEY, polariton::operation::Typed::Bool(false)); + resp_params.insert(Self::NEW_USER_KEY, polariton::operation::Typed::Bool(false)); resp_params.insert(Self::AB_TEST_KEY, polariton::operation::Typed::Str("".into())); resp_params.insert(Self::AB_GROUP_KEY, polariton::operation::Typed::Str("".into())); polariton::operation::OperationResponse { diff --git a/rc_services_room/src/operations/maintenancer.rs b/rc_services_room/src/operations/maintenancer.rs index 48e4c5f..d694cd3 100644 --- a/rc_services_room/src/operations/maintenancer.rs +++ b/rc_services_room/src/operations/maintenancer.rs @@ -9,7 +9,7 @@ impl Operation for MaintenanceModeTeller { fn handle(&self, _: polariton::operation::ParameterTable, _: &Self::User) -> polariton::operation::OperationResponse { let mut resp_params = HashMap::new(); - resp_params.insert(20 /* is in maintenance mode? */, polariton::operation::Typed::Bool(false.into())); + resp_params.insert(20 /* is in maintenance mode? */, polariton::operation::Typed::Bool(false)); resp_params.insert(19 /* maintenace mode message */, polariton::operation::Typed::Str("OpenJam's servers are currently undergoing maintenance".into())); polariton::operation::OperationResponse { code: 20, diff --git a/rc_services_room/src/operations/platform_config.rs b/rc_services_room/src/operations/platform_config.rs index 851b03e..caa76cb 100644 --- a/rc_services_room/src/operations/platform_config.rs +++ b/rc_services_room/src/operations/platform_config.rs @@ -47,7 +47,7 @@ impl SimpleOperation for PlatformConfigProvider { (Typed::Str("FeedbackURL".into()), Typed::Str(self.links.feedback_url.clone().into())), (Typed::Str("SupportURL".into()), Typed::Str(self.links.support_url.clone().into())), (Typed::Str("WikiURL".into()), Typed::Str(self.links.wiki_url.clone().into())), - ].into(), + ], })); Ok(params.into()) } diff --git a/rc_services_room/src/operations/player_started_purchase.rs b/rc_services_room/src/operations/player_started_purchase.rs index f8f8583..59f4c25 100644 --- a/rc_services_room/src/operations/player_started_purchase.rs +++ b/rc_services_room/src/operations/player_started_purchase.rs @@ -6,7 +6,7 @@ const PARAM_KEY: u8 = 135; pub(super) fn started_purchase_provider() -> SimpleFunc<54, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result) + Sync + Sync> { SimpleFunc::new(|params, _| { let mut params = params.to_dict(); - params.insert(PARAM_KEY, Typed::Bool(false.into())); + params.insert(PARAM_KEY, Typed::Bool(false)); Ok(params.into()) }) } diff --git a/rc_services_room/src/operations/reconnect_game.rs b/rc_services_room/src/operations/reconnect_game.rs index 7080e30..c1ad52b 100644 --- a/rc_services_room/src/operations/reconnect_game.rs +++ b/rc_services_room/src/operations/reconnect_game.rs @@ -6,7 +6,7 @@ const PARAM_KEY: u8 = 207; pub(super) fn available_reconnect_provider() -> SimpleFunc<171, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result) + Sync + Sync> { SimpleFunc::new(|params, _| { let mut params = params.to_dict(); - params.insert(PARAM_KEY, Typed::Bool(false.into())); + params.insert(PARAM_KEY, Typed::Bool(false)); Ok(params.into()) }) } diff --git a/rc_services_room/src/operations/special_items.rs b/rc_services_room/src/operations/special_items.rs index 11db869..da26226 100644 --- a/rc_services_room/src/operations/special_items.rs +++ b/rc_services_room/src/operations/special_items.rs @@ -18,7 +18,7 @@ pub(super) fn special_item_list_provider() -> SimpleFunc<6, crate::UserTy, impl sprite: "chair".to_string(), size: 1, }.as_transmissible()) - ].into(), + ], })); Ok(params.into()) }) diff --git a/rc_services_room/src/operations/tier_banding.rs b/rc_services_room/src/operations/tier_banding.rs index 298f232..2472432 100644 --- a/rc_services_room/src/operations/tier_banding.rs +++ b/rc_services_room/src/operations/tier_banding.rs @@ -14,7 +14,7 @@ pub(super) fn tiers_banding_provider() -> SimpleFunc<7, crate::UserTy, impl (Fn( 1 ].into())), (Typed::Str("maximumRobotRankingARobotCanObtain".into()), Typed::Int(1)), - ].into(), + ], })); Ok(params.into()) }) diff --git a/rc_services_room/src/operations/tutorial_status.rs b/rc_services_room/src/operations/tutorial_status.rs index 3ebb65b..120208f 100644 --- a/rc_services_room/src/operations/tutorial_status.rs +++ b/rc_services_room/src/operations/tutorial_status.rs @@ -8,9 +8,9 @@ const SKIPPED_PARAM_KEY: u8 = 142; pub(super) fn tutorial_info_provider() -> SimpleFunc<122, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result) + Sync + Sync> { SimpleFunc::new(|params, _| { let mut params = params.to_dict(); - params.insert(IN_PROGRESS_PARAM_KEY, Typed::Bool(false.into())); - params.insert(COMPLETED_PARAM_KEY, Typed::Bool(true.into())); - params.insert(SKIPPED_PARAM_KEY, Typed::Bool(true.into())); + params.insert(IN_PROGRESS_PARAM_KEY, Typed::Bool(false)); + params.insert(COMPLETED_PARAM_KEY, Typed::Bool(true)); + params.insert(SKIPPED_PARAM_KEY, Typed::Bool(true)); Ok(params.into()) }) } diff --git a/rc_social_room/src/data/clan.rs b/rc_social_room/src/data/clan.rs index 37fed4a..0d204ff 100644 --- a/rc_social_room/src/data/clan.rs +++ b/rc_social_room/src/data/clan.rs @@ -18,10 +18,10 @@ impl ClanMember { (Typed::Str("userName".into()), Typed::Str(self.username.clone().into())), (Typed::Str("displayName".into()), Typed::Str(self.display_name.clone().into())), (Typed::Str("memberState".into()), Typed::Int(self.member_state as i32)), - (Typed::Str("useCustomAvatar".into()), Typed::Bool(self.use_custom_avatar.into())), + (Typed::Str("useCustomAvatar".into()), Typed::Bool(self.use_custom_avatar)), (Typed::Str("avatarId".into()), Typed::Int(self.avatar_id)), (Typed::Str("rank".into()), Typed::Int(self.rank as i32)), - (Typed::Str("isOnline".into()), Typed::Bool(self.is_online.into())), + (Typed::Str("isOnline".into()), Typed::Bool(self.is_online)), (Typed::Str("seasonXP".into()), Typed::Int(self.season_xp)), ].into()) } diff --git a/rc_social_room/src/data/clan_invite.rs b/rc_social_room/src/data/clan_invite.rs index 9853bd4..bf13510 100644 --- a/rc_social_room/src/data/clan_invite.rs +++ b/rc_social_room/src/data/clan_invite.rs @@ -16,7 +16,7 @@ impl ClanInviteInfo { (Typed::Str("displayName".into()), Typed::Str(self.display_name.clone().into())), (Typed::Str("clanName".into()), Typed::Str(self.clan_name.clone().into())), (Typed::Str("clanSize".into()), Typed::Int(self.clan_size)), - (Typed::Str("useCustomAvatar".into()), Typed::Bool(self.use_custom_avatar.into())), + (Typed::Str("useCustomAvatar".into()), Typed::Bool(self.use_custom_avatar)), (Typed::Str("avatarId".into()), Typed::Int(self.avatar_id)), ].into()) } diff --git a/rc_social_room/src/data/friend.rs b/rc_social_room/src/data/friend.rs index da0e439..3038725 100644 --- a/rc_social_room/src/data/friend.rs +++ b/rc_social_room/src/data/friend.rs @@ -10,7 +10,7 @@ impl AvatarInfo { pub fn as_transmissible(&self) -> Typed { Typed::HashMap(vec![ (Typed::Str("name".into()), Typed::Str(self.name.clone().into())), - (Typed::Str("useCustomAvatar".into()), Typed::Bool(self.use_custom_avatar.into())), + (Typed::Str("useCustomAvatar".into()), Typed::Bool(self.use_custom_avatar)), (Typed::Str("avatarId".into()), Typed::Int(self.avatar_id)), ].into()) } diff --git a/rc_social_room/src/operations/previous_battle_rewards.rs b/rc_social_room/src/operations/previous_battle_rewards.rs index a19bdd6..8574409 100644 --- a/rc_social_room/src/operations/previous_battle_rewards.rs +++ b/rc_social_room/src/operations/previous_battle_rewards.rs @@ -7,7 +7,7 @@ const PARAM_KEY: u8 = 60; pub(super) fn pending_battle_rewards_provider() -> SimpleFunc<54, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result, i16>) + Sync + Sync, C> { SimpleFunc::new(|params, _| { let mut params = params.to_dict(); - params.insert(PARAM_KEY, Typed::Bool(false.into())); + params.insert(PARAM_KEY, Typed::Bool(false)); Ok(params.into()) }) } diff --git a/rc_social_room/src/operations/season_rewards.rs b/rc_social_room/src/operations/season_rewards.rs index 6a634e4..a8b5f6c 100644 --- a/rc_social_room/src/operations/season_rewards.rs +++ b/rc_social_room/src/operations/season_rewards.rs @@ -13,10 +13,10 @@ const PLAYER_XP_PARAM_KEY: u8 = 57; pub(super) fn season_rewards_provider() -> SimpleFunc<50, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result, i16>) + Sync + Sync, C> { SimpleFunc::new(|params, _| { let mut params = params.to_dict(); - params.insert(MONTH_PARAM_KEY, Typed::Int(02)); + params.insert(MONTH_PARAM_KEY, Typed::Int(2)); params.insert(YEAR_PARAM_KEY, Typed::Int(2025)); params.insert(ROBITS_PARAM_KEY, Typed::Int(42)); - params.insert(IS_CLAIMED_PARAM_KEY, Typed::Bool(true.into())); + params.insert(IS_CLAIMED_PARAM_KEY, Typed::Bool(true)); params.insert(CLAN_AVERAGE_PARAM_KEY, Typed::Int(67)); params.insert(CLAN_TOTAL_PARAM_KEY, Typed::Int(42_123)); params.insert(CLAN_NAME_PARAM_KEY, Typed::Str("RE_clan_name_rewards".into()));