You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's three big blobs (one on block_state.rs, two on model.rs) which could be a lot simpler if we used the auto-derive capabilities of json::decode.
Example:
externcrate"rustc-serialize" as rustc_serialize;use std::collections::BTreeMap;use std::io::File;use std::io::fs::walk_dir;use rustc_serialize::Decodable;use rustc_serialize::json::{self,Json};#[derive(RustcDecodable,PartialEq,Show)]structFaceInfo{cullface:Option<String>,rotation:Option<i64>,texture:String,tintindex:Option<i64>,uv:Option<Vec<f64>>,}#[derive(RustcDecodable,PartialEq,Show)]structFaces{down:Option<FaceInfo>,east:Option<FaceInfo>,north:Option<FaceInfo>,south:Option<FaceInfo>,up:Option<FaceInfo>,west:Option<FaceInfo>,}#[derive(RustcDecodable,PartialEq,Show)]structRotation{angle:f64,axis:String,origin:Vec<f64>,rescale:Option<bool>,}#[derive(RustcDecodable,PartialEq,Show)]structElement{from:Vec<f64>,to:Vec<f64>,rotation:Option<Rotation>,shade:Option<bool>,faces:Faces,}#[derive(RustcDecodable,PartialEq,Show)]structBlockModel{parent:Option<String>,ambientocclusion:Option<bool>,textures:Option<BTreeMap<String,String>>,elements:Option<Vec<Element>>,}fnmain(){let path = Path::new("src/bin/block");letmut n = 0;for p inwalk_dir(&path).unwrap(){letmut file = File::open(&p).unwrap();let body = Json::from_reader(&mut file).unwrap();letmut dec = json::Decoder::new(body);let bm:BlockModel = Decodable::decode(&mut dec).unwrap();// Use bm here
n += 1;}println!("Read {} files.", n);}
This thing, seems huge but it's mostly struct definitions, with optional fields mostly. It reads all files inside assets/minecraft/models/block (assuming they are inside src/bin/block and counts them.
Of course it lacks the real logic so it's not usable with the graphics code but still it's way easier to understand. Here is the real thing.
Let me know what you think.
The text was updated successfully, but these errors were encountered:
@toqueteos that must've changed since when I've written this.
I'll merge any cleanup based on this (awesome!) face - I think I never ended up using the NBT decoder - but that's mostly because there's a lot of bulk data which would be inefficiently treated by the decoder model (it's not streaming q_q).
There's three big blobs (one on
block_state.rs
, two onmodel.rs
) which could be a lot simpler if we used the auto-derive capabilities ofjson::decode
.Example:
This thing, seems huge but it's mostly struct definitions, with optional fields mostly. It reads all files inside
assets/minecraft/models/block
(assuming they are insidesrc/bin/block
and counts them.Of course it lacks the real logic so it's not usable with the graphics code but still it's way easier to understand. Here is the real thing.
Let me know what you think.
The text was updated successfully, but these errors were encountered: