mirror of
https://github.com/HoonTB/Project-AS.git
synced 2025-12-26 11:51:21 +09:00
refactor(store): improve ChangeVariables() logic
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
public class Store
|
public class Store
|
||||||
{
|
{
|
||||||
@@ -54,20 +55,17 @@ public class Store
|
|||||||
{
|
{
|
||||||
Debug.LogWarning($"VariableManager :: Cannot add {valueStr} to {name} (Type: {current.GetType()})");
|
Debug.LogWarning($"VariableManager :: Cannot add {valueStr} to {name} (Type: {current.GetType()})");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Debug.Log($"VariableManager :: Add {name} += {valueStr} -> {_variables[name]}");
|
Debug.Log($"VariableManager :: Add {name} += {valueStr} -> {_variables[name]}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public string ReplaceVariables(string text)
|
public string ReplaceVariables(string text)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(text) || !text.Contains("{")) return text;
|
if (string.IsNullOrEmpty(text) || !text.Contains("{")) return text;
|
||||||
|
|
||||||
foreach (var kvp in _variables)
|
return Regex.Replace(text, @"\{([^}]+)\}", match =>
|
||||||
{
|
{
|
||||||
text = text.Replace($"{{{kvp.Key}}}", kvp.Value.ToString());
|
string key = match.Groups[1].Value;
|
||||||
}
|
return _variables.ContainsKey(key) ? _variables[key].ToString() : match.Value;
|
||||||
return text;
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,6 @@ public class VNManager : MonoBehaviour
|
|||||||
NextStep();
|
NextStep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
DisplayEffects(dialogueText);
|
DisplayEffects(dialogueText);
|
||||||
|
|||||||
Reference in New Issue
Block a user