Skip to content

Commit

Permalink
Fixed a few minor code issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
lilSander committed Oct 25, 2023
1 parent a3d3ed1 commit f868dea
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 22 deletions.
11 changes: 4 additions & 7 deletions Assets/SEE/Controls/Actions/MarkAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@ public override bool Update()
{
// the hit object is the parent in which to create the new node
GameObject parent = raycastHit.collider.gameObject;
Vector3 position = GameObjectExtensions.GetTop(parent);
Vector3 scale = parent.transform.lossyScale;
addedSphere = GameNodeMarker.NewSphere(parent, scale);
addedSphere = GameNodeMarker.NewSphere(parent);
// addedSphere has the scale of parent and position on top of the parent.
memento = new Memento(parent, position, scale);
new MarkNetAction(memento.Parent.name, position, scale).Execute(); //ID: memento.Parent.name, memento.Position, memento.Scale
memento = new Memento(parent, addedSphere.transform.position, addedSphere.transform.position);
new MarkNetAction(memento.Parent.name, addedSphere.transform.position, addedSphere.transform.position).Execute();
result = true;
CurrentState = IReversibleAction.Progress.Completed;
AudioManagerImpl.EnqueueSoundEffect(IAudioManager.SoundEffect.NewNodeSound, parent);
Expand Down Expand Up @@ -111,7 +109,7 @@ public override void Undo()
public override void Redo()
{
base.Redo();
addedSphere = GameNodeMarker.NewSphere(memento.Parent, memento.Scale);
addedSphere = GameNodeMarker.NewSphere(memento.Parent);
if (addedSphere != null)
{
new MarkNetAction(memento.Parent.name, memento.Position, memento.Scale).Execute();
Expand Down Expand Up @@ -153,7 +151,6 @@ public override HashSet<string> GetChangedObjects()
{
return new HashSet<string>
{
memento.Parent.name,
memento.ParentID
};
}
Expand Down
26 changes: 12 additions & 14 deletions Assets/SEE/Game/SceneManipulation/GameNodeMarker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
namespace SEE.Game.SceneManipulation
{
/// <summary>
/// Creates new game objects representing marker.
/// Creates new game objects representing a marker.
/// The position is over the marked Node.
/// The scale is proportional to the marked Node.
/// </summary>
public static class GameNodeMarker
{
Expand All @@ -22,24 +24,23 @@ public static class GameNodeMarker

private static GameObject sphere = GameObject.CreatePrimitive(PrimitiveType.Sphere);
//[SerializeField] private static List<GameObject> markedNodes;
public static GameObject NewSphere(GameObject parent, Vector3 scale)
public static GameObject NewSphere(GameObject parent)
{
if (parent == null)
{
throw new Exception("Parent must not be null.");
}
else if (existing(parent) && (sphere.activeSelf != false))
else if (Existing(parent) && !sphere.activeSelf)
{
sphere.SetActive(false);
return null;
}

sphere.GetComponent<Renderer>().material.color = Color.red;
float realScale = Math.Min(scale.x, scale.y);
Vector3 position = GameObjectExtensions.GetTop(parent);
sphere.transform.position = position; //parent.transform.position;
sphere.transform.localScale = new Vector3(realScale, realScale, realScale); //parent.transform.lossyScale;
//bool hm = parent.transform.GetChild(parent.transform.childCount) == sphere;
float realScale = Math.Min(parent.transform.lossyScale.x, parent.transform.lossyScale.y);
Vector3 position = parent.GetTop();
sphere.transform.position = position;
sphere.transform.localScale = new Vector3(realScale, realScale, realScale);
sphere.transform.SetParent(parent.transform);
sphere.SetActive(true);
return sphere;
Expand All @@ -50,14 +51,11 @@ public static GameObject NewSphere(GameObject parent, Vector3 scale)
/// </summary>
/// <param name="parent">the parent node of the sphere</param>
/// <returns>true if the parent already has a sphere</returns>
public static bool existing(GameObject parent)
public static bool Existing(GameObject parent)
{
for (int i = 0; i <= parent.transform.childCount - 1; i++)
if (parent.transform.Find("Sphere"))
{
if (parent.transform.GetChild(i).transform.name == "Sphere")
{
return true;
}
return true;
}
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/SEE/Net/Actions/MarkNetAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
namespace SEE.Net.Actions
{
/// <summary>
/// This class is responsible for adding a node via network from one client to all others and
/// This class is responsible for marking a node via network from one client to all others and
/// to the server.
/// </summary>
public class MarkNetAction : AbstractNetAction
Expand Down

0 comments on commit f868dea

Please sign in to comment.