Skip to content

Commit

Permalink
ParalinguisticsNameKey
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaPiggy committed Jul 23, 2024
1 parent f747a67 commit 8db9cba
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"speakerNameKey": "exampleitems.alex.name",
"paralinguisticsNameKey": "TRAVELLING_MERCHANT_NAME_KEY",
"paralinguisticsNameKey": "TRAVELLING_MERCHANT",
"portraitSprite": "Alex",
"smallPortraitSprite": "AlexSmall"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"speakerNameKey": "exampleitems.steve.name",
"paralinguisticsNameKey": "MAYOR_NAME_KEY",
"paralinguisticsNameKey": "MAYOR",
"portraitSprite": "Steve",
"smallPortraitSprite": "SteveSmall"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"speakerNameKey": "exampleitems.test.name",
"paralinguisticsNameKey": "COLLECTOR_REVEALED"
}
15 changes: 12 additions & 3 deletions Winch/Data/Character/AdvancedSpeakerData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,22 @@ namespace Winch.Data.Character
{
public class AdvancedSpeakerData : SpeakerData
{
public string id;
/// <summary>
/// The id of this speaker data
/// </summary>
public string id = string.Empty;

public string paralinguisticsNameKey;
/// <summary>
/// The character you'd like to copy the paralinguistics from.
/// </summary>
public ParalinguisticsNameKey paralinguisticsNameKey = ParalinguisticsNameKey.NONE;

/// <summary>
/// The image of the character. This will show up when you are talking to them.
/// </summary>
public Sprite portraitSprite;

public void AddPortraitPrefab()
public virtual void MakePortraitPrefab()
{
portraitPrefab = new GameObject($"{id} PortraitPrefab", typeof(RectTransform), typeof(Canvas), typeof(GraphicRaycaster), typeof(SpeakerPortraitAnimator)).Prefabitize();
portraitPrefab.layer = Layer.UI;
Expand Down
38 changes: 38 additions & 0 deletions Winch/Data/Character/ParalinguisticsNameKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Winch.Data.Character
{
public enum ParalinguisticsNameKey
{
NONE,
FISHMONGER,
SHIPWRIGHT,
MAYOR,
DOCKWORKER,
COLLECTOR,
COLLECTOR_REVEALED,
TRADER,
BUILDER,
GRIEVING_FATHER,
LIGHTHOUSE_KEEPER,
INGFELL_RESIDENT,
CASTAWAY,
HOODED_FIGURE,
TRAVELLING_MERCHANT,
RETIRED_WHALER,
HERMIT,
RESEARCHER,
SOLDIER,
OLD_MAYOR,
FANATIC,
COURIER,
PLAYER,
PHOTOGRAPHER,
PAINTER,
SOUL
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using UnityEngine;
using UnityEngine.Localization;
using Winch.Core;
using Winch.Data.Character;
using Winch.Util;

namespace Winch.Serialization.Character;
Expand All @@ -12,7 +13,7 @@ public class AdvancedSpeakerDataConverter : SpeakerDataConverter
private readonly Dictionary<string, FieldDefinition> _definitions = new()
{
{ "id", new(null, null) },
{ "paralinguisticsNameKey", new(null, null) },
{ "paralinguisticsNameKey", new(ParalinguisticsNameKey.NONE, o=> DredgeTypeHelpers.GetEnumValue<ParalinguisticsNameKey>(o)) },
{ "portraitSprite", new(TextureUtil.GetSprite("EmptyPortrait"), o=> TextureUtil.GetSprite(o.ToString())) },
};

Expand Down
2 changes: 2 additions & 0 deletions Winch/Serialization/Character/SpeakerDataConverter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Localization;
using UnityEngine.UI;
using Winch.Core;
Expand All @@ -25,6 +26,7 @@ public class SpeakerDataConverter : DredgeTypeConverter<AdvancedSpeakerData>
{ "speakerNameKeyOverrides", new(new List<NameKeyOverride>(), null) },
{ "portraitOverrideConditions", new(new List<PortraitOverride>(), null) },
{ "highlightConditions", new(new List<HighlightCondition>(), null) },
{ "paralinguistics", new(new Dictionary<ParalinguisticType, List<AssetReference>>(), null) },
{ "paralinguisticOverrideConditions", new(new List<ParalinguisticOverride>(), null) }
};

Expand Down
6 changes: 3 additions & 3 deletions Winch/Util/CharacterUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public static void AddModdedSpeakerData(IDictionary<string, SpeakerData> lookupT
{
foreach (var speaker in ModdedSpeakerDataDict.Values)
{
if (lookupTable.TryGetValue(speaker.paralinguisticsNameKey, out SpeakerData data))
if (lookupTable.TryGetParalinguisticsFromNameKey(speaker.paralinguisticsNameKey, out var paralinguistics))
{
speaker.paralinguistics = data.paralinguistics;
speaker.paralinguistics = paralinguistics;
}
lookupTable.Add(speaker.id, speaker);
}
Expand Down Expand Up @@ -83,7 +83,7 @@ internal static void AddCharacterFromMeta(string metaPath)
if (PopulateSpeakerDataFromMetaWithConverter(speaker, meta))
{
ModdedSpeakerDataDict.Add(id, speaker);
speaker.AddPortraitPrefab();
speaker.MakePortraitPrefab();
}
else
{
Expand Down
34 changes: 34 additions & 0 deletions Winch/Util/WinchExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
using System.Reflection;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
using UnityEngine.ResourceManagement.AsyncOperations;
using Winch.Core;
using Winch.Data.Character;
using Winch.Data.Item;

public static class WinchExtensions
Expand Down Expand Up @@ -95,6 +97,38 @@ public static void ShowNotificationWithItemName(this UIController UI, Notificati
}
};
}

public static bool TryGetParalinguisticsFromNameKey(this IDictionary<string, SpeakerData> lookupTable, ParalinguisticsNameKey nameKey, out Dictionary<ParalinguisticType, List<AssetReference>> paralinguistics)
{
var stringNameKey = nameKey.ToString();
switch (nameKey)
{
case ParalinguisticsNameKey.NONE:
break;
case ParalinguisticsNameKey.COLLECTOR_REVEALED:
if (lookupTable.TryGetValue("COLLECTOR_NAME_KEY", out SpeakerData collectorData))
{
paralinguistics = collectorData.paralinguisticOverrideConditions.First().config.paralinguistics;
return true;
}
break;
case ParalinguisticsNameKey.HOODED_FIGURE:
stringNameKey += "_1";
goto default;
case ParalinguisticsNameKey.SOUL:
stringNameKey += "_MIDDLE";
goto default;
default:
if (lookupTable.TryGetValue(stringNameKey + "_NAME_KEY", out SpeakerData data))
{
paralinguistics = data.paralinguistics;
return true;
}
break;
}
paralinguistics = null;
return false;
}
#endregion

#region Reflection
Expand Down

0 comments on commit 8db9cba

Please sign in to comment.