This commit is contained in:
SoulliesOfficial
2025-10-24 09:11:22 -04:00
parent 61a397dd4c
commit 76157e3cb1
329 changed files with 8609 additions and 4549 deletions

View File

@@ -13,11 +13,15 @@ namespace Continentis.MainGame
public static string Parse(Interpreter interpreter, string template, List<string> keywords, List<string> hintKeywords)
{
interpreter.UnsetFunction("Keyword");
interpreter.SetFunction("Keyword", new Func<string, string>(kw => SetKeyword(ref keywords, kw)));
interpreter.SetFunction("Keyword", new Func<string, string>(kw => SetKeyword(ref keywords, kw, "#FFA500")));
interpreter.UnsetFunction("HintKeyword");
interpreter.SetFunction("HintKeyword", new Func<string, string>(kw => SetKeyword(ref hintKeywords, kw)));
interpreter.SetFunction("HintKeyword", new Func<string, string>(kw => SetKeyword(ref hintKeywords, kw, "#FFA500")));
interpreter.SetFunction("HintKeyword", new Func<string, string, string>((kw, colorHex) => SetKeyword(ref hintKeywords, kw, colorHex)));
interpreter.UnsetFunction("DescKeyword");
interpreter.SetFunction("DescKeyword", new Func<string, string>(DescKeyword));
interpreter.SetFunction("DescKeyword", new Func<string, string>(kw =>DescKeyword(kw, "#FFA500")));
interpreter.SetFunction("DescKeyword", new Func<string, string, string>(DescKeyword));
interpreter.UnsetFunction("ColorText");
interpreter.SetFunction("ColorText", new Func<string, string, string>(ColorText));
try
{
@@ -34,7 +38,7 @@ namespace Continentis.MainGame
string expressionToEvaluate = template.Substring(startIndex, endIndex - startIndex + 1);
string cleanExpression = expressionToEvaluate.Substring(1);
Debug.Log($"Evaluating expression: {cleanExpression}");
object result = interpreter.Eval(cleanExpression);
string resultAsLiteral = result.ToString();
template = template.Substring(0, startIndex) + resultAsLiteral + template.Substring(endIndex + 1);
@@ -48,14 +52,14 @@ namespace Continentis.MainGame
return template;
//本地函数,用于添加关键词到集合中并返回格式化后的关键词字符串
string SetKeyword(ref List<string> collection, string keyword)
string SetKeyword(ref List<string> collection, string keyword, string colorHex)
{
if (!string.IsNullOrEmpty(keyword) && !collection.Contains(keyword))
{
collection.Add(keyword);
}
return Keyword(keyword);
return Keyword(keyword, colorHex);
}
}
@@ -139,10 +143,10 @@ namespace Continentis.MainGame
return valueStr;
}
public static string Keyword(string key)
public static string Keyword(string key, string colorHex)
{
string color = "orange";
string color = colorHex;
string result = key;
if (MainGameManager.Instance.keywordData.TryGetKeyword(key, out InterpretedKeyword keyword))
{
@@ -152,9 +156,9 @@ namespace Continentis.MainGame
return $"<color={color}>{result}</color>";
}
public static string DescKeyword(string key)
public static string DescKeyword(string key, string colorHex)
{
string color = "yellow";
string color = colorHex;
string result = key;
if (MainGameManager.Instance.keywordData.TryGetKeyword(key, out InterpretedKeyword keyword))
{
@@ -163,5 +167,11 @@ namespace Continentis.MainGame
return $"<color={color}>{result}</color>";
}
public static string ColorText(string text, string colorHex)
{
string color = colorHex;
return $"<color={color}>{text}</color>";
}
}
}