Skip to content

Commit

Permalink
[feat, fix] Put some finishing touches on the editor, actors, and com…
Browse files Browse the repository at this point in the history
…ponents for the new update

- Added DescantActor references to the default components
- Added a SerializableDictionary to the DescantActors
- Added a ton of new DescantComponent variable types that can be added
- Added a small version indicator in the editor
- Updated the screenshots
- Updated the README and the website
  • Loading branch information
Owmacohe committed May 11, 2024
1 parent d63c173 commit 1c53fda
Show file tree
Hide file tree
Showing 40 changed files with 971 additions and 276 deletions.
20 changes: 8 additions & 12 deletions Components/Default/ChangedChoice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Descant.Components
[Serializable, MaxQuantity(float.PositiveInfinity), NodeType(DescantNodeType.Choice)]
public class ChangedChoice : DescantComponent
{
[Inline] public string ActorName;
[Inline] public DescantActor Actor;

[ParameterGroup("Index of the choice to change (base 1)")] public int ChoiceNumber;

Expand All @@ -24,17 +24,13 @@ public class ChangedChoice : DescantComponent

public override DescantNodeInvokeResult Invoke(DescantNodeInvokeResult result)
{
DescantActor actor = DescantComponentUtilities.GetActor(this, result.Actors, ActorName);

if (actor == null) return result;

if ((VariableType.Equals(VariableType.Statistic) && CompareVariable(
actor.StatisticValues[actor.StatisticKeys.IndexOf(VariableName)], Comparison, ComparisonType)) ||
(VariableType.Equals(VariableType.Topic) && actor.Topics.Contains(VariableName)) ||
(VariableType.Equals(VariableType.Relationship) && CompareVariable(
actor.RelationshipValues[actor.RelationshipKeys.IndexOf(VariableName)], Comparison, ComparisonType)) ||
(VariableType.Equals(VariableType.DialogueAttempts) && CompareVariable(
actor.DialogueAttempts, Comparison, ComparisonType)))
if ((VariableType.Equals(VariableType.Statistic) && DescantComponentUtilities.CompareVariable(
Actor.Statistics[VariableName], Comparison, ComparisonType)) ||
(VariableType.Equals(VariableType.Topic) && Actor.Topics.Contains(VariableName)) ||
(VariableType.Equals(VariableType.Relationship) && DescantComponentUtilities.CompareVariable(
Actor.Relationships[VariableName], Comparison, ComparisonType)) ||
(VariableType.Equals(VariableType.DialogueAttempts) && DescantComponentUtilities.CompareVariable(
Actor.DialogueAttempts, Comparison, ComparisonType)))
{
result.Text[ChoiceNumber - 1] = new KeyValuePair<int, string>(
result.Text[ChoiceNumber - 1].Key,
Expand Down
20 changes: 8 additions & 12 deletions Components/Default/ChangedResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Descant.Components
[Serializable, MaxQuantity(float.PositiveInfinity), NodeType(DescantNodeType.Response)]
public class ChangedResponse : DescantComponent
{
[Inline] public string ActorName;
[Inline] public DescantActor Actor;

[ParameterGroup("Variable to check")] public VariableType VariableType;
[ParameterGroup("Variable to check")] public string VariableName;
Expand All @@ -22,17 +22,13 @@ public class ChangedResponse : DescantComponent

public override DescantNodeInvokeResult Invoke(DescantNodeInvokeResult result)
{
DescantActor actor = DescantComponentUtilities.GetActor(this, result.Actors, ActorName);

if (actor == null) return result;

if ((VariableType.Equals(VariableType.Statistic) && CompareVariable(
actor.StatisticValues[actor.StatisticKeys.IndexOf(VariableName)], Comparison, ComparisonType)) ||
(VariableType.Equals(VariableType.Topic) && actor.Topics.Contains(VariableName)) ||
(VariableType.Equals(VariableType.Relationship) && CompareVariable(
actor.RelationshipValues[actor.RelationshipKeys.IndexOf(VariableName)], Comparison, ComparisonType)) ||
(VariableType.Equals(VariableType.DialogueAttempts) && CompareVariable(
actor.DialogueAttempts, Comparison, ComparisonType)))
if ((VariableType.Equals(VariableType.Statistic) && DescantComponentUtilities.CompareVariable(
Actor.Statistics[VariableName], Comparison, ComparisonType)) ||
(VariableType.Equals(VariableType.Topic) && Actor.Topics.Contains(VariableName)) ||
(VariableType.Equals(VariableType.Relationship) && DescantComponentUtilities.CompareVariable(
Actor.Relationships[VariableName], Comparison, ComparisonType)) ||
(VariableType.Equals(VariableType.DialogueAttempts) && DescantComponentUtilities.CompareVariable(
Actor.DialogueAttempts, Comparison, ComparisonType)))
{
result.Text[0] = new KeyValuePair<int, string>(result.Text[0].Key, ChangeTo);
}
Expand Down
20 changes: 8 additions & 12 deletions Components/Default/LockedChoice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Descant.Components
[Serializable, MaxQuantity(Single.PositiveInfinity), NodeType(DescantNodeType.Choice)]
public class LockedChoice : DescantComponent
{
[Inline] public string ActorName;
[Inline] public DescantActor Actor;

[ParameterGroup("Index of the choice to change (base 1)")] public int ChoiceNumber;

Expand All @@ -20,17 +20,13 @@ public class LockedChoice : DescantComponent

public override DescantNodeInvokeResult Invoke(DescantNodeInvokeResult result)
{
DescantActor actor = DescantComponentUtilities.GetActor(this, result.Actors, ActorName);

if (actor == null) return result;

if ((VariableType.Equals(VariableType.Statistic) && CompareVariable(
actor.StatisticValues[actor.StatisticKeys.IndexOf(VariableName)], Comparison, ComparisonType)) ||
(VariableType.Equals(VariableType.Topic) && actor.Topics.Contains(VariableName)) ||
(VariableType.Equals(VariableType.Relationship) && CompareVariable(
actor.RelationshipValues[actor.RelationshipKeys.IndexOf(VariableName)], Comparison, ComparisonType)) ||
(VariableType.Equals(VariableType.DialogueAttempts) && CompareVariable(
actor.DialogueAttempts, Comparison, ComparisonType)))
if ((VariableType.Equals(VariableType.Statistic) && DescantComponentUtilities.CompareVariable(
Actor.Statistics[VariableName], Comparison, ComparisonType)) ||
(VariableType.Equals(VariableType.Topic) && Actor.Topics.Contains(VariableName)) ||
(VariableType.Equals(VariableType.Relationship) && DescantComponentUtilities.CompareVariable(
Actor.Relationships[VariableName], Comparison, ComparisonType)) ||
(VariableType.Equals(VariableType.DialogueAttempts) && DescantComponentUtilities.CompareVariable(
Actor.DialogueAttempts, Comparison, ComparisonType)))
{
result.Text.RemoveAt(ChoiceNumber - 1);
}
Expand Down
12 changes: 4 additions & 8 deletions Components/Default/PortraitChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,25 @@ namespace Descant.Components
[Serializable, MaxQuantity(Single.PositiveInfinity), NodeType(DescantNodeType.Any)]
public class PortraitChange : DescantComponent
{
[Inline] public string ActorName;
[Inline] public DescantActor Actor;

[ParameterGroup("Change to perform")] public PortraitChangeType ChangeType;
[ParameterGroup("Change to perform")] public int PortraitIndex;

public override DescantNodeInvokeResult Invoke(DescantNodeInvokeResult result)
{
DescantActor actor = DescantComponentUtilities.GetActor(this, result.Actors, ActorName);

if (actor == null) return result;

switch (ChangeType)
{
case PortraitChangeType.Set:
actor.Portrait = actor.Portraits[PortraitIndex];
Actor.Portrait = Actor.Portraits[PortraitIndex];
break;

case PortraitChangeType.Enable:
actor.PortraitEnabled = true;
Actor.PortraitEnabled = true;
break;

case PortraitChangeType.Disable:
actor.PortraitEnabled = false;
Actor.PortraitEnabled = false;
break;
}

Expand Down
2 changes: 1 addition & 1 deletion Components/Default/RandomizedChoice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace Descant.Components
{
[Serializable, MaxQuantity(1), NodeType(DescantNodeType.Choice)]
public class RandomizedChoice : DescantComponent // TODO: make this always last
public class RandomizedChoice : DescantComponent
{
public override DescantNodeInvokeResult Invoke(DescantNodeInvokeResult result)
{
Expand Down
22 changes: 8 additions & 14 deletions Components/Default/RelationshipChange.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
// Please see https://omch.tech/descant/#relationshipchange for documentation

using System;
using System.Linq;
using Descant.Utilities;

namespace Descant.Components
{
[Serializable, MaxQuantity(Single.PositiveInfinity), NodeType(DescantNodeType.Any)]
public class RelationshipChange : DescantComponent
{
[ParameterGroup("Actors")] public string FirstActorName;
[ParameterGroup("Actors")] public string SecondActorName;
[ParameterGroup("Actors")] public DescantActor FirstActor;
[ParameterGroup("Actors")] public DescantActor SecondActor;

[ParameterGroup("Operation to perform")] public OperationType OperationType;
[ParameterGroup("Operation to perform")] public float OperationValue;

public override DescantNodeInvokeResult Invoke(DescantNodeInvokeResult result)
{
DescantActor actor = DescantComponentUtilities.GetActor(this, result.Actors, FirstActorName);

if (actor == null) return result;

if (!actor.RelationshipKeys.Contains(SecondActorName))
{
actor.RelationshipKeys.Add(SecondActorName);
actor.RelationshipValues.Add(0);
}
if (!FirstActor.Relationships.Keys.Contains(SecondActor.name))
FirstActor.Relationships.Add(SecondActor.name, 0);

switch (OperationType)
{
case OperationType.IncreaseBy:
actor.RelationshipValues[actor.RelationshipKeys.IndexOf(SecondActorName)] += OperationValue;
FirstActor.Relationships[SecondActor.name] += OperationValue;
break;

case OperationType.DecreaseBy:
actor.RelationshipValues[actor.RelationshipKeys.IndexOf(SecondActorName)] -= OperationValue;
FirstActor.Relationships[SecondActor.name] -= OperationValue;
break;

case OperationType.Set:
actor.RelationshipValues[actor.RelationshipKeys.IndexOf(SecondActorName)] = OperationValue;
FirstActor.Relationships[SecondActor.name] = OperationValue;
break;
}

Expand Down
12 changes: 4 additions & 8 deletions Components/Default/StatisticChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Descant.Components
[Serializable, MaxQuantity(Single.PositiveInfinity), NodeType(DescantNodeType.Any)]
public class StatisticChange : DescantComponent
{
[Inline] public string ActorName;
[Inline] public DescantActor Actor;

[ParameterGroup("Statistic to change")] public string StatisticName;

Expand All @@ -17,22 +17,18 @@ public class StatisticChange : DescantComponent

public override DescantNodeInvokeResult Invoke(DescantNodeInvokeResult result)
{
DescantActor actor = DescantComponentUtilities.GetActor(this, result.Actors, ActorName);

if (actor == null) return result;

switch (OperationType)
{
case OperationType.IncreaseBy:
actor.StatisticValues[actor.StatisticKeys.IndexOf(StatisticName)] += OperationValue;
Actor.Statistics[StatisticName] += OperationValue;
break;

case OperationType.DecreaseBy:
actor.StatisticValues[actor.StatisticKeys.IndexOf(StatisticName)] -= OperationValue;
Actor.Statistics[StatisticName] -= OperationValue;
break;

case OperationType.Set:
actor.StatisticValues[actor.StatisticKeys.IndexOf(StatisticName)] = OperationValue;
Actor.Statistics[StatisticName] = OperationValue;
break;
}

Expand Down
8 changes: 2 additions & 6 deletions Components/Default/StatisticReveal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Descant.Components
[Serializable, MaxQuantity(Single.PositiveInfinity), NodeType(DescantNodeType.Any)]
public class StatisticReveal : DescantComponent
{
[Inline] public string ActorName;
[Inline] public DescantActor Actor;

[ParameterGroup("Statistic to reveal")] public string StatisticName;

Expand All @@ -19,16 +19,12 @@ public class StatisticReveal : DescantComponent

public override DescantNodeInvokeResult Invoke(DescantNodeInvokeResult result)
{
DescantActor actor = DescantComponentUtilities.GetActor(this, result.Actors, ActorName);

if (actor == null || ScriptName == "" || MethodName == "") return result;

if (DescantComponentUtilities.InvokeFromObjectOrScript(
this,
ObjectTag,
ScriptName,
MethodName,
actor.StatisticValues[actor.StatisticKeys.IndexOf(StatisticName)].ToString()
Actor.Statistics[StatisticName].ToString()
)) return result;

DescantComponentUtilities.MissingMethodError(this, ScriptName, MethodName);
Expand Down
10 changes: 3 additions & 7 deletions Components/Default/TopicChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,21 @@ namespace Descant.Components
[Serializable, MaxQuantity(Single.PositiveInfinity), NodeType(DescantNodeType.Response)]
public class TopicChange : DescantComponent
{
[Inline] public string ActorName;
[Inline] public DescantActor Actor;

[ParameterGroup("Topic to change")] public string TopicName;

[ParameterGroup("Change to perform")] public ListChangeType ChangeType;

public override DescantNodeInvokeResult Invoke(DescantNodeInvokeResult result)
{
DescantActor actor = DescantComponentUtilities.GetActor(this, result.Actors, ActorName);

if (actor == null) return result;

switch (ChangeType)
{
case ListChangeType.Add:
if (!actor.Topics.Contains(TopicName)) actor.Topics.Add(TopicName);
if (!Actor.Topics.Contains(TopicName)) Actor.Topics.Add(TopicName);
break;
case ListChangeType.Remove:
if (actor.Topics.Contains(TopicName)) actor.Topics.Remove(TopicName);
if (Actor.Topics.Contains(TopicName)) Actor.Topics.Remove(TopicName);
break;
}

Expand Down
36 changes: 11 additions & 25 deletions Components/DescantActor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,21 @@ public class DescantActor : ScriptableObject
/// All the possible portraits that this Actor can switch between (the first Sprite is used by default)
/// </summary>
public Sprite[] Portraits;

/// <summary>
/// The actor's statistics dictionary keys
/// (C# Dictionaries can't be [Serialized], so we use two Lists instead)
/// </summary>
public List<string> StatisticKeys;


/// <summary>
/// The actor's statistics dictionary values
/// (C# Dictionaries can't be [Serialized], so we use two Lists instead)
/// The actor's statistics
/// </summary>
public List<float> StatisticValues;
public SerializableDictionary<string, float> Statistics;

/// <summary>
/// The actor's topics list
/// </summary>
public List<string> Topics;

/// <summary>
/// The actor's relationships dictionary keys
/// (C# Dictionaries can't be [Serialized], so we use two Lists instead)
/// </summary>
public List<string> RelationshipKeys;


/// <summary>
/// The actor's relationships dictionary values
/// (C# Dictionaries can't be [Serialized], so we use two Lists instead)
/// The actor's relationship values
/// </summary>
public List<float> RelationshipValues;
public SerializableDictionary<string, float> Relationships;

/// <summary>
/// The number of times that the player has attempted to start a dialogue with the actor
Expand All @@ -66,18 +52,18 @@ public override string ToString()
{
string statistics = "";

for (int i = 0; i < StatisticKeys.Count; i++)
statistics += " (" + StatisticKeys[i] + " " + StatisticValues[i] + ")";
foreach (var i in Statistics)
statistics += "(" + i.Key + " : " + i.Value + ")";

string topics = "";

foreach (var j in Topics)
topics += " " + j;

string relationships = "";

for (int i = 0; i < RelationshipKeys.Count; i++)
relationships += " (" + RelationshipKeys[i] + " " + RelationshipValues[i] + ")";
foreach (var k in Relationships)
statistics += "(" + k.Key + " : " + k.Value + ")";

return GetType() +
" (" + (statistics.Length > 0 ? statistics.Substring(1) : "") + ")" +
Expand Down
Loading

0 comments on commit 1c53fda

Please sign in to comment.