Skip to content

Commit

Permalink
[feat] Added a bunch of new features from the todo list
Browse files Browse the repository at this point in the history
- Added autosave back in
- Now saving a graph panned position and scrolled scale
- Added the framework for a search function (not fully implemented)
- Added a comment box under each node and each group
  • Loading branch information
Owmacohe committed Apr 23, 2024
1 parent b7452cf commit e093f33
Show file tree
Hide file tree
Showing 16 changed files with 638 additions and 133 deletions.
8 changes: 4 additions & 4 deletions Documentation/todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
- Create a proper video tutorial
- Add `DescantIfNode`
- ~~Make script calling easier~~
- Make autosave better (removed temporarily)
- ~~Make autosave better (removed temporarily)~~
- ~~Create log system~~
- ~~Create an online Component documentation website~~
- Ctrl-S saving functionality for editors
- Save panned position in `Descant Graph Editor`
- ~~Save panned position in `Descant Graph Editor`~~



Expand All @@ -43,7 +43,7 @@
- Add If Node
- Make a video tutorial
- ~~Make `RandomizedNode` automatically last~~
- Create a search functionality in the graph editor
- ~~Create a search functionality in the graph editor~~
- Make the Log less busy
- Add a note-taking function
- ~~Add a note-taking function~~
- Typewriter speed-changing functionality
51 changes: 49 additions & 2 deletions Editor/Data/DescantGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using Descant.Components;
using UnityEngine;
using UnityEngine.Serialization;

namespace Descant.Editor
{
Expand All @@ -11,11 +12,28 @@ namespace Descant.Editor
[Serializable, CreateAssetMenu(menuName = "Descant/Graph")]
public class DescantGraph : ScriptableObject
{
#region Properties

/// <summary>
/// Whether to autosave the graph when in the Editor
/// </summary>
[HideInInspector] public bool Autosave;

/// <summary>
/// Whether to show or hide the advanced features when in the editor
/// </summary>
[HideInInspector] public bool Advanced;

/// <summary>
/// The position that the graph view has been panned to
/// </summary>
[HideInInspector] public Vector3 PannedPosition;

/// <summary>
/// The scale that the graph view has been scrolled to
/// </summary>
[HideInInspector] public Vector3 ScrolledScale;

/// <summary>
/// Whether or not to type out ResponseNode text one character at a time
/// </summary>
Expand Down Expand Up @@ -76,6 +94,8 @@ public class DescantGraph : ScriptableObject
/// The connections between Nodes in the graph
/// </summary>
[HideInInspector] public List<DescantConnectionData> Connections;

#endregion

/// <summary>
/// Parameterized constructor
Expand All @@ -85,6 +105,9 @@ public class DescantGraph : ScriptableObject
public DescantGraph()
{
Autosave = false;
Advanced = false;
PannedPosition = Vector3.zero;
ScrolledScale = Vector3.one;
Typewriter = true;
TypewriterSpeed = 1;
ChoiceNodes = new List<DescantChoiceNodeData>();
Expand All @@ -95,7 +118,8 @@ public DescantGraph()
"StartNode",
"Start",
Vector2.zero,
new List<DescantComponent>()
new List<DescantComponent>(),
""
);

EndNodes = new List<DescantEndNodeData>();
Expand All @@ -122,6 +146,29 @@ public override bool Equals(object other)
return Equals((DescantGraph)other);
}

public override int GetHashCode()
{
var hashCode = new HashCode();
hashCode.Add(base.GetHashCode());
hashCode.Add(Autosave);
hashCode.Add(Advanced);
hashCode.Add(PannedPosition);
hashCode.Add(ScrolledScale);
hashCode.Add(Typewriter);
hashCode.Add(TypewriterSpeed);
hashCode.Add(ChoiceNodeID);
hashCode.Add(ResponseNodeID);
hashCode.Add(EndNodeID);
hashCode.Add(GroupID);
hashCode.Add(ChoiceNodes);
hashCode.Add(ResponseNodes);
hashCode.Add(StartNode);
hashCode.Add(EndNodes);
hashCode.Add(Groups);
hashCode.Add(Connections);
return hashCode.ToHashCode();
}

#if UNITY_EDITOR
/// <summary>
/// Custom Equals method
Expand Down Expand Up @@ -158,7 +205,7 @@ public override string ToString()
foreach (var m in Connections)
temp += "\n\t" + m;

return GetType() + " (" + name + " " + Autosave + " " +
return GetType() + " (" + name + " " + Autosave + " " + Advanced + " " + Typewriter + " " + TypewriterSpeed + " " +
ChoiceNodeID + " " + ResponseNodeID + " " + EndNodeID + " " + GroupID + ")" +
(temp.Length > 1 ? temp : "");
}
Expand Down
76 changes: 63 additions & 13 deletions Editor/Data/DescantNodesData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

namespace Descant.Editor
{
#region DescantNodeData

/// <summary>
/// Parent class to hold the data for saving and loading Descant nodes
/// </summary>
Expand Down Expand Up @@ -37,6 +39,11 @@ public abstract class DescantNodeData
/// </summary>
[SerializeReference] public List<DescantComponent> NodeComponents;

/// <summary>
/// The comments associated with this node
/// </summary>
public string Comments;

/// <summary>
/// Parameterized constructor
/// </summary>
Expand All @@ -45,18 +52,21 @@ public abstract class DescantNodeData
/// <param name="id">The type of this node</param>
/// <param name="position">The node's current position</param>
/// <param name="nodeComponents">The list of Components attached to the node</param>
/// <param name="comments">The comments associated with this node</param>
protected DescantNodeData(
string name,
string type,
int id,
Vector2 position,
List<DescantComponent> nodeComponents)
List<DescantComponent> nodeComponents,
string comments)
{
Name = name;
Type = type;
ID = id;
Position = position;
NodeComponents = nodeComponents;
Comments = comments;
}

