更新插件功能

This commit is contained in:
ShallowT1Dream
2026-05-29 16:57:16 +08:00
parent d06041c0de
commit 00eafcb5f9
3 changed files with 523 additions and 209 deletions

View File

@@ -12,6 +12,7 @@ public class ConfigTableInfo
public string description;
public List<FieldRelation> relations = new List<FieldRelation>();
public bool isExistInProject;
public string fileExtension = ".xlsx";
}
[Serializable]
@@ -24,13 +25,70 @@ public class FieldRelation
public string description;
}
public class ReverseRelation
{
public string sourceTable;
public string sourceDisplayName;
public string fieldName;
public string description;
public string relationFormat;
}
[Serializable]
public class FieldRelationBackup
{
public string fieldName;
public string targetTable;
public string targetField;
public string relationFormat;
public string description;
}
public static class ConfigLinkDatabase
{
private static List<ConfigTableInfo> _cachedData;
private static HashSet<string> _existingTableNames;
private static string _excelFolderPath;
private const string CONFIG_PATH = "Resources/Resources_moved/config";
public static void SetExcelFolderPath(string path)
{
_excelFolderPath = path;
PlayerPrefs.SetString("ConfigLinkExcelFolderPath", path);
}
public static string GetExcelFolderPath()
{
if (string.IsNullOrEmpty(_excelFolderPath))
{
_excelFolderPath = PlayerPrefs.GetString("ConfigLinkExcelFolderPath", "");
}
return _excelFolderPath;
}
public static string GetExcelFilePath(string tableName)
{
string folderPath = GetExcelFolderPath();
if (string.IsNullOrEmpty(folderPath))
return null;
var tableInfo = GetTableInfo(tableName);
string extension = tableInfo?.fileExtension ?? ".xlsx";
string excelPath = Path.Combine(folderPath, $"{tableName}{extension}");
return File.Exists(excelPath) ? excelPath : null;
}
public static bool IsExcelFolderSet()
{
return !string.IsNullOrEmpty(GetExcelFolderPath());
}
public static bool IsExcelFileExists(string tableName)
{
return GetExcelFilePath(tableName) != null;
}
public static List<ConfigTableInfo> GetAllTableInfo()
{
if (_cachedData != null)
@@ -319,7 +377,9 @@ public static class ConfigLinkDatabase
}},
new ConfigTableInfo { tableName = "fishingreward", displayName = "钓鱼奖励表", description = "钓鱼游戏奖励", relations = new List<FieldRelation> {
new FieldRelation { fieldName = "rewards", targetTable = "prop", targetField = "id", relationFormat = "type_id_num", description = "奖励" }
}}
}},
new ConfigTableInfo { tableName = "dirty_words", displayName = "敏感词表", description = "敏感词过滤配置TXT文件", fileExtension = ".txt" },
new ConfigTableInfo { tableName = "奖励格式说明", displayName = "奖励格式说明", description = "奖励数据格式说明文档TXT文件", fileExtension = ".txt" }
};
MarkExistingTables();
@@ -341,12 +401,62 @@ public static class ConfigLinkDatabase
}
}
string configPathAlt = Path.Combine(Application.dataPath, "../Resources/Resources_moved/config");
if (Directory.Exists(configPathAlt))
{
string[] jsonFilesAlt = Directory.GetFiles(configPathAlt, "*.json");
foreach (string file in jsonFilesAlt)
{
string tableName = Path.GetFileNameWithoutExtension(file);
_existingTableNames.Add(tableName.ToLower());
}
}
foreach (var table in _cachedData)
{
table.isExistInProject = _existingTableNames.Contains(table.tableName.ToLower());
bool existInConfig = _existingTableNames.Contains(table.tableName.ToLower());
if (!existInConfig && table.fileExtension == ".txt")
{
string excelFolderPath = GetExcelFolderPath();
if (!string.IsNullOrEmpty(excelFolderPath))
{
string txtPath = Path.Combine(excelFolderPath, $"{table.tableName}{table.fileExtension}");
existInConfig = File.Exists(txtPath);
}
}
table.isExistInProject = existInConfig;
}
}
public static bool IsTableExistInConfigFolder(string tableName)
{
string configPath = Path.Combine(Application.dataPath, CONFIG_PATH);
if (!Directory.Exists(configPath))
return false;
var tableInfo = GetTableInfo(tableName);
string extension = tableInfo?.fileExtension ?? ".xlsx";
string jsonPath = Path.Combine(configPath, $"{tableName}.json");
string configPathAlt = Path.Combine(Application.dataPath, "../Resources/Resources_moved/config");
string jsonPathAlt = Path.Combine(configPathAlt, $"{tableName}.json");
if (extension == ".txt")
{
string excelFolderPath = GetExcelFolderPath();
if (!string.IsNullOrEmpty(excelFolderPath))
{
string txtPath = Path.Combine(excelFolderPath, $"{tableName}{extension}");
if (File.Exists(txtPath))
return true;
}
}
return File.Exists(jsonPath) || File.Exists(jsonPathAlt);
}
public static ConfigTableInfo GetTableInfo(string tableName)
{
return GetAllTableInfo().Find(x => x.tableName.Equals(tableName, StringComparison.OrdinalIgnoreCase));
@@ -357,6 +467,90 @@ public static class ConfigLinkDatabase
return GetAllTableInfo().ConvertAll(x => x.tableName);
}
public static List<ReverseRelation> GetReverseRelations(string targetTableName)
{
List<ReverseRelation> result = new List<ReverseRelation>();
foreach (var table in GetAllTableInfo())
{
foreach (var relation in table.relations)
{
if (relation.targetTable.Equals(targetTableName, StringComparison.OrdinalIgnoreCase))
{
result.Add(new ReverseRelation
{
sourceTable = table.tableName,
sourceDisplayName = table.displayName,
fieldName = relation.fieldName,
description = relation.description,
relationFormat = relation.relationFormat
});
}
}
}
return result;
}
public static string FormatRelationValue(string format, string value)
{
if (string.IsNullOrEmpty(format) || string.IsNullOrEmpty(value))
return value;
string[] parts = value.Split('_');
string result = "";
switch (format.ToLower())
{
case "item_id_num":
if (parts.Length >= 3)
result = $"类型:{parts[0]}, ID:{parts[1]}, 数量:{parts[2]}";
break;
case "type_id_num":
if (parts.Length >= 3)
result = $"类型:{parts[0]}, ID:{parts[1]}, 数量:{parts[2]}";
break;
case "id_pos_lv":
if (parts.Length >= 3)
result = $"ID:{parts[0]}, 位置:{parts[1]}, 等级:{parts[2]}";
break;
case "id_lv_num":
if (parts.Length >= 3)
result = $"ID:{parts[0]}, 等级:{parts[1]}, 数量:{parts[2]}";
break;
case "id_lv_num_time":
if (parts.Length >= 4)
result = $"ID:{parts[0]}, 等级:{parts[1]}, 数量:{parts[2]}, 时间:{parts[3]}";
break;
case "buffid_lv":
if (parts.Length >= 2)
result = $"BuffID:{parts[0]}, 等级:{parts[1]}";
break;
case "rune_id_num":
if (parts.Length >= 2)
result = $"符文ID:{parts[0]}, 数量:{parts[1]}";
break;
case "equip_id_num":
if (parts.Length >= 2)
result = $"装备ID:{parts[0]}, 数量:{parts[1]}";
break;
case "表名":
result = $"表名: {value}";
break;
}
return string.IsNullOrEmpty(result) ? value : result;
}
public static List<string> GetRelatedTableNames(string tableName)
{
var tableInfo = GetTableInfo(tableName);
if (tableInfo == null)
return new List<string>();
return tableInfo.relations.Select(r => r.targetTable).Distinct().ToList();
}
public static List<string> GetAllDisplayNames()
{
return GetAllTableInfo().ConvertAll(x => $"{x.displayName} ({x.tableName})");