#![allow(dead_code)]
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum NlaBlendMode {
Replace,
Add,
Subtract,
Multiply,
}
#[derive(Debug, Clone)]
pub struct NlaStrip {
pub name: String,
pub blend_mode: NlaBlendMode,
pub start_frame: f32,
pub end_frame: f32,
pub influence: f32,
}
#[derive(Debug, Clone)]
pub struct NlaTrackView {
pub strips: Vec<NlaStrip>,
pub track_height: f32,
pub show_influence: bool,
pub enabled: bool,
}
impl NlaTrackView {
pub fn new() -> Self {
NlaTrackView {
strips: Vec::new(),
track_height: 20.0,
show_influence: true,
enabled: true,
}
}
}
impl Default for NlaTrackView {
fn default() -> Self {
Self::new()
}
}
pub fn new_nla_track_view() -> NlaTrackView {
NlaTrackView::new()
}
pub fn ntv_add_strip(view: &mut NlaTrackView, strip: NlaStrip) {
view.strips.push(strip);
}
pub fn ntv_clear(view: &mut NlaTrackView) {
view.strips.clear();
}
pub fn ntv_set_track_height(view: &mut NlaTrackView, height: f32) {
view.track_height = height.max(8.0);
}
pub fn ntv_show_influence(view: &mut NlaTrackView, show: bool) {
view.show_influence = show;
}
pub fn ntv_set_enabled(view: &mut NlaTrackView, enabled: bool) {
view.enabled = enabled;
}
pub fn ntv_strip_count(view: &NlaTrackView) -> usize {
view.strips.len()
}
pub fn ntv_to_json(view: &NlaTrackView) -> String {
format!(
r#"{{"strip_count":{},"track_height":{},"show_influence":{},"enabled":{}}}"#,
view.strips.len(),
view.track_height,
view.show_influence,
view.enabled
)
}
#[cfg(test)]
mod tests {
use super::*;
fn make_strip() -> NlaStrip {
NlaStrip {
name: "idle".to_string(),
blend_mode: NlaBlendMode::Replace,
start_frame: 0.0,
end_frame: 60.0,
influence: 1.0,
}
}
#[test]
fn test_initial_empty() {
let v = new_nla_track_view();
assert_eq!(ntv_strip_count(&v), 0 );
}
#[test]
fn test_add_strip() {
let mut v = new_nla_track_view();
ntv_add_strip(&mut v, make_strip());
assert_eq!(ntv_strip_count(&v), 1 );
}
#[test]
fn test_clear() {
let mut v = new_nla_track_view();
ntv_add_strip(&mut v, make_strip());
ntv_clear(&mut v);
assert_eq!(ntv_strip_count(&v), 0 );
}
#[test]
fn test_track_height_min() {
let mut v = new_nla_track_view();
ntv_set_track_height(&mut v, 1.0);
assert!((v.track_height - 8.0).abs() < 1e-6 );
}
#[test]
fn test_set_track_height() {
let mut v = new_nla_track_view();
ntv_set_track_height(&mut v, 30.0);
assert!((v.track_height - 30.0).abs() < 1e-6 );
}
#[test]
fn test_show_influence() {
let mut v = new_nla_track_view();
ntv_show_influence(&mut v, false);
assert!(!v.show_influence );
}
#[test]
fn test_set_enabled() {
let mut v = new_nla_track_view();
ntv_set_enabled(&mut v, false);
assert!(!v.enabled );
}
#[test]
fn test_to_json_has_strip_count() {
let v = new_nla_track_view();
let j = ntv_to_json(&v);
assert!(j.contains("\"strip_count\"") );
}
#[test]
fn test_enabled_default() {
let v = new_nla_track_view();
assert!(v.enabled );
}
}