Skip to content

Commit cb7cc9e

Browse files
committed
[fix, refactor, feat] Added DescantIfNodes, and fixed a bunch of small bugs that arose during their implementation
1 parent 1c53fda commit cb7cc9e

33 files changed

Lines changed: 649 additions & 185 deletions

Components/DescantComponent.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public override string ToString()
9292
}
9393

9494
/// <summary>
95-
/// A DescantNode class attribute to indicate the maximum number of
95+
/// A DescantComponent class attribute to indicate the maximum number of
9696
/// Components of the attached type that can be added to a DescantNode
9797
/// </summary>
9898
public class MaxQuantityAttribute : Attribute
@@ -103,23 +103,30 @@ public class MaxQuantityAttribute : Attribute
103103
}
104104

105105
/// <summary>
106-
/// A DescantNode class attribute to indicate which type(s) of DescantNodes that the attached type can be added to
106+
/// A DescantComponent class attribute to indicate which type(s) of
107+
/// DescantNodes that the attached type can be added to
107108
/// </summary>
108109
public class NodeTypeAttribute : Attribute
109110
{
110111
public readonly DescantNodeType Type;
111112

112113
public NodeTypeAttribute(DescantNodeType type) => Type = type;
113114
}
115+
116+
/// <summary>
117+
/// A DescantComponent class attribute to indicate whether to show the
118+
/// component in the DescantNodes' component dropdowns
119+
/// </summary>
120+
public class DontShowInEditorAttribute : Attribute { }
114121

115122
/// <summary>
116-
/// A DescantNode property attribute to indicate that the attached parameter
123+
/// A DescantComponent property attribute to indicate that the attached parameter
117124
/// should be rendered inline with the name in the Descant Graph GUI
118125
/// </summary>
119126
public class InlineAttribute : Attribute { }
120127

121128
/// <summary>
122-
/// A DescantNode property attribute to indicate to which group/row
129+
/// A DescantComponent property attribute to indicate to which group/row
123130
/// the attached parameter should be rendered in the Descant Graph GUI
124131
/// </summary>
125132
public class ParameterGroupAttribute : Attribute
@@ -130,7 +137,7 @@ public class ParameterGroupAttribute : Attribute
130137
}
131138

132139
/// <summary>
133-
/// A DescantNode property attribute to indicate that the attached
140+
/// A DescantComponent property attribute to indicate that the attached
134141
/// parameter should not be filtered in the Descant Graph GUI
135142
/// </summary>
136143
public class NoFilteringAttribute : Attribute { }

Components/IfComponent.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
using Descant.Utilities;
3+
4+
namespace Descant.Components
5+
{
6+
/// <summary>
7+
/// Custom Component used for displaying the DescantIfNode's check
8+
/// (should never be added as an actual node component as it doesn't do anything)
9+
/// </summary>
10+
[Serializable, MaxQuantity(0), NodeType(DescantNodeType.If), DontShowInEditor]
11+
public class IfComponent : DescantComponent
12+
{
13+
public DescantActor Actor;
14+
15+
[ParameterGroup("Variable to check")] public VariableType VariableType;
16+
[ParameterGroup("Variable to check")] public string VariableName;
17+
18+
[ParameterGroup("Comparison to make")] public ComparisonType ComparisonType;
19+
[ParameterGroup("Comparison to make")] public float Comparison;
20+
21+
/// <summary>
22+
/// Method to make the comparison
23+
/// </summary>
24+
/// <returns>Whether the DescantIfNode's comparison passes or fails</returns>
25+
public bool Check()
26+
{
27+
return (VariableType.Equals(VariableType.Statistic) && DescantComponentUtilities.CompareVariable(
28+
Actor.Statistics[VariableName], Comparison, ComparisonType)) ||
29+
(VariableType.Equals(VariableType.Topic) && Actor.Topics.Contains(VariableName)) ||
30+
(VariableType.Equals(VariableType.Relationship) && DescantComponentUtilities.CompareVariable(
31+
Actor.Relationships[VariableName], Comparison, ComparisonType)) ||
32+
(VariableType.Equals(VariableType.DialogueAttempts) && DescantComponentUtilities.CompareVariable(
33+
Actor.DialogueAttempts, Comparison, ComparisonType));
34+
}
35+
}
36+
}

