Skip to content

Commit

Permalink
#479 MarkAction korrigieren
Browse files Browse the repository at this point in the history
  • Loading branch information
ZerlindaYu authored and koschke committed Dec 28, 2022
1 parent 5ebcbfe commit 1f659d6
Showing 1 changed file with 41 additions and 16 deletions.
57 changes: 41 additions & 16 deletions Assets/SEE/Controls/Actions/MarkAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace SEE.Controls.Actions
internal class MarkAction : AbstractPlayerAction
{
/// <summary>
/// If the user clicks with the mouse hitting a game object representing a graph node,
/// this graph node is a parent to which a new node is created and added as a child.
/// If the user clicks with the mouse hitting a game object representing a node mark,
/// this node mark is a mark to which a node is created.
/// <see cref="ReversibleAction.Update"/>.
/// </summary>
/// <returns>true if completed</returns>
Expand Down Expand Up @@ -44,14 +44,14 @@ public override bool Update()
}
else
{
Debug.LogError($"New node could not be created.\n");
Debug.LogError($"New mark could not be created.\n");
}
}
return result;
}

/// <summary>
/// The node that was added when this action was executed. It is saved so
/// The mark that was added when this action was executed. It is saved so
/// that it can be removed on Undo().
/// </summary>
private GameObject addedGameMark;
Expand Down Expand Up @@ -105,13 +105,11 @@ public Memento(GameObject mark,int diameter ,int x,int y,string nodeid)
}

/// <summary>
/// Returns a scale of a square with the given center <see cref="position"/>
/// that fits into the ground area of <paramref name="parent"/>.
/// Returns a diameter of a sphere
/// </summary>
/// <param name="parent">parent in which to fit the rectangle</param>
/// <param name="position">center position of the rectangle</param>
/// <returns>the scale of a square (actually a cube, but with a very small height)
/// with center <see cref="position"/> that fits into the ground area of <paramref name="parent"/></returns>
/// <param name="x">width of the marked node</param>
/// <param name="y">depth of the markde node</param>
/// <returns>the diameter of the sphere</returns>
private static int FindDiameter(int x, int y)
{
int diameter = 0;
Expand All @@ -128,7 +126,34 @@ private static int FindDiameter(int x, int y)
}

/// <summary>
/// Undoes this AddNodeAction.
/// Returns a scale of a square with the given center <see cref="position"/>
/// that fits into the ground area of <paramref name="parent"/>.
/// </summary>
/// <param name="parent">parent in which to fit the rectangle</param>
/// <param name="position">center position of the rectangle</param>
/// <returns>the scale of a square (actually a cube, but with a very small height)
/// with center <see cref="position"/> that fits into the ground area of <paramref name="parent"/></returns>
private static Vector3 FindSize(GameObject parent, Vector3 position)
{
// TODO: We might want to implement something smarter
// than that, see for instance:
// https://stackoverflow.com/questions/51574829/how-to-algorithmically-find-the-biggest-rectangle-that-can-fit-in-a-space-with-o
Vector3 result = parent.transform.lossyScale / 10;
// The ground area of the result must be a square.
if (result.x > result.z)
{
result.x = result.z;
}
else
{
result.z = result.x;
}
result.y = 0.01f;
return result;
}

/// <summary>
/// Undoes this MarkAction.
/// </summary>
public override void Undo()
{
Expand All @@ -143,7 +168,7 @@ public override void Undo()
}

/// <summary>
/// Redoes this AddNodeAction.
/// Redoes this MarkAction.
/// </summary>
public override void Redo()
{
Expand All @@ -156,7 +181,7 @@ public override void Redo()
}

/// <summary>
/// Returns a new instance of <see cref="AddNodeAction"/>.
/// Returns a new instance of <see cref="MarkAction"/>.
/// </summary>
/// <returns>new instance</returns>
public static ReversibleAction CreateReversibleAction()
Expand All @@ -165,7 +190,7 @@ public static ReversibleAction CreateReversibleAction()
}

/// <summary>
/// Returns a new instance of <see cref="AddNodeAction"/>.
/// Returns a new instance of <see cref="MarkAction"/>.
/// </summary>
/// <returns>new instance</returns>
public override ReversibleAction NewInstance()
Expand All @@ -176,7 +201,7 @@ public override ReversibleAction NewInstance()
/// <summary>
/// Returns the <see cref="ActionStateType"/> of this action.
/// </summary>
/// <returns><see cref="ActionStateType.NewNode"/></returns>
/// <returns><see cref="ActionStateType.NewMark"/></returns>
public override ActionStateType GetActionStateType()
{
return ActionStateType.NewMark;
Expand All @@ -190,7 +215,7 @@ public override HashSet<string> GetChangedObjects()
{
return new HashSet<string>
{
memento.Parent.name,
memento.Mark.name,
memento.NodeID
};
}
Expand Down

0 comments on commit 1f659d6

Please sign in to comment.