gled-core 2.33.0

The engine of gled without a user interface: inputs, timing, rendering, Art-Net/DMX output and storage
Documentation
//! Actions on animation assets and their shaders.

use crate::action::{UiAction, update_animation};
use crate::engine::{Engine, EngineEvent};
use crate::runtime::render_thread::RenderCommand;
use crate::storage::asset::animation::argument::{Argument, ArgumentKind};

use super::ignore_without_project;

impl Engine {
    /// Edits animation assets and reloads their shaders.
    pub(super) fn apply_animation_action(&mut self, action: UiAction) {
        match (self.project.is_some(), action) {
            (true, UiAction::ReloadShaderCode(animation)) => {
                // The output is rebuilt on the render thread, previews in
                // the user interfaces.
                self.render_thread
                    .send_command(RenderCommand::ReloadShaderCode(animation));
                self.send_event(EngineEvent::ShaderReloaded(animation));
            }
            (_, UiAction::SetAnimationShaderCode(animation_id, shader_code)) => {
                update_animation(&mut self.collections, animation_id, |animation| {
                    animation.shader_code = shader_code;
                });
            }
            (_, UiAction::AddAnimationArgument(animation_id)) => {
                update_animation(&mut self.collections, animation_id, |animation| {
                    animation.arguments.push(Argument::default());
                });
            }
            (_, UiAction::RemoveAnimationArgument(animation_id, argument_index)) => {
                update_animation(&mut self.collections, animation_id, |animation| {
                    if argument_index < animation.arguments.len() {
                        animation.arguments.remove(argument_index);
                    }
                });
            }
            (_, UiAction::SetAnimationArgumentName(animation_id, argument_index, name)) => {
                update_animation(&mut self.collections, animation_id, |animation| {
                    if let Some(argument) = animation.arguments.get_mut(argument_index) {
                        argument.name = name;
                    }
                });
            }
            (_, UiAction::SetAnimationArgumentKind(animation_id, argument_index, kind)) => {
                update_animation(&mut self.collections, animation_id, |animation| {
                    if let Some(argument) = animation.arguments.get_mut(argument_index) {
                        argument.kind = ArgumentKind::from(kind);
                    }
                });
            }
            (false, _) => ignore_without_project(),
            // `apply_action` routes only animation actions here.
            (true, _) => {}
        }
    }
}