Skip to content

Commit

Permalink
Fix IDE warning with asynchronous call. Combine the multi and single …
Browse files Browse the repository at this point in the history
…selections of actions.
  • Loading branch information
Cyclone1337 committed Sep 27, 2024
1 parent 3aec8ea commit 0f316cb
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 142 deletions.
108 changes: 33 additions & 75 deletions Assets/SEE/Controls/Actions/AcceptDivergenceAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ public Memento(Node source, Node target, string type)
/// </summary>
private Memento memento;

/// <summary>
/// The edge created by this action. Can be null if no edge has been created yet or whether
/// an Undo was called. The created edge is stored only to delete it again if Undo is
/// called. All information to create the edge is kept in <see cref="memento"/>.
/// </summary>
private Edge createdEdge;

/// <summary>
/// The information required to (re-)create the edges that solve the divergence
/// via the multi-selection context menu.
Expand All @@ -95,11 +88,6 @@ public Memento(Node source, Node target, string type)
/// </summary>
private readonly List<Edge> createdEdgeList = new();

/// <summary>
/// Whether the context menu was executed in multiselection mode.
/// </summary>
private bool multiselection = false;

/// <summary>
/// Registers itself at <see cref="InteractableObject"/> to listen for hovering events.
/// </summary>
Expand Down Expand Up @@ -155,17 +143,14 @@ public override bool Update()
memento = new Memento(source, target, Edge.SourceDependency);

// create the edge
createdEdge = CreateConvergentEdge(memento);
createdEdgeList.Add(CreateConvergentEdge(memento));

// check whether edge creation was successful
bool divergenceSolved = createdEdge != null;
bool divergenceSolved = createdEdgeList[0] != null;

// add audio cue to the appearance of the new architecture edge
AudioManagerImpl.EnqueueSoundEffect(IAudioManager.SoundEffect.NewEdgeSound);

/// Sets the multiselection to false.
multiselection = false;

// update the current state depending on whether the divergence has been solved
// (required in order to register as an undo-able action)
CurrentState = divergenceSolved ? IReversibleAction.Progress.Completed : IReversibleAction.Progress.NoEffect;
Expand All @@ -181,7 +166,7 @@ public override bool Update()
}
if (ExecuteViaContextMenu)
{
bool divergenceSolved = multiselection ? createdEdgeList.All(e => e != null) : createdEdge != null;
bool divergenceSolved = createdEdgeList.All(e => e != null);
CurrentState = divergenceSolved ? IReversibleAction.Progress.Completed : IReversibleAction.Progress.NoEffect;
return true;
}
Expand All @@ -194,20 +179,11 @@ public override bool Update()
public override void Undo()
{
base.Undo();
if (!multiselection)
{
RemoveDivergence(createdEdge);
// set any edge references back to null
createdEdge = null;
}
else
foreach (Edge edge in createdEdgeList)
{
foreach (Edge edge in createdEdgeList)
{
RemoveDivergence(edge);
}
createdEdgeList.Clear();
RemoveDivergence(edge);
}
createdEdgeList.Clear();
}

/// <summary>
Expand Down Expand Up @@ -246,17 +222,9 @@ private void RemoveDivergence(Edge edge)
public override void Redo()
{
base.Redo();
if (!multiselection)
foreach (Memento mem in mementoList)
{
// recreate the edge
createdEdge = CreateConvergentEdge(memento);
}
else
{
foreach (Memento mem in mementoList)
{
createdEdgeList.Add(CreateConvergentEdge(mem));
}
createdEdgeList.Add(CreateConvergentEdge(mem));
}
}

Expand All @@ -282,16 +250,10 @@ private static Edge CreateConvergentEdge(Memento memento)
/// </summary>
/// <param name="divergence">the edge representing the divergence</param>
/// <returns>the new edge</returns>
public Edge ContextMenuExecution(Edge divergence)
public void ContextMenuExecution(Edge divergence)
{
ExecuteViaContextMenu = true;
multiselection = false;
ReflexionGraph graph = (ReflexionGraph)divergence.ItsGraph;
Node source = graph.MapsTo(divergence.Source);
Node target = graph.MapsTo(divergence.Target);
memento = new(source, target, Edge.SourceDependency);
createdEdge = CreateConvergentEdge(memento);
return createdEdge;
CreateMementoAndConvergentEdge(divergence);
}

/// <summary>
Expand All @@ -303,19 +265,27 @@ public Edge ContextMenuExecution(Edge divergence)
public void ContextMenuExection(IList<Edge> divergences)
{
ExecuteViaContextMenu = true;
multiselection = true;
foreach (Edge divergence in divergences)
{
ReflexionGraph graph = (ReflexionGraph)divergence.ItsGraph;
Node source = graph.MapsTo(divergence.Source);
Node target = graph.MapsTo(divergence.Target);
memento = new(source, target, Edge.SourceDependency);
mementoList.Add(memento);
createdEdge = CreateConvergentEdge(memento);
createdEdgeList.Add(createdEdge);
mementoList.Add(CreateMementoAndConvergentEdge(divergence));
}
}

/// <summary>
/// Creates the memento for restoring the edge and creates the edge.
/// </summary>
/// <param name="divergence">the edge representing the divergence.</param>
/// <returns>The created memento.</returns>
private Memento CreateMementoAndConvergentEdge(Edge divergence)
{
ReflexionGraph graph = (ReflexionGraph)divergence.ItsGraph;
Node source = graph.MapsTo(divergence.Source);
Node target = graph.MapsTo(divergence.Target);
memento = new(source, target, Edge.SourceDependency);
createdEdgeList.Add(CreateConvergentEdge(memento));
return memento;
}

