Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/#479-Onboarding-hannes' into #479-…
Browse files Browse the repository at this point in the history
…Onboarding-hannes

# Conflicts:
#	Assets/SEE/Controls/Actions/MarkAction.cs
  • Loading branch information
hlkuss committed Oct 24, 2022
2 parents 0a5e586 + a0a574e commit 7118c16
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 26 deletions.
75 changes: 49 additions & 26 deletions Assets/SEE/Controls/Actions/MarkAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ namespace SEE.Controls.Actions
{
internal class NodeNotFoundException : Exception
{

}
///


/// <summary>
/// Author: Hannes Kuss
///
Expand Down Expand Up @@ -51,13 +50,9 @@ public override HashSet<string> GetChangedObjects() =>
// Is set, when the undo/redo stack should be cleaned up next time
private bool doCleanUpUndoNextTime;

private (GameObject, bool) lastA;

public static MarkAction CreateMarkAction() => new MarkAction();

public static ReversibleAction CreateReversibleAction()
{
return new MarkAction();
}

public override void Undo()
Expand Down Expand Up @@ -133,26 +128,21 @@ public override void Redo()
}
}

public override ActionStateType GetActionStateType()
{
throw new System.NotImplementedException();
}
public override ActionStateType GetActionStateType() => ActionStateType.MarkNode;

public override ReversibleAction NewInstance() => new MarkAction();

public override ReversibleAction NewInstance()
{
throw new System.NotImplementedException();
}

/// <summary>
/// Checks if a node is marked
/// </summary>
/// <param name="node">The node to check</param>
/// <returns></returns>
private bool IsNodeMarked(GameObject node)
{
foreach (var i in markedNodes)
for (int i = 0; i < node.transform.childCount; i++)
{
if (i.Item1 == node)
// When a the child has the tag -MARKED
if (node.transform.GetChild(i).name.EndsWith(MARKER_NAME_SUFFIX))
{
return true;
}
Expand All @@ -161,6 +151,12 @@ private bool IsNodeMarked(GameObject node)
return false;
}

/// <summary>
/// Removes a node from the marked list if the node exists and was marked.
///
/// The marker sphere is untouched in this method.
/// </summary>
/// <param name="node">The node you want to remove</param>
private void RemoveNodeFromMarked(GameObject node)
{
foreach (var i in markedNodes)
Expand All @@ -172,13 +168,19 @@ private void RemoveNodeFromMarked(GameObject node)
}
}

/// <summary>
/// Returns the Marker sphere of a node
/// </summary>
/// <param name="node"></param>
/// <returns>The marker object of the node.
/// Can be null</returns>
private GameObject GetMarkerOfNode(GameObject node)
{
foreach (var i in markedNodes)
for (int i = 0; i < node.transform.childCount; i++)
{
if (i.Item1 == node)
if (node.transform.GetChild(i).name.EndsWith("MARKED"))
{
return i.Item2;
return node.transform.GetChild(i).gameObject;
}
}

Expand All @@ -189,32 +191,53 @@ private GameObject GetMarkerOfNode(GameObject node)
public override bool Update()
{
var ret = true;
if (Input.GetKeyDown(KeyCode.U))
{
if (Input.GetKeyDown(KeyCode.LeftShift))
{
Redo();
}
else
{
Undo();
}
}

// When the user clicks the left mouse button and is pointing to a node
if (Input.GetMouseButtonDown(0) &&
Raycasting.RaycastGraphElement(out RaycastHit raycastHit, out GraphElementRef _) ==
HitGraphElement.Node)
{
GameObject cnode = raycastHit.collider.gameObject;

if (doCleanUpUndoNextTime)
{
undoMarkers.Clear();
redoMarkers.Clear();
doCleanUpUndoNextTime = false;
}

// When the clicked node wasn't marked until now
if (!IsNodeMarked(cnode))
{
currentState = ReversibleAction.Progress.Completed;
// Extract the code city node.
string sphereTag = cnode.tag += "-MARKED";
string sphereTag = cnode.name += MARKER_NAME_SUFFIX;
GameObject marker = GameNodeMarker.CreateMarker(cnode);
marker.name = sphereTag;
markedNodes.Add((cnode, marker));
lastA = (cnode, true);
this.undoMarkers.Push((cnode, true));
}

undoMarkers.Push((cnode, true));
}
// When the clicked node was already marked
else
{
currentState = ReversibleAction.Progress.Completed;
GameObject marker = GetMarkerOfNode(cnode) ??
throw new ArgumentNullException("GetMarkerOfNode(cnode)");
Destroyer.DestroyGameObject(marker);
RemoveNodeFromMarked(cnode);

undoMarkers.Push((cnode, false));
}
}

Expand Down
35 changes: 35 additions & 0 deletions Assets/SEE/Net/Actions/MarkNetAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using SEE.Game;
using UnityEngine;

namespace SEE.Net.Actions
{
public class MarkNetAction : AbstractNetAction
{

public GameObject Node { get; }
public bool Added { get; }

public MarkNetAction(GameObject node, bool added)
{
Node = node;
Added = added;
}

protected override void ExecuteOnServer()
{
throw new System.NotImplementedException();
}

protected override void ExecuteOnClient()
{
if (Added)
{
GameNodeMarker.CreateMarker(Node);
}
else
{
GameNodeMarker.RemoveMarker(Node);
}
}
}
}

0 comments on commit 7118c16

Please sign in to comment.