提交示例代码

This commit is contained in:
Bob.Song
2026-03-05 11:39:06 +08:00
commit 25958f58c3
2534 changed files with 209593 additions and 0 deletions

View File

@@ -0,0 +1,148 @@
using System;
using System.Text;
using Fantasy.Exporter;
using Fantasy.Tools.ConfigTable;
using System.Collections.Generic;
namespace Exporter;
public class ConstValueToConst : ACustomExport
{
private class ConstValueInfo
{
public string Name;
public string Type;
public string Value;
public string Remark;
}
[Flags]
private enum ExportType
{
None = 0,
Server = 1,
Client = 1 << 1,
All = Server | Client
}
public override void Run()
{
if (!ExcelExporter.IgnoreTable.TryGetValue("#ConstValue", out var constValuePath))
{
Log.Error("ConstValue is null");
return;
}
var serverDic = new List<ConstValueInfo>();
var clientDic = new List<ConstValueInfo>();
var excelWorksheet = ExcelExporter.LoadExcel(constValuePath, false);
for (int row = 2; row <= excelWorksheet.Dimension.Rows; row++)
{
var exportType = ExportType.All;
var exportTypeStr = excelWorksheet.GetCellValue(row, 1);
if (!string.IsNullOrEmpty(exportTypeStr))
{
exportType = ExportType.None;
exportTypeStr = exportTypeStr.ToUpper();
if (exportTypeStr.Contains("S"))
{
exportType |= ExportType.Server;
}
if (exportTypeStr.Contains("C"))
{
exportType |= ExportType.Client;
}
}
var constValueInfo = new ConstValueInfo()
{
Name = excelWorksheet.GetCellValue(row, 2),
Type = excelWorksheet.GetCellValue(row, 3),
Value = excelWorksheet.GetCellValue(row, 4),
Remark = excelWorksheet.GetCellValue(row, 5)
};
if (exportType.HasFlag(ExportType.Server))
{
serverDic.Add(constValueInfo);
}
if (exportType.HasFlag(ExportType.Client))
{
clientDic.Add(constValueInfo);
}
}
if (serverDic.Count > 0)
{
Write(serverDic, CustomExportType.Server);
}
if (clientDic.Count > 0)
{
Write(clientDic, CustomExportType.Client);
}
}
private void Write(List<ConstValueInfo> dic, CustomExportType customExportType)
{
var strBuilder = new StringBuilder();
strBuilder.AppendLine("namespace Fantasy\n{");
strBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑,修改请在#ConstValue.xsl里。");
strBuilder.AppendLine("\tpublic partial class ConstValue\n\t{");
foreach (var constValueInfo in dic)
{
var remark = string.IsNullOrEmpty(constValueInfo.Remark) ? constValueInfo.Name : constValueInfo.Remark;
strBuilder.AppendLine($"\t\t/// <summary>\n\t\t/// {remark}\n\t\t/// </summary>");
strBuilder.AppendLine(
$"\t\tpublic const {constValueInfo.Type} {constValueInfo.Name} = {DefaultValue(constValueInfo.Type, constValueInfo.Value)};");
}
strBuilder.AppendLine("\t}\n}");
Write("ConstValue.cs", strBuilder.ToString(), customExportType);
}
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.Exporter;
using Fantasy.Tools.ConfigTable;
using System.Collections.Generic;
namespace Exporter;
public class ContainerConfigToEnum : ACustomExport
{
private class ContainerConfigInfo
{
public int Type;
public string Name;
public string Descride;
}
public override void Run()
{
if (!Worksheets.TryGetValue("ContainerConfig", out var containerConfig))
{
Log.Info("ContainerConfig is null");
return;
}
var dic = new List<ContainerConfigInfo>();
for (int row = 7; row <= containerConfig.Dimension.Rows; row++)
{
var containerName = containerConfig.GetCellValue(row, 4);
var containerType = containerConfig.GetCellValue(row, 6);
var containerDes = containerConfig.GetCellValue(row, 5);
dic.Add(new ContainerConfigInfo()
{
Type = int.Parse(containerType),
Name = containerName,
Descride = containerDes,
});
}
Write(dic, CustomExportType.Server);
Write(dic, CustomExportType.Client);
}
private void Write(List<ContainerConfigInfo> dic, CustomExportType customExportType)
{
var strBuilder = new StringBuilder();
strBuilder.AppendLine("using System;\n");
strBuilder.AppendLine("namespace Fantasy\n{");
strBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑,修改请在ContainerConfig.xsl里。");
strBuilder.AppendLine("\t[Flags]");
strBuilder.AppendLine("\tpublic enum ContainerType : byte\n\t{");
strBuilder.AppendLine("\t\tNone = 0,");
foreach (var constValueInfo in dic)
{
strBuilder.AppendLine($"\t\t{constValueInfo.Name} = {constValueInfo.Type},// {constValueInfo.Descride}");
}
strBuilder.AppendLine("\t\tCell = Equip | Trade,// 按格子存储的容器");
strBuilder.AppendLine("\t\tNormal = Bag,// 正常的容器");
strBuilder.AppendLine("\t}\n}");
Write("ContainerType.cs", strBuilder.ToString(), customExportType);
}
}

View File

@@ -0,0 +1,56 @@
using System.Text;
using Fantasy.Exporter;
using Fantasy.Tools.ConfigTable;
using System.Collections.Generic;
namespace Exporter;
public class ErrorCodeToConst : ACustomExport
{
private class ErrorCodeInfo
{
public uint Id;
public string Name;
public string Text;
}
public override void Run()
{
if (!Worksheets.TryGetValue("ErrorCode", out var errorCodeConfig))
{
Log.Info("ErrorCode is null");
return;
}
var dic = new List<ErrorCodeInfo>();
for (var row = 7; row <= errorCodeConfig.Dimension.Rows; row++)
{
var errorCodeInfo = new ErrorCodeInfo()
{
Id = uint.Parse( errorCodeConfig.GetCellValue(row, 3)),
Name = errorCodeConfig.GetCellValue(row, 4),
Text = errorCodeConfig.GetCellValue(row, 5)
};
dic.Add(errorCodeInfo);
}
Write(dic, CustomExportType.Server);
Write(dic, CustomExportType.Client);
}
private void Write(List<ErrorCodeInfo> dic, CustomExportType customExportType)
{
var strBuilder = new StringBuilder();
strBuilder.AppendLine("namespace Fantasy\n{");
strBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑,修改请在ErrorCode.xsl里。");
strBuilder.AppendLine("\tpublic partial class ErrorCode\n\t{");
foreach (var errorCodeInfo in dic)
{
strBuilder.AppendLine($"\t\t/// <summary>\n\t\t/// {errorCodeInfo.Text}\n\t\t/// </summary>");
strBuilder.AppendLine($"\t\tpublic const uint {errorCodeInfo.Name} = {errorCodeInfo.Id};");
}
strBuilder.AppendLine("\t}\n}");
Write("ErrorCode.cs", strBuilder.ToString(), customExportType);
}
}

View File

@@ -0,0 +1,60 @@
using System.Text;
using System.Collections.Generic;
using Fantasy.Exporter;
using Fantasy.Tools.ConfigTable;
namespace Exporter;
public sealed class ItemTypeToEnum : ACustomExport
{
private class ItemTypeInfo
{
public int Index;
public string Name;
public string Descride;
}
public override void Run()
{
if (!ExcelExporter.IgnoreTable.TryGetValue("#ItemType", out var itemTypePath))
{
Log.Error("#ItemType is null");
return;
}
var dic = new List<ItemTypeInfo>();
var excelWorksheet = ExcelExporter.LoadExcel(itemTypePath, false);
for (int row = 2; row <= excelWorksheet.Dimension.Rows; row++)
{
var exportIndex = excelWorksheet.GetCellValue(row, 1);
if (string.IsNullOrEmpty(exportIndex))
{
continue;
}
dic.Add(new ItemTypeInfo()
{
Index = int.Parse(exportIndex),
Name = excelWorksheet.GetCellValue(row, 2),
Descride = excelWorksheet.GetCellValue(row, 3),
});
}
Write(dic, CustomExportType.Server);
Write(dic, CustomExportType.Client);
}
private void Write(List<ItemTypeInfo> dic, CustomExportType customExportType)
{
var strBuilder = new StringBuilder();
strBuilder.AppendLine("namespace Fantasy\n{");
strBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑,修改请在#ItemType.xsl里。");
strBuilder.AppendLine("\tpublic enum ItemType\n\t{");
strBuilder.AppendLine("\t\tNone = 0,");
foreach (var constValueInfo in dic)
{
strBuilder.AppendLine($"\t\t{constValueInfo.Name} = {constValueInfo.Index},// {constValueInfo.Descride}");
}
strBuilder.AppendLine("\t}\n}");
Write("ItemType.cs", strBuilder.ToString(), customExportType);
}
}

View File

@@ -0,0 +1,60 @@
using System.Text;
using System.Collections.Generic;
using Fantasy.Exporter;
using Fantasy.Tools.ConfigTable;
namespace Exporter;
public sealed class ItemUseEffectToEnum : ACustomExport
{
private class ItemUseEffectInfo
{
public int Index;
public string Name;
public string Descride;
}
public override void Run()
{
if (!ExcelExporter.IgnoreTable.TryGetValue("#ItemUseEffect", out var itemTypePath))
{
Log.Error("ItemUseEffect is null");
return;
}
var dic = new List<ItemUseEffectInfo>();
var excelWorksheet = ExcelExporter.LoadExcel(itemTypePath, false);
for (int row = 2; row <= excelWorksheet.Dimension.Rows; row++)
{
var exportIndex = excelWorksheet.GetCellValue(row, 1);
if (string.IsNullOrEmpty(exportIndex))
{
continue;
}
dic.Add(new ItemUseEffectInfo()
{
Index = int.Parse(exportIndex),
Name = excelWorksheet.GetCellValue(row, 2),
Descride = excelWorksheet.GetCellValue(row, 3),
});
}
Write(dic, CustomExportType.Server);
Write(dic, CustomExportType.Client);
}
private void Write(List<ItemUseEffectInfo> dic, CustomExportType customExportType)
{
var strBuilder = new StringBuilder();
strBuilder.AppendLine("namespace Fantasy\n{");
strBuilder.AppendLine("\t// 生成器自动生成,请不要手动编辑,修改请在#ItemUseEffect.xsl里。");
strBuilder.AppendLine("\tpublic enum ItemUseEffect\n\t{");
strBuilder.AppendLine("\t\tNone = 0,");
foreach (var constValueInfo in dic)
{
strBuilder.AppendLine($"\t\t{constValueInfo.Name} = {constValueInfo.Index},// {constValueInfo.Descride}");
}
strBuilder.AppendLine("\t}\n}");
Write("ItemUseEffect.cs", strBuilder.ToString(), customExportType);
}
}