Skip to content

Commit

Permalink
Use action merge logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Jupeyy committed Jan 16, 2025
1 parent 2b69521 commit bc8d3a2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 3 additions & 1 deletion game/editor/src/action_logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ pub fn merge_actions(actions: &mut Vec<EditorAction>) -> anyhow::Result<()> {
}

while actions.len() > 1 {
let act1 = actions.pop();
let act2 = actions.pop();
let act1 = actions.pop();

if let (Some(act1), Some(act2)) = (act1, act2) {
let (act1, act2) = merge_actions_group(act1, act2)?;
Expand All @@ -562,6 +562,8 @@ pub fn merge_actions(actions: &mut Vec<EditorAction>) -> anyhow::Result<()> {
actions.push(act2);
break;
}
} else {
break;
}
}

Expand Down
1 change: 1 addition & 0 deletions game/editor/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,7 @@ impl Editor {
&self.backend_handle,
&self.texture_handle,
&mut tab.map,
&mut self.notifications_overlay,
);
}

Expand Down
21 changes: 15 additions & 6 deletions game/editor/src/server.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use std::{
collections::HashMap,
sync::{atomic::AtomicBool, Arc},
time::Duration,
};

use base::system::System;
use client_notifications::overlay::ClientNotifications;
use graphics::{
graphics_mt::GraphicsMultiThreaded,
handles::{
Expand All @@ -21,7 +23,7 @@ use network::network::{
use sound::sound_mt::SoundMultiThreaded;

use crate::{
action_logic::{do_action, undo_action},
action_logic::{do_action, merge_actions, undo_action},
actions::actions::EditorActionGroup,
event::{
ClientProps, EditorCommand, EditorEvent, EditorEventClientToServer, EditorEventGenerator,
Expand Down Expand Up @@ -95,6 +97,7 @@ impl EditorServer {
backend_handle: &GraphicsBackendHandle,
texture_handle: &GraphicsTextureHandle,
map: &mut EditorMap,
notifications: &mut ClientNotifications,
) {
if self.has_events.load(std::sync::atomic::Ordering::Relaxed) {
let events = self.event_generator.take();
Expand Down Expand Up @@ -205,11 +208,15 @@ impl EditorServer {
.last_mut()
.is_some_and(|group| group.identifier == act.identifier)
{
self.action_groups
.last_mut()
.unwrap()
.actions
.append(&mut act.actions.clone());
let group = self.action_groups.last_mut().unwrap();
group.actions.append(&mut act.actions.clone());

if let Err(err) = merge_actions(&mut group.actions) {
notifications.add_err(
err.to_string(),
Duration::from_secs(10),
);
}
} else {
let new_index = self.action_groups.len();
self.action_groups.push(act.clone());
Expand Down Expand Up @@ -306,6 +313,8 @@ impl EditorServer {
{err}",
if is_undo { "undo" } else { "redo" }
);
notifications
.add_err(&err, Duration::from_secs(10));
self.network.send_to(
&id,
EditorEvent::Server(
Expand Down

0 comments on commit bc8d3a2

Please sign in to comment.