Skip to content

Commit

Permalink
rust fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
theaddonn committed Jul 4, 2024
1 parent d7cf13c commit ffdc850
Show file tree
Hide file tree
Showing 39 changed files with 251 additions and 191 deletions.
2 changes: 0 additions & 2 deletions bedrock_core/src/actor_runtime_id.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
use crate::VAR;

#[derive(Debug, Clone)]
pub struct ActorRuntimeID(pub u64);
2 changes: 0 additions & 2 deletions bedrock_core/src/actor_unique_id.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
use crate::VAR;

#[derive(Debug, Clone)]
pub struct ActorUniqueID(pub i64);
2 changes: 1 addition & 1 deletion bedrock_core/src/generator_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ pub enum GeneratorType {
Nether,
End,
Void,
}
}
16 changes: 8 additions & 8 deletions bedrock_core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
pub use actor_runtime_id::*;
pub use actor_unique_id::*;
pub use difficulty::*;
pub use dimension::*;
pub use generator_type::*;
pub use int::be::*;
pub use int::le::*;
pub use int::var::*;
pub use permissions_level::*;
pub use semver::*;
pub use stream::*;
pub use uuid::*;
pub use vec::vec2::Vec2;
pub use vec::vec2f::Vec2f;
pub use vec::vec3::Vec3;
pub use vec::vec3f::Vec3f;
pub use semver::*;
pub use actor_unique_id::*;
pub use actor_runtime_id::*;
pub use generator_type::*;

pub mod int;
pub mod vec;

pub mod stream;

pub mod actor_runtime_id;
pub mod actor_unique_id;
pub mod difficulty;
pub mod dimension;
pub mod permissions_level;
pub mod actor_unique_id;
pub mod actor_runtime_id;
pub mod generator_type;
pub mod gamemode;
pub mod generator_type;
pub mod permissions_level;
pub mod semver;
8 changes: 6 additions & 2 deletions bedrock_core/src/semver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ pub struct SemVer {

impl Debug for SemVer {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}.{}.{}.{}", self.major, self.minor, self.patch, self.build)
write!(
f,
"{}.{}.{}.{}",
self.major, self.minor, self.patch, self.build
)
}
}

impl Display for SemVer {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)
}
}
}
88 changes: 56 additions & 32 deletions packs/src/behavior/behavior_pack.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::string::FromUtf8Error;

use bedrock_core::SemVer;
use image::{ImageBuffer, RgbaImage};
use serde_json::{Number, Value};
use uuid::{Uuid, Version};
use image::RgbaImage;
use serde_json::Value;
use uuid::Uuid;

