refactor(store): improve ChangeVariables() logic

This commit is contained in:
2025-11-30 22:27:47 +09:00
parent fcc9d7a78b
commit 2a832f18af
2 changed files with 5 additions and 8 deletions

View File

@@ -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; });
} }
} }

View File

@@ -62,7 +62,6 @@ public class VNManager : MonoBehaviour
NextStep(); NextStep();
} }
void Update() void Update()
{ {
DisplayEffects(dialogueText); DisplayEffects(dialogueText);