饭太稀

This commit is contained in:
bob
2025-06-30 10:51:37 +08:00
commit 8e45469c83
753 changed files with 87652 additions and 0 deletions

View File

@@ -0,0 +1,158 @@
// using System;
// using System.Text;
// using Exporter.Excel;
// using Fantasy.Exporter;
// using OfficeOpenXml;
//
// namespace Exporter;
//
// public class ConstValueToConst : ACustomExport
// {
// public override void Run()
// {
// if (!ExcelExporter.LoadIgnoreExcel("#ConstValue", out var excelPackage))
// {
// Log.Error("ConstValueToConst: Load Excel failed.");
// return;
// }
//
// var worksheet = excelPackage.Workbook.Worksheets[0];
//
// var serverHotfixStrBuilder = new StringBuilder();
// serverHotfixStrBuilder.AppendLine("namespace Fantasy\n{");
// serverHotfixStrBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑,修改请在#ConstValue.xsl里。");
// serverHotfixStrBuilder.AppendLine("\tpublic partial class ConstValueHotfix\n\t{");
//
// var serverModelStrBuilder = new StringBuilder();
// serverModelStrBuilder.AppendLine("namespace Fantasy\n{");
// serverModelStrBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑。");
// serverModelStrBuilder.AppendLine("\tpublic partial class ConstValue\n\t{");
//
// var clientStrBuilder = new StringBuilder();
// clientStrBuilder.AppendLine("namespace Fantasy\n{");
// clientStrBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑。");
// clientStrBuilder.AppendLine("\tpublic class ConstValue\n\t{");
//
// for (var row = 2; row <= worksheet.Dimension.Rows; row++)
// {
// var first = worksheet.GetCellValue(row, 1);
// var second = worksheet.GetCellValue(row, 2);
// var lower = first?.ToLower() ?? "";
// var isClient = lower.Contains("c");
// var isServerModel = lower.Contains("sh");
// var isServerHotfix = lower.Contains("sm");
//
// if (string.IsNullOrEmpty(second))
// {
// continue;
// }
//
// string str;
//
// if (second.StartsWith("#"))
// {
// str = $"\t\t// {second}";
// clientStrBuilder.AppendLine(str);
// serverModelStrBuilder.AppendLine(str);
// serverHotfixStrBuilder.AppendLine(str);
// continue;
// }
//
// str = GetCodeStr(worksheet, row);
//
// if (isServerModel)
// {
// serverModelStrBuilder.AppendLine(str);
// }
//
// if (isServerHotfix)
// {
// serverHotfixStrBuilder.AppendLine(str);
// }
//
// if (isClient)
// {
// clientStrBuilder.AppendLine(str);
// }
// }
//
// clientStrBuilder.AppendLine("\t}\n}");
// serverModelStrBuilder.AppendLine("\t}\n}");
// serverHotfixStrBuilder.AppendLine("\t}\n}");
//
// Write("ConstValue.cs", clientStrBuilder.ToString(), CustomExportType.Client);
// Write("ConstValue.cs", serverModelStrBuilder.ToString(), CustomExportType.Server);
// Write("ConstValueHotfix.cs", serverHotfixStrBuilder.ToString(),"../../Server/Hotfix/Generate/CustomExport123" ,CustomExportType.Server);
// }
//
// private static string GetCodeStr(ExcelWorksheet sheet, int row)
// {
// var typeStr = sheet.GetCellValue(row, 3);
// var name = sheet.GetCellValue(row, 2);
// var value = sheet.GetCellValue(row, 4);
// var desc = sheet.GetCellValue(row, 5);
//
// try
// {
// if (typeStr.Contains("[]") || typeStr.Contains("[,]"))
// {
// return $"\t\tpublic static readonly {typeStr} {name} = {DefaultValue(typeStr, value)}; // {desc}";
// }
//
// if (typeStr.Contains("Vector"))
// {
// return $"\t\tpublic static readonly {typeStr} {name} = {DefaultValue(typeStr, value)}; // {desc}";
// }
//
// return $"\t\tpublic const {typeStr} {name} = {DefaultValue(typeStr, value)}; // {desc}";
// }
// catch (Exception e)
// {
// Log.Error($"{name} 常量导出异常 : {e}");
// return "";
// }
// }
//
// private static string DefaultValue(string type, string value)
// {
// switch (type)
// {
// case "byte[]":
// case "int[]":
// case "long[]":
// case "string[]":
// case "double[]":
// case "float[]":
// return $"new {type} {{{value}}}";
// case "byte[,]":
// case "int[,]":
// case "long[,]":
// case "string[,]":
// case "float[,]":
// case "double[,]":
// return $"new {type} {{{value}}}";
// case "int":
// case "bool":
// case "uint":
// case "long":
// case "double":
// return $"{value}";
// case "float":
// return value[^1] == 'f' ? value : $"{value}f";
// case "string":
// return $"\"{value}\"";
// case "Vector2":
// {
// var strings = value.Split(',', StringSplitOptions.TrimEntries);
// return $"new Vector2({strings[0]},{strings[1]})";
// }
// case "Vector3":
// {
// var strings = value.Split(',', StringSplitOptions.TrimEntries);
// return $"new Vector3({strings[0]},{strings[1]},{strings[2]})";
// }
// default:
// throw new Exception($"不支持此类型: {type}");
// }
// }
// }

