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 UnityEngine;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
public class Store
|
||||
{
|
||||
@@ -54,20 +55,17 @@ public class Store
|
||||
{
|
||||
Debug.LogWarning($"VariableManager :: Cannot add {valueStr} to {name} (Type: {current.GetType()})");
|
||||
}
|
||||
|
||||
|
||||
Debug.Log($"VariableManager :: Add {name} += {valueStr} -> {_variables[name]}");
|
||||
}
|
||||
|
||||
|
||||
public string ReplaceVariables(string 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());
|
||||
}
|
||||
return text;
|
||||
string key = match.Groups[1].Value;
|
||||
return _variables.ContainsKey(key) ? _variables[key].ToString() : match.Value;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,6 @@ public class VNManager : MonoBehaviour
|
||||
NextStep();
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
DisplayEffects(dialogueText);
|
||||
|
||||
Reference in New Issue
Block a user