Skip to content

Commit

Permalink
[fix, refactor, feat] Converted Descant files from .json to Scriptabl…
Browse files Browse the repository at this point in the history
…eObjects (also fixed a few tiny bugs)
  • Loading branch information
Owmacohe committed Mar 11, 2024
1 parent b846484 commit f93aad8
Show file tree
Hide file tree
Showing 58 changed files with 343 additions and 1,692 deletions.
4 changes: 2 additions & 2 deletions Components/Custom.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Components/Default.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions Components/Custom/Log.cs → Components/Default/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace DescantComponents
[Serializable, MaxQuantity(float.PositiveInfinity), NodeType(DescantNodeType.Any)]
public class Log : DescantComponent
{
[Inline] public string Message;
[Inline, NoFiltering] public string Message;

public override DescantNodeInvokeResult Invoke(DescantNodeInvokeResult result)
{
Debug.Log(Message);
DescantUtilities.LogMessage(GetType(), Message);
return result;
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 3 additions & 19 deletions Components/DescantActor.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
using System;
using System.Collections.Generic;
using UnityEngine;

namespace DescantComponents
{
/// <summary>
/// A data class representing an actor (player or NPC) in a Descant Dialogue
/// </summary>
[Serializable]
public class DescantActor
[Serializable, CreateAssetMenu]
public class DescantActor : ScriptableObject
{
/// <summary>
/// The name of the actor
/// </summary>
public string Name;

/// <summary>
/// The local path to the file after the Assets folder
/// (useful for knowing where to save the file when no longer in its directory)
/// </summary>
public string Path;

/// <summary>
/// The actor's statistics dictionary keys
/// (C# Dictionaries can't be [Serialized], so we use two Lists instead)
Expand Down Expand Up @@ -62,12 +52,6 @@ public class DescantActor
/// <param name="name">The name of the actor</param>
public DescantActor(string name)
{
#if UNITY_EDITOR
Name = DescantUtilities.FilterText(name);
#else
Name = name;
#endif

StatisticKeys = new List<string>();
StatisticValues = new List<float>();

Expand Down
1 change: 0 additions & 1 deletion Components/DescantComponent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;

namespace DescantComponents
{
Expand Down
2 changes: 1 addition & 1 deletion Components/DescantComponentUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public static void MissingMethodError(DescantComponent component, string scriptN
public static DescantActor GetActor(DescantComponent component, List<DescantActor> actors, string name)
{
foreach (var i in actors)
if (i.Name.Equals(name.Trim()))
if (i.name.Equals(name.Trim()))
return i;

DescantUtilities.ErrorMessage(
Expand Down
76 changes: 8 additions & 68 deletions Editor/Data/DescantGraphData.cs → Editor/Data/DescantGraph.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using DescantComponents;
using UnityEngine;

Expand All @@ -9,24 +8,13 @@ namespace DescantEditor
/// <summary>
/// Serializable class to hold the data for saving and loading Descant graphs
/// </summary>
[Serializable]
public class DescantGraphData
[Serializable, CreateAssetMenu]
public class DescantGraph : ScriptableObject
{
/// <summary>
/// The name of the Descant Graph
/// </summary>
public string Name;

/// <summary>
/// The local path to the file after the Assets folder
/// (useful for knowing where to save the file when no longer in its directory)
/// </summary>
public string Path;

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

/// <summary>
/// Whether or not to type out ResponseNode text one character at a time
Expand Down Expand Up @@ -94,16 +82,8 @@ public class DescantGraphData
/// (most of the DescantGroupData's properties are set after
/// it has been initialized, as part of the saving process)
/// </summary>
/// <param name="name">The name of the Descant Graph</param>
public DescantGraphData(string name)
public DescantGraph()
{
#if UNITY_EDITOR
Name = DescantUtilities.FilterText(name);
#else
Name = name;
#endif

Path = "";
Autosave = false;
Typewriter = true;
TypewriterSpeed = 1;
Expand Down Expand Up @@ -132,14 +112,14 @@ public override bool Equals(object other)
{
try
{
_ = (DescantGraphData) other;
_ = (DescantGraph) other;
}
catch
{
return false;
}

return Equals((DescantGraphData)other);
return Equals((DescantGraph)other);
}

#if UNITY_EDITOR
Expand All @@ -148,7 +128,7 @@ public override bool Equals(object other)
/// </summary>
/// <param name="other">The data object being compared against</param>
/// <returns>Whether the other DescantGraphData has the same data as this one</returns>
public bool Equals(DescantGraphData other)
public bool Equals(DescantGraph other)
{
return ToString() == other.ToString();
}
Expand Down Expand Up @@ -178,51 +158,11 @@ public override string ToString()
foreach (var m in Connections)
temp += "\n\t" + m;

return GetType() + " (" + Name + " " + Autosave + " " +
return GetType() + " (" + name + " " + Autosave + " " +
ChoiceNodeID + " " + ResponseNodeID + " " + EndNodeID + " " + GroupID + ")" +
"\n" + Path +
(temp.Length > 1 ? temp : "");
}

#if UNITY_EDITOR
/// <summary>
/// Saves all the data from this graph to its path
/// </summary>
/// <param name="newFile">Whether this is the first time this graph has been saved</param>
public void Save(bool newFile)
{
// Setting the local path if this is the first time
if (newFile) Path = DescantEditorUtilities.GetCurrentLocalDirectory() + Name + ".desc.json";

DescantUtilities.RoundObjectToDecimal(this, 2);

// Saving to the full path
File.WriteAllText(
Application.dataPath + "/" + Path,
DescantUtilities.FormatJSON(JsonUtility.ToJson(this)));
}
#endif

/// <summary>
/// Loads and returns a new graph from a full disc path
/// </summary>
/// <param name="fullPath">The full disc path to the file</param>
/// <returns>A loaded Descant graph</returns>
public static DescantGraphData LoadGraphFromPath(string fullPath)
{
return LoadGraphFromString(File.ReadAllText(fullPath));
}

/// <summary>
/// Loads and returns a new graph from a JSON-formatted string
/// </summary>
/// <param name="str">The string containing all the data for the graph</param>
/// <returns>A loaded Descant graph</returns>
public static DescantGraphData LoadGraphFromString(string str)
{
return JsonUtility.FromJson<DescantGraphData>(str);
}

/// <summary>
/// Checks through all the graph's connections, making sure none of them are redundant or connect to themselves
/// </summary>
Expand Down
File renamed without changes.
Loading

0 comments on commit f93aad8

Please sign in to comment.