我死去

目前添加了一个能够深度查找和设置反射的helper,但是Tag的系统仍然不完全,另外我觉得console可以重构了

Signed-off-by: TRAfoer <lhf190@outlook.com>
This commit is contained in:
2025-12-14 12:15:07 +08:00
parent 1bbb1c51ab
commit 7a2bc844bd
22 changed files with 127636 additions and 35827 deletions

View File

@@ -46,6 +46,8 @@ namespace Ichni.Editor
));
return $"{methodName} {paramHint}".Trim() + "\n";
}
// ... (omitted parts)
public void GetChange(string change)
{
if (change == "help")
@@ -80,8 +82,9 @@ namespace Ichni.Editor
string funcName = match.Groups[1].Value;
// 2. 查找方法
// 【修改点】:使用 StringComparison.OrdinalIgnoreCase 实现忽略大小写的查找
List<MethodInfo> methods = typeof(EditorConsoleMethods).GetMethods()
.Where(m => m.IsStatic && m.IsPublic && m.ReturnType == typeof(void) && m.Name.Contains(funcName)).ToList();
.Where(m => m.IsStatic && m.IsPublic && m.ReturnType == typeof(void) && m.Name.IndexOf(funcName, StringComparison.OrdinalIgnoreCase) >= 0).ToList();
cueText.text = "";
for (int i = 0; i < methods.Count; i++)
{
@@ -96,6 +99,7 @@ namespace Ichni.Editor
// t.RunSynchronously();
}
// ... (omitted parts)
public void GetCommand(string Command)//当提交命令时
{
try
@@ -132,7 +136,42 @@ namespace Ichni.Editor
}
}
// 在 TransformCommand 或 CheckCtrlNumberShortcut 附近添加
// 辅助方法:获取 cueText 中第一个提示的命令名
private string GetFinalCommandForExecution(string input)
{
string trimmed = input.Trim();
// 1. 提取用户输入的命令名部分
var match = Regex.Match(trimmed, @"^(\w+)");
if (!match.Success)
{
// 如果不是合法的命令开头,直接尝试转换并返回 (DynamicExpresso 也许能处理赋值)
return TransformCommand(trimmed);
}
string funcName = match.Groups[1].Value;
// 2. 重新查找匹配的方法 (和 GetChange 逻辑一致,保证一致性)
List<MethodInfo> methods = typeof(EditorConsoleMethods).GetMethods()
.Where(m => m.IsStatic && m.IsPublic && m.ReturnType == typeof(void) && m.Name.IndexOf(funcName, StringComparison.OrdinalIgnoreCase) >= 0).ToList();
string finalCommandToTransform = input;
// 3. 找到最佳匹配并替换
if (methods.Count > 0)
{
// 最佳匹配是列表中的第一个方法名
string firstCommand = methods[0].Name;
// 替换用户输入中的命令名部分为完整的、匹配到的命令名
// 例如:用户输入 "pr 10",替换为 "print 10"
finalCommandToTransform = Regex.Replace(trimmed, @"^(\w+)", firstCommand);
}
// 4. 转换并返回 DynamicExpresso 表达式
return TransformCommand(finalCommandToTransform);
}
//这是史,不要看
@@ -165,19 +204,20 @@ namespace Ichni.Editor
// 提交命令
if (Keyboard.current.enterKey.wasPressedThisFrame)
{
string input = InputCommand.text;
string input = InputCommand.text; // 原始命令文本
if (string.IsNullOrWhiteSpace(input))
{
InputCommand.text = "";
return;
}
string ExpoCommand = TransformCommand(input);
// 【修改点】:调用新方法获取最终执行的命令(已包含修正逻辑和 TransformCommand
string ExpoCommand = GetFinalCommandForExecution(input);
print(ExpoCommand);
// print(ExpoCommand); // 调试语句,可选
GetCommand(ExpoCommand);
// 记录历史命令
// 记录历史命令,使用原始命令 input
if (historyCommand.ContainsKey(historycount))
historyCommand[historycount] = input;
else
@@ -306,6 +346,7 @@ namespace Ichni.Editor
{
functionInterpreter = new Interpreter()
.Reference(typeof(Vector3))
.Reference(typeof(Color))
.Reference(typeof(Vector2));//这是AI给的东西
foreach (MethodInfo i in typeof(EditorConsoleMethods).GetMethods().
ToList().Where(i => i.IsStatic && i.IsPublic && (i.ReturnType == typeof(void))))