feat(event): 在事件描述中添加变量支持
事件对话框现在会格式化描述文本,将 `{变量名}` 这样的占位符替换为来自 `EventContext` 的当前值。
这允许事件文本能够动态变化,以反映游戏状态或事件中的选择。添加了 `Wula_Test_VariableEvent` 测试事件来演示和验证此功能。
This commit is contained in:
@@ -84,6 +84,9 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
|
||||
HandleAction(def.immediateEffects);
|
||||
|
||||
// Format the description AFTER immediate effects have run
|
||||
selectedDescription = FormatDescription(selectedDescription);
|
||||
}
|
||||
|
||||
public override void DoWindowContents(Rect inRect)
|
||||
@@ -256,5 +259,14 @@ namespace WulaFallenEmpire
|
||||
base.PostClose();
|
||||
HandleAction(def.dismissEffects);
|
||||
}
|
||||
private string FormatDescription(string description)
|
||||
{
|
||||
var variables = EventContext.GetAllVariables();
|
||||
foreach (var variable in variables)
|
||||
{
|
||||
description = description.Replace("{" + variable.Key + "}", variable.Value.ToString());
|
||||
}
|
||||
return description;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,6 +48,11 @@ namespace WulaFallenEmpire
|
||||
return variables.ContainsKey(name);
|
||||
}
|
||||
|
||||
public static Dictionary<string, object> GetAllVariables()
|
||||
{
|
||||
return new Dictionary<string, object>(variables);
|
||||
}
|
||||
|
||||
public static void Clear()
|
||||
{
|
||||
variables.Clear();
|
||||
|
||||
Reference in New Issue
Block a user