Skip to content

Commit

Permalink
[refactor] Some small tweaks here and there
Browse files Browse the repository at this point in the history
  • Loading branch information
Owmacohe committed May 11, 2024
1 parent e093f33 commit d63c173
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ crashlytics-build.properties

# Descant
*.DS_Store
*.afdesign
*.afdesign
*.afdesign.meta
4 changes: 2 additions & 2 deletions Editor/DescantEditorUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static T FindFirstElement<T>(VisualElement element) where T : VisualEleme
// Searching through each child and its children before moving to the next
foreach (var i in element.Children())
{
if (i.GetType() == typeof(T)) return (T)i; // Returning the current element if it matches
if (i.GetType() == typeof(T) || i.GetType().IsSubclassOf(typeof(T))) return (T)i; // Returning the current element if it matches

// Checking all the children's children
// (only returning if they aren't null as so not to return null pre-emptively)
Expand All @@ -57,7 +57,7 @@ public static List<T> FindAllElements<T>(VisualElement element) where T : Visual
foreach (var i in element.Children())
{
// Adding the current element to the list if it matches
if (i.GetType() == typeof(T)) lst.Add((T)i);
if (i.GetType() == typeof(T) || i.GetType().IsSubclassOf(typeof(T))) lst.Add((T)i);

// Checking all the children's children
// (then adding the results to the main list)
Expand Down
17 changes: 12 additions & 5 deletions Editor/Window/DescantEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -691,15 +691,15 @@ bool SearchGroups(string query)
/// <param name="element">The element being searched through</param>
/// <param name="query">The formatted phrase that should be looked for</param>
/// <returns>Whether or not a field somewhere in the VisualElement was found that contained the phrase</returns>
bool SearchElement(VisualElement element, string query)
bool SearchElement(GraphElement element, string query)
{
foreach (var i in DescantEditorUtilities.FindAllElements<TextField>(element))
{
string formattedValue = i.value.ToLower();

if (!formattedValue.Equals("") && formattedValue.Contains(query))
{
SnapTo(i); // Snapping the view to the target element when its found
SnapTo(element, i); // Snapping the view to the target element when its found
return true;
}
}
Expand All @@ -711,9 +711,16 @@ bool SearchElement(VisualElement element, string query)
/// Quick method to snap the Descant Graph's view to a particular VisualElement within the graph
/// </summary>
/// <param name="target">The element to be snapped to</param>
void SnapTo(VisualElement target)
/// <param name="field">The TextField that the search query was found in</param>
void SnapTo(GraphElement target, TextField field)
{
graphView.UpdateViewTransform(target.transform.position, Vector3.one); // TODO: incorrect
Rect temp = target.GetPosition();

graphView.UpdateViewTransform(
-temp.position
+ new Vector2(30, 110),
Vector3.one
);
}

#endregion
Expand Down
9 changes: 5 additions & 4 deletions Runtime/DescantDialogueController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public DescantNodeInvokeResult Next(int choiceIndex, bool verbose)
for (int j = 0; j < currentResult.Text.Count; j++)
{
var temp = currentResult.Text[j];
currentResult.Text[j] = new KeyValuePair<int, string>(temp.Key, CheckForStatistics(temp.Value));
currentResult.Text[j] = new KeyValuePair<int, string>(temp.Key, CheckForActorProperties(temp.Value));
}

return currentResult.Text.Count == 0 ? null : currentResult; // Stopping if there are no choices
Expand Down Expand Up @@ -328,11 +328,12 @@ DescantNodeInvokeResult InvokeComponents(DescantNodeInvokeResult currentResult,
}

/// <summary>
/// Method to check through a string, replacing all instances of DescantActor statistic injections
/// Method to check through a string, replacing all instances of DescantActor property injections
/// (statistics, topics, and relationships)
/// </summary>
/// <param name="text">A DescantChoiceNode's or DescantResponseNode's text to be checked through</param>
/// <returns>The string, with the injection replaced with its corresponding statistic</returns>
string CheckForStatistics(string text)
/// <returns>The string, with the injection replaced with its corresponding property</returns>
string CheckForActorProperties(string text)
{
string temp = "";

Expand Down

0 comments on commit d63c173

Please sign in to comment.