Browse Source

Change Conversation Character Find

Previous method used exclusively StartsWith to find matching character, change to using an exact match with fallback to partial, warning user if partial is used.
Fix #854
master
Steve Halliwell 4 years ago
parent
commit
ef380c1bce
  1. 11
      Assets/Fungus/Scripts/Components/Character.cs
  2. 19
      Assets/Fungus/Scripts/Utils/ConversationManager.cs
  3. 1340
      Assets/Tests/Conversation_SimilarNames.unity
  4. 8
      Assets/Tests/Conversation_SimilarNames.unity.meta

11
Assets/Fungus/Scripts/Components/Character.cs

@ -121,7 +121,16 @@ namespace Fungus
|| nameText.StartsWith(matchString, true, System.Globalization.CultureInfo.CurrentCulture);
#endif
}
/// <summary>
/// Returns true if the character name is a complete match to the specified string. Case insensitive.
/// </summary>
public virtual bool NameMatch(string matchString)
{
return string.Compare(name, matchString, true, CultureInfo.CurrentCulture) == 0
|| string.Compare(nameText, matchString, true, CultureInfo.CurrentCulture) == 0;
}
public int Compare(Character x, Character y)
{
if (x == y)

19
Assets/Fungus/Scripts/Utils/ConversationManager.cs

@ -243,6 +243,8 @@ namespace Fungus
// try to find the character param first, since we need to get its portrait
int characterIndex = -1;
int characterParamIndexPartial = characterIndex;
Character partialCharacter = null;
if (characters == null)
{
PopulateCharacterCache();
@ -252,15 +254,30 @@ namespace Fungus
{
for (int j = 0; j < characters.Length; j++)
{
if (characters[j].NameStartsWith(sayParams[i]))
if (characters[j].NameMatch(sayParams[i]))
{
characterIndex = i;
item.Character = characters[j];
break;
}
else if (characters[j].NameStartsWith(sayParams[i]))
{
characterParamIndexPartial = i;
partialCharacter = characters[j];
}
}
}
//if still no charcter was found but we found a partial we use it for backcompat but warn user
if(item.Character == null && partialCharacter != null)
{
Debug.LogWarning("Conversation Manager Character Partial Match; found '" + sayParams[characterParamIndexPartial] +
"' and will use " + partialCharacter.NameText + "\n Recommend modifying conversation and characters so they match exactly.");
characterIndex = characterParamIndexPartial;
item.Character = partialCharacter;
}
// Assume last used character if none is specified now
if (item.Character == null)
{

1340
Assets/Tests/Conversation_SimilarNames.unity

File diff suppressed because it is too large Load Diff

8
Assets/Tests/Conversation_SimilarNames.unity.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 30fbad6648dcae64aaa1f05538aa68d1
timeCreated: 1469542890
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
Loading…
Cancel
Save