Components/IfComponent.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Descant-1.2.0.unitypackage.meta

Lines changed: 0 additions & 7 deletions
This file was deleted.

Descant-1.2.0.zip

-99.8 KB
Binary file not shown.

Descant-1.2.0.zip.meta

Lines changed: 0 additions & 7 deletions
This file was deleted.

Documentation/todo.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
## Hard
2323

2424
- Create a proper video tutorial
25-
- Add `DescantIfNode`
25+
- ~~Add `DescantIfNode`~~
2626
- ~~Make script calling easier~~
2727
- ~~Make autosave better (removed temporarily)~~
2828
- ~~Create log system~~
@@ -40,7 +40,7 @@
4040
- Allow ~~actors~~ and other data to be dragged and dropped
4141
- Show thumbnails
4242
- Indicate that scripts and methods are there when typing in the components
43-
- Add If Node
43+
- ~~Add If Node~~
4444
- Make a video tutorial
4545
- ~~Make `RandomizedNode` automatically last~~
4646
- ~~Create a search functionality in the graph editor~~

Editor/Data/DescantGraph.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public class DescantGraph : ScriptableObject
5454
/// A unique ID number that will be applied to the next-created ResponseNode
5555
/// </summary>
5656
[HideInInspector] public int ResponseNodeID;
57+
58+
/// <summary>
59+
/// A unique ID number that will be applied to the next-created IfNode
60+
/// </summary>
61+
[HideInInspector] public int IfNodeID;
5762

5863
/// <summary>
5964
/// A unique ID number that will be applied to the next-created EndNode
@@ -74,6 +79,11 @@ public class DescantGraph : ScriptableObject
7479
/// The ResponseNodes in the graph
7580
/// </summary>
7681
public List<DescantResponseNodeData> ResponseNodes;
82+
83+
/// <summary>
84+
/// The IfNodes in the graph
85+
/// </summary>
86+
public List<DescantIfNodeData> IfNodes;
7787

7888
/// <summary>
7989
/// The StartNode in the graph
@@ -112,6 +122,7 @@ public DescantGraph()
112122
TypewriterSpeed = 1;
113123
ChoiceNodes = new List<DescantChoiceNodeData>();
114124
ResponseNodes = new List<DescantResponseNodeData>();
125+
IfNodes = new List<DescantIfNodeData>();
115126

116127
// We assume that we'll replace this later, but just in case we don't, we create a default StartNode
117128
StartNode = new DescantStartNodeData(
@@ -162,6 +173,7 @@ public override int GetHashCode()
162173
hashCode.Add(GroupID);
163174
hashCode.Add(ChoiceNodes);
164175
hashCode.Add(ResponseNodes);
176+
hashCode.Add(IfNodes);
165177
hashCode.Add(StartNode);
166178
hashCode.Add(EndNodes);
167179
hashCode.Add(Groups);
@@ -193,17 +205,20 @@ public override string ToString()
193205

194206
foreach (var j in ResponseNodes)
195207
temp += "\n\t" + j;
196-
197-
temp += "\n\t" + StartNode;
198208

199-
foreach (var k in EndNodes)
209+
foreach (var k in IfNodes)
200210
temp += "\n\t" + k;
211+
212+
temp += "\n\t" + StartNode;
201213

202-
foreach (var l in Groups)
214+
foreach (var l in EndNodes)
203215
temp += "\n\t" + l;
204216

205-
foreach (var m in Connections)
217+
foreach (var m in Groups)
206218
temp += "\n\t" + m;
219+
220+
foreach (var n in Connections)
221+
temp += "\n\t" + n;
207222

208223
return GetType() + " (" + name + " " + Autosave + " " + Advanced + " " + Typewriter + " " + TypewriterSpeed + " " +
209224
ChoiceNodeID + " " + ResponseNodeID + " " + EndNodeID + " " + GroupID + ")" +
@@ -221,8 +236,9 @@ public void CleanUpConnections(int checksToPerform = 2)
221236
for (int j = i + 1; j < Connections.Count; j++)
222237
{
223238
if (Connections[j].Equals(Connections[i]) ||
224-
Connections[j].IllegalChoiceFrom() ||
225-
Connections[j].ToItself())
239+
Connections[j].IllegalChoiceOrIf() ||
240+
Connections[j].ToItself() ||
241+
Connections[j].To.Equals("null"))
226242
Connections.RemoveAt(j);
227243
}
228244
}

