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 {
pub(super) fn apply_animation_action(&mut self, action: UiAction) {
match (self.project.is_some(), action) {
(true, UiAction::ReloadShaderCode(animation)) => {
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(),
(true, _) => {}
}
}
}