/// <summary>
Expand All @@ -78,6 +88,11 @@ public override bool Equals(object other)
return Equals((DescantNodeData)other);
}

public override int GetHashCode()
{
return HashCode.Combine(Name, Type, ID, Position, NodeComponents, Comments);
}

#if UNITY_EDITOR
/// <summary>
/// Custom Equals method
Expand All @@ -90,7 +105,8 @@ protected bool Equals(DescantNodeData other)
Name == other.Name &&
ID == other.ID &&
Position == other.Position &&
DescantEditorUtilities.AreListsEqual(NodeComponents, other.NodeComponents);
DescantEditorUtilities.AreListsEqual(NodeComponents, other.NodeComponents) &&
Comments == other.Comments;
}
#endif

Expand All @@ -104,9 +120,15 @@ public override string ToString()
foreach (var i in NodeComponents)
temp += " " + i;

return GetType() + " (" + ID + Name + " " + Type + " " + Position + ") (" + (temp.Length > 1 ? temp.Substring(1) : "") + ")";
return GetType() + " (" + ID + Name + " " + Type + " " + Position + ") (" +
(temp.Length > 1 ? temp.Substring(1) : "") + ") (" +
Comments + ")";
}
}

#endregion

#region DescantChoiceNodeData

/// <summary>
/// Serializable class to hold the data for saving and loading Descant choice nodes
Expand All @@ -126,16 +148,18 @@ public class DescantChoiceNodeData : DescantNodeData
/// <param name="type">The unique identifier ID for the node</param>
/// <param name="id">The type of this node</param>
/// <param name="position">The node's current position</param>
/// <param name="nodeComponents">The list of Components attached to the node</param>
/// <param name="choices">The list of possible choices that the player can make at the ChoiceNode</param>
/// <param name="nodeComponents">The list of Components attached to the node</param>
/// <param name="comments">The comments associated with this node</param>
public DescantChoiceNodeData(
string name,
string type,
int id,
Vector2 position,
List<string> choices,
List<DescantComponent> nodeComponents)
: base(name, type, id, position, nodeComponents)
List<DescantComponent> nodeComponents,
string comments)
: base(name, type, id, position, nodeComponents, comments)
{
Choices = choices;
}
Expand All @@ -159,6 +183,11 @@ public override bool Equals(object other)
return Equals((DescantChoiceNodeData)other);
}

public override int GetHashCode()
{
return HashCode.Combine(base.GetHashCode(), Choices);
}

#if UNITY_EDITOR
/// <summary>
/// Custom Equals method
Expand Down Expand Up @@ -187,6 +216,10 @@ public override string ToString()
}
}

#endregion

#region DescantResponseNodeData

/// <summary>
/// Serializable class to hold the data for saving and loading Descant response nodes
/// </summary>
Expand All @@ -205,16 +238,18 @@ public class DescantResponseNodeData : DescantNodeData
/// <param name="type">The unique identifier ID for the node</param>
/// <param name="id">The type of this node</param>
/// <param name="position">The node's current position</param>
/// <param name="nodeComponents">The list of Components attached to the node</param>
/// <param name="response">The response text at the ResponseNode</param>
/// <param name="nodeComponents">The list of Components attached to the node</param>
/// <param name="comments">The comments associated with this node</param>
public DescantResponseNodeData(
string name,
string type,
int id,
Vector2 position,
string response,
List<DescantComponent> nodeComponents)
: base(name, type, id, position, nodeComponents)
List<DescantComponent> nodeComponents,
string comments)
: base(name, type, id, position, nodeComponents, comments)
{
Response = response;
}
Expand All @@ -238,6 +273,11 @@ public override bool Equals(object other)
return Equals((DescantResponseNodeData)other);
}

public override int GetHashCode()
{
return HashCode.Combine(base.GetHashCode(), Response);
}

#if UNITY_EDITOR
/// <summary>
/// Custom Equals method
Expand All @@ -260,6 +300,10 @@ public override string ToString()
return base.ToString() + " (" + Response + ")";
}
}

#endregion

#region DescantStartNodeData and DescantEndNodeData

/// <summary>
/// Serializable class to hold the data for saving and loading Descant start nodes
Expand All @@ -274,12 +318,14 @@ public class DescantStartNodeData : DescantNodeData
/// <param name="type">The unique identifier ID for the node</param>
/// <param name="position">The node's current position</param>
/// <param name="nodeComponents">The list of Components attached to the node</param>
/// <param name="comments">The comments associated with this node</param>
public DescantStartNodeData(
string name,
string type,
Vector2 position,
List<DescantComponent> nodeComponents)
: base(name, type, 0, position, nodeComponents) { }
List<DescantComponent> nodeComponents,
string comments)
: base(name, type, 0, position, nodeComponents, comments) { }
}

/// <summary>
Expand All @@ -296,12 +342,16 @@ public class DescantEndNodeData : DescantNodeData
/// <param name="id">The type of this node</param>
/// <param name="position">The node's current position</param>
/// <param name="nodeComponents">The list of Components attached to the node</param>
/// <param name="comments">The comments associated with this node</param>
public DescantEndNodeData(
string name,
string type,
int id,
Vector2 position,
List<DescantComponent> nodeComponents)
: base(name, type, id, position, nodeComponents) { }
List<DescantComponent> nodeComponents,
string comments)
: base(name, type, id, position, nodeComponents, comments) { }
}

#endregion
}
Loading

0 comments on commit e093f33

Please sign in to comment.