Editor/Data/DescantNodesData.cs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,93 @@ public override string ToString()
303303

304304
#endregion
305305

306+
#region DescantIfNodeData
307+
308+
/// <summary>
309+
/// Serializable class to hold the data for saving and loading Descant if nodes
310+
/// </summary>
311+
[Serializable]
312+
public class DescantIfNodeData : DescantNodeData
313+
{
314+
/// <summary>
315+
/// The component used to determine which path the dialogue will take after the node
316+
/// </summary>
317+
[SerializeReference] public IfComponent IfComponent;
318+
319+
/// <summary>
320+
/// Parameterized constructor
321+
/// </summary>
322+
/// <param name="name">The custom name of the node</param>
323+
/// <param name="type">The unique identifier ID for the node</param>
324+
/// <param name="id">The type of this node</param>
325+
/// <param name="position">The node's current position</param>
326+
/// <param name="ifComponent">
327+
/// The component used to determine which path the dialogue will take after the node
328+
/// </param>
329+
/// <param name="nodeComponents">The list of Components attached to the node</param>
330+
/// <param name="comments">The comments associated with this node</param>
331+
public DescantIfNodeData(
332+
string name,
333+
string type,
334+
int id,
335+
Vector2 position,
336+
IfComponent ifComponent,
337+
List<DescantComponent> nodeComponents,
338+
string comments)
339+
: base(name, type, id, position, nodeComponents, comments)
340+
{
341+
IfComponent = ifComponent;
342+
}
343+
344+
/// <summary>
345+
/// Overridden Equals method
346+
/// </summary>
347+
/// <param name="other">The object being compared against</param>
348+
/// <returns>Whether the other object has the same data as this one</returns>
349+
public override bool Equals(object other)
350+
{
351+
try
352+
{
353+
_ = (DescantIfNodeData) other;
354+
}
355+
catch
356+
{
357+
return false;
358+
}
359+
360+
return Equals((DescantIfNodeData)other);
361+
}
362+
363+
public override int GetHashCode()
364+
{
365+
return HashCode.Combine(base.GetHashCode(), IfComponent.GetHashCode());
366+
}
367+
368+
#if UNITY_EDITOR
369+
/// <summary>
370+
/// Custom Equals method
371+
/// </summary>
372+
/// <param name="other">The data object being compared against</param>
373+
/// <returns>Whether the other DescantIfNodeData has the same data as this one</returns>
374+
public bool Equals(DescantIfNodeData other)
375+
{
376+
return
377+
base.Equals(other) &&
378+
IfComponent.Equals(other.IfComponent);
379+
}
380+
#endif
381+
382+
/// <summary>
383+
/// Overridden ToString method
384+
/// </summary>
385+
public override string ToString()
386+
{
387+
return base.ToString() + " (" + IfComponent + ")";
388+
}
389+
}
390+
391+
#endregion
392+
306393
#region DescantStartNodeData and DescantEndNodeData
307394

308395
/// <summary>

