Update to serde_json 1.0 (#6)
* Replace find() with get() * Update for renamed as_string->as_str and as_boolean->as_bool https://github.com/serde-rs/json/releases/tag/v0.8.0 Value::as_string() has been renamed to as_str() and Value::as_boolean() has been renamed to as_bool() to improve consistency https://github.com/serde-rs/json/issues/126 * No serde_json::Value::I64/U64/F64 anymore, only Number * Update from lookup() to pointer(), using JSON pointer syntax https://github.com/iceiix/steven/pull/6#issuecomment-432472123 * Remove unused and removed ObjectBuilder import * Use into_iter().collect() to convert BTreeMap to serde_json::Map * Change parse_rules to accept serde_json::Map instead of BTreeMap * Remove unused serde_json macro_use * Update Cargo.lock
This commit is contained in:
parent
edbed5e319
commit
de6cd2044e
|
@ -342,7 +342,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "0.1.1"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
|
@ -572,14 +572,6 @@ dependencies = [
|
|||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.1.43"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.6"
|
||||
|
@ -768,6 +760,11 @@ name = "rustc-serialize"
|
|||
version = "0.3.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "safemem"
|
||||
version = "0.3.0"
|
||||
|
@ -813,11 +810,6 @@ dependencies = [
|
|||
"cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "0.7.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
version = "1.0.79"
|
||||
|
@ -825,12 +817,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "0.7.4"
|
||||
version = "1.0.32"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -871,7 +863,7 @@ dependencies = [
|
|||
"rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sdl2 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sha-1 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"steven_blocks 0.0.1",
|
||||
"steven_gl 0.0.1",
|
||||
|
@ -1142,7 +1134,7 @@ dependencies = [
|
|||
"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e"
|
||||
"checksum image 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60710fd3cb40c2434451d8d5147bcf39bbb68aae0741041133e09439cb2401e3"
|
||||
"checksum inflate 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6f53b811ee8e2057ccf9643ca6b4277de90efaf5e61e55fd5254576926bb4245"
|
||||
"checksum itoa 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae3088ea4baeceb0284ee9eea42f591226e6beaecf65373e41b38d95a1b8e7a1"
|
||||
"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
|
||||
"checksum jpeg-decoder 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "c8b7d43206b34b3f94ea9445174bda196e772049b9bddbc620c9d29b2d20110d"
|
||||
"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d"
|
||||
"checksum khronos_api 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d5a08e2a31d665af8f1ca437eab6d00a93c9d62a549f73f9ed8fc2e55b5a91a7"
|
||||
|
@ -1172,7 +1164,6 @@ dependencies = [
|
|||
"checksum num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "af3fdbbc3291a5464dc57b03860ec37ca6bf915ed6ee385e7c6c052c422b2124"
|
||||
"checksum num-rational 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "ee314c74bd753fc86b4780aa9475da469155f3848473a261d2d18e35245a784e"
|
||||
"checksum num-rational 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e96f040177bb3da242b5b1ecf3f54b5d5af3efbbfb18608977a5d2767b22f10"
|
||||
"checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"
|
||||
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
|
||||
"checksum num_cpus 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "cee7e88156f3f9e19bdd598f8d6c9db7bf4078f99f8381f43a55b09648d1a6e3"
|
||||
"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30"
|
||||
|
@ -1196,15 +1187,15 @@ dependencies = [
|
|||
"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1"
|
||||
"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
|
||||
"checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
|
||||
"checksum ryu 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7153dd96dade874ab973e098cb62fcdbb89a03682e46b144fd09550998d4a4a7"
|
||||
"checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
|
||||
"checksum same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d931a44fdaa43b8637009e7632a02adc4f2b2e0733c08caa4cf00e8da4a117a7"
|
||||
"checksum scoped_threadpool 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8"
|
||||
"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
|
||||
"checksum sdl2 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a74c2a98a354b20713b90cce70aef9e927e46110d1bc4ef728fd74e0d53eba60"
|
||||
"checksum sdl2-sys 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5c543ce8a6e33a30cb909612eeeb22e693848211a84558d5a00bb11e791b7ab7"
|
||||
"checksum serde 0.7.15 (registry+https://github.com/rust-lang/crates.io-index)" = "1b0e0732aa8ec4267f61815a396a942ba3525062e3bd5520aa8419927cfc0a92"
|
||||
"checksum serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "84257ccd054dc351472528c8587b4de2dbf0dc0fe2e634030c1a90bfdacebaa9"
|
||||
"checksum serde_json 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b22e8a0554f31cb0f501e027de07b253553b308124f61c57598b9678dba35c0b"
|
||||
"checksum serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)" = "43344e7ce05d0d8280c5940cabb4964bea626aa58b1ec0e8c73fa2a8512a38ce"
|
||||
"checksum sha-1 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2cfd94fe9ed1245c2a1459f99373217b131a1b32b6d0922988b1e45b35249249"
|
||||
"checksum solicit 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "172382bac9424588d7840732b250faeeef88942e37b6e35317dce98cafdd75b2"
|
||||
"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741"
|
||||
|
|
|
@ -15,7 +15,7 @@ sdl2 = "0.31.0"
|
|||
byteorder = "1.2.6"
|
||||
hyper = "0.8.0"
|
||||
serde = "1.0.79"
|
||||
serde_json = "0.7.0"
|
||||
serde_json = "1.0.31"
|
||||
flate2 = "1.0.2"
|
||||
zip = "0.4.2"
|
||||
image = "0.20.0"
|
||||
|
|
|
@ -38,12 +38,12 @@ 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() {
|
||||
if let Some(val) = v.as_str() {
|
||||
Component::Text(TextComponent {
|
||||
text: val.to_owned(),
|
||||
modifier: modifier,
|
||||
})
|
||||
} else if v.find("text").is_some() {
|
||||
} else if v.get("text").is_some() {
|
||||
Component::Text(TextComponent::from_value(v, modifier))
|
||||
} else {
|
||||
modifier.color = Some(Color::RGB(255, 0, 0));
|
||||
|
@ -92,17 +92,17 @@ pub struct Modifier {
|
|||
impl Modifier {
|
||||
pub fn from_value(v: &serde_json::Value) -> Self {
|
||||
let mut m = Modifier {
|
||||
bold: v.find("bold").map_or(Option::None, |v| v.as_boolean()),
|
||||
italic: v.find("italic").map_or(Option::None, |v| v.as_boolean()),
|
||||
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())
|
||||
bold: v.get("bold").map_or(Option::None, |v| v.as_bool()),
|
||||
italic: v.get("italic").map_or(Option::None, |v| v.as_bool()),
|
||||
underlined: v.get("underlined").map_or(Option::None, |v| v.as_bool()),
|
||||
strikethrough: v.get("strikethrough").map_or(Option::None, |v| v.as_bool()),
|
||||
obfuscated: v.get("obfuscated").map_or(Option::None, |v| v.as_bool()),
|
||||
color: v.get("color")
|
||||
.map_or(Option::None, |v| v.as_str())
|
||||
.map(|v| Color::from_string(&v.to_owned())),
|
||||
extra: Option::None,
|
||||
};
|
||||
if let Some(extra) = v.find("extra") {
|
||||
if let Some(extra) = v.get("extra") {
|
||||
if let Some(data) = extra.as_array() {
|
||||
let mut ex = Vec::new();
|
||||
for e in data {
|
||||
|
@ -135,7 +135,7 @@ impl TextComponent {
|
|||
|
||||
pub fn from_value(v: &serde_json::Value, modifier: Modifier) -> Self {
|
||||
TextComponent {
|
||||
text: v.find("text").unwrap().as_string().unwrap_or("").to_owned(),
|
||||
text: v.get("text").unwrap().as_str().unwrap_or("").to_owned(),
|
||||
modifier: modifier,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ extern crate zip;
|
|||
extern crate image;
|
||||
use std::time::{Instant, Duration};
|
||||
extern crate byteorder;
|
||||
#[macro_use]
|
||||
extern crate serde_json;
|
||||
extern crate openssl;
|
||||
extern crate sha1;
|
||||
|
|
|
@ -200,7 +200,7 @@ impl Factory {
|
|||
multipart: vec![],
|
||||
};
|
||||
|
||||
if let Some(variants) = mdl.find("variants").and_then(|v| v.as_object()) {
|
||||
if let Some(variants) = mdl.get("variants").and_then(|v| v.as_object()) {
|
||||
for (k, v) in variants {
|
||||
let vars = self.parse_model_list(plugin, v);
|
||||
if vars.models.is_empty() {
|
||||
|
@ -209,11 +209,11 @@ impl Factory {
|
|||
model.variants.insert(k.clone(), vars);
|
||||
}
|
||||
}
|
||||
if let Some(multipart) = mdl.find("multipart").and_then(|v| v.as_array()) {
|
||||
if let Some(multipart) = mdl.get("multipart").and_then(|v| v.as_array()) {
|
||||
for rule in multipart {
|
||||
let apply = self.parse_model_list(plugin, rule.find("apply").unwrap());
|
||||
let apply = self.parse_model_list(plugin, rule.get("apply").unwrap());
|
||||
let mut rules = vec![];
|
||||
if let Some(when) = rule.find("when").and_then(|v| v.as_object()) {
|
||||
if let Some(when) = rule.get("when").and_then(|v| v.as_object()) {
|
||||
Self::parse_rules(when, &mut rules);
|
||||
}
|
||||
model.multipart.push(MultipartRule {
|
||||
|
@ -227,7 +227,7 @@ impl Factory {
|
|||
true
|
||||
}
|
||||
|
||||
fn parse_rules(when: &::std::collections::BTreeMap<String, serde_json::Value>, rules: &mut Vec<Rule>) {
|
||||
fn parse_rules(when: &serde_json::Map<String, serde_json::Value>, rules: &mut Vec<Rule>) {
|
||||
for (name, val) in when {
|
||||
if name == "OR" {
|
||||
let mut or_rules = vec![];
|
||||
|
@ -239,10 +239,8 @@ impl Factory {
|
|||
rules.push(Rule::Or(or_rules));
|
||||
} else {
|
||||
let v = match *val {
|
||||
serde_json::Value::Bool(v) => v.to_string(),
|
||||
serde_json::Value::I64(v) => v.to_string(),
|
||||
serde_json::Value::U64(v) => v.to_string(),
|
||||
serde_json::Value::F64(v) => v.to_string(),
|
||||
serde_json::Value::Bool(ref v) => v.to_string(),
|
||||
serde_json::Value::Number(ref v) => v.to_string(),
|
||||
serde_json::Value::String(ref v) => v.to_owned(),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
@ -268,7 +266,7 @@ impl Factory {
|
|||
}
|
||||
|
||||
fn parse_block_state_variant(&self, plugin: &str, v: &serde_json::Value) -> Option<RawModel> {
|
||||
let model_name = match v.find("model").and_then(|v| v.as_string()) {
|
||||
let model_name = match v.get("model").and_then(|v| v.as_str()) {
|
||||
Some(val) => val,
|
||||
None => {
|
||||
error!("Couldn't find model name");
|
||||
|
@ -293,15 +291,15 @@ impl Factory {
|
|||
},
|
||||
};
|
||||
|
||||
model.y = v.find("y").and_then(|v| v.as_f64()).unwrap_or(0.0);
|
||||
model.x = v.find("x").and_then(|v| v.as_f64()).unwrap_or(0.0);
|
||||
model.uvlock = v.find("uvlock").and_then(|v| v.as_boolean()).unwrap_or(false);
|
||||
model.weight = v.find("weight").and_then(|v| v.as_f64()).unwrap_or(1.0);
|
||||
model.y = v.get("y").and_then(|v| v.as_f64()).unwrap_or(0.0);
|
||||
model.x = v.get("x").and_then(|v| v.as_f64()).unwrap_or(0.0);
|
||||
model.uvlock = v.get("uvlock").and_then(|v| v.as_bool()).unwrap_or(false);
|
||||
model.weight = v.get("weight").and_then(|v| v.as_f64()).unwrap_or(1.0);
|
||||
Some(model)
|
||||
}
|
||||
|
||||
fn parse_model(&self, plugin: &str, v: &serde_json::Value) -> Option<RawModel> {
|
||||
let parent = v.find("parent").and_then(|v| v.as_string()).unwrap_or("");
|
||||
let parent = v.get("parent").and_then(|v| v.as_str()).unwrap_or("");
|
||||
let mut model = if !parent.is_empty() && !parent.starts_with("builtin/") {
|
||||
let file = match self.resources.read().unwrap().open(plugin, &format!("models/{}.json", parent)) {
|
||||
Some(val) => val,
|
||||
|
@ -341,20 +339,20 @@ impl Factory {
|
|||
}
|
||||
};
|
||||
|
||||
if let Some(textures) = v.find("textures").and_then(|v| v.as_object()) {
|
||||
if let Some(textures) = v.get("textures").and_then(|v| v.as_object()) {
|
||||
for (k, v) in textures {
|
||||
model.texture_vars.insert(k.clone(), v.as_string().unwrap_or("").to_owned());
|
||||
model.texture_vars.insert(k.clone(), v.as_str().unwrap_or("").to_owned());
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(ao) = v.find("ambientocclusion").and_then(|v| v.as_boolean()) {
|
||||
if let Some(ao) = v.get("ambientocclusion").and_then(|v| v.as_bool()) {
|
||||
model.ambient_occlusion = ao;
|
||||
model.ao_set = true;
|
||||
} else if !model.ao_set {
|
||||
model.ambient_occlusion = true;
|
||||
}
|
||||
|
||||
if let Some(elements) = v.find("elements").and_then(|v| v.as_array()) {
|
||||
if let Some(elements) = v.get("elements").and_then(|v| v.as_array()) {
|
||||
for e in elements {
|
||||
model.elements.push(self.parse_block_element(e));
|
||||
}
|
||||
|
@ -367,25 +365,25 @@ impl Factory {
|
|||
|
||||
fn parse_block_element(&self, v: &serde_json::Value) -> ModelElement {
|
||||
let mut element = ModelElement {
|
||||
from: v.find("from").and_then(|v| v.as_array()).map(|v| [
|
||||
from: v.get("from").and_then(|v| v.as_array()).map(|v| [
|
||||
v[0].as_f64().unwrap(),
|
||||
v[1].as_f64().unwrap(),
|
||||
v[2].as_f64().unwrap()
|
||||
]).unwrap(),
|
||||
to: v.find("to").and_then(|v| v.as_array()).map(|v| [
|
||||
to: v.get("to").and_then(|v| v.as_array()).map(|v| [
|
||||
v[0].as_f64().unwrap(),
|
||||
v[1].as_f64().unwrap(),
|
||||
v[2].as_f64().unwrap()
|
||||
]).unwrap(),
|
||||
shade: v.find("shade").and_then(|v| v.as_boolean()).unwrap_or(false),
|
||||
shade: v.get("shade").and_then(|v| v.as_bool()).unwrap_or(false),
|
||||
faces: [None, None, None, None, None, None],
|
||||
rotation: None,
|
||||
};
|
||||
if let Some(faces) = v.find("faces").and_then(|v| v.as_object()) {
|
||||
if let Some(faces) = v.get("faces").and_then(|v| v.as_object()) {
|
||||
for dir in Direction::all() {
|
||||
if let Some(face) = faces.get(dir.as_string()) {
|
||||
element.faces[dir.index()] = Some(BlockFace {
|
||||
uv: face.find("uv").and_then(|v| v.as_array()).map_or_else(
|
||||
uv: face.get("uv").and_then(|v| v.as_array()).map_or_else(
|
||||
|| {
|
||||
let mut uv = [0.0, 0.0, 16.0, 16.0];
|
||||
match dir {
|
||||
|
@ -418,22 +416,22 @@ impl Factory {
|
|||
v[3].as_f64().unwrap()
|
||||
]
|
||||
),
|
||||
texture: face.find("texture")
|
||||
.and_then(|v| v.as_string())
|
||||
texture: face.get("texture")
|
||||
.and_then(|v| v.as_str())
|
||||
.map(|v| if v.starts_with('#') {
|
||||
v.to_owned()
|
||||
} else {
|
||||
"#".to_owned() + v
|
||||
}).unwrap(),
|
||||
cull_face: Direction::from_string(
|
||||
face.find("cullface")
|
||||
.and_then(|v| v.as_string())
|
||||
face.get("cullface")
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("invalid")
|
||||
),
|
||||
rotation: face.find("rotation")
|
||||
rotation: face.get("rotation")
|
||||
.and_then(|v| v.as_i64())
|
||||
.map_or(0, |v| v as i32),
|
||||
tint_index: face.find("tintindex")
|
||||
tint_index: face.get("tintindex")
|
||||
.and_then(|v| v.as_i64())
|
||||
.map_or(-1, |v| v as i32),
|
||||
});
|
||||
|
@ -441,16 +439,16 @@ impl Factory {
|
|||
}
|
||||
}
|
||||
|
||||
if let Some(rotation) = v.find("rotation") {
|
||||
if let Some(rotation) = v.get("rotation") {
|
||||
element.rotation = Some(BlockRotation {
|
||||
origin: rotation.find("origin").and_then(|v| v.as_array()).map_or([8.0, 8.0, 8.0], |v| [
|
||||
origin: rotation.get("origin").and_then(|v| v.as_array()).map_or([8.0, 8.0, 8.0], |v| [
|
||||
v[0].as_f64().unwrap(),
|
||||
v[1].as_f64().unwrap(),
|
||||
v[2].as_f64().unwrap()
|
||||
]),
|
||||
axis: rotation.find("axis").and_then(|v| v.as_string()).unwrap_or("").to_owned(),
|
||||
angle: rotation.find("angle").and_then(|v| v.as_f64()).unwrap_or(0.0),
|
||||
rescale: rotation.find("rescale").and_then(|v| v.as_boolean()).unwrap_or(false),
|
||||
axis: rotation.get("axis").and_then(|v| v.as_str()).unwrap_or("").to_owned(),
|
||||
angle: rotation.get("angle").and_then(|v| v.as_f64()).unwrap_or(0.0),
|
||||
rescale: rotation.get("rescale").and_then(|v| v.as_bool()).unwrap_or(false),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ impl Tag {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn as_string(&self) -> Option<&str> {
|
||||
pub fn as_str(&self) -> Option<&str> {
|
||||
match *self {
|
||||
Tag::String(ref val) => Some(&val[..]),
|
||||
_ => None,
|
||||
|
|
|
@ -906,29 +906,29 @@ impl Conn {
|
|||
|
||||
let invalid_status = || Error::Err("Invalid status".to_owned());
|
||||
|
||||
let version = try!(val.find("version").ok_or(invalid_status()));
|
||||
let players = try!(val.find("players").ok_or(invalid_status()));
|
||||
let version = try!(val.get("version").ok_or(invalid_status()));
|
||||
let players = try!(val.get("players").ok_or(invalid_status()));
|
||||
|
||||
Ok((Status {
|
||||
version: StatusVersion {
|
||||
name: try!(version.find("name").and_then(Value::as_string).ok_or(invalid_status()))
|
||||
name: try!(version.get("name").and_then(Value::as_str).ok_or(invalid_status()))
|
||||
.to_owned(),
|
||||
protocol: try!(version.find("protocol")
|
||||
protocol: try!(version.get("protocol")
|
||||
.and_then(Value::as_i64)
|
||||
.ok_or(invalid_status())) as i32,
|
||||
},
|
||||
players: StatusPlayers {
|
||||
max: try!(players.find("max")
|
||||
max: try!(players.get("max")
|
||||
.and_then(Value::as_i64)
|
||||
.ok_or(invalid_status())) as i32,
|
||||
online: try!(players.find("online")
|
||||
online: try!(players.get("online")
|
||||
.and_then(Value::as_i64)
|
||||
.ok_or(invalid_status())) as i32,
|
||||
sample: Vec::new(), /* TODO */
|
||||
},
|
||||
description: format::Component::from_value(try!(val.find("description")
|
||||
description: format::Component::from_value(try!(val.get("description")
|
||||
.ok_or(invalid_status()))),
|
||||
favicon: val.find("favicon").and_then(Value::as_string).map(|v| v.to_owned()),
|
||||
favicon: val.get("favicon").and_then(Value::as_str).map(|v| v.to_owned()),
|
||||
},
|
||||
ping))
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
use sha1::{self, Digest};
|
||||
use serde_json;
|
||||
use serde_json::builder::ObjectBuilder;
|
||||
use hyper;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -31,15 +30,14 @@ const VALIDATE_URL: &'static str = "https://authserver.mojang.com/validate";
|
|||
|
||||
impl Profile {
|
||||
pub fn login(username: &str, password: &str, token: &str) -> Result<Profile, super::Error> {
|
||||
let req_msg = ObjectBuilder::new()
|
||||
.insert("username", username)
|
||||
.insert("password", password)
|
||||
.insert("clientToken", token)
|
||||
.insert_object("agent", |b| b
|
||||
.insert("name", "Minecraft")
|
||||
.insert("version", 1)
|
||||
)
|
||||
.unwrap();
|
||||
let req_msg = json!({
|
||||
"username": username,
|
||||
"password": password,
|
||||
"clientToken": token,
|
||||
"agent": {
|
||||
"name": "Minecraft",
|
||||
"version": 1
|
||||
}});
|
||||
let req = try!(serde_json::to_string(&req_msg));
|
||||
|
||||
let client = hyper::Client::new();
|
||||
|
@ -49,25 +47,25 @@ impl Profile {
|
|||
.send());
|
||||
|
||||
let ret: serde_json::Value = try!(serde_json::from_reader(res));
|
||||
if let Some(error) = ret.find("error").and_then(|v| v.as_string()) {
|
||||
if let Some(error) = ret.get("error").and_then(|v| v.as_str()) {
|
||||
return Err(super::Error::Err(format!(
|
||||
"{}: {}",
|
||||
error,
|
||||
ret.find("errorMessage").and_then(|v| v.as_string()).unwrap())
|
||||
ret.get("errorMessage").and_then(|v| v.as_str()).unwrap())
|
||||
));
|
||||
}
|
||||
Ok(Profile {
|
||||
username: ret.lookup("selectedProfile.name").and_then(|v| v.as_string()).unwrap().to_owned(),
|
||||
id: ret.lookup("selectedProfile.id").and_then(|v| v.as_string()).unwrap().to_owned(),
|
||||
access_token: ret.find("accessToken").and_then(|v| v.as_string()).unwrap().to_owned(),
|
||||
username: ret.pointer("/selectedProfile/name").and_then(|v| v.as_str()).unwrap().to_owned(),
|
||||
id: ret.pointer("/selectedProfile/id").and_then(|v| v.as_str()).unwrap().to_owned(),
|
||||
access_token: ret.get("accessToken").and_then(|v| v.as_str()).unwrap().to_owned(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn refresh(self, token: &str) -> Result<Profile, super::Error> {
|
||||
let req_msg = ObjectBuilder::new()
|
||||
.insert("accessToken", self.access_token.clone())
|
||||
.insert("clientToken", token)
|
||||
.unwrap();
|
||||
let req_msg = json!({
|
||||
"accessToken": self.access_token.clone(),
|
||||
"clientToken": token
|
||||
});
|
||||
let req = try!(serde_json::to_string(&req_msg));
|
||||
|
||||
let client = hyper::Client::new();
|
||||
|
@ -84,17 +82,17 @@ impl Profile {
|
|||
.send());
|
||||
|
||||
let ret: serde_json::Value = try!(serde_json::from_reader(res));
|
||||
if let Some(error) = ret.find("error").and_then(|v| v.as_string()) {
|
||||
if let Some(error) = ret.get("error").and_then(|v| v.as_str()) {
|
||||
return Err(super::Error::Err(format!(
|
||||
"{}: {}",
|
||||
error,
|
||||
ret.find("errorMessage").and_then(|v| v.as_string()).unwrap())
|
||||
ret.get("errorMessage").and_then(|v| v.as_str()).unwrap())
|
||||
));
|
||||
}
|
||||
return Ok(Profile {
|
||||
username: ret.lookup("selectedProfile.name").and_then(|v| v.as_string()).unwrap().to_owned(),
|
||||
id: ret.lookup("selectedProfile.id").and_then(|v| v.as_string()).unwrap().to_owned(),
|
||||
access_token: ret.find("accessToken").and_then(|v| v.as_string()).unwrap().to_owned(),
|
||||
username: ret.pointer("/selectedProfile/name").and_then(|v| v.as_str()).unwrap().to_owned(),
|
||||
id: ret.pointer("/selectedProfile/id").and_then(|v| v.as_str()).unwrap().to_owned(),
|
||||
access_token: ret.get("accessToken").and_then(|v| v.as_str()).unwrap().to_owned(),
|
||||
});
|
||||
}
|
||||
Ok(self)
|
||||
|
@ -121,11 +119,11 @@ impl Profile {
|
|||
hash_val.to_owned()
|
||||
};
|
||||
|
||||
let join_msg = ObjectBuilder::new()
|
||||
.insert("accessToken", &self.access_token)
|
||||
.insert("selectedProfile", &self.id)
|
||||
.insert("serverId", hash_str)
|
||||
.unwrap();
|
||||
let join_msg = json!({
|
||||
"accessToken": &self.access_token,
|
||||
"selectedProfile": &self.id,
|
||||
"serverId": hash_str
|
||||
});
|
||||
let join = serde_json::to_string(&join_msg).unwrap();
|
||||
|
||||
let client = hyper::Client::new();
|
||||
|
|
|
@ -1060,12 +1060,12 @@ impl TextureManager {
|
|||
let res = self.resources.clone();
|
||||
if let Some(val) = res.read().unwrap().open(plugin, &path) {
|
||||
let meta: serde_json::Value = serde_json::from_reader(val).unwrap();
|
||||
let animation = meta.find("animation").unwrap();
|
||||
let frame_time = animation.find("frametime").and_then(|v| v.as_i64()).unwrap_or(1);
|
||||
let interpolate = animation.find("interpolate")
|
||||
.and_then(|v| v.as_boolean())
|
||||
let animation = meta.get("animation").unwrap();
|
||||
let frame_time = animation.get("frametime").and_then(|v| v.as_i64()).unwrap_or(1);
|
||||
let interpolate = animation.get("interpolate")
|
||||
.and_then(|v| v.as_bool())
|
||||
.unwrap_or(false);
|
||||
let frames = if let Some(frames) = animation.find("frames")
|
||||
let frames = if let Some(frames) = animation.get("frames")
|
||||
.and_then(|v| v.as_array()) {
|
||||
let mut out = Vec::with_capacity(frames.len());
|
||||
for frame in frames {
|
||||
|
@ -1076,8 +1076,8 @@ impl TextureManager {
|
|||
})
|
||||
} else {
|
||||
out.push(AnimationFrame{
|
||||
index: frame.find("index").unwrap().as_i64().unwrap() as usize,
|
||||
time: frame_time * frame.find("frameTime").unwrap().as_i64().unwrap(),
|
||||
index: frame.get("index").unwrap().as_i64().unwrap() as usize,
|
||||
time: frame_time * frame.get("frameTime").unwrap().as_i64().unwrap(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -310,10 +310,10 @@ impl Manager {
|
|||
let file = fs::File::open(&location).unwrap();
|
||||
let index: serde_json::Value = serde_json::from_reader(&file).unwrap();
|
||||
let root_location = path::Path::new("./objects/");
|
||||
let objects = index.find("objects").and_then(|v| v.as_object()).unwrap();
|
||||
let objects = index.get("objects").and_then(|v| v.as_object()).unwrap();
|
||||
Self::add_task(&progress_info, "Downloading Assets", "./objects", objects.len() as u64);
|
||||
for (k, v) in objects {
|
||||
let hash = v.find("hash").and_then(|v| v.as_string()).unwrap();
|
||||
let hash = v.get("hash").and_then(|v| v.as_str()).unwrap();
|
||||
let hash_path = format!("{}/{}", &hash[..2], hash);
|
||||
let location = root_location.join(&hash_path);
|
||||
if fs::metadata(&location).is_err(){
|
||||
|
@ -321,7 +321,7 @@ impl Manager {
|
|||
let res = client.get(&format!("http://resources.download.minecraft.net/{}", hash_path))
|
||||
.send()
|
||||
.unwrap();
|
||||
let length = v.find("size").and_then(|v| v.as_u64()).unwrap();
|
||||
let length = v.get("size").and_then(|v| v.as_u64()).unwrap();
|
||||
Self::add_task(&progress_info, "Downloading Asset", k, length);
|
||||
let mut tmp_file = location.to_owned();
|
||||
tmp_file.set_file_name(format!("{}.tmp", hash));
|
||||
|
@ -456,10 +456,10 @@ impl ObjectPack {
|
|||
let location = path::Path::new(&loc);
|
||||
let file = fs::File::open(&location).unwrap();
|
||||
let index: serde_json::Value = serde_json::from_reader(&file).unwrap();
|
||||
let objects = index.find("objects").and_then(|v| v.as_object()).unwrap();
|
||||
let objects = index.get("objects").and_then(|v| v.as_object()).unwrap();
|
||||
let mut hash_objs = HashMap::with_hasher(BuildHasherDefault::default());
|
||||
for (k, v) in objects {
|
||||
hash_objs.insert(k.clone(), v.find("hash").and_then(|v| v.as_string()).unwrap().to_owned());
|
||||
hash_objs.insert(k.clone(), v.get("hash").and_then(|v| v.as_str()).unwrap().to_owned());
|
||||
}
|
||||
ObjectPack {
|
||||
objects: hash_objs,
|
||||
|
|
|
@ -48,7 +48,7 @@ impl EditServerEntry {
|
|||
Err(_) => {
|
||||
let mut info = BTreeMap::default();
|
||||
info.insert("servers".to_owned(), Value::Array(vec![]));
|
||||
Value::Object(info)
|
||||
Value::Object(info.into_iter().collect())
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -56,7 +56,7 @@ impl EditServerEntry {
|
|||
let mut entry = BTreeMap::default();
|
||||
entry.insert("name".to_owned(), Value::String(name.to_owned()));
|
||||
entry.insert("address".to_owned(), Value::String(address.to_owned()));
|
||||
Value::Object(entry)
|
||||
Value::Object(entry.into_iter().collect())
|
||||
};
|
||||
|
||||
{
|
||||
|
|
|
@ -118,12 +118,12 @@ impl ServerList {
|
|||
Err(_) => return,
|
||||
};
|
||||
let servers_info: serde_json::Value = serde_json::from_reader(file).unwrap();
|
||||
let servers = servers_info.find("servers").unwrap().as_array().unwrap();
|
||||
let servers = servers_info.get("servers").unwrap().as_array().unwrap();
|
||||
let mut offset = 0.0;
|
||||
|
||||
for (index, svr) in servers.iter().enumerate() {
|
||||
let name = svr.find("name").unwrap().as_string().unwrap().to_owned();
|
||||
let address = svr.find("address").unwrap().as_string().unwrap().to_owned();
|
||||
let name = svr.get("name").unwrap().as_str().unwrap().to_owned();
|
||||
let address = svr.get("address").unwrap().as_str().unwrap().to_owned();
|
||||
|
||||
// Everything is attached to this
|
||||
let back = ui::ImageBuilder::new()
|
||||
|
|
|
@ -718,10 +718,10 @@ impl Server {
|
|||
Some(nbt) => {
|
||||
if block_update.action == 9 {
|
||||
use format;
|
||||
let line1 = format::Component::from_string(nbt.1.get("Text1").unwrap().as_string().unwrap());
|
||||
let line2 = format::Component::from_string(nbt.1.get("Text2").unwrap().as_string().unwrap());
|
||||
let line3 = format::Component::from_string(nbt.1.get("Text3").unwrap().as_string().unwrap());
|
||||
let line4 = format::Component::from_string(nbt.1.get("Text4").unwrap().as_string().unwrap());
|
||||
let line1 = format::Component::from_string(nbt.1.get("Text1").unwrap().as_str().unwrap());
|
||||
let line2 = format::Component::from_string(nbt.1.get("Text2").unwrap().as_str().unwrap());
|
||||
let line3 = format::Component::from_string(nbt.1.get("Text3").unwrap().as_str().unwrap());
|
||||
let line4 = format::Component::from_string(nbt.1.get("Text4").unwrap().as_str().unwrap());
|
||||
self.world.add_block_entity_action(world::BlockEntityAction::UpdateSignText(
|
||||
block_update.location,
|
||||
line1,
|
||||
|
@ -780,7 +780,7 @@ impl Server {
|
|||
continue;
|
||||
},
|
||||
};
|
||||
if let Some(skin_url) = skin_blob.lookup("textures.SKIN.url").and_then(|v| v.as_string()) {
|
||||
if let Some(skin_url) = skin_blob.pointer("/textures/SKIN/url").and_then(|v| v.as_str()) {
|
||||
info.skin_url = Some(skin_url.to_owned());
|
||||
}
|
||||
}
|
||||
|
@ -830,7 +830,7 @@ impl Server {
|
|||
let x = block_entity.1.get("x").unwrap().as_int().unwrap();
|
||||
let y = block_entity.1.get("y").unwrap().as_int().unwrap();
|
||||
let z = block_entity.1.get("z").unwrap().as_int().unwrap();
|
||||
let tile_id = block_entity.1.get("id").unwrap().as_string().unwrap();
|
||||
let tile_id = block_entity.1.get("id").unwrap().as_str().unwrap();
|
||||
let action;
|
||||
match tile_id {
|
||||
// Fake a sign update
|
||||
|
|
Loading…
Reference in New Issue