# HG changeset patch # User Emmanuel Gil Peyrot # Date 1562269673 -7200 # Node ID 37d151fe000b26197516a10bde9014631f9756d2 # Parent a8e0219162b6f56c86f46ff6633423509dbd09b6 Implement better defaults for Sprite, and a beginning of diff --git a/src/th06/anm0_vm.rs b/src/th06/anm0_vm.rs --- a/src/th06/anm0_vm.rs +++ b/src/th06/anm0_vm.rs @@ -51,13 +51,58 @@ pub struct Sprite { impl Sprite { /// Create a new sprite. - pub fn new() -> Sprite { - Default::default() + pub fn new(width_override: f32, height_override: f32) -> Sprite { + Sprite { + width_override, + height_override, + changed: true, + visible: true, + rescale: [1., 1.], + color: [255, 255, 255, 255], + ..Default::default() + } } /// Update sprite values from the interpolators. pub fn update(&mut self) { - self.changed = false; + self.frame += 1; + + let [sax, say, saz] = self.rotations_speed_3d; + if sax != 0. || say != 0. || saz != 0. { + let [ax, ay, az] = self.rotations_3d; + self.rotations_3d = [ax + sax, ay + say, az + saz]; + self.changed = true; + } else if let Some(ref interpolator) = self.rotation_interpolator { + unimplemented!(); + self.changed = true; + } + + let [rsx, rsy] = self.scale_speed; + if rsx != 0. || rsy != 0. { + let [rx, ry] = self.rescale; + self.rescale = [rx + rsx, ry + rsy]; + self.changed = true; + } + + if let Some(ref interpolator) = self.fade_interpolator { + unimplemented!(); + self.changed = true; + } + + if let Some(ref interpolator) = self.scale_interpolator { + unimplemented!(); + self.changed = true; + } + + if let Some(ref interpolator) = self.offset_interpolator { + unimplemented!(); + self.changed = true; + } + + if let Some(ref interpolator) = self.color_interpolator { + unimplemented!(); + self.changed = true; + } } } @@ -282,7 +327,7 @@ mod tests { let anm0 = Anm0::from_slice(&buf).unwrap(); assert_eq!(anm0.size, (256, 256)); assert_eq!(anm0.format, 5); - let sprite = Rc::new(RefCell::new(Sprite::new())); + let sprite = Rc::new(RefCell::new(Sprite::new(0., 0.))); let mut anm_runner = AnmRunner::new(&anm0, 1, sprite.clone(), 0); for _ in 0..50 { anm_runner.run_frame();