View File

@@ -0,0 +1,62 @@
using System.Text;
using Fantasy.Tools.ConfigTable;
using System.Collections.Generic;
namespace Exporter;
/// <summary>
/// 将场景类型配置表转换为枚举和字典的自定义导出类。
/// </summary>
public class SceneTypeConfigToEnum : ACustomExport
{
public override void Run()
{
var sceneType = new Dictionary<string, string>();
// 获取场景配置表的完整路径
if (!Worksheets.TryGetValue("SceneTypeConfig", out var sceneTypeConfig))
{
return;
}
for (var row = 3; row <= sceneTypeConfig.Dimension.Rows; row++)
{
var sceneTypeId = sceneTypeConfig.GetCellValue(row, 1);
var sceneTypeStr = sceneTypeConfig.GetCellValue(row, 2);
if (string.IsNullOrEmpty(sceneTypeId) || string.IsNullOrEmpty(sceneTypeStr))
{
continue;
}
sceneType.Add(sceneTypeId, sceneTypeStr);
}
// 如果存在场景类型或场景子类型,执行导出操作
if (sceneType.Count > 0)
{
Write(CustomExportType.Server, sceneType);
}
}
private void Write(CustomExportType customExportType, Dictionary<string, string> sceneTypes)
{
var strBuilder = new StringBuilder();
var dicBuilder = new StringBuilder();
// 添加命名空间和注释头部
strBuilder.AppendLine("namespace Fantasy\n{");
strBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑。");
// 生成场景类型的静态类
strBuilder.AppendLine("\tpublic static class SceneType\n\t{");
dicBuilder.AppendLine("\n\t\tpublic static readonly Dictionary<string, int> SceneTypeDic = new Dictionary<string, int>()\n\t\t{");
// 遍历场景类型字典,生成场景类型的常量和字典项
foreach (var (sceneTypeId, sceneTypeStr) in sceneTypes)
{
dicBuilder.AppendLine($"\t\t\t{{ \"{sceneTypeStr}\", {sceneTypeId} }},");
strBuilder.AppendLine($"\t\tpublic const int {sceneTypeStr} = {sceneTypeId};");
}
// 添加场景类型字典尾部,合并到主字符串构建器中
dicBuilder.AppendLine("\t\t};");
strBuilder.Append(dicBuilder);
strBuilder.AppendLine("\t}\n}");
// 调用外部方法将生成的代码写入文件
Write("SceneType.cs", strBuilder.ToString(), customExportType);
}
}