【优化】优化cfg生成的typescript代码中可空变量的定义代码在eslint下警告的问题

【完善】优化install.md文档,简化流程,更加清晰易理解。
main
walon 2021-09-06 10:32:43 +08:00
parent 533ab56f86
commit 70db1dca9e
8 changed files with 162 additions and 168 deletions

View File

@ -7,64 +7,73 @@
![icon](docs/images/icon.png)
## Introduction
-----
## links
- [README - English](./README.en-us.md)
- [github link](https://github.com/focus-creative-games/luban)
- [gitee link](https://gitee.com/focus-creative-games/luban)
----
Luban is a general-purpose object generation and caching solution. On this basis, a **game configuration solution** that is **complete, powerful, flexible and easy to use** is implemented.
## introduce
Luban was originally designed for super-large projects such as seamless open world MMORPG. It is good at handling large and complex configuration data and structures. It is also suitable for use in card, turn-based, ARPG and other light and medium games.
Luban is a subordinated project of [BrightDB](https://github.com/focus-creative-games/BrightDB), a general-purpose object generation and caching tool, on this basis it has realized a function ** complete, powerful, flexible and easy to use **The **Game Configuration Solution**.
Based on the design of **meta definition + data source**, luban implements a **complete type system**, enhances the excel format, and provides support for multiple data sources such as json, xml, lua, and unified data definition and loading The game configuration pipeline of, inspection, data export and code generation completely solves the problem that it is difficult to configure complex data in excel in medium and large projects and the coexistence of multiple configuration schemes such as excel and json in one project.
Based on the design of **meta definition + data source**, luban implements a **complete type system**, enhances the excel format, and provides rich data source support such as json, xml, lua, yaml, etc. It can handle both conventional simple configurations and complex configurations such as **AI, skills, and duengon**. It truly realizes the game configuration workflow of unified data definition, loading, verification, data export and code generation. It is better to solve the problem that it is difficult to check complex configuration errors in real-time and iteratively edit the program in the planning of medium and large projects, and the problem that complex AI, skills and other configuration data cannot be unified with the excel configuration and need to be dealt with separately by the programmer.
The Luban generation process is extremely fast. For ordinary meter guide tools, it often takes tens of seconds to generate the configuration in the later stage of a typical MMORPG project. Luban uses the client/server cloud generation model, through multi-threading and generation + object caching mechanism, in most cases, the entire generation process can be completed within 1 second.
**Luban has relatively complete functions and supports almost all mainstream front-end and back-end languages and client engines in the game industry**. Luban is currently maintained by a professional team to maintain active feature updates and function optimizations, and R&D personnel provide timely development guidance and follow-up feedback.
Luban is suitable for developers with the following needs:
1. I hope to find a fast and powerful game configuration solution that has passed the test of the online project and meets the configuration requirements of **medium and large** game projects
2. Hope to easily customize configuration and message generation according to project requirements to meet more stringent memory and performance requirements
3. Hope to do other custom generation or caching
====** If you feel usable, please give it a like, your support will give us great motivation ^_^**====
## Support and contact
If you have any questions about the use, please add the QQ group to ask in time, and someone can help solve it at any time.
- QQ group: 692890842
- Email: taojingjian#gmail.com
- Skypy group: https://join.skype.com/xr2nhdMKjac0
-I hope to find a game configuration solution that meets the configuration requirements of **medium and large** game projects with complete functions and has been tested by online projects
-Hope to have a more complete workflow to effectively improve the efficiency of planning and program development
-Hope to easily customize configuration and message generation according to project requirements to meet more stringent memory and performance requirements
-Hope to do other custom generation or caching
====** If you feel good, please click a star, your support will give us great motivation ^_^**====
## Documentation
- [Homepage](https://focus-creative-games.github.io/luban/index.html)
- [Features](docs/traits.md)
- [Quick Start](docs/install.md)
- [Introduction to Excel Configuration Data](docs/data_excel.md)
- [Client&server installation and usage instructions](docs/luban_install_manual.md)
- [Document Catalog](docs/catalog.md)
- [FAQ](docs/faq.md)
- [[TODO] Quick Start and Advanced](docs/start_up.md)
- [[TODO] Complete Manual](docs/manual.md)
- **[====>Highly recommended to explore: example project <====](https://github.com/focus-creative-games/luban_examples)**
- **====>Highly recommended to view: Example project** ([github](https://github.com/focus-creative-games/luban_examples)) ([gitee](https://gitee.com /focus-creative-games/luban_examples)) **<====**
- Support and contact
- QQ group: 692890842 (Luban development exchange group) [click the link to join](https://qm.qq.com/cgi-bin/qm/qr?k=4bMoe11knBW7Tcs1sqMafZE1I4zpT4sh&jump_from=webapi). If you have any questions about use, please add to the QQ group to ask, and someone can help solve it at any time.
- Email: taojingjian#gmail.com
- Skypy group: https://join.skype.com/xr2nhdMKjac0
-----
## Features
- Supports enhanced excel format, you can fill in arbitrarily complex data more concisely in excel
- Supports multiple data formats of excel, json, xml, and lua, which basically unifies the configuration data in the game
- Powerful and complete type system. Supports all common primitive types, datetime types, container types list, set, map, enumeration and structure, **polymorphic structure** and **nullable type**
- Supports multiple data formats of excel family, json, xml, lua, yaml, which basically unifies the common configuration data of the game
- **Powerful and complete type system**. **Any complex data structure can be expressed elegantly**. Supports all common primitive types, datetime types, container types list, set, map, enumeration and structure, **polymorphic structure** and **nullable type**.
- Support enhanced excel format. You can fill in very complex data more concisely in excel (for example, the top-level field contains "list, A" type fields, and A is a structure and it contains "list, B" type fields, and B is also a structure and contains "list, C" "Such a field...).
- The generated code is clear, easy to read, and well modularized. Specially supports atomic hot update configuration at runtime.
- Generate extremely fast. It supports the regular local cache incremental generation mode, and also supports the cloud generation mode. Large projects like MMORPG can also be generated within seconds. The daily incremental generation is basically within 300ms, which greatly saves iteration time in the later stage of the project. In addition, it supports **watch monitoring mode**, and the data directory changes are regenerated immediately.
- Flexible data source definition. A table can come from multiple files or multiple tables defined in a file, or all files in a directory or even from cloud tables, and a combination of the above
- Support table and field level grouping. You can selectively export tables and fields used by the client or server
- Multiple export data format support. Support export data formats such as binary, json, lua, etc.
- Multiple export data format support. Support export data formats such as binary, json, lua, xml, erlang, etc.
- Powerful and flexible customization capabilities
- Support code templates, you can use custom templates to customize the generated code format
- **Support data template**, you can customize the export format with the template file. It means that you can use luban as a **configuration processing front end** without changing the existing program code, and generate data in a custom format to work with the configuration loading code of your own project. Long-developed projects or old projects that have been launched can also benefit from luban's powerful data processing workflow
- Support data tags. You can choose to export the data that meets the requirements, and you dont have to manually comment out those test data when planning to release the official data.
- Powerful data verification capabilities. Support built-in data format check; support ref table reference check (don't worry about filling in the wrong id for planning); support path resource check (don't worry about filling in the wrong resource path for planning); support advanced custom verification (for example, two fields and must be 100)
- Powerful data verification capabilities. Support built-in data format check; support ref table reference check (dont worry about filling in the wrong id for planning); support path resource check (dont worry about filling in the wrong resource path for planning); support range check
- Support constant alias. Planning no longer has to write specific item IDs for items such as Upgrade Dan
- Support a variety of common data table modes. one (singleton table), map (regular key-value table)
- Support emmylua anntations. The generated lua contains anntations information that conforms to the emmylua format. Cooperate with emmylua, have good configuration code prompt ability
- Support res resource mark. You can export all resource lists (icon, ui, assetbundle, etc.) referenced in the configuration with one click
- Good modularity of generated code
- Unify the configuration data of the custom editor. It works well with Unity and UE4 custom editors, and generates suitable c# (Unity) or c++ (UE4) code for loading and saving json configuration for the editor. The saved json configuration can be recognized and processed by luban.
- Support emmylua anntations. The generated lua contains anntations information that conforms to the emmylua format. Cooperate with emmylua, have good configuration code prompt ability
- **Localization Support**
- Support time localization. The datetime type data will be converted to UTC time in the target area at that time according to the specified timezone, which is convenient for the program to use.
- **Support text static localization. When exporting, all text type data is correctly replaced with the final localized string.**
- [TODO] supports dynamic localization of text. Dynamically switch all text type data to the target localized string at runtime.
- **Support main + patches data merging. On the basic data, differential data is applied to generate the final complete data, which is suitable for the production of configuration data with subtle differences in multiple regions.**
- Support time localization. The datetime type data will be converted to UTC time in the target area at that time according to the specified timezone, which is convenient for the program to use.
- Support text static localization. When exporting, all text type data is correctly replaced with the final localized string. Most business functions no longer need to run to find the content of the text according to the localized id, simplifying the programmer's work.
- Support text dynamic localization. Dynamically switch all text type data to the target localized string at runtime.
- Support main + patches data merging. On the basic data, differential data is applied to generate the final complete data, which is suitable for the production of configuration data with subtle differences in multiple regions.
- [TODO] [Original] Support the localization of any granularity and any type of data (such as int, bean, list, map).
- Support mainstream game development languages
- c++ (11+)
- c# (.net framework 4+. dotnet core 3+)
@ -72,28 +81,103 @@ If you have any questions about the use, please add the QQ group to ask in time,
- go (1.10+)
- lua (5.1+)
- js and typescript (3.0+)
- python (2.7+ and 3.0+)
- python (3.0+)
- erlang (18+)
- Support mainstream engines and platforms
- unity + c#
- unity + tolua, xlua
- unity + ILRuntime
- unity + puerts
- unity + [tolua](https://github.com/topameng/tolua), [xlua](https://github.com/Tencent/xLua)
- unity + [ILRuntime](https://github.com/Ourpalm/ILRuntime)
- unity + [puerts](https://github.com/Tencent/puerts)
- unity + [GameFramework](https://github.com/EllanJiang/GameFramework)
- unity + [ET game framework](https://github.com/egametang/ET)
- unreal + c++
- unreal + unlua
- unreal + sluaunreal
- unreal + puerts
- unreal + [unlua](https://github.com/Tencent/UnLua)
- unreal + [sluaunreal](https://github.com/Tencent/sluaunreal)
- unreal + [puerts](https://github.com/Tencent/puerts)
- cocos2d-x + lua
- cocos2d-x + js
- WeChat Mini Program Platform
- [skynet](https://github.com/cloudwu/skynet)
- WeChat app Program Platform
- Other js-based small program platforms
- All other engines and platforms that support lua
- All other engines and platforms that support js
-----
## luban workflow Pipeline
![pipeline](docs/images/pipeline.jpg)
## benchmark performance test results
Hardware: Intel(R) Core i7-10700 @ 2.9G 16 core, 32G memory
Data set: 500 excel tables, each table has 1000 rows of records, the records are complicated
Test Results:
| Format | Time-consuming full generation | Time-consuming incremental generation | Single output file size | Total output file size |
| ---- | --------| ------ | ---- | ------ |
| bin | 15.652 s| 797 ms | 164 K | 59.5 M |
| json | 17.746 s| 796 ms | 1.11 M | 555 M |
| lua | 17.323 s| 739 ms | 433 K | 212 M |
## Code usage example
Here is only a brief display of the usage of lua, c#, typescript, and go languages in development. For more languages and more detailed usage examples and codes, please see [Sample Project](https://github.com/focus-creative-games/luban_examples ).
- C# usage example
```C#
// One line of code can load all configurations. cfg.Tables contains an instance field for all tables.
var tables = new cfg.Tables(file => return new ByteBuf(File.ReadAllBytes("<data path>/" + file)));
// Access a singleton table
Console.WriteLine(tables.TbGlobal.Name);
// Access the ordinary key-value table
Console.WriteLine(tables.TbItem.Get(12).X1);
// Support operator [] usage
Console.WriteLine(tables.TbMail[1001].X2);
```
- Typescript usage example
```typescript
// One line of code can load all configurations. cfg.Tables contains an instance field for all tables.
let tables = new cfg.Tables(f => JsHelpers.LoadFromFile(gameConfDir, f))
// Access a singleton table
console.log(tables.TbGlobal.name)
// Access ordinary key-value table
console.log(tables.TbItem.get(12).x1)
```
- golang usage example
```go
// One line of code can load all configurations. cfg.Tables contains an instance field for all tables.
if tables, err := cfg.NewTables(loader); err != nil {
println(err.Error())
return
}
// Access a singleton table
println(tables.TbGlobal.Name)
// Access the ordinary key-value table
println(tables.TbItem.Get(12).X1)
```
- Lua usage example
```Lua
-- Access a singleton table
print(require("TbGlobal").name)
-- Access ordinary key-value table
print(require("TbItem")[12].x1)
```
- [Examples in more languages](docs/samples.md)
------
## Quick preview
**luban is compatible with commonplace excel table generation tools, and a complete data table can be defined in excel**. Unlike common table guide tools that focus on excel, because luban supports a powerful type system and supports json, xml, lua and other file types, lubans native usage is to separate definition and data, and use separate xml to define tables and structures* *, the data file only contains data.
@ -741,60 +825,6 @@ return
}
```
------
## Code usage example
Here is only a brief display of the usage of lua, c#, typescript, and go languages in development. For more languages and more detailed usage examples and codes, please see [Sample Project](https://github.com/focus-creative-games/luban_examples ).
- Lua usage example
```Lua
-- Access a singleton table
print(require("TbGlobal").name)
-- Access ordinary key-value table
print(require("TbItem")[12].x1)
```
- C# usage example
```C#
// One line of code can load all configurations. cfg.Tables contains an instance field for all tables.
var tables = new cfg.Tables(file => return new ByteBuf(File.ReadAllBytes("<data path>/" + file)));
// Access a singleton table
Console.WriteLine(tables.TbGlobal.Name);
// Access the ordinary key-value table
Console.WriteLine(tables.TbItem.Get(12).X1);
// Support operator [] usage
Console.WriteLine(tables.TbMail[1001].X2);
```
- Typescript usage example
```typescript
// One line of code can load all configurations. cfg.Tables contains an instance field for all tables.
let tables = new cfg.Tables(f => JsHelpers.LoadFromFile(gameConfDir, f))
// Access a singleton table
console.log(tables.TbGlobal.name)
// Access ordinary key-value table
console.log(tables.TbItem.get(12).x1)
```
- golang usage example
```go
// One line of code can load all configurations. cfg.Tables contains an instance field for all tables.
if tables, err := cfg.NewTables(loader); err != nil {
println(err.Error())
return
}
// Access a singleton table
println(tables.TbGlobal.Name)
// Access the ordinary key-value table
println(tables.TbItem.Get(12).X1)
```
- [Examples in more languages](docs/samples.md)
------
## route map

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -10,41 +10,9 @@
## 创建游戏配置
1. 创建目录结构
config 为根目录,下面创建两个子目录 Datas 和 Defines分别用于 存放策划 excel 及各种配置数据 以及 配置定义。
![如图](images/install/install_01.png)
2. 在 Defines 目录下创建 \_\_root__.xml 根定义文件
```xml
<root>
<topmodule name="cfg"/>
<branch name="cn"/>
<branch name="tw"/>
<branch name="en"/>
<branch name="jp"/>
<group name="c" default="1"/> client
<group name="s" default="1"/> server
<group name="e" default="1"/> editor
<import name="."/>
<importexcel name="tables.xlsx" type="table"/> 补充table表声明。文件相对data目录
<importexcel name="enums.xlsx" type="enum"/> 补充enum定义。相对data目录
<importexcel name="beans.xlsx" type="bean"/> 补充bean定义。相对data目录
<service name="server" manager="Tables" group="s"/>
<service name="client" manager="Tables" group="c"/>
<service name="all" manager="Tables" group="c,s,e"/>
</root>
```
可以直接从 [示例配置](https://github.com/focus-creative-games/luban_examples/tree/main/DesignerConfigs/Defines) 拷贝这个文件。
4. 添加物品表 excel 文件
在 Datas 目录下新建一个 item 目录,目录下创建一个 “物品表.xlsx” 文件。
1. 从示例项目拷贝[MiniDesignerConfigsTemplate](https://github.com/focus-creative-games/luban_examples/MiniDesignerConfigsTemplate) 到一个合适的目录,假设为 <YourConfigs>
2. 添加物品表 excel 文件
<YouConfigs>/Datas 目录下创建一个 “物品表.xlsx” 文件。
![如图](images/install/install_03.png)
@ -52,7 +20,7 @@
![配置](images/install/install_04.png)
- 第 1 行是 meta 行包含关于excel文件的元描述title_rows:4表示除了meta行外有4行标题头。
- 第 1 行是 meta 行包含关于excel文件的元描述title_rows:4表示除了meta行外有4行标题头。此值默认为3可以根据需求调整。
单元格 A1 必须是 ##。表示这是一个有效数据表。
- 第 2 行是程序字段名行。
- 第3行是属性行。格式为 type&属性1=值1&属性2=值2 ...
@ -60,79 +28,75 @@
- 第 5 行是描述行。策划可以填写字段的补充描述。可留空。
- 从第 6 开始为实际的数据行。如果某个数据行整行为空,则会被跳过。
然后再在 Datas 目录下的tables.xlsx请从 DesignerConfigs/Datas目录拷贝过来添加表声明。如下图:
3. 在 Datas 目录下的__tables__.xlsx添加表声明。如下图:
![添加声明](images/install/install_10.png)
10. 至此,物品表的创建工作大功告成!
4. 至此,物品表的创建工作大功告成!
## 生成代码和数据以及在程序中使用
假设是Unity项目使用json导出格式。 示例参考项目为 [Csharp_Unity_Json](https://github.com/focus-creative-games/luban_examples/Projects/Csharp_Unity_json)。其他语言或者导出类型的组合,请参考 [luban_examples](https://github.com/focus-creative-games/luban_examples)
1. 项目准备。
拷贝示例项目中 Csharp_DotNetCore_bin\Core 目录到项目中,可以自由组织位置。 此时尝试编译项目,理论上应该能成功编译。
拷贝示例项目中 Assets\LubanLib 目录到你的Unity项目中可以自由组织位置此时尝试编译项目理论上应该能成功编译。
2. 运行生成命令可以参考示例项目的gen_code_json.bat
2. 运行生成命令
```bat
dotnet <luban.clientserver.dll>
-j cfg ^
--^
--define_file <root.xml >^
--input_data_dir <配置数据根目录(Datas)的路径>^
--output_code_dir <生成的代码文件的路径>^
--output_data_dir <导出的数据文件的路径>^
--service all^
--export_test_data^
--gen_types "code_cs_bin,data_bin"
-- ^
--define_file <__root__.xml > ^
--input_data_dir <配置数据根目录(Datas)的路径> ^
--output_code_dir <生成的代码文件的路径> ^
--output_data_dir <导出的数据文件的路径> ^
--service all ^
--export_test_data ^
--gen_types "code_cs_json,data_json"
```
其中
- <luban.clientserver.dll> 指向 Tools/Luban.ClientServer/Luban.ClientServer.dll
- <root.xml> 指向 Define/__root__.xml
- --define_file 参数为 <YourConfigs>/Defines/__root__.xml 的路径
- --input_data_dir 参数为 <YourConfigs>/Datas 的路径
- --output_code_dir 参数为生成的代码文件存放的路径。 建议建议指向 unity的 Assets 目录下的某级子目录
- --output_data_dir 参数为生成的数据文件的存放路径。
详细的命令文档请看 [install_manual](./luban_install_manual.md)。
更多语言或者导出类型的组合,请参考 [luban_examples](https://github.com/focus-creative-games/luban_examples)
如果一切正常,会产生一系列日志,最终一行是 == succ == 。
![类似这样](images/install/install_07.png)
类似这样
![生成结果](images/install/install_07.png)
如果一切顺利。生成的代码文件会在 output_code_dir 参数指定的 目录中,生成的配置数据会在 output_data_dir 参数指定的目录中。
output_code_dir 加入到 项目中,编译。此时应该能编译成功。
如果一切顺利。生成的代码文件会在 output_code_dir 参数指定的 目录中,生成的配置数据会在 output_data_dir 参数指定的目录中。把 output_code_dir 加入到 项目中,编译。此时应该能编译成功。
3. 加载配置
只需一行代码既可完成所有配置表的加载工具
```c#
var tables = new cfg.Tables(file =>
new Bright.Serialization.ByteBuf(
System.IO.File.ReadAllBytes( <output_data_dir > + "/" + file)));
var tables = new cfg.Tables(file => new Bright.Serialization.ByteBuf(
System.IO.File.ReadAllBytes( <output_data_dir > + "/" + file)));
```
![代码](images/install/install_09.png)
4. 使用加载后的配置表
cfg.Tables 里包含所有配置表的一个实例字段。
加载完 cfg.Tables 后,只需要用 tables.<表名> 就能获得那个表实例,接着可以做各种操作。
例如我们要访问 id = 1 的那个记录。代码如下
cfg.Tables 里包含所有配置表的一个实例字段。加载完 cfg.Tables 后,只需要用 tables.<表名> 就能获得那个表实例接着可以做各种操作。例如我们要获取id = 10000 的那个道具。代码如下
```c#
cfg.item.Item itemInfo = tables.TbItem.Get(1);
Console.WriteLine(“{0} {1} {2} {3}”,
itemInfo.Id, itemInfo.X1, itemInfo.X2,itemInfo.X3)
cfg.item.Item itemInfo = tables.TbItem.Get(10000);
Console.WriteLine("id:{0} name:{1} desc:{2}", itemInfo.Id, itemInfo.Name, itemInfo.Desc);
```
可能你会注意到item.xml 里定义 Item 时,字段名 id,x1,x2,x3 首字母被大写了。工具会根据输出的语言,自动作相应代码风格的字段名转换,也即 boo_bar 会被转换为 BooBar 这样的名字。这也是为什么推荐 配置字段定义时统一使用 xx_yy_zz 的风格。
可能你会注意到item.xml 里定义 Item 时,字段名 id,name,desc的首字母被大写了。这是因为工具会根据输出的语言,自动作相应代码风格的字段名转换,也即 boo_bar 会被转换为 BooBar 这样的名字。这也是为什么推荐 配置字段定义时统一使用 xx_yy_zz 的风格。
5. 至此完成 配置加载与使用!

View File

@ -20,7 +20,7 @@ namespace Luban.Job.Cfg.Defs
public bool IsMultiRow { get; set; }
public String Sep { get; }
public string Sep { get; }
public List<DefField> HierarchyExportFields { get; private set; }

View File

@ -39,7 +39,7 @@ export {{if x.is_abstract_type}} abstract {{end}} class {{name}} {{if parent_def
* {{field.comment}}
*/
{{~end~}}
readonly {{field.ts_style_name}}{{if field.is_nullable}}?{{end}}: {{ts_define_type field.ctype}}
readonly {{field.ts_style_name}}: {{ts_define_type field.ctype}}
{{~if field.gen_ref~}}
{{field.ts_ref_validator_define}}
{{~end~}}