use crate::error::PackError;
use crate::language::{LanguageValues, Languages};
use crate::language::Languages;
use crate::pack::Pack;

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -38,53 +37,78 @@ impl Pack for BehaviorPack {

fn import(path: impl AsRef<Path>) -> Result<Self, PackError>
where
Self: Sized
Self: Sized,
{
// Convert the given path into a PathBuf
let directory: PathBuf = path.as_ref().to_path_buf();

let manifest_content = std::fs::read(directory.join("manifest.json")).map_err(|e| { todo!() })?;
let manifest_content =
std::fs::read(directory.join("manifest.json")).map_err(|e| todo!())?;

let text = String::from_utf8(manifest_content).map_err(|e| { todo!() })?;
let text = String::from_utf8(manifest_content).map_err(|e| todo!())?;

let json: Value = match serde_json::from_str(&text) {
Ok(v) => { v }
Err(e) => { todo!() }
Ok(v) => v,
Err(e) => {
todo!()
}
};

let main_obj = match json {
Value::Object(ref v) => { v.clone() }
other => { todo!() }
Value::Object(ref v) => v.clone(),
other => {
todo!()
}
};

let format_version: u32 = match main_obj.get("format_version") {
Some(Value::Number(ref v)) => { match v.as_u64() {
None => { todo!() }
Some(v) => { match v.try_into() {
Ok(v) => { v }
Err(e) => { todo!() }
}}
}}
Some(other) => { todo!() }
None => { todo!() }
Some(Value::Number(ref v)) => match v.as_u64() {
None => {
todo!()
}
Some(v) => match v.try_into() {
Ok(v) => v,
Err(e) => {
todo!()
}
},
},
Some(other) => {
todo!()
}
None => {
todo!()
}
};

let header_obj = match main_obj.get("header") {
Some(Value::Object(ref v)) => { v.clone() }
Some(other) => { todo!() }
None => { todo!() }
Some(Value::Object(ref v)) => v.clone(),
Some(other) => {
todo!()
}
None => {
todo!()
}
};

let name = match header_obj.get("name") {
Some(Value::String(v)) => { v.clone() }
Some(other) => { todo!() }
None => { todo!() }
Some(Value::String(v)) => v.clone(),
Some(other) => {
todo!()
}
None => {
todo!()
}
};

let description = match header_obj.get("description") {
Some(Value::String(v)) => { v.clone() }
Some(other) => { todo!() }
None => { todo!() }
Some(Value::String(v)) => v.clone(),
Some(other) => {
todo!()
}
None => {
todo!()
}
};

println!("\"format_version\": {format_version:?}");
Expand All @@ -98,7 +122,7 @@ impl Pack for BehaviorPack {

fn export(path: impl AsRef<Path>) -> Result<Self, PackError>
where
Self: Sized
Self: Sized,
{
todo!()
}
Expand Down
12 changes: 6 additions & 6 deletions packs/src/language/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
pub mod values;

use std::collections::HashMap;
use std::path::Path;

pub use values::*;

use crate::error::PackError;

pub mod values;

#[derive(Debug, Clone)]
pub struct Languages(HashMap<String, LanguageValues>);

Expand All @@ -14,8 +16,6 @@ impl Languages {
}

pub fn languages(&self) -> Vec<String> {
self.0.keys().map(|f| {
f.clone()
}).collect()
self.0.keys().map(|f| f.clone()).collect()
}
}
}
25 changes: 16 additions & 9 deletions packs/src/language/values.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;
use std::path::Path;

use crate::error::PackError;

#[derive(Debug, Clone)]
Expand All @@ -8,13 +9,17 @@ pub struct LanguageValues(HashMap<String, String>);
impl LanguageValues {
pub fn open(path: impl AsRef<Path>) -> Result<Self, PackError> {
let data = match std::fs::read(path) {
Ok(v) => { v }
Err(e) => { todo!() }
Ok(v) => v,
Err(e) => {
todo!()
}
};

let lines = match String::from_utf8(data) {
Ok(v) => { v }
Err(e) => { todo!() }
Ok(v) => v,
Err(e) => {
todo!()
}
};

let mut map = HashMap::new();
Expand All @@ -34,18 +39,20 @@ impl LanguageValues {

// Remove possible inline comments
let line = match line.split_once("\t##") {
None => { line }
Some((v, _)) => { v }
None => line,
Some((v, _)) => v,
};

// Split identifier and value
let (id, val) = match line.split_once("=") {
None => { todo!() }
Some((i, v)) => { (String::from(i), String::from(v)) }
None => {
todo!()
}
Some((i, v)) => (String::from(i), String::from(v)),
};

map.insert(id, val);
};
}

Ok(Self(map))
}
Expand Down
2 changes: 1 addition & 1 deletion packs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod behavior;
pub mod error;
pub mod language;
pub mod pack;
pub mod resource;
pub mod language;
3 changes: 2 additions & 1 deletion packs/src/pack.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::Path;

use bedrock_core::SemVer;
use uuid::{Uuid, Version};
use uuid::Uuid;

use crate::error::PackError;

Expand Down
10 changes: 5 additions & 5 deletions packs/src/resource/resource_pack.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::collections::HashMap;
use std::path::Path;

use bedrock_core::SemVer;
use image::RgbaImage;
use uuid::{Uuid, Version};
use uuid::Uuid;

use crate::error::PackError;
use crate::language::{LanguageValues, Languages};
use crate::language::Languages;
use crate::pack::Pack;

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -36,14 +36,14 @@ impl Pack for ResourcePack {

fn import(path: impl AsRef<Path>) -> Result<Self, PackError>
where
Self: Sized
Self: Sized,
{
todo!()
}

fn export(path: impl AsRef<Path>) -> Result<Self, PackError>
where
Self: Sized
Self: Sized,
{
todo!()
}
Expand Down
2 changes: 0 additions & 2 deletions proto/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ impl Connection {
}
}



pub async fn send(&mut self, gamepackets: Vec<GamePacket>) -> Result<(), ConnectionError> {
let mut pk_stream = ByteStreamWrite::new();

Expand Down
8 changes: 5 additions & 3 deletions proto/src/gamepacket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ macro_rules! ser_packet {
($stream:expr, $packet_id:expr, $packet_data:expr) => {{
let mut pk_stream = ByteStreamWrite::new();

println!("[SEND] {:#?}", $packet_data);

// TODO add correct header generation
// let header = "";

Expand Down Expand Up @@ -887,9 +889,7 @@ impl GamePacket {
GamePacket::SetTimeID => {
unimplemented!()
}
GamePacket::StartGameID => GamePacket::StartGame(
de_packet!(stream, StartGamePacket),
),
GamePacket::StartGameID => GamePacket::StartGame(de_packet!(stream, StartGamePacket)),
GamePacket::AddPlayerID => {
unimplemented!()
}
Expand Down Expand Up @@ -1303,6 +1303,8 @@ impl GamePacket {
}
};

println!("[RECV] {:#?}", game_packet);

Ok((game_packet, sub_client_sender_id, sub_client_target_id))
}
}
2 changes: 1 addition & 1 deletion proto/src/login/handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use crate::login::handshake::handshake;
use crate::login::login::login;
use crate::login::network_settings::network_settings;
use crate::login::packs::packs;
use crate::login::provider::{LoginProviderClient, LoginProviderServer};
use crate::login::play_status::play_status_login;
use crate::login::provider::{LoginProviderClient, LoginProviderServer};
use crate::login::start_game::start_game;

pub async fn login_to_server(
Expand Down
2 changes: 1 addition & 1 deletion proto/src/login/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ mod handshake;
mod login;
mod network_settings;
mod packs;
mod play_status;
pub mod provider;
mod start_game;
mod play_status;
Loading

0 comments on commit ffdc850

Please sign in to comment.