diff --git a/src/plugins/hero_editor.rs b/src/plugins/hero_editor.rs index c0ffda610..73b9130dc 100644 --- a/src/plugins/hero_editor.rs +++ b/src/plugins/hero_editor.rs @@ -23,6 +23,10 @@ impl HeroEditorPlugin { let mut pd = PersistentData::load(world); pd.hero_editor_data.active = None; pd.hero_editor_data.load(world); + world.insert_resource(HeroEditorHistory { + frames: vec![(0.0, pd.hero_editor_data.clone())], + ind: default(), + }); pd.save(world).unwrap(); Pools::get_mut(world).only_local_cache = true; } @@ -50,18 +54,21 @@ impl HeroEditorPlugin { fn input(world: &mut World) { let mut pd = PersistentData::load(world); let ed = &mut pd.hero_editor_data; - if world - .resource::>() - .just_pressed(KeyCode::ArrowUp) - { + let input = world.resource::>(); + if input.just_pressed(KeyCode::ArrowUp) { ed.camera_scale *= 1.2; pd.save(world).unwrap(); - } else if world - .resource::>() - .just_pressed(KeyCode::ArrowDown) - { + } else if input.just_pressed(KeyCode::ArrowDown) { ed.camera_scale /= 1.2; pd.save(world).unwrap(); + } else if input.pressed(KeyCode::SuperLeft) && input.pressed(KeyCode::ControlLeft) { + if input.just_pressed(KeyCode::KeyZ) { + if input.pressed(KeyCode::ShiftLeft) { + HeroEditorHistory::redo(world); + } else { + HeroEditorHistory::undo(world); + } + } } } @@ -355,6 +362,56 @@ impl HeroEditorPlugin { } } +#[derive(Serialize, Deserialize, Resource, Default)] +struct HeroEditorHistory { + frames: Vec<(f32, HeroEditorData)>, + ind: usize, +} + +impl HeroEditorHistory { + fn push(ed: HeroEditorData, world: &mut World) { + const CD: f32 = 0.5; + const LIMIT: usize = 100; + let ts = world.resource::