/// <summary>
/// Returns the <see cref="ActionStateType"/> of this action.
/// </summary>
Expand All @@ -331,32 +301,20 @@ public override ActionStateType GetActionStateType()
/// <returns>all IDs of GameObjects manipulated by this action</returns>
public override HashSet<string> GetChangedObjects()
{
if (createdEdge == null)
if (createdEdgeList.Count == 0)
{
return new HashSet<string>();
}
else
{
if (!multiselection)
HashSet<string> strings = new();
for (int i = 0; i < mementoList.Count; i++)
{
return new HashSet<string>
{
memento.From.ID,
memento.To.ID,
createdEdge.ID
};
}
else
{
HashSet<string> strings = new ();
for (int i = 0; i < mementoList.Count; i++)
{
strings.Add(mementoList[i].From.ID);
strings.Add(mementoList[i].To.ID);
strings.Add(createdEdgeList[i].ID);
}
return strings;
strings.Add(mementoList[i].From.ID);
strings.Add(mementoList[i].To.ID);
strings.Add(createdEdgeList[i].ID);
}
return strings;
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions Assets/SEE/Controls/Actions/ContextMenuAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void Delete()
GlobalActionHistory.Execute(ActionStateTypes.Delete);
DeleteAction action = (DeleteAction)GlobalActionHistory.CurrentAction();
action.ContextMenuExecution(selectedObjects.Select(iO => iO.gameObject));
ExcecutePreviousActionAsync(action, previousAction);
_ = ExcecutePreviousActionAsync(action, previousAction);
}

void AcceptDivergence()
Expand All @@ -187,7 +187,7 @@ void AcceptDivergence()
}
}
action.ContextMenuExection(divergences);
ExcecutePreviousActionAsync(action, previousAction);
_ = ExcecutePreviousActionAsync(action, previousAction);
}

void ShowProperties()
Expand Down Expand Up @@ -408,7 +408,7 @@ void DeleteElement()
GlobalActionHistory.Execute(ActionStateTypes.Delete);
DeleteAction action = (DeleteAction)GlobalActionHistory.CurrentAction();
action.ContextMenuExecution(gameObject);
ExcecutePreviousActionAsync(action, previousAction);
_ = ExcecutePreviousActionAsync(action, previousAction);
}
else
{
Expand Down Expand Up @@ -570,7 +570,7 @@ void MoveNode()
UpdatePlayerMenu();
MoveAction action = (MoveAction)GlobalActionHistory.CurrentAction();
action.ContextMenuExecution(gameObject, raycastHitPosition);
ExcecutePreviousActionAsync(action, previousAction);
_ = ExcecutePreviousActionAsync(action, previousAction);
}

void RotateNode()
Expand All @@ -580,7 +580,7 @@ void RotateNode()
UpdatePlayerMenu();
RotateAction action = (RotateAction)GlobalActionHistory.CurrentAction();
action.ContextMenuExecution(gameObject);
ExcecutePreviousActionAsync(action, previousAction);
_ = ExcecutePreviousActionAsync(action, previousAction);
}

void NewNode()
Expand All @@ -589,7 +589,7 @@ void NewNode()
GlobalActionHistory.Execute(ActionStateTypes.NewNode);
AddNodeAction action = (AddNodeAction)GlobalActionHistory.CurrentAction();
action.ContextMenuExecution(gameObject, raycastHitPosition);
ExcecutePreviousActionAsync(action, previousAction);
_ = ExcecutePreviousActionAsync(action, previousAction);
}

void NewEdge()
Expand All @@ -599,7 +599,7 @@ void NewEdge()
UpdatePlayerMenu();
AddEdgeAction action = (AddEdgeAction)GlobalActionHistory.CurrentAction();
action.ContextMenuExecution(gameObject);
ExcecutePreviousActionAsync(action, previousAction);
_ = ExcecutePreviousActionAsync(action, previousAction);
}

void EditNode()
Expand All @@ -609,7 +609,7 @@ void EditNode()
UpdatePlayerMenu();
EditNodeAction action = (EditNodeAction)GlobalActionHistory.CurrentAction();
action.ContextMenuExecution(node);
ExcecutePreviousActionAsync(action, previousAction);
_ = ExcecutePreviousActionAsync(action, previousAction);
}

void ResizeNode()
Expand All @@ -619,7 +619,7 @@ void ResizeNode()
UpdatePlayerMenu();
ResizeNodeAction action = (ResizeNodeAction)GlobalActionHistory.CurrentAction();
action.ContextMenuExecution(gameObject);
ExcecutePreviousActionAsync(action, previousAction);
_ = ExcecutePreviousActionAsync(action, previousAction);
}

void ScaleNode()
Expand All @@ -629,7 +629,7 @@ void ScaleNode()
UpdatePlayerMenu();
ScaleNodeAction action = (ScaleNodeAction)GlobalActionHistory.CurrentAction();
action.ContextMenuExecution(gameObject);
ExcecutePreviousActionAsync(action, previousAction);
_ = ExcecutePreviousActionAsync(action, previousAction);
}
}

Expand Down Expand Up @@ -710,7 +710,7 @@ void AcceptDivergence()
GlobalActionHistory.Execute(ActionStateTypes.AcceptDivergence);
AcceptDivergenceAction action = (AcceptDivergenceAction)GlobalActionHistory.CurrentAction();
action.ContextMenuExecution(edge);
ExcecutePreviousActionAsync(action, previousAction);
_ = ExcecutePreviousActionAsync(action, previousAction);
}
}
#endregion
Expand Down
Loading

0 comments on commit 0f316cb

Please sign in to comment.