1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
use serde::Deserialize; use std::error::Error; use std::fs::File; use std::io::BufReader; #[derive(Debug, Deserialize)] pub struct AnimateChar { #[serde(rename = "frameRate")] pub frame_rate: Option<i64>, pub name: Option<String>, pub version: Option<String>, #[serde(rename = "compatibleVersion")] pub compatible_version: Option<String>, pub armature: Option<Vec<Armature>>, } #[derive(Debug, Deserialize)] pub struct Armature { #[serde(rename = "type")] pub armature_type: Option<String>, #[serde(rename = "frameRate")] pub frame_rate: Option<i64>, pub name: Option<String>, pub aabb: Option<Aabb>, pub bone: Option<Vec<ArmatureBone>>, pub slot: Option<Vec<ArmatureSlot>>, pub skin: Option<Vec<Skin>>, pub animation: Option<Vec<Animation>>, #[serde(rename = "defaultActions")] pub default_actions: Option<Vec<DefaultAction>>, } #[derive(Debug, Deserialize)] pub struct Aabb { pub x: Option<f64>, pub y: Option<f64>, pub width: Option<f64>, pub height: Option<f64>, } #[derive(Debug, Deserialize)] pub struct Animation { pub duration: Option<i64>, #[serde(rename = "playTimes")] pub play_times: Option<i64>, pub name: Option<String>, pub bone: Option<Vec<AnimationBone>>, } #[derive(Debug, Deserialize)] pub struct AnimationBone { pub name: Option<String>, #[serde(rename = "translateFrame")] pub translate_frame: Option<Vec<TranslateFrame>>, #[serde(rename = "rotateFrame")] pub rotate_frame: Option<Vec<RotateFrame>>, } #[derive(Debug, Deserialize)] pub struct RotateFrame { pub duration: Option<i64>, #[serde(rename = "tweenEasing")] pub tween_easing: Option<i64>, pub rotate: Option<f64>, } #[derive(Debug, Deserialize)] pub struct TranslateFrame { #[serde(rename = "tweenEasing")] pub tween_easing: Option<i64>, pub y: Option<f64>, pub duration: Option<i64>, pub x: Option<f64>, } #[derive(Debug, Deserialize)] pub struct ArmatureBone { pub name: Option<String>, pub transform: Option<Transform>, pub parent: Option<String>, } #[derive(Debug, Deserialize)] pub struct Transform { pub x: Option<f64>, pub y: Option<f64>, #[serde(rename = "skX")] pub sk_x: Option<f64>, #[serde(rename = "skY")] pub sk_y: Option<f64>, } #[derive(Debug, Deserialize)] pub struct DefaultAction { #[serde(rename = "gotoAndPlay")] pub goto_and_play: Option<String>, } #[derive(Debug, Deserialize)] pub struct Skin { pub slot: Option<Vec<SkinSlot>>, } #[derive(Debug, Deserialize)] pub struct SkinSlot { pub name: Option<String>, pub display: Option<Vec<Display>>, } #[derive(Debug, Deserialize)] pub struct Display { pub name: Option<String>, pub transform: Option<Transform>, } #[derive(Debug, Deserialize)] pub struct ArmatureSlot { pub name: Option<String>, pub parent: Option<String>, } pub fn load_character(path: String) -> Result<AnimateChar, Box<dyn Error>> { println!("Loading texture file: {}", path); let file = File::open(path)?; let reader = BufReader::new(file); let t = serde_json::from_reader(reader)?; Ok(t) }