【调整】调整xlsx中定义enum的格式。完整对应xml定义。
parent
85937685b6
commit
ff93a074c4
18
README.md
18
README.md
|
|
@ -188,11 +188,15 @@ array与list类型都能表示列表,它们区别在于array生成的代码为
|
|||
</enum>
|
||||
```
|
||||
或者在 \_\_enums\_\_.xlsx 中 定义
|
||||
|##|full_name|item|alias|value|comment|tags|
|
||||
|- | - | - | - | - | - | - |
|
||||
||ItemQuality|WHITE|白|1|||
|
||||
||ItemQuality|GREEN|绿|2|||
|
||||
||ItemQuality|RED|红|3|||
|
||||
|
||||
<table border="1">
|
||||
<tr align="center"><td>##</td><td>full_name</td><td>flags</td><td>unique</td><td>comment</td><td>tags</td><td colspan="5">*items</td></tr>
|
||||
<tr align="center"><td>##+</td><td></td><td></td><td></td><td></td><td></td><td>name</td><td>alias</td><td>value</td><td>comment</td><td>tags</td></tr>
|
||||
<tr align="center"><td/><td>ItemQuality</td><td>false</td><td>true</td><td/><td/><td>WHITE</td><td>白</td><td>0</td><td/><td/></tr>
|
||||
<tr align="center"><td/><td></td><td></td><td></td><td/><td/><td>GREEN</td><td>绿</td><td>1</td><td/><td/></tr>
|
||||
<tr align="center"><td/><td></td><td></td><td></td><td/><td/><td>RED</td><td>红</td><td>2</td><td/><td/></tr>
|
||||
|
||||
</table>
|
||||
|
||||
|
||||
数据表如下
|
||||
|
|
@ -360,8 +364,8 @@ xml中定义如下
|
|||
</tr>
|
||||
|
||||
<tr align="center"><td/><td>1</td><td>task1</td><td>1</td><td>10</td><td>desc1</td><td>2</td><td>12</td><td>desc2</td><td>3</td><td>13</td><td>desc3</td></tr>
|
||||
<tr align="center"><td/><td>2</td><td>task1</td><td>3</td><td>30</td><td>desc3</td><td>4</td><td>40</td><td>desc4</td></tr>
|
||||
<tr align="center"><td/><td>3</td><td>task1</td><td>5</td><td>50</td><td>desc5</td></tr>
|
||||
<tr align="center"><td/><td>2</td><td>task1</td><td>3</td><td>30</td><td>desc3</td><td>4</td><td>40</td><td>desc4</td><td/><td/><td/></tr>
|
||||
<tr align="center"><td/><td>3</td><td>task1</td><td>5</td><td>50</td><td>desc5</td><td/><td/><td/><td/><td/><td/></tr>
|
||||
</table>
|
||||
|
||||
### 多行结构列表
|
||||
|
|
|
|||
|
|
@ -52,16 +52,15 @@ namespace Luban.Job.Cfg.Defs
|
|||
|
||||
public Defines BuildDefines()
|
||||
{
|
||||
return new Defines()
|
||||
var defines = new Defines()
|
||||
{
|
||||
TopModule = TopModule,
|
||||
Patches = _patches,
|
||||
Enums = _enums,
|
||||
Beans = _beans,
|
||||
Tables = _cfgTables,
|
||||
Services = _cfgServices,
|
||||
Groups = _cfgGroups,
|
||||
};
|
||||
BuildCommonDefines(defines);
|
||||
return defines;
|
||||
}
|
||||
|
||||
private static readonly List<string> _excelImportRequireAttrs = new List<string> { "name", "type" };
|
||||
|
|
@ -480,6 +479,36 @@ namespace Luban.Job.Cfg.Defs
|
|||
}
|
||||
var inputFileInfos = await DataLoaderUtil.CollectInputFilesAsync(this.Agent, this._importExcelEnumFiles, dataDir);
|
||||
|
||||
|
||||
var ass = new DefAssembly("", null, new List<string>(), Agent);
|
||||
|
||||
var enumItemType = new DefBean(new CfgBean()
|
||||
{
|
||||
Namespace = "__intern__",
|
||||
Name = "__EnumItem__",
|
||||
Parent = "",
|
||||
Alias = "",
|
||||
IsValueType = false,
|
||||
Sep = "",
|
||||
TypeId = 0,
|
||||
IsSerializeCompatible = false,
|
||||
Fields = new List<Field>
|
||||
{
|
||||
new CfgField() { Name = "name", Type = "string" },
|
||||
new CfgField() { Name = "alias", Type = "string" },
|
||||
new CfgField() { Name = "value", Type = "string" },
|
||||
new CfgField() { Name = "comment", Type = "string" },
|
||||
new CfgField() { Name = "tags", Type = "string" },
|
||||
}
|
||||
})
|
||||
{
|
||||
AssemblyBase = ass,
|
||||
};
|
||||
ass.AddType(enumItemType);
|
||||
enumItemType.PreCompile();
|
||||
enumItemType.Compile();
|
||||
enumItemType.PostCompile();
|
||||
|
||||
var defTableRecordType = new DefBean(new CfgBean()
|
||||
{
|
||||
Namespace = "__intern__",
|
||||
|
|
@ -493,16 +522,17 @@ namespace Luban.Job.Cfg.Defs
|
|||
Fields = new List<Field>
|
||||
{
|
||||
new CfgField() { Name = "full_name", Type = "string" },
|
||||
new CfgField() { Name = "item", Type = "string" },
|
||||
new CfgField() { Name = "alias", Type = "string" },
|
||||
new CfgField() { Name = "value", Type = "int" },
|
||||
new CfgField() { Name = "comment", Type = "string" },
|
||||
new CfgField() { Name = "flags", Type = "bool" },
|
||||
new CfgField() { Name = "tags", Type = "string" },
|
||||
new CfgField() { Name = "unique", Type = "bool" },
|
||||
new CfgField() { Name = "items", Type = "list,__EnumItem__" },
|
||||
}
|
||||
})
|
||||
{
|
||||
AssemblyBase = new DefAssembly("", null, new List<string>(), Agent),
|
||||
AssemblyBase = ass,
|
||||
};
|
||||
ass.AddType(defTableRecordType);
|
||||
defTableRecordType.PreCompile();
|
||||
defTableRecordType.Compile();
|
||||
defTableRecordType.PostCompile();
|
||||
|
|
@ -514,7 +544,6 @@ namespace Luban.Job.Cfg.Defs
|
|||
var bytes = await this.Agent.GetFromCacheOrReadAllBytesAsync(file.ActualFile, file.MD5);
|
||||
var records = DataLoaderUtil.LoadCfgRecords(tableRecordType, file.OriginFile, null, bytes, true);
|
||||
|
||||
PEnum curEnum = null;
|
||||
foreach (var r in records)
|
||||
{
|
||||
DBean data = r.Data;
|
||||
|
|
@ -527,22 +556,26 @@ namespace Luban.Job.Cfg.Defs
|
|||
}
|
||||
string module = TypeUtil.GetNamespace(fullName);
|
||||
|
||||
if (curEnum == null || curEnum.Name != name || curEnum.Namespace != module)
|
||||
{
|
||||
curEnum = new PEnum() { Name = name, Namespace = module, IsFlags = false, Comment = "", IsUniqueItemId = true };
|
||||
this._enums.Add(curEnum);
|
||||
}
|
||||
DList items = (data.GetField("items") as DList);
|
||||
|
||||
string item = (data.GetField("item") as DString).Value.Trim();
|
||||
if (string.IsNullOrWhiteSpace(item))
|
||||
var curEnum = new PEnum()
|
||||
{
|
||||
throw new Exception($"file:{file.ActualFile} module:'{module}' name:'{name}' 定义了一个空枚举项");
|
||||
}
|
||||
string alias = (data.GetField("alias") as DString).Value.Trim();
|
||||
string value = (data.GetField("value") as DInt).Value.ToString();
|
||||
string comment = (data.GetField("comment") as DString).Value.Trim();
|
||||
string tags = (data.GetField("tags") as DString).Value.Trim();
|
||||
curEnum.Items.Add(new EnumItem() { Name = item, Alias = alias, Value = value, Comment = comment, Tags = tags });
|
||||
Name = name,
|
||||
Namespace = module,
|
||||
IsFlags = (data.GetField("flags") as DBool).Value,
|
||||
Tags = (data.GetField("tags") as DString).Value,
|
||||
Comment = (data.GetField("comment") as DString).Value,
|
||||
IsUniqueItemId = (data.GetField("unique") as DBool).Value,
|
||||
Items = items.Datas.Cast<DBean>().Select(d => new EnumItem()
|
||||
{
|
||||
Name = (d.GetField("name") as DString).Value,
|
||||
Alias = (d.GetField("alias") as DString).Value,
|
||||
Value = (d.GetField("value") as DString).Value,
|
||||
Comment = (d.GetField("comment") as DString).Value,
|
||||
Tags = (d.GetField("tags") as DString).Value,
|
||||
}).ToList(),
|
||||
};
|
||||
this._enums.Add(curEnum);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,16 +3,10 @@ using System.Collections.Generic;
|
|||
|
||||
namespace Luban.Job.Cfg.RawDefs
|
||||
{
|
||||
public class Defines
|
||||
public class Defines : DefinesCommon
|
||||
{
|
||||
public string TopModule { get; set; } = "";
|
||||
|
||||
public List<Patch> Patches { get; set; } = new List<Patch>();
|
||||
|
||||
public List<Bean> Beans { get; set; } = new List<Bean>();
|
||||
|
||||
public List<PEnum> Enums { get; set; } = new List<PEnum>();
|
||||
|
||||
public List<Table> Tables { get; set; } = new List<Table>();
|
||||
|
||||
public List<Group> Groups { get; set; } = new List<Group>();
|
||||
|
|
|
|||
|
|
@ -49,12 +49,14 @@ namespace Luban.Job.Common.Defs
|
|||
|
||||
protected readonly List<PEnum> _enums = new List<PEnum>();
|
||||
protected readonly List<Bean> _beans = new List<Bean>();
|
||||
protected readonly HashSet<string> _externalSelectors = new();
|
||||
|
||||
protected CommonDefLoader(IAgent agent)
|
||||
{
|
||||
Agent = agent;
|
||||
|
||||
_rootDefineHandlers.Add("topmodule", SetTopModule);
|
||||
_rootDefineHandlers.Add("externalselector", AddExternalSelector);
|
||||
|
||||
_moduleDefineHandlers.Add("module", AddModule);
|
||||
_moduleDefineHandlers.Add("enum", AddEnum);
|
||||
|
|
@ -103,6 +105,14 @@ namespace Luban.Job.Common.Defs
|
|||
|
||||
protected string CurNamespace => _namespaceStack.Count > 0 ? _namespaceStack.Peek() : "";
|
||||
|
||||
protected void BuildCommonDefines(DefinesCommon defines)
|
||||
{
|
||||
defines.TopModule = TopModule;
|
||||
defines.Enums = _enums;
|
||||
defines.Beans = _beans;
|
||||
defines.ExternalSelectors = _externalSelectors;
|
||||
}
|
||||
|
||||
#region root handler
|
||||
|
||||
private void SetTopModule(XElement e)
|
||||
|
|
@ -327,6 +337,18 @@ namespace Luban.Job.Common.Defs
|
|||
s_logger.Trace("add enum:{@enum}", en);
|
||||
_enums.Add(en);
|
||||
}
|
||||
|
||||
private static readonly List<string> _selectorRequiredAttrs = new List<string> { "name" };
|
||||
private void AddExternalSelector(XElement e)
|
||||
{
|
||||
ValidAttrKeys(_rootXml, e, null, _selectorRequiredAttrs);
|
||||
string name = XmlUtil.GetRequiredAttribute(e, "name");
|
||||
if (!_externalSelectors.Add(name))
|
||||
{
|
||||
throw new LoadDefException($"定义文件:{_rootXml} externalselector name:{name} 重复");
|
||||
}
|
||||
s_logger.Info("add selector:{}", name);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,9 @@ namespace Luban.Job.Common
|
|||
[Option("cs:use_unity_vector", Required = false, HelpText = "use UnityEngine.Vector{2,3,4}")]
|
||||
public bool CsUseUnityVectors { get; set; }
|
||||
|
||||
[Option("external:selectors", Required = false, HelpText = "external selectors")]
|
||||
public string ExternalSelectors { get; set; }
|
||||
|
||||
public AccessConvention AccessConventionBeanMember { get; set; }
|
||||
|
||||
public bool ValidateOutouptCodeDir(ref string errMsg)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Luban.Job.Common.RawDefs
|
||||
{
|
||||
public class DefinesCommon
|
||||
{
|
||||
public string TopModule { get; set; } = "";
|
||||
|
||||
public HashSet<string> ExternalSelectors { get; set; } = new HashSet<string>();
|
||||
|
||||
public List<Bean> Beans { get; set; } = new List<Bean>();
|
||||
|
||||
public List<PEnum> Enums { get; set; } = new List<PEnum>();
|
||||
}
|
||||
}
|
||||
|
|
@ -20,13 +20,12 @@ namespace Luban.Job.Db.Defs
|
|||
|
||||
public Defines BuildDefines()
|
||||
{
|
||||
return new Defines()
|
||||
var defines = new Defines()
|
||||
{
|
||||
TopModule = TopModule,
|
||||
Enums = _enums,
|
||||
Beans = _beans,
|
||||
DbTables = _tables,
|
||||
};
|
||||
BuildCommonDefines(defines);
|
||||
return defines;
|
||||
}
|
||||
|
||||
private readonly List<string> _tableOptionalAttrs = new List<string> { "memory", "comment" };
|
||||
|
|
|
|||
|
|
@ -3,14 +3,8 @@ using System.Collections.Generic;
|
|||
|
||||
namespace Luban.Job.Db.RawDefs
|
||||
{
|
||||
public class Defines
|
||||
public class Defines : DefinesCommon
|
||||
{
|
||||
public string TopModule { get; set; } = "";
|
||||
|
||||
public List<Bean> Beans { get; set; } = new List<Bean>();
|
||||
|
||||
public List<PEnum> Enums { get; set; } = new List<PEnum>();
|
||||
|
||||
public List<Table> DbTables { get; set; } = new List<Table>();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,14 +24,13 @@ namespace Luban.Job.Proto.Defs
|
|||
|
||||
public Defines BuildDefines()
|
||||
{
|
||||
return new Defines()
|
||||
var defines = new Defines()
|
||||
{
|
||||
TopModule = TopModule,
|
||||
Enums = _enums,
|
||||
Beans = _beans,
|
||||
Protos = _protos,
|
||||
Rpcs = _rpcs,
|
||||
};
|
||||
BuildCommonDefines(defines);
|
||||
return defines;
|
||||
}
|
||||
|
||||
private readonly List<string> rpcAttrs = new List<string> { "id" };
|
||||
|
|
|
|||
|
|
@ -3,16 +3,10 @@ using System.Collections.Generic;
|
|||
|
||||
namespace Luban.Job.Proto.RawDefs
|
||||
{
|
||||
public class Defines
|
||||
public class Defines : DefinesCommon
|
||||
{
|
||||
public string TopModule { get; set; } = "";
|
||||
|
||||
public List<Service> ProtoServices { get; set; } = new List<Service>();
|
||||
|
||||
public List<Bean> Beans { get; set; } = new List<Bean>();
|
||||
|
||||
public List<PEnum> Enums { get; set; } = new List<PEnum>();
|
||||
|
||||
public List<PProto> Protos { get; set; } = new List<PProto>();
|
||||
|
||||
public List<PRpc> Rpcs { get; set; } = new List<PRpc>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue