pub mod color;
pub mod effect;
pub mod grid;
pub mod instance;
use super::AssetTrait;
use crate::patching::layout::LayoutSelection;
use crate::sound::trigger_ref::{CollectSoundTriggers, SoundTriggerSet};
use effect::Effect;
use serde::{Deserialize, Serialize};
use std::collections::BTreeSet;
#[derive(Serialize, Deserialize, Clone, Debug, Default, PartialEq, Eq)]
pub struct Scene {
pub effects: Vec<Effect>,
}
impl Scene {
pub fn selections(&self) -> BTreeSet<LayoutSelection> {
self.effects
.iter()
.filter_map(|effect| effect.selection)
.collect()
}
pub fn effect(&mut self, index: usize) -> Option<&mut Effect> {
self.effects.get_mut(index)
}
pub fn effects(&self) -> &[Effect] {
&self.effects
}
pub fn add_effect(&mut self, effect: Effect) -> usize {
self.effects.push(effect);
self.effects.len() - 1
}
pub fn remove_effect(&mut self, index: usize) -> Option<Effect> {
let mut effect = None;
if self.effects.len() > index {
effect = Some(self.effects.remove(index));
}
effect
}
}
impl AssetTrait for Scene {
const DIR_NAME: &'static str = "scenes";
const NAME: &'static str = "Scene";
const SHOW_NAME_IF_SELECTED: bool = true;
}
impl CollectSoundTriggers for Scene {
fn collect_sound_triggers(&self, triggers: &mut SoundTriggerSet) {
for effect in &self.effects {
effect.collect_sound_triggers(triggers);
}
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::patching::layout::LayoutRef;
fn effect(selection: Option<LayoutSelection>) -> Effect {
Effect {
selection,
..Effect::default()
}
}
#[test]
fn effect_selections_are_the_overrides_only() {
let topology = LayoutSelection::default();
let layout = LayoutSelection::new(LayoutRef::Layout(0), 1);
let scene = Scene {
effects: vec![
effect(None),
effect(Some(layout)),
effect(Some(topology)),
effect(Some(layout)),
],
};
assert_eq!(scene.selections(), BTreeSet::from([topology, layout]));
}
}