Editor/Data/DescantOtherData.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using UnityEngine;
4+
using UnityEngine.Serialization;
45

56
namespace Descant.Editor
67
{
@@ -139,6 +140,11 @@ public class DescantConnectionData
139140
/// </summary>
140141
public int FromID;
141142

143+
/// <summary>
144+
/// The index of the port that this connection is coming from (base 1)
145+
/// </summary>
146+
public int FromIndex;
147+
142148
/// <summary>
143149
/// The name of the node the connection is going to
144150
/// </summary>
@@ -148,11 +154,6 @@ public class DescantConnectionData
148154
/// The ID of the node the connection is going to
149155
/// </summary>
150156
public int ToID;
151-
152-
/// <summary>
153-
/// The index of the port that this connection is coming from (base 1 for ChoiceNodes and ResponseNodes)
154-
/// </summary>
155-
public int ChoiceIndex;
156157

157158
/// <summary>
158159
/// Parameterized constructor
@@ -161,31 +162,29 @@ public class DescantConnectionData
161162
/// <param name="fromID">The ID of the node the connection is coming from</param>
162163
/// <param name="to">The name of the node the connection is going to</param>
163164
/// <param name="toID">The ID of the node the connection is going to</param>
164-
/// <param name="choiceIndex">
165+
/// <param name="fromIndex">
165166
/// The index of the port that this connection is coming from (base 1 for ChoiceNodes and ResponseNodes)
166167
/// </param>
167-
public DescantConnectionData(string from, int fromID, string to, int toID, int choiceIndex = 0)
168+
public DescantConnectionData(string from, int fromID, string to, int toID, int fromIndex = 0)
168169
{
169170
From = from;
170171
FromID = fromID;
172+
FromIndex = fromIndex;
171173
To = to;
172174
ToID = toID;
173-
ChoiceIndex = choiceIndex;
174175
}
175176

176177
/// <summary>
177-
/// Checks to make sure that the connection isn't an illegal one coming from a Choice node's input port
178+
/// Checks to make sure that the connection isn't an illegal one coming from a Choice or If node's input port
178179
/// </summary>
179-
/// <returns>Whether this connection is illegally coming from a Choice node's input port</returns>
180-
public bool IllegalChoiceFrom()
180+
public bool IllegalChoiceOrIf()
181181
{
182-
return From.Trim() == "Choice" && ChoiceIndex == 0;
182+
return (From.Equals("Choice") || From.Equals("If")) && FromIndex == 0;
183183
}
184184

185185
/// <summary>
186186
/// Determines whether the connection points to itself
187187
/// </summary>
188-
/// <returns></returns>
189188
public bool ToItself()
190189
{
191190
return From == To && FromID == ToID;
@@ -212,7 +211,7 @@ public override bool Equals(object other)
212211

213212
public override int GetHashCode()
214213
{
215-
return HashCode.Combine(From, FromID, To, ToID, ChoiceIndex);
214+
return HashCode.Combine(From, FromID, FromIndex, To, ToID);
216215
}
217216

218217
#if UNITY_EDITOR
@@ -225,8 +224,8 @@ public bool Equals(DescantConnectionData other)
225224
{
226225
return
227226
From == other.From && FromID == other.FromID &&
228-
To == other.To && ToID == other.ToID &&
229-
ChoiceIndex == other.ChoiceIndex;
227+
FromIndex == other.FromIndex &&
228+
To == other.To && ToID == other.ToID;
230229
}
231230
#endif
232231

@@ -235,7 +234,7 @@ public bool Equals(DescantConnectionData other)
235234
/// </summary>
236235
public override string ToString()
237236
{
238-
return GetType() + " (" + FromID + From + " " + ToID + To + " " + ChoiceIndex + ")";
237+
return GetType() + " (" + FromID + From + " " + FromIndex + " " + ToID + To + ")";
239238
}
240239
}
241240

0 commit comments

Comments
 (0)