Browse Source

Added 3 level deep variation to VariationText demo scene

TextVariation now passes down the current key hash to better prevent hash collisions on sub sections being very similar
master
desktop-maesty/steve 6 years ago
parent
commit
beee4991c1
  1. 14
      Assets/Fungus/Scripts/Utils/TextVariationHandler.cs
  2. 14
      Assets/FungusExamples/VariationText/TextVariation.unity

14
Assets/Fungus/Scripts/Utils/TextVariationHandler.cs

@ -163,8 +163,14 @@ namespace Fungus
return varyingSections.Count > 0;
}
static public string SelectVariations(string input)
/// <summary>
/// Uses the results of a run of tokenisation to choose the appropriate elements
/// </summary>
/// <param name="input"></param>
/// <param name="parentHash">When called recursively, we pass down the current objects hash so as to
/// avoid similar sub /sub sub/ etc. variations</param>
/// <returns></returns>
static public string SelectVariations(string input, int parentHash = 0)
{
// Match the regular expression pattern against a text string.
List<Section> sections = new List<Section>();
@ -184,7 +190,7 @@ namespace Fungus
//fetched hashed value
int index = -1;
int key = input.GetHashCode() ^ curSection.entire.GetHashCode();
int key = input.GetHashCode() ^ curSection.entire.GetHashCode() ^ parentHash;
int foundVal = 0;
if (hashedSections.TryGetValue(key, out foundVal))
@ -200,7 +206,7 @@ namespace Fungus
hashedSections[key] = index;
//handle sub vary within selected section
selected = SelectVariations(selected);
selected = SelectVariations(selected, key);
//update with selecton
sb.Replace(curSection.entire, selected);

14
Assets/FungusExamples/VariationText/TextVariation.unity

@ -942,10 +942,8 @@ MonoBehaviour:
y: -340
width: 1114
height: 859
selectedBlocks:
- {fileID: 1755499608}
selectedCommands:
- {fileID: 1755499607}
selectedBlocks: []
selectedCommands: []
variables: []
description:
stepPause: 0
@ -972,7 +970,7 @@ MonoBehaviour:
indentLevel: 0
conversationText:
stringRef: {fileID: 0}
stringVal: 'john calling-neutral left: [Good [~morning|day], it''s John|Hmm|[~Yes,
stringVal: 'john calling-neutral left: [[~Good [~morning|day]|Hey], it''s John|Hmm|[~Yes,
still|I''m|We''re] here].
sherlock explaining right: [!Who are you talking to?||Still at it, I see.] We
@ -1076,8 +1074,8 @@ MonoBehaviour:
m_EditorClassIdentifier:
itemId: 3
indentLevel: 0
storyText: '[&I''m not sure|He doesn''t seem to be doing well|Sherlock, please put
some pants on].'
storyText: '[&I''m not so sure[~ about that Sherlock||]|He doesn''t seem to be doing
well|[~Sherlock, p|P]lease put some pants on].'
description:
character: {fileID: 275029863}
portrait: {fileID: 0}
@ -1174,7 +1172,7 @@ MonoBehaviour:
itemId: 11
indentLevel: 0
storyText: Alright Sherlock, [~let's go through it again|seriously, pants|let's
sit down|let's get some breakfast and then get to the logic].
[~sit down|let's get some [~breakfast|tea]] and then get to the logic].
description:
character: {fileID: 0}
portrait: {fileID: 0}

Loading…
Cancel
Save