Reformat using rustfmt
This commit is contained in:
parent
dc810c15dd
commit
35306c62e1
|
@ -18,19 +18,25 @@ use std::mem;
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Component {
|
||||
Text(TextComponent)
|
||||
Text(TextComponent),
|
||||
}
|
||||
|
||||
impl Component {
|
||||
pub fn from_value(v: &serde_json::Value) -> Self {
|
||||
let mut modifier = Modifier::from_value(v);
|
||||
if let Some(val) = v.as_string() {
|
||||
Component::Text(TextComponent{text: val.to_owned(), modifier: modifier})
|
||||
Component::Text(TextComponent {
|
||||
text: val.to_owned(),
|
||||
modifier: modifier,
|
||||
})
|
||||
} else if v.find("text").is_some() {
|
||||
Component::Text(TextComponent::from_value(v, modifier))
|
||||
} else {
|
||||
modifier.color = Some(Color::RGB(255, 0, 0));
|
||||
Component::Text(TextComponent{text: "UNHANDLED".to_owned(), modifier: modifier})
|
||||
Component::Text(TextComponent {
|
||||
text: "UNHANDLED".to_owned(),
|
||||
modifier: modifier,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +55,10 @@ impl fmt::Display for Component {
|
|||
|
||||
impl Default for Component {
|
||||
fn default() -> Self {
|
||||
Component::Text(TextComponent{text: "".to_owned(), modifier: Default::default()})
|
||||
Component::Text(TextComponent {
|
||||
text: "".to_owned(),
|
||||
modifier: Default::default(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,12 +71,10 @@ pub struct Modifier {
|
|||
pub strikethrough: Option<bool>,
|
||||
pub obfuscated: Option<bool>,
|
||||
pub color: Option<Color>,
|
||||
|
||||
// click_event
|
||||
// hover_event
|
||||
// insertion
|
||||
}
|
||||
|
||||
// TODO: Missing events click/hover/insert
|
||||
|
||||
impl Modifier {
|
||||
pub fn from_value(v: &serde_json::Value) -> Self {
|
||||
let mut m = Modifier {
|
||||
|
@ -76,7 +83,9 @@ impl Modifier {
|
|||
underlined: v.find("underlined").map_or(Option::None, |v| v.as_boolean()),
|
||||
strikethrough: v.find("strikethrough").map_or(Option::None, |v| v.as_boolean()),
|
||||
obfuscated: v.find("obfuscated").map_or(Option::None, |v| v.as_boolean()),
|
||||
color: v.find("color").map_or(Option::None, |v| v.as_string()).map(|v| Color::from_string(&v.to_owned())),
|
||||
color: v.find("color")
|
||||
.map_or(Option::None, |v| v.as_string())
|
||||
.map(|v| Color::from_string(&v.to_owned())),
|
||||
extra: Option::None,
|
||||
};
|
||||
if let Some(extra) = v.find("extra") {
|
||||
|
@ -106,9 +115,7 @@ impl TextComponent {
|
|||
pub fn new(val: &str) -> TextComponent {
|
||||
TextComponent {
|
||||
text: val.to_owned(),
|
||||
modifier: Modifier {
|
||||
.. Default::default()
|
||||
}
|
||||
modifier: Modifier { ..Default::default() },
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -154,7 +161,7 @@ pub enum Color {
|
|||
LightPurple,
|
||||
Yellow,
|
||||
White,
|
||||
RGB(u8, u8, u8)
|
||||
RGB(u8, u8, u8),
|
||||
}
|
||||
|
||||
impl fmt::Display for Color {
|
||||
|
@ -195,11 +202,7 @@ impl Color {
|
|||
Ok(b) => b,
|
||||
Err(_) => return Color::White,
|
||||
};
|
||||
Color::RGB(
|
||||
r,
|
||||
g,
|
||||
b
|
||||
)
|
||||
Color::RGB(r, g, b)
|
||||
}
|
||||
_ => Color::White,
|
||||
}
|
||||
|
@ -264,12 +267,12 @@ fn test_color_from() {
|
|||
}
|
||||
let test = Color::from_string(&"red".to_owned());
|
||||
match test {
|
||||
Color::Red => {},
|
||||
Color::Red => {}
|
||||
_ => panic!("Wrong type"),
|
||||
}
|
||||
let test = Color::from_string(&"dark_blue".to_owned());
|
||||
match test {
|
||||
Color::DarkBlue => {},
|
||||
Color::DarkBlue => {}
|
||||
_ => panic!("Wrong type"),
|
||||
}
|
||||
}
|
||||
|
@ -300,7 +303,8 @@ pub fn convert_legacy(c: &mut Component) {
|
|||
current.text = txt.text[last..i].to_owned();
|
||||
last = next.0 + 1;
|
||||
|
||||
let mut modifier = if (color_char >= 'a' && color_char <= 'f') || (color_char >= '0' && color_char <= '9') {
|
||||
let mut modifier = if (color_char >= 'a' && color_char <= 'f') ||
|
||||
(color_char >= '0' && color_char <= '9') {
|
||||
Default::default()
|
||||
} else {
|
||||
current.modifier.clone()
|
||||
|
@ -331,7 +335,7 @@ pub fn convert_legacy(c: &mut Component) {
|
|||
'm' => modifier.strikethrough = Some(true),
|
||||
'n' => modifier.underlined = Some(true),
|
||||
'o' => modifier.italic = Some(true),
|
||||
'r' => {},
|
||||
'r' => {}
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
|
||||
|
@ -352,6 +356,6 @@ pub fn convert_legacy(c: &mut Component) {
|
|||
}
|
||||
txt.text = "".to_owned();
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,7 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
use nbt;
|
||||
use protocol::{Serializable};
|
||||
use protocol::Serializable;
|
||||
use std::io;
|
||||
use std::io::{Read, Write};
|
||||
use byteorder::{BigEndian, WriteBytesExt, ReadBytesExt};
|
||||
|
@ -58,7 +58,7 @@ impl Serializable for Option<Stack> {
|
|||
try!(buf.write_u8(val.count as u8));
|
||||
try!(buf.write_i16::<BigEndian>(val.damage as i16));
|
||||
try!(val.tag.write_to(buf));
|
||||
},
|
||||
}
|
||||
None => try!(buf.write_i16::<BigEndian>(-1)),
|
||||
}
|
||||
Result::Ok(())
|
||||
|
|
|
@ -16,7 +16,7 @@ use std::collections::HashMap;
|
|||
use std::io;
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use super::protocol::{Serializable};
|
||||
use super::protocol::Serializable;
|
||||
use super::protocol;
|
||||
use byteorder::{BigEndian, WriteBytesExt, ReadBytesExt};
|
||||
|
||||
|
@ -196,7 +196,7 @@ impl Tag {
|
|||
l.push(try!(Tag::read_type(ty, buf)));
|
||||
}
|
||||
Ok(Tag::List(l))
|
||||
},
|
||||
}
|
||||
10 => {
|
||||
let mut c = Tag::new_compound();
|
||||
loop {
|
||||
|
@ -208,7 +208,7 @@ impl Tag {
|
|||
c.put(&name[..], try!(Tag::read_type(ty, buf)));
|
||||
}
|
||||
Ok(c)
|
||||
},
|
||||
}
|
||||
11 => Ok(Tag::IntArray({
|
||||
let len: i32 = try!(Serializable::read_from(buf));
|
||||
let mut data = Vec::with_capacity(len as usize);
|
||||
|
@ -217,7 +217,8 @@ impl Tag {
|
|||
}
|
||||
data
|
||||
})),
|
||||
_ => Err(io::Error::new(io::ErrorKind::InvalidData, protocol::Error::Err("invalid tag".to_owned()))),
|
||||
_ => Err(io::Error::new(io::ErrorKind::InvalidData,
|
||||
protocol::Error::Err("invalid tag".to_owned()))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -229,7 +230,7 @@ impl Serializable for Tag {
|
|||
|
||||
fn write_to(&self, buf: &mut io::Write) -> Result<(), io::Error> {
|
||||
match *self {
|
||||
Tag::End => {},
|
||||
Tag::End => {}
|
||||
Tag::Byte(val) => try!(buf.write_i8(val)),
|
||||
Tag::Short(val) => try!(buf.write_i16::<BigEndian>(val)),
|
||||
Tag::Int(val) => try!(buf.write_i32::<BigEndian>(val)),
|
||||
|
@ -239,7 +240,7 @@ impl Serializable for Tag {
|
|||
Tag::ByteArray(ref val) => {
|
||||
try!((val.len() as i32).write_to(buf));
|
||||
try!(buf.write_all(val));
|
||||
},
|
||||
}
|
||||
Tag::String(ref val) => try!(write_string(buf, val)),
|
||||
Tag::List(ref val) => {
|
||||
if val.is_empty() {
|
||||
|
@ -252,7 +253,7 @@ impl Serializable for Tag {
|
|||
try!(e.write_to(buf));
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
Tag::Compound(ref val) => {
|
||||
for (k, v) in val {
|
||||
try!(v.internal_id().write_to(buf));
|
||||
|
@ -260,13 +261,13 @@ impl Serializable for Tag {
|
|||
try!(v.write_to(buf));
|
||||
}
|
||||
try!(buf.write_u8(0));
|
||||
},
|
||||
}
|
||||
Tag::IntArray(ref val) => {
|
||||
try!((val.len() as i32).write_to(buf));
|
||||
for v in val {
|
||||
try!(v.write_to(buf));
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
Result::Ok(())
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
pub struct Map {
|
||||
bits: Vec<u64>,
|
||||
bit_size: usize,
|
||||
length: usize
|
||||
length: usize,
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -52,7 +52,7 @@ impl Map {
|
|||
let mut map = Map {
|
||||
bit_size: size,
|
||||
length: len,
|
||||
bits: Vec::with_capacity((len*size)/64)
|
||||
bits: Vec::with_capacity((len * size) / 64),
|
||||
};
|
||||
for _ in 0..len {
|
||||
map.bits.push(0)
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
// limitations under the License.
|
||||
|
||||
pub struct Set {
|
||||
data : Vec<u64>
|
||||
data: Vec<u64>,
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -33,9 +33,7 @@ fn test_set() {
|
|||
|
||||
impl Set {
|
||||
pub fn new(size: usize) -> Set {
|
||||
let mut set = Set {
|
||||
data: Vec::with_capacity(size)
|
||||
};
|
||||
let mut set = Set { data: Vec::with_capacity(size) };
|
||||
for _ in 0..size {
|
||||
set.data.push(0)
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
extern crate byteorder;
|
||||
|
||||
use std::fmt;
|
||||
use protocol::{Serializable};
|
||||
use protocol::Serializable;
|
||||
use std::io;
|
||||
use std::io::{Read, Write};
|
||||
use self::byteorder::{BigEndian, WriteBytesExt, ReadBytesExt};
|
||||
|
@ -26,11 +26,8 @@ pub struct Position(u64);
|
|||
impl Position {
|
||||
#[allow(dead_code)]
|
||||
fn new(x: i32, y: i32, z: i32) -> Position {
|
||||
Position(
|
||||
(((x as u64) & 0x3FFFFFF) << 38) |
|
||||
(((y as u64) & 0xFFF) << 26) |
|
||||
((z as u64) & 0x3FFFFFF)
|
||||
)
|
||||
Position((((x as u64) & 0x3FFFFFF) << 38) | (((y as u64) & 0xFFF) << 26) |
|
||||
((z as u64) & 0x3FFFFFF))
|
||||
}
|
||||
|
||||
fn get_x(&self) -> i32 {
|
||||
|
|
|
@ -18,7 +18,7 @@ use std::io;
|
|||
use std::io::{Read, Write};
|
||||
use std::fmt;
|
||||
use protocol;
|
||||
use protocol::{Serializable};
|
||||
use protocol::Serializable;
|
||||
use format;
|
||||
use item;
|
||||
|
||||
|
@ -78,11 +78,10 @@ impl Serializable for Metadata {
|
|||
4 => m.put_raw(index, try!(format::Component::read_from(buf))),
|
||||
5 => m.put_raw(index, try!(Option::<item::Stack>::read_from(buf))),
|
||||
6 => m.put_raw(index, try!(bool::read_from(buf))),
|
||||
7 => m.put_raw(index, [
|
||||
7 => m.put_raw(index,
|
||||
[try!(f32::read_from(buf)),
|
||||
try!(f32::read_from(buf)),
|
||||
try!(f32::read_from(buf)),
|
||||
try!(f32::read_from(buf))
|
||||
]),
|
||||
try!(f32::read_from(buf))]),
|
||||
8 => m.put_raw(index, try!(super::Position::read_from(buf))),
|
||||
9 => {
|
||||
if try!(bool::read_from(buf)) {
|
||||
|
@ -90,7 +89,7 @@ impl Serializable for Metadata {
|
|||
} else {
|
||||
m.put_raw::<Option<super::Position>>(index, None);
|
||||
}
|
||||
},
|
||||
}
|
||||
10 => m.put_raw(index, try!(protocol::VarInt::read_from(buf))),
|
||||
11 => {
|
||||
if try!(bool::read_from(buf)) {
|
||||
|
@ -98,9 +97,11 @@ impl Serializable for Metadata {
|
|||
} else {
|
||||
m.put_raw::<Option<protocol::UUID>>(index, None);
|
||||
}
|
||||
},
|
||||
}
|
||||
12 => m.put_raw(index, try!(protocol::VarInt::read_from(buf)).0 as u16),
|
||||
_ => return Err(io::Error::new(io::ErrorKind::InvalidInput, protocol::Error::Err("unknown metadata type".to_owned()))),
|
||||
_ => return Err(io::Error::new(io::ErrorKind::InvalidInput,
|
||||
protocol::Error::Err("unknown metadata type"
|
||||
.to_owned()))),
|
||||
}
|
||||
}
|
||||
Ok(m)
|
||||
|
@ -113,46 +114,46 @@ impl Serializable for Metadata {
|
|||
Value::Byte(ref val) => {
|
||||
try!(u8::write_to(&0, buf));
|
||||
try!(val.write_to(buf));
|
||||
},
|
||||
}
|
||||
Value::Int(ref val) => {
|
||||
try!(u8::write_to(&1, buf));
|
||||
try!(protocol::VarInt(*val).write_to(buf));
|
||||
},
|
||||
}
|
||||
Value::Float(ref val) => {
|
||||
try!(u8::write_to(&2, buf));
|
||||
try!(val.write_to(buf));
|
||||
},
|
||||
}
|
||||
Value::String(ref val) => {
|
||||
try!(u8::write_to(&3, buf));
|
||||
try!(val.write_to(buf));
|
||||
},
|
||||
}
|
||||
Value::FormatComponent(ref val) => {
|
||||
try!(u8::write_to(&4, buf));
|
||||
try!(val.write_to(buf));
|
||||
},
|
||||
}
|
||||
Value::OptionalItemStack(ref val) => {
|
||||
try!(u8::write_to(&5, buf));
|
||||
try!(val.write_to(buf));
|
||||
},
|
||||
}
|
||||
Value::Bool(ref val) => {
|
||||
try!(u8::write_to(&6, buf));
|
||||
try!(val.write_to(buf));
|
||||
},
|
||||
}
|
||||
Value::Vector(ref val) => {
|
||||
try!(u8::write_to(&7, buf));
|
||||
try!(val[0].write_to(buf));
|
||||
try!(val[1].write_to(buf));
|
||||
try!(val[2].write_to(buf));
|
||||
},
|
||||
}
|
||||
Value::Position(ref val) => {
|
||||
try!(u8::write_to(&8, buf));
|
||||
try!(val.write_to(buf));
|
||||
},
|
||||
}
|
||||
Value::OptionalPosition(ref val) => {
|
||||
try!(u8::write_to(&9, buf));
|
||||
try!(val.is_some().write_to(buf));
|
||||
try!(val.write_to(buf));
|
||||
},
|
||||
}
|
||||
Value::Direction(ref val) => {
|
||||
try!(u8::write_to(&10, buf));
|
||||
try!(val.write_to(buf));
|
||||
|
@ -161,7 +162,7 @@ impl Serializable for Metadata {
|
|||
try!(u8::write_to(&11, buf));
|
||||
try!(val.is_some().write_to(buf));
|
||||
try!(val.write_to(buf));
|
||||
},
|
||||
}
|
||||
Value::Block(ref val) => {
|
||||
try!(u8::write_to(&11, buf));
|
||||
try!(protocol::VarInt(*val as i32).write_to(buf));
|
||||
|
|
Loading…
Reference in New Issue