Browse Source

Fixed Localization only localizes character name, not story text #611, #614

Wasn’t able to replicate this, but I think it was an issue around
caching SubstitutionHandlers. I’ve changed this system to use a static
list that each substituter registers / unregisters with on OnEnable /
OnDisable. Should be more robust now.
master
Christopher 8 years ago
parent
commit
b8a96bef8a
  1. 15
      Assets/Fungus/Scripts/Components/Flowchart.cs
  2. 10
      Assets/Fungus/Scripts/Components/Localization.cs
  3. 8
      Assets/Fungus/Scripts/Components/SayDialog.cs
  4. 11
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaUtils.cs
  5. 5
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/IStringSubstituter.cs
  6. 43
      Assets/Fungus/Thirdparty/FungusLua/Scripts/Utils/StringSubstituter.cs

15
Assets/Fungus/Scripts/Components/Flowchart.cs

@ -147,6 +147,15 @@ namespace Fungus
CheckItemIds();
CleanupComponents();
UpdateVersion();
StringSubstituter.RegisterHandler(this);
}
protected virtual void OnDisable()
{
cachedFlowcharts.Remove(this);
StringSubstituter.UnregisterHandler(this);
}
protected virtual void UpdateVersion()
@ -172,11 +181,6 @@ namespace Fungus
version = FungusConstants.CurrentVersion;
}
protected virtual void OnDisable()
{
cachedFlowcharts.Remove(this);
}
protected virtual void CheckItemIds()
{
// Make sure item ids are unique and monotonically increasing.
@ -1181,7 +1185,6 @@ namespace Fungus
if (stringSubstituer == null)
{
stringSubstituer = new StringSubstituter();
stringSubstituer.CacheSubstitutionHandlers();
}
// Use the string builder from StringSubstituter for efficiency.

10
Assets/Fungus/Scripts/Components/Localization.cs

@ -65,6 +65,16 @@ namespace Fungus
}
}
protected virtual void OnEnable()
{
StringSubstituter.RegisterHandler(this);
}
protected virtual void OnDisable()
{
StringSubstituter.UnregisterHandler(this);
}
protected virtual void Start()
{
Init();

8
Assets/Fungus/Scripts/Components/SayDialog.cs

@ -149,14 +149,6 @@ namespace Fungus
}
}
protected virtual void OnEnable()
{
// We need to update the cached list every time the Say Dialog is enabled
// due to an initialization order issue after loading scenes.
stringSubstituter.CacheSubstitutionHandlers();
}
protected virtual void LateUpdate()
{
UpdateAlpha();

11
Assets/Fungus/Thirdparty/FungusLua/Scripts/Components/LuaUtils.cs vendored

@ -68,6 +68,16 @@ namespace Fungus
protected ConversationManager conversationManager;
#endif
protected virtual void OnEnable()
{
StringSubstituter.RegisterHandler(this);
}
protected virtual void OnDisable()
{
StringSubstituter.UnregisterHandler(this);
}
/// <summary>
/// Registers all listed c# types for interop with Lua.
/// You can also register types directly in the Awake method of any
@ -245,7 +255,6 @@ namespace Fungus
}
stringSubstituter = new StringSubstituter();
stringSubstituter.CacheSubstitutionHandlers();
#if !FUNGUSLUA_STANDALONE
conversationManager = new ConversationManager();

5
Assets/Fungus/Thirdparty/FungusLua/Scripts/Interfaces/IStringSubstituter.cs vendored

@ -16,11 +16,6 @@ namespace Fungus
/// </summary>
StringBuilder _StringBuilder { get; }
/// <summary>
/// Populates a cache of all components in the scene that implement ISubstitutionHandler.
/// </summary>
void CacheSubstitutionHandlers();
/// <summary>
/// Returns a new string that has been processed by all substitution handlers in the scene.
/// </summary>

43
Assets/Fungus/Thirdparty/FungusLua/Scripts/Utils/StringSubstituter.cs vendored

@ -16,7 +16,7 @@ namespace Fungus
/// </summary>
public class StringSubstituter : IStringSubstituter
{
protected List<ISubstitutionHandler> substitutionHandlers = new List<ISubstitutionHandler>();
protected static List<ISubstitutionHandler> substitutionHandlers = new List<ISubstitutionHandler>();
/// <summary>
/// The StringBuilder instance used to substitute strings optimally.
@ -27,6 +27,19 @@ namespace Fungus
#region Public members
public static void RegisterHandler(ISubstitutionHandler handler)
{
if (!substitutionHandlers.Contains(handler))
{
substitutionHandlers.Add(handler);
}
}
public static void UnregisterHandler(ISubstitutionHandler handler)
{
substitutionHandlers.Remove(handler);
}
/// <summary>
/// Constructor which caches all components in the scene that implement ISubstitutionHandler.
/// <param name="recursionDepth">Number of levels of recursively embedded keys to resolve.</param>
@ -43,34 +56,6 @@ namespace Fungus
public virtual StringBuilder _StringBuilder { get { return stringBuilder; } }
public virtual void CacheSubstitutionHandlers()
{
// Use reflection to find all components in the scene that implement ISubstitutionHandler
#if NETFX_CORE
var types = this.GetType().GetAssembly().GetTypes().Where(type => type.IsClass() &&
!type.IsAbstract() &&
typeof(ISubstitutionHandler).IsAssignableFrom(type));
#else
var types = this.GetType().Assembly.GetTypes().Where(type => type.IsClass &&
!type.IsAbstract &&
typeof(ISubstitutionHandler).IsAssignableFrom(type));
#endif
substitutionHandlers.Clear();
foreach (System.Type t in types)
{
Object[] objects = GameObject.FindObjectsOfType(t);
foreach (Object o in objects)
{
ISubstitutionHandler handler = o as ISubstitutionHandler;
if (handler != null)
{
substitutionHandlers.Add(handler);
}
}
}
}
public virtual string SubstituteStrings(string input)
{
stringBuilder.Length = 0;

Loading…
Cancel
Save