This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

at main 1.2 kB View raw
1use crate::video::hooks::{AttachHooks, Hook}; 2 3pub struct Scene<C: Default> { 4 pub name: String, 5 pub hooks: Vec<Hook<C>>, 6} 7 8impl<C: Default> Scene<C> { 9 pub fn new(name: &str) -> Self { 10 Self { 11 name: name.to_string(), 12 hooks: Vec::new(), 13 } 14 } 15} 16 17impl<C: Default + 'static> AttachHooks<C> for Scene<C> { 18 fn with_hook(self, hook: Hook<C>) -> Self { 19 let mut hooks = self.hooks; 20 let scene_name = self.name.clone(); 21 22 hooks.push(Hook { 23 when: Box::new(move |canvas, ctx, prev_beat, prev_frame| { 24 if ctx.current_scene.as_ref() == Some(&scene_name) { 25 (hook.when)(canvas, ctx, prev_beat, prev_frame) 26 } else { 27 false 28 } 29 }), 30 ..hook 31 }); 32 33 Self { hooks, ..self } 34 } 35 36 fn init( 37 self, 38 render_function: &'static super::hooks::RenderFunction<C>, 39 ) -> Self { 40 self.with_hook(Hook { 41 render_function: Box::new(render_function), 42 when: Box::new(move |_, ctx, _, _| ctx.scene_frame() == Some(0)), 43 }) 44 } 45}