Compare commits

..

No commits in common. "main" and "v2022.5.0" have entirely different histories.

140 changed files with 763 additions and 2840 deletions

View File

@ -1,4 +1,4 @@
# Luban
#Luban
[![license](http://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Build Status](https://travis-ci.com/focus-creative-games/luban.svg?branch=main)](https://travis-ci.com/focus-creative-games/luban )
@ -21,34 +21,35 @@
luban is your **best game configuration solution**.
Luban efficiently processes data such as excel, json, and xml common in game development, checks data errors, generates codes in various languages such as c#, and exports them into various formats such as bytes or json.
Luban efficiently handles data such as excel, json, and xml that are common in game development, checks for data errors, generates code in various languages such as c#, and exports it to various formats such as bytes or json.
luban unifies the game configuration development workflow, greatly improving the efficiency of planning and programming.
Luban unifies the game configuration development workflow, greatly improving the efficiency of planning and programming.
## Core features
## Core Features
- Powerful data analysis and conversion capabilities {excel(csv,xls,xlsx), json, bson, xml, yaml, lua, unity ScriptableObject} => {binary, json, bson, xml, lua, yaml, erlang, custom format }
- Enhanced excel format, which can succinctly configure simple lists, substructures, structured lists, and arbitrarily complex deep nested structures.
- Complete type system, **Support OOP type inheritance**, with data in excel, json, lua, xml and other formats **Flexible and elegant** Express complex GamePlay data such as behavior trees, skills, plots, and copies
- Supports generating c#, java, go, c++, lua, python, javascript, typescript, erlang, rust, gdscript code
- Powerful data parsing and conversion capabilities {excel(csv,xls,xlsx), json, bson, xml, yaml, lua, unity ScriptableObject} => {binary, json, bson, xml, lua, yaml, erlang, custom format }
- Enhanced excel format that can be easily configured like simple lists, substructures, structured lists, and arbitrarily complex deeply nested structures.
- Complete type system, **support OOP type inheritance**, with data in excel, json, lua, xml and other formats **flexibly and elegantly** to express complex GamePlay data such as behavior trees, skills, plots, and copies
- Support to generate c#, java, go, c++, lua, python, javascript, typescript, erlang, rust code
- Support generating protobuf(schema + binary + json), flatbuffers(schema + json), msgpack(binary)
- Powerful data verification capability. ref reference check, path resource path, range range check, etc.
- Powerful data verification capabilities. ref reference check, path resource path, range range check, etc.
- Perfect localization support. Static text value localization, dynamic text value localization, time localization, main-patch multi-region version
- Powerful and flexible customization capabilities, support for custom code templates and data templates
- **Universal generation and caching tool**. It can also be used to generate code such as protocols, databases, and even as an object caching service
- **Good support for mainstream engines, all platforms, mainstream hot update solutions, and mainstream front-end and back-end frameworks**. Supports mainstream engines such as Unity, Unreal, Cocos2x, Godot, and WeChat games. The tool itself is cross-platform and can work well on Win, Linux, and Mac platforms.
- **Generic generation and caching tool**. Can also be used to generate code like protocols, databases, or even as an object caching service
- **Good support for mainstream engines, all platforms, mainstream hot update solutions, mainstream front-end and back-end frameworks**. Support mainstream engines such as unity, unreal, cocos2x, and WeChat mini-games. The tool itself is cross-platform and can work well on Win, Linux, and Mac platforms. [See details](https://focus-creative-games.github.io/lubandoc/feature.html#%E6%94%AF%E6%8C%81%E4%B8%BB%E6%B5%81% E7%9A%84%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80)
See [feature](https://focus-creative-games.github.io/luban-doc/#/manual/traits) for complete features
See [feature](https://focus-creative-games.github.io/lubandoc/feature.html) for full features
## Documentation
- [Official Documentation](https://focus-creative-games.github.io/luban-doc/)
- [Quickstart](https://focus-creative-games.github.io/luban-doc/#/beginner/quickstart)
- [Quick Start](https://focus-creative-games.github.io/lubandoc/start_up.html)
- [Document](https://focus-creative-games.github.io/lubandoc), it is relatively complete, if you have any questions, please check this document first.
- **Example Project** ([github](https://github.com/focus-creative-games/luban_examples)) ([gitee](https://gitee.com/focus-creative-games/luban_examples) )
- [Version Change Log](https://focus-creative-games.github.io/luban-doc/#/changelog)
- Support and contact
- QQ group: 692890842 (Luban development exchange group). If you have any questions about usage, please join the QQ group to ask in time, and someone will help you solve it at any time.
- Email: luban@code-philosophy.com
- [Version Changelog](https://focus-creative-games.github.io/lubandoc/changelog.html)
- Support and Contact
- QQ group: 692890842 (Luban development exchange group). If you have any questions about use, please add the QQ group to ask in time, and someone will help you at any time.
- Email: taojingjian#gmail.com
## Excel format overview
@ -90,6 +91,7 @@ For a complete example, please refer to [Excel Format Introduction](https://focu
<td>desc3</td>
<td colspan="3">desc4</td>
</tr>
<tr align="center">
<td/>
<td>1</td>
@ -98,6 +100,7 @@ For a complete example, please refer to [Excel Format Introduction](https://focu
<td>xx|yy</td>
<td>xxx</td><td>zzz</td><td></td>
</tr>
<tr align="center">
<td/>
<td>2</td>
@ -106,6 +109,7 @@ For a complete example, please refer to [Excel Format Introduction](https://focu
<td>aaaa|bbbb|cccc</td>
<td>aaa</td><td>bbb</td><td>ccc</td>
</tr>
<tr align="center">
<td/>
<td>3</td>
@ -114,6 +118,7 @@ For a complete example, please refer to [Excel Format Introduction](https://focu
<td>aaaa|bbbb|cccc</td>
<td>aaa</td><td>bbb</td><td>ccc</td>
</tr>
</table>
### substructure
@ -121,11 +126,13 @@ For a complete example, please refer to [Excel Format Introduction](https://focu
Reward is a substructure containing the three fields of "int item_id; int count; string desc;".
<table border="1">
<tr align="center"><td>##var</td><td>id</td><td colspan="3">reward</td><td colspan="3">reward2</ td><td>reward3</td></tr>
<tr align="center"><td>##type</td><td>int</td><td colspan="3">Reward</td><td colspan="3">Reward</ td><td>Reward#sep=,</td></tr>
<tr align="center"><td>##var</td><td></td><td>item_id</td><td>count</td><td>desc</td><td></td><td></td><td></td><td/></tr>
<tr align="center"><td/><td>1</td><td>1001</td><td>10</td><td>item 1</td><td>1002< /td><td>11</td><td>item 2</td><td>1002,1,item 3</td></tr>
<tr align="center"><td/><td>2</td><td>2001</td><td>10</td><td>item 2</td><td>2002< /td><td>20</td><td>item 4</td><td>2003,2,item 5</td></tr>
</table>
### Structure List 1
@ -155,6 +162,7 @@ Reward is a substructure containing the three fields of "int item_id; int count;
<td>1001</td><td>1</td><td>desc1</td><td>1002</td><td>2</td><td>desc2</td>
<td>1001,1,desc1</td><td>1002,2,desc2</td><td>1003,3,desc3</td>
</tr>
<tr align="center">
<td/>
<td>2</td>
@ -167,6 +175,7 @@ Reward is a substructure containing the three fields of "int item_id; int count;
### Structure List 2
<table border="1">
<tr align="center">
<td>##var</td>
<td>id</td>
@ -179,6 +188,7 @@ Reward is a substructure containing the three fields of "int item_id; int count;
<td>string</td>
<td colspan="9">list,Reward</td>
</tr>
<tr align="center">
<td>##var</td>
<td></td>
@ -187,6 +197,7 @@ Reward is a substructure containing the three fields of "int item_id; int count;
<td colspan="3">1</td>
<td colspan="3">2</td>
</tr>
<tr align="center"><td/><td>1</td><td>task1</td><td>1001</td><td>10</td><td>desc1</ td><td>1002</td><td>12</td><td>desc2</td><td>1003</td><td>13</td><td>desc3</td> </tr>
<tr align="center"><td/><td>2</td><td>task1</td><td>1003</td><td>30</td><td>desc3</ td><td>1004</td><td>40</td><td>desc4</td><td/><td/><td/></tr>
<tr align="center"><td/><td>3</td><td>task1</td><td>1005</td><td>50</td><td>desc5</ td><td/><td/><td/><td/><td/><td/></tr>
@ -195,6 +206,7 @@ Reward is a substructure containing the three fields of "int item_id; int count;
### Structure List 3
<table border="1">
<tr align="center">
<td>##var</td>
<td>id</td>
@ -207,6 +219,7 @@ Reward is a substructure containing the three fields of "int item_id; int count;
<td>string</td>
<td colspan="9">list,Reward</td>
</tr>
<tr align="center">
<td>##var</td>
<td></td>
@ -223,6 +236,7 @@ Reward is a substructure containing the three fields of "int item_id; int count;
<td>item_id</td><td>num</td><td>desc</td>
<td>item_id</td><td>num</td><td>desc</td>
</tr>
<tr align="center"><td/><td>1</td><td>task1</td><td>1001</td><td>10</td><td>desc1</ td><td>1002</td><td>12</td><td>desc2</td><td>1003</td><td>13</td><td>desc3</td> </tr>
<tr align="center"><td/><td>2</td><td>task1</td><td>1003</td><td>30</td><td>desc3</ td><td>1004</td><td>40</td><td>desc4</td><td/><td/><td/></tr>
<tr align="center"><td/><td>3</td><td>task1</td><td>1005</td><td>50</td><td>desc5</ td><td/><td/><td/><td/><td/><td/></tr>
@ -231,6 +245,7 @@ Reward is a substructure containing the three fields of "int item_id; int count;
### Multi-row table
<table border="1">
<tr align="center">
<td>##var</td>
<td>id</td>
@ -265,6 +280,7 @@ Reward is a substructure containing the three fields of "int item_id; int count;
<td>desc5</td>
<td>desc6</td>
</tr>
<tr align="center">
<td/>
<td>1</td>
@ -285,21 +301,25 @@ Reward is a substructure containing the three fields of "int item_id; int count;
<tr align="center">
<td/><td/><td/><td>2</td><td>stage2</td><td>stage desc2</td><td>1,2,3</td><td>1002</td><td>1</td>
</tr>
</table>
### Multi-level subheadings of type map
<table border="1">
<tr align="center"><td>##var</td><td>id</td><td colspan="4">lans</td></tr>
<tr align="center"><td>##type</td><td>int</td><td colspan="4">map,string,string</td></tr>
<tr align="center"><td>##var</td><td/><td>ch-zn</td><td>en</td><td>jp</td><td >fr</td></tr>
<tr align="center"><td/><td>1</td><td>apple</td><td>apple</td><td>aaa</td><td>aaa</td></tr>
<tr align="center"><td/><td>2</td><td>banana</td><td>banana</td><td>bbb</td><td>bbb</td></tr>
</table>
### Type inheritance (suitable for skills, buff related configuration)
<table border="1">
<tr align="center"><td>##var</td><td>id</td><td colspan="4">shape</td><td colspan="4">shape2</ td></tr>
<tr align="center"><td>##type</td><td>int</td><td colspan="4">Shape</td><td colspan="4">Shape</ td></tr>
<tr align="center"><td>##var</td><td></td><td>$type</td><td>radius</td><td>width</td><td>height</td><td></td><td></td><td></td><td></td></tr>
@ -307,6 +327,7 @@ Reward is a substructure containing the three fields of "int item_id; int count;
<tr align="center"><td/><td>2</td><td>Rectangle</td><td></td><td>10</td><td>20</td ><td>Rectangle</td><td>10</td><td>20</td><td></td></tr>
<tr align="center"><td/><td>3</td><td>Circle</td><td>10</td><td/><td/><td>Triangle</td><td>15</td><td>15</td><td>15</td></tr>
<tr align="center"><td/><td>4</td><td>Circle</td><td>10</td><td/><td/><td>Rectangle</td><td>30</td><td>20</td><td></td></tr>
</table>
### Multiple primary key table (joint index)
@ -370,7 +391,7 @@ Some configurations only have one copy globally, such as the opening level of th
## json, lua, xml, yaml format quick overview
Take the behavior tree as an example to show how to configure the behavior tree configuration in json format. For formats such as xml, lua, yaml, etc., please refer to [detailed documentation](https://focus-creative-games.github.io/luban/data_source/).
Take the behavior tree as an example to show how to configure the behavior tree configuration in json format. For formats such as xml, lua, yaml, etc., please refer to [detailed documentation](https://focus-creative-games.github.io/lubandoc).
````json

View File

@ -31,28 +31,31 @@ luban统一了游戏配置开发工作流极大提升了策划和程序的工
- 强大的数据解析和转换能力 {excel(csv,xls,xlsx)、json、bson、xml、yaml、lua、unity ScriptableObject} => {binary、json、bson、xml、lua、yaml、erlang、 custom format}
- 增强的excel格式可以简洁地配置出像简单列表、子结构、结构列表以及任意复杂的深层次的嵌套结构。
- 完备的类型系统,**支持OOP类型继承**搭配excel、json、lua、xml等格式数据**灵活优雅**表达行为树、技能、剧情、副本之类复杂GamePlay数据
- 支持生成c#、java、go、c++、lua、python、javascript、typescript、erlang、rust、gdscript 代码
- 支持生成c#、java、go、c++、lua、python、javascript、typescript、erlang、rust代码
- 支持生成 protobuf(schema + binary + json)、flatbuffers(schema + json)、msgpack(binary)
- 强大的数据校验能力。ref引用检查、path资源路径、range范围检查等等
- 完善的本地化支持。静态文本值本地化、动态文本值本地化、时间本地化、main-patch多地区版本
- 强大灵活的自定义能力,支持自定义代码模板和数据模板
- **通用型生成和缓存工具**。也可以用于生成协议、数据库之类的代码,甚至可以用作对象缓存服务
- **良好支持主流引擎、全平台、主流热更新方案、主流前后端框架**。支持Unity、Unreal、Cocos2x、Godot、微信小游戏等主流引擎。工具自身跨平台能在Win,Linux,Mac平台良好工作。
- **良好支持主流引擎、全平台、主流热更新方案、主流前后端框架**。支持unity、unreal、cocos2x、微信小游戏等主流引擎。工具自身跨平台能在Win,Linux,Mac平台良好工作。[详见](https://focus-creative-games.github.io/lubandoc/feature.html#%E6%94%AF%E6%8C%81%E4%B8%BB%E6%B5%81%E7%9A%84%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91%E8%AF%AD%E8%A8%80)
完整特性请参见 [feature](https://focus-creative-games.github.io/luban-doc/#/manual/traits)
完整特性请参见 [feature](https://focus-creative-games.github.io/lubandoc/feature.html)
## 文档
- [官方文档](https://focus-creative-games.github.io/luban-doc/)
- [快速上手](https://focus-creative-games.github.io/luban-doc/#/beginner/quickstart)
- [快速上手](https://focus-creative-games.github.io/lubandoc/start_up.html)
- [Document](https://focus-creative-games.github.io/lubandoc) ,比较完善,有使用疑问,请先查看此文档。
- **示例项目** ([github](https://github.com/focus-creative-games/luban_examples)) ([gitee](https://gitee.com/focus-creative-games/luban_examples))
- [版本变更记录](https://focus-creative-games.github.io/luban-doc/#/changelog)
- [版本变更记录](https://focus-creative-games.github.io/lubandoc/changelog.html)
- 支持与联系
- QQ群: 692890842 Luban开发交流群。有使用方面的疑问请及时加QQ群询问随时有人帮助解决。
- 邮箱: luban@code-philosophy.com
- 邮箱: taojingjian#gmail.com
## excel格式速览
完整示例请详见 [excel格式介绍](https://focus-creative-games.github.io/lubandoc/excel.html)
### 普通表
|##var| id | x1 | x5 | x6 | s1 | s2 | v3 | t1 |
@ -90,6 +93,7 @@ luban统一了游戏配置开发工作流极大提升了策划和程序的工
<td>desc3</td>
<td colspan="3">desc4</td>
</tr>
<tr align="center">
<td/>
<td>1</td>
@ -98,6 +102,7 @@ luban统一了游戏配置开发工作流极大提升了策划和程序的工
<td>xx|yy</td>
<td>xxx</td><td>zzz</td><td></td>
</tr>
<tr align="center">
<td/>
<td>2</td>
@ -106,6 +111,7 @@ luban统一了游戏配置开发工作流极大提升了策划和程序的工
<td>aaaa|bbbb|cccc</td>
<td>aaa</td><td>bbb</td><td>ccc</td>
</tr>
<tr align="center">
<td/>
<td>3</td>
@ -114,6 +120,7 @@ luban统一了游戏配置开发工作流极大提升了策划和程序的工
<td>aaaa|bbbb|cccc</td>
<td>aaa</td><td>bbb</td><td>ccc</td>
</tr>
</table>
### 子结构
@ -121,6 +128,7 @@ luban统一了游戏配置开发工作流极大提升了策划和程序的工
Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结构。
<table border="1">
<tr align="center"><td>##var</td><td>id</td><td colspan="3">reward</td><td colspan="3">reward2</td><td>reward3</td></tr>
<tr align="center"><td>##type</td><td>int</td><td colspan="3">Reward</td><td colspan="3">Reward</td><td>Reward#sep=,</td></tr>
<tr align="center"><td>##var</td><td></td><td>item_id</td><td>count</td><td>desc</td><td></td><td></td><td></td><td/></tr>
@ -156,17 +164,20 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
<td>1001</td><td>1</td><td>desc1</td><td>1002</td><td>2</td><td>desc2</td>
<td>1001,1,desc1</td><td>1002,2,desc2</td><td>1003,3,desc3</td>
</tr>
<tr align="center">
<td/>
<td>2</td>
<td>1001</td><td>1</td><td>desc1</td><td></td><td></td><td></td>
<td>1001,1,desc1</td><td>1002,2,desc2</td><td></td>
</tr>
</table>
### 结构列表 2
<table border="1">
<tr align="center">
<td>##var</td>
<td>id</td>
@ -179,6 +190,7 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
<td>string</td>
<td colspan="9">list,Reward</td>
</tr>
<tr align="center">
<td>##var</td>
<td></td>
@ -187,6 +199,7 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
<td colspan="3">1</td>
<td colspan="3">2</td>
</tr>
<tr align="center"><td/><td>1</td><td>task1</td><td>1001</td><td>10</td><td>desc1</td><td>1002</td><td>12</td><td>desc2</td><td>1003</td><td>13</td><td>desc3</td></tr>
<tr align="center"><td/><td>2</td><td>task1</td><td>1003</td><td>30</td><td>desc3</td><td>1004</td><td>40</td><td>desc4</td><td/><td/><td/></tr>
<tr align="center"><td/><td>3</td><td>task1</td><td>1005</td><td>50</td><td>desc5</td><td/><td/><td/><td/><td/><td/></tr>
@ -195,6 +208,7 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
### 结构列表 3
<table border="1">
<tr align="center">
<td>##var</td>
<td>id</td>
@ -207,6 +221,7 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
<td>string</td>
<td colspan="9">list,Reward</td>
</tr>
<tr align="center">
<td>##var</td>
<td></td>
@ -223,6 +238,7 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
<td>item_id</td><td>num</td><td>desc</td>
<td>item_id</td><td>num</td><td>desc</td>
</tr>
<tr align="center"><td/><td>1</td><td>task1</td><td>1001</td><td>10</td><td>desc1</td><td>1002</td><td>12</td><td>desc2</td><td>1003</td><td>13</td><td>desc3</td></tr>
<tr align="center"><td/><td>2</td><td>task1</td><td>1003</td><td>30</td><td>desc3</td><td>1004</td><td>40</td><td>desc4</td><td/><td/><td/></tr>
<tr align="center"><td/><td>3</td><td>task1</td><td>1005</td><td>50</td><td>desc5</td><td/><td/><td/><td/><td/><td/></tr>
@ -231,6 +247,7 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
### 多行表
<table border="1">
<tr align="center">
<td>##var</td>
<td>id</td>
@ -265,6 +282,7 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
<td>desc5</td>
<td>desc6</td>
</tr>
<tr align="center">
<td/>
<td>1</td>
@ -285,6 +303,7 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
<tr align="center">
<td/><td/><td/><td>2</td><td>stage2</td><td>stage desc2</td><td>1,2,3</td><td>1002</td><td>1</td>
</tr>
</table>
### 多级多行表
@ -292,6 +311,7 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
多行表的列表字段,每个列表元素还可以是多行。支持任意多级的多行嵌套。另外也允许有多个多行字段,每个字段的行数还可以不同。
<table border="1">
<tr align="center">
<td>##var</td>
<td>id</td>
@ -344,6 +364,7 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
<td>item id</td>
<td>count</td>
</tr>
<tr align="center">
<td/>
<td>1</td>
@ -388,11 +409,25 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
<tr align="center">
<td/><td/><td/><td></td><td></td><td></td><td>2,2,2</td><td>1002</td><td>2</td><td></td><td></td><td></td><td></td>
</tr>
</table>
### map 类型的多级子标题
<table border="1">
<tr align="center"><td>##var</td><td>id</td><td colspan="4">lans</td></tr>
<tr align="center"><td>##type</td><td>int</td><td colspan="4">map,string,string</td></tr>
<tr align="center"><td>##var</td><td/><td>ch-zn</td><td>en</td><td>jp</td><td>fr</td></tr>
<tr align="center"><td/><td>1</td><td>苹果</td><td>apple</td><td>aaa</td><td>aaa</td></tr>
<tr align="center"><td/><td>2</td><td>香蕉</td><td>banana</td><td>bbb</td><td>bbb</td></tr>
</table>
### 类型继承适合技能、buff相关配置
<table border="1">
<tr align="center"><td>##var</td><td>id</td><td colspan="4">shape</td><td colspan="4">shape2</td></tr>
<tr align="center"><td>##type</td><td>int</td><td colspan="4">Shape</td><td colspan="4">Shape</td></tr>
<tr align="center"><td>##var</td><td></td><td>$type</td><td>radius</td><td>width</td><td>height</td><td></td><td></td><td></td><td></td></tr>
@ -400,6 +435,7 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
<tr align="center"><td/><td>2</td><td>Rectangle</td><td></td><td>10</td><td>20</td><td>矩形</td><td>10</td><td>20</td><td></td></tr>
<tr align="center"><td/><td>3</td><td></td><td>10</td><td/><td/><td>Triangle</td><td>15</td><td>15</td><td>15</td></tr>
<tr align="center"><td/><td>4</td><td>Circle</td><td>10</td><td/><td/><td>Rectangle</td><td>30</td><td>20</td><td></td></tr>
</table>
### 多主键表(联合索引)
@ -463,7 +499,8 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
## json、lua、xml、yaml 格式速览
以行为树为例展示json格式下如何配置行为树配置。xml、lua、yaml等等格式请参见 [详细文档](https://focus-creative-games.github.io/luban-doc/#/manual/datasource)。
以行为树为例展示json格式下如何配置行为树配置。xml、lua、yaml等等格式请参见 [详细文档](https://focus-creative-games.github.io/lubandoc)。
```json
{
@ -517,13 +554,13 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
## 代码使用预览
这儿只简略展示c#、typescript、go、c++ 语言在开发中的用法,更多语言以及更详细的使用范例和代码见[示例项目](https://github.com/focus-creative-games/luban_examples)。
这儿只简略展示c#、typescript、go语言在开发中的用法更多语言以及更详细的使用范例和代码见[示例项目](https://github.com/focus-creative-games/luban_examples)。
- C# 使用示例
```C#
// 一行代码可以加载所有配置。 cfg.Tables 包含所有表的一个实例字段。
var tables = new cfg.Tables(file => return new ByteBuf(File.ReadAllBytes($"{gameConfDir}/{file}.bytes")));
var tables = new cfg.Tables(file => return new ByteBuf(File.ReadAllBytes(gameConfDir + "/" + file + ".bytes")));
// 访问一个单例表
Console.WriteLine(tables.TbGlobal.Name);
// 访问普通的 key-value 表
@ -555,19 +592,7 @@ if tables , err := cfg.NewTables(loader) ; err != nil {
println(tables.TbGlobal.Name)
// 访问普通的 key-value 表
println(tables.TbItem.Get(12).Name)
```
- c++ 使用示例
```c++
cfg::Tables tables;
if (!tables.load([](ByteBuf& buf, const std::string& s) { buf.clear(); return buf.loadFromFile("../GenerateDatas/bytes/" + s + ".bytes"); }))
{
std::cout << "== load fail == " << std::endl;
return;
}
std::cout << tables.TbGlobal->name << std::endl;
std::cout << tables.TbItem.get(12)->name << std::endl;
```
## 路线图
@ -576,11 +601,6 @@ println(tables.TbItem.Get(12).Name)
- [ ] 新增 unreal 内置编辑器
- [ ] 补充单元测试
## 友情链接
- [Luban Unity插件](https://github.com/LiuOcean/Luban_Unity_GUI) 在Unity里完成生成命令的配置和生成操作
- [LubanTools](https://github.com/MOMOLAXI/LubanTools) Luban的Win GUI命令配置和生成工具
## License
Luban is licensed under the [MIT](LICENSE.TXT) license.

View File

@ -10,7 +10,6 @@ using Luban.Job.Common.Utils;
using Luban.Server;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@ -138,15 +137,7 @@ Options:
case "-t":
case "--template_search_path":
{
var dirName = args[++i];
if (Directory.Exists(dirName))
{
ops.TemplateSearchPath = dirName;
}
else
{
Console.WriteLine("[WARN] 对于Luban.ClientServer参数 {0} {1} 路径不存在,忽略。", arg, dirName);
}
ops.TemplateSearchPath = args[++i];
break;
}
case "--":

View File

@ -14,7 +14,7 @@ namespace Luban.Common.Utils
public static string GetApplicationDirectory()
{
return AppContext.BaseDirectory;
return Path.GetDirectoryName(System.Reflection.Assembly.GetCallingAssembly().Location);
}
public static string GetPathRelateApplicationDirectory(string relatePath)

View File

@ -121,11 +121,6 @@ namespace Luban.Common.Utils
return module.Replace('.', '_') + name;
}
public static string MakeGDScriptFullName(string module, string name)
{
return UpperCaseFirstChar(module.Replace('.', '_') + name);
}
public static string MakeRustFullName(string module, string name)
{
return MakeGoNamespace(module) + name;

View File

@ -18,7 +18,6 @@
<PackageReference Include="ExcelDataReader" Version="3.6.0" />
<PackageReference Include="MessagePack" Version="2.3.85" />
<PackageReference Include="NeoLua" Version="1.3.14" />
<PackageReference Include="Newtonsoft.Json.Bson" Version="1.0.2" />
<PackageReference Include="Ude.NetStandard" Version="1.2.0" />
<PackageReference Include="YamlDotNet" Version="11.2.1" />
</ItemGroup>

View File

@ -29,7 +29,14 @@ namespace Luban.Job.Cfg.DataCreators
return b;
}
var s = x.ToString().ToLower().Trim();
return DataUtil.ParseExcelBool(s);
switch (s)
{
case "true":
case "是": return true;
case "false":
case "否": return false;
default: throw new InvalidExcelDataException($"{s} 不是 bool 类型的值 (true 或 false)");
}
}
public DType Accept(TBool type, ExcelStream x)

View File

@ -15,7 +15,7 @@ using System.Threading.Tasks;
namespace Luban.Job.Cfg.DataCreators
{
class SheetDataCreator : ITypeFuncVisitor<RowColumnSheet, TitleRow, DType>
class SheetDataCreator : ITypeFuncVisitor<Sheet, TitleRow, DType>
{
public static SheetDataCreator Ins { get; } = new();
@ -37,7 +37,7 @@ namespace Luban.Job.Cfg.DataCreators
}
}
public DType Accept(TBool type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TBool type, Sheet sheet, TitleRow row)
{
object x = row.Current;
if (CheckNull(type.IsNullable, x))
@ -53,10 +53,10 @@ namespace Luban.Job.Cfg.DataCreators
{
return DBool.ValueOf(v);
}
return DBool.ValueOf(DataUtil.ParseExcelBool(x.ToString()));
return DBool.ValueOf(bool.Parse(x.ToString()));
}
public DType Accept(TByte type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TByte type, Sheet sheet, TitleRow row)
{
object x = row.Current;
if (CheckNull(type.IsNullable, x))
@ -70,7 +70,7 @@ namespace Luban.Job.Cfg.DataCreators
return DByte.ValueOf(byte.Parse(x.ToString()));
}
public DType Accept(TShort type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TShort type, Sheet sheet, TitleRow row)
{
object x = row.Current;
if (CheckNull(type.IsNullable, x))
@ -85,7 +85,7 @@ namespace Luban.Job.Cfg.DataCreators
return DShort.ValueOf(short.Parse(x.ToString()));
}
public DType Accept(TFshort type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TFshort type, Sheet sheet, TitleRow row)
{
object x = row.Current;
if (CheckNull(type.IsNullable, x))
@ -99,7 +99,7 @@ namespace Luban.Job.Cfg.DataCreators
return DFshort.ValueOf(short.Parse(x.ToString()));
}
public DType Accept(TInt type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TInt type, Sheet sheet, TitleRow row)
{
object x = row.Current;
if (CheckNull(type.IsNullable, x))
@ -114,7 +114,7 @@ namespace Luban.Job.Cfg.DataCreators
return DInt.ValueOf(int.Parse(x.ToString()));
}
public DType Accept(TFint type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TFint type, Sheet sheet, TitleRow row)
{
object x = row.Current;
if (CheckNull(type.IsNullable, x))
@ -129,7 +129,7 @@ namespace Luban.Job.Cfg.DataCreators
return DFint.ValueOf(int.Parse(x.ToString()));
}
public DType Accept(TLong type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TLong type, Sheet sheet, TitleRow row)
{
object x = row.Current;
if (CheckNull(type.IsNullable, x))
@ -144,7 +144,7 @@ namespace Luban.Job.Cfg.DataCreators
return DLong.ValueOf(long.Parse(x.ToString()));
}
public DType Accept(TFlong type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TFlong type, Sheet sheet, TitleRow row)
{
object x = row.Current;
if (CheckNull(type.IsNullable, x))
@ -159,7 +159,7 @@ namespace Luban.Job.Cfg.DataCreators
return DFlong.ValueOf(long.Parse(x.ToString()));
}
public DType Accept(TFloat type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TFloat type, Sheet sheet, TitleRow row)
{
object x = row.Current;
if (CheckNull(type.IsNullable, x))
@ -174,7 +174,7 @@ namespace Luban.Job.Cfg.DataCreators
return DFloat.ValueOf(float.Parse(x.ToString()));
}
public DType Accept(TDouble type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TDouble type, Sheet sheet, TitleRow row)
{
object x = row.Current;
if (CheckNull(type.IsNullable, x))
@ -189,82 +189,25 @@ namespace Luban.Job.Cfg.DataCreators
return DDouble.ValueOf(double.Parse(x.ToString()));
}
public DType Accept(TEnum type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TEnum type, Sheet sheet, TitleRow row)
{
if (row.Row != null)
object x = row.Current;
if (CheckNull(type.IsNullable, x))
{
object x = row.Current;
if (CheckNull(type.IsNullable, x))
return null;
}
if (CheckDefault(x))
{
if (type.DefineEnum.HasZeroValueItem)
{
return null;
return new DEnum(type, "0");
}
if (CheckDefault(x))
else
{
if (type.DefineEnum.IsFlags || type.DefineEnum.HasZeroValueItem)
{
return new DEnum(type, "0");
}
else
{
throw new InvalidExcelDataException($"枚举类:'{type.DefineEnum.FullName}' 没有value为0的枚举项, 不支持默认值");
}
throw new InvalidExcelDataException($"枚举类:'{type.DefineEnum.FullName}' 没有value为0的枚举项, 不支持默认值");
}
return new DEnum(type, x.ToString());
}
else if (row.Rows != null)
{
throw new Exception($"{type.DefineEnum.FullName} 不支持多行格式");
}
else if (row.Fields != null)
{
//throw new Exception($"array 不支持 子字段. 忘记将字段设为多行模式? {row.SelfTitle.Name} => *{row.SelfTitle.Name}");
var items = new List<string>();
var sortedFields = row.Fields.Values.ToList();
sortedFields.Sort((a, b) => a.SelfTitle.FromIndex - b.SelfTitle.FromIndex);
foreach (var field in sortedFields)
{
string itemName = field.SelfTitle.Name;
if (!type.DefineEnum.TryValueByNameOrAlias(itemName, out _))
{
throw new Exception($"列名:{itemName} 不是枚举类型'{type.DefineEnum.FullName}'的有效枚举项");
}
if (field.IsBlank)
{
continue;
}
string cur = field.Current.ToString().ToLower();
if (cur != "0" && cur != "false")
{
items.Add(itemName);
}
}
if (items.Count == 0)
{
if (type.IsNullable)
{
return null;
}
if (type.DefineEnum.IsFlags || type.DefineEnum.HasZeroValueItem)
{
return new DEnum(type, "0");
}
else
{
throw new InvalidExcelDataException($"枚举类:'{type.DefineEnum.FullName}' 没有value为0的枚举项, 不支持默认值");
}
}
return new DEnum(type, string.Join('|', items));
}
else if (row.Elements != null)
{
throw new Exception($"{type.DefineEnum.FullName} 不支持多行子字段格式");
}
else
{
throw new Exception();
}
return new DEnum(type, x.ToString());
}
@ -284,7 +227,7 @@ namespace Luban.Job.Cfg.DataCreators
}
}
public DType Accept(TString type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TString type, Sheet sheet, TitleRow row)
{
object x = row.Current;
if (CheckDefault(x))
@ -306,12 +249,12 @@ namespace Luban.Job.Cfg.DataCreators
return DString.ValueOf(s);
}
public DType Accept(TBytes type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TBytes type, Sheet sheet, TitleRow row)
{
throw new NotSupportedException();
}
public DType Accept(TText type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TText type, Sheet sheet, TitleRow row)
{
if (string.IsNullOrEmpty(row.SelfTitle.SepOr(type.GetTag("sep"))))
{
@ -336,7 +279,7 @@ namespace Luban.Job.Cfg.DataCreators
}
}
public DType Accept(TDateTime type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TDateTime type, Sheet sheet, TitleRow row)
{
var d = row.Current;
if (CheckNull(type.IsNullable, d))
@ -350,7 +293,7 @@ namespace Luban.Job.Cfg.DataCreators
return DataUtil.CreateDateTime(d.ToString());
}
public DType Accept(TVector2 type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TVector2 type, Sheet sheet, TitleRow row)
{
var d = row.Current;
if (CheckNull(type.IsNullable, d))
@ -365,7 +308,7 @@ namespace Luban.Job.Cfg.DataCreators
return DataUtil.CreateVector(type, d.ToString());
}
public DType Accept(TVector3 type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TVector3 type, Sheet sheet, TitleRow row)
{
var d = row.Current;
if (CheckNull(type.IsNullable, d))
@ -380,7 +323,7 @@ namespace Luban.Job.Cfg.DataCreators
return DataUtil.CreateVector(type, d.ToString());
}
public DType Accept(TVector4 type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TVector4 type, Sheet sheet, TitleRow row)
{
var d = row.Current;
if (CheckNull(type.IsNullable, d))
@ -395,7 +338,7 @@ namespace Luban.Job.Cfg.DataCreators
return DataUtil.CreateVector(type, d.ToString());
}
private List<DType> CreateBeanFields(DefBean bean, RowColumnSheet sheet, TitleRow row)
private List<DType> CreateBeanFields(DefBean bean, Sheet sheet, TitleRow row)
{
var list = new List<DType>();
foreach (DefField f in bean.HierarchyFields)
@ -426,9 +369,10 @@ namespace Luban.Job.Cfg.DataCreators
return list;
}
public DType Accept(TBean type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TBean type, Sheet sheet, TitleRow row)
{
string sep = row.SelfTitle.Sep;// type.GetBeanAs<DefBean>().Sep;
if (row.Row != null)
{
var s = row.AsStream(sep);
@ -449,7 +393,6 @@ namespace Luban.Job.Cfg.DataCreators
}
else if (row.Fields != null)
{
sep += type.GetBeanAs<DefBean>().Sep;
var originBean = (DefBean)type.Bean;
if (originBean.IsAbstractType)
{
@ -458,8 +401,7 @@ namespace Luban.Job.Cfg.DataCreators
{
throw new Exception($"type:'{originBean.FullName}' 是多态类型,需要定义'{DefBean.EXCEL_TYPE_NAME_KEY}'列来指定具体子类型");
}
TitleRow valueTitle = row.GetSubTitleNamedRow(DefBean.EXCEL_VALUE_NAME_KEY);
sep += type.GetTag("sep");
string subType = typeTitle.Current?.ToString()?.Trim();
if (subType == null || subType == DefBean.BEAN_NULL_STR)
{
@ -470,36 +412,7 @@ namespace Luban.Job.Cfg.DataCreators
return null;
}
DefBean implType = DataUtil.GetImplTypeByNameOrAlias(originBean, subType);
if (valueTitle == null)
{
return new DBean(type, implType, CreateBeanFields(implType, sheet, row));
}
else
{
sep += valueTitle.SelfTitle.Sep;
if (valueTitle.Row != null)
{
var s = valueTitle.AsStream(sep);
if (type.IsNullable && s.TryReadEOF())
{
return null;
}
return new DBean(type, implType, CreateBeanFields(implType, s));
}
else if (valueTitle.Rows != null)
{
var s = valueTitle.AsMultiRowConcatStream(sep);
if (type.IsNullable && s.TryReadEOF())
{
return null;
}
return new DBean(type, implType, CreateBeanFields(implType, s));
}
else
{
throw new Exception();
}
}
return new DBean(type, implType, CreateBeanFields(implType, sheet, row));
}
else
{
@ -566,7 +479,7 @@ namespace Luban.Job.Cfg.DataCreators
return datas;
}
private List<DType> ReadCollectionDatas(TType type, TType elementType, RowColumnSheet sheet, TitleRow row)
private List<DType> ReadCollectionDatas(TType type, TType elementType, Sheet sheet, TitleRow row)
{
if (row.Row != null)
{
@ -605,23 +518,23 @@ namespace Luban.Job.Cfg.DataCreators
}
}
public DType Accept(TArray type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TArray type, Sheet sheet, TitleRow row)
{
//string sep = DataUtil.GetSep(type);
return new DArray(type, ReadCollectionDatas(type, type.ElementType, sheet, row));
}
public DType Accept(TList type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TList type, Sheet sheet, TitleRow row)
{
return new DList(type, ReadCollectionDatas(type, type.ElementType, sheet, row));
}
public DType Accept(TSet type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TSet type, Sheet sheet, TitleRow row)
{
return new DSet(type, ReadCollectionDatas(type, type.ElementType, sheet, row));
}
public DType Accept(TMap type, RowColumnSheet sheet, TitleRow row)
public DType Accept(TMap type, Sheet sheet, TitleRow row)
{
string sep = row.SelfTitle.Sep;
@ -650,7 +563,7 @@ namespace Luban.Job.Cfg.DataCreators
foreach (var e in row.Fields)
{
var keyData = type.KeyType.Apply(StringDataCreator.Ins, e.Key);
if (RowColumnSheet.IsBlankRow(e.Value.Row, e.Value.SelfTitle.FromIndex, e.Value.SelfTitle.ToIndex))
if (Sheet.IsBlankRow(e.Value.Row, e.Value.SelfTitle.FromIndex, e.Value.SelfTitle.ToIndex))
{
continue;
}
@ -676,29 +589,5 @@ namespace Luban.Job.Cfg.DataCreators
throw new Exception();
}
}
private List<DType> CreateBeanFields(DefBean bean, ExcelStream stream)
{
var list = new List<DType>();
foreach (DefField f in bean.HierarchyFields)
{
try
{
list.Add(f.CType.Apply(ExcelStreamDataCreator.Ins, stream));
}
catch (DataCreateException dce)
{
dce.Push(bean, f);
throw;
}
catch (Exception e)
{
var dce = new DataCreateException(e, stream.LastReadDataInfo);
dce.Push(bean, f);
throw dce;
}
}
return list;
}
}
}

View File

@ -179,7 +179,7 @@ namespace Luban.Job.Cfg.DataExporters
public void Accept(DDateTime type, ByteBuf x)
{
x.WriteLong(type.UnixTimeOfCurrentAssembly);
x.WriteInt(type.UnixTimeOfCurrentAssembly);
}
}
}

View File

@ -1,40 +0,0 @@
using Bright.Serialization;
using Luban.Job.Cfg.Datas;
using Luban.Job.Cfg.DataSources;
using Luban.Job.Cfg.DataVisitors;
using Luban.Job.Cfg.Defs;
using Luban.Job.Cfg.RawDefs;
using System;
using System.Collections.Generic;
namespace Luban.Job.Cfg.DataExporters
{
class BinaryIndexExportor
{
public static BinaryIndexExportor Ins { get; } = new BinaryIndexExportor();
public void WriteList(DefTable table, List<Record> datas, ByteBuf x)
{
x.WriteSize(datas.Count);
var tableDataBuf = new ByteBuf(10 * 1024);
tableDataBuf.WriteSize(datas.Count);
foreach (var d in datas)
{
int offset = tableDataBuf.Size;
d.Data.Apply(BinaryExportor.Ins, tableDataBuf);
string keyStr = "";
foreach (IndexInfo index in table.IndexList)
{
DType key = d.Data.Fields[index.IndexFieldIdIndex];
key.Apply(BinaryExportor.Ins, x);
keyStr += key.ToString() + ",";
}
x.WriteSize(offset);
Console.WriteLine($"table:{table.Name} key:{keyStr} offset:{offset}");
}
}
}
}

View File

@ -1,203 +0,0 @@
using Luban.Job.Cfg.Datas;
using Luban.Job.Cfg.DataSources;
using Luban.Job.Cfg.DataVisitors;
using Luban.Job.Cfg.Defs;
using Luban.Job.Cfg.Utils;
using Newtonsoft.Json.Bson;
using System;
using System.Collections.Generic;
using System.Text.Json;
namespace Luban.Job.Cfg.DataExporters
{
class BsonExportor : IDataActionVisitor<BsonDataWriter>
{
public static BsonExportor Ins { get; } = new BsonExportor();
public void WriteAsArray(List<Record> datas, BsonDataWriter x)
{
x.WriteStartArray();
foreach (var d in datas)
{
d.Data.Apply(this, x);
}
x.WriteEndArray();
}
public void Accept(DBool type, BsonDataWriter x)
{
x.WriteValue(type.Value);
}
public void Accept(DByte type, BsonDataWriter x)
{
x.WriteValue(type.Value);
}
public void Accept(DShort type, BsonDataWriter x)
{
x.WriteValue(type.Value);
}
public void Accept(DFshort type, BsonDataWriter x)
{
x.WriteValue(type.Value);
}
public void Accept(DInt type, BsonDataWriter x)
{
x.WriteValue(type.Value);
}
public void Accept(DFint type, BsonDataWriter x)
{
x.WriteValue(type.Value);
}
public void Accept(DLong type, BsonDataWriter x)
{
x.WriteValue(type.Value);
}
public void Accept(DFlong type, BsonDataWriter x)
{
x.WriteValue(type.Value);
}
public void Accept(DFloat type, BsonDataWriter x)
{
x.WriteValue(type.Value);
}
public void Accept(DDouble type, BsonDataWriter x)
{
x.WriteValue(type.Value);
}
public virtual void Accept(DEnum type, BsonDataWriter x)
{
x.WriteValue(type.Value);
}
public void Accept(DString type, BsonDataWriter x)
{
x.WriteValue(type.Value);
}
public void Accept(DBytes type, BsonDataWriter x)
{
throw new NotImplementedException();
}
public virtual void Accept(DText type, BsonDataWriter x)
{
x.WriteStartObject();
x.WritePropertyName(DText.KEY_NAME);
x.WriteValue(type.Key);
x.WritePropertyName(DText.TEXT_NAME);
x.WriteValue(type.TextOfCurrentAssembly);
x.WriteEndObject();
}
public virtual void Accept(DBean type, BsonDataWriter x)
{
x.WriteStartObject();
if (type.Type.IsAbstractType)
{
x.WritePropertyName(DefBean.JSON_TYPE_NAME_KEY);
x.WriteValue(DataUtil.GetImplTypeName(type));
}
var defFields = type.ImplType.HierarchyFields;
int index = 0;
foreach (var d in type.Fields)
{
var defField = (DefField)defFields[index++];
// 特殊处理 bean 多态类型
// 另外,不生成 xxx:null 这样
if (d == null || !defField.NeedExport)
{
//x.WriteNullValue();
}
else
{
x.WritePropertyName(defField.Name);
d.Apply(this, x);
}
}
x.WriteEndObject();
}
public void WriteList(List<DType> datas, BsonDataWriter x)
{
x.WriteStartArray();
foreach (var d in datas)
{
d.Apply(this, x);
}
x.WriteEndArray();
}
public void Accept(DArray type, BsonDataWriter x)
{
WriteList(type.Datas, x);
}
public void Accept(DList type, BsonDataWriter x)
{
WriteList(type.Datas, x);
}
public void Accept(DSet type, BsonDataWriter x)
{
WriteList(type.Datas, x);
}
public virtual void Accept(DMap type, BsonDataWriter x)
{
x.WriteStartArray();
foreach (var d in type.Datas)
{
x.WriteStartArray();
d.Key.Apply(this, x);
d.Value.Apply(this, x);
x.WriteEndArray();
}
x.WriteEndArray();
}
public void Accept(DVector2 type, BsonDataWriter x)
{
x.WriteStartObject();
x.WritePropertyName("x"); x.WriteValue(type.Value.X);
x.WritePropertyName("y"); x.WriteValue(type.Value.Y);
x.WriteEndObject();
}
public void Accept(DVector3 type, BsonDataWriter x)
{
x.WriteStartObject();
x.WritePropertyName("x"); x.WriteValue(type.Value.X);
x.WritePropertyName("y"); x.WriteValue(type.Value.Y);
x.WritePropertyName("z"); x.WriteValue(type.Value.Z);
x.WriteEndObject();
}
public void Accept(DVector4 type, BsonDataWriter x)
{
x.WriteStartObject();
x.WritePropertyName("x"); x.WriteValue(type.Value.X);
x.WritePropertyName("y"); x.WriteValue(type.Value.Y);
x.WritePropertyName("z"); x.WriteValue(type.Value.Z);
x.WritePropertyName("w"); x.WriteValue(type.Value.W);
x.WriteEndObject();
}
public virtual void Accept(DDateTime type, BsonDataWriter x)
{
x.WriteValue(type.UnixTimeOfCurrentAssembly);
}
}
}

View File

@ -87,7 +87,7 @@ namespace Luban.Job.Cfg.DataExporters
public void Accept(DDateTime type, CodedOutputStream x)
{
x.WriteInt64(type.UnixTimeOfCurrentAssembly);
x.WriteInt32(type.UnixTimeOfCurrentAssembly);
}
public void Accept(DString type, CodedOutputStream x)

View File

@ -1,8 +1,5 @@
using Luban.Job.Cfg.DataCreators;
using Luban.Job.Cfg.DataSources.Excel;
using Luban.Job.Cfg.Defs;
using System;
using System.Collections.Generic;
using System.IO;
namespace Luban.Job.Cfg.DataSources
@ -21,35 +18,7 @@ namespace Luban.Job.Cfg.DataSources
".asset",
};
private static string GetSheetParserMode(Dictionary<string, string> options)
{
if (options != null && options.TryGetValue("parser_mode", out var modeStr))
{
return modeStr;
}
//options = DefAssembly.LocalAssebmly.Options;
//if (options != null && options.TryGetValue("sheet.parser_mode", out modeStr))
//{
// return modeStr;
//}
return "";
}
private static bool IsColumnMode(string mode)
{
if (string.IsNullOrEmpty(mode))
{
return true;
}
switch(mode.ToLowerInvariant())
{
case "column": return true;
case "stream": return false;
default: throw new Exception($"unknown parser_mode:{mode}");
}
}
public static AbstractDataSource Create(string url, string sheetName, Dictionary<string, string> options, Stream stream)
public static AbstractDataSource Create(string url, string sheetName, Stream stream)
{
try
{
@ -60,11 +29,7 @@ namespace Luban.Job.Cfg.DataSources
case "csv":
case "xls":
case "xlsx":
case "xlsm":
{
source = IsColumnMode(GetSheetParserMode(options)) ? new ExcelRowColumnDataSource() : new ExcelStreamDataSource();
break;
}
case "xlsm": source = new Excel.ExcelDataSource(); break;
case "xml": source = new Xml.XmlDataSource(); break;
case "lua": source = new Lua.LuaDataSource(); break;
case "json": source = new Json.JsonDataSource(); break;

View File

@ -10,11 +10,11 @@ using System.IO;
namespace Luban.Job.Cfg.DataSources.Excel
{
class ExcelRowColumnDataSource : AbstractDataSource
class ExcelDataSource : AbstractDataSource
{
private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger();
private readonly List<RowColumnSheet> _sheets = new List<RowColumnSheet>();
private readonly List<Sheet> _sheets = new List<Sheet>();
public override void Load(string rawUrl, string sheetName, Stream stream)
@ -25,7 +25,7 @@ namespace Luban.Job.Cfg.DataSources.Excel
foreach (RawSheet rawSheet in SheetLoadUtil.LoadRawSheets(rawUrl, sheetName, stream))
{
var sheet = new RowColumnSheet(rawUrl, sheetName);
var sheet = new Sheet(rawUrl, sheetName);
sheet.Load(rawSheet);
_sheets.Add(sheet);
}
@ -40,7 +40,7 @@ namespace Luban.Job.Cfg.DataSources.Excel
{
foreach (RawSheet rawSheet in rawSheets)
{
var sheet = new RowColumnSheet("__intern__", rawSheet.TableName);
var sheet = new Sheet("__intern__", rawSheet.TableName);
sheet.Load(rawSheet);
_sheets.Add(sheet);
}

View File

@ -1,76 +0,0 @@
using ExcelDataReader;
using Luban.Job.Cfg.DataCreators;
using Luban.Job.Cfg.Datas;
using Luban.Job.Cfg.Utils;
using Luban.Job.Common.Types;
using System;
using System.Collections.Generic;
using System.IO;
namespace Luban.Job.Cfg.DataSources.Excel
{
class ExcelStreamDataSource : AbstractDataSource
{
private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger();
private readonly List<StreamSheet> _sheets = new List<StreamSheet>();
public override void Load(string rawUrl, string sheetName, Stream stream)
{
s_logger.Trace("{filename} {sheet}", rawUrl, sheetName);
RawUrl = rawUrl;
foreach (RawSheet rawSheet in SheetLoadUtil.LoadRawSheets(rawUrl, sheetName, stream))
{
var sheet = new StreamSheet(rawUrl, sheetName);
sheet.Load(rawSheet);
_sheets.Add(sheet);
}
if (_sheets.Count == 0)
{
throw new Exception($"excel:{rawUrl} 不包含有效的单元薄(有效单元薄的A0单元格必须是##).");
}
}
public RawSheetTableDefInfo LoadTableDefInfo(string rawUrl, string sheetName, Stream stream)
{
return SheetLoadUtil.LoadSheetTableDefInfo(rawUrl, sheetName, stream);
}
public override List<Record> ReadMulti(TBean type)
{
var datas = new List<Record>();
foreach (var sheet in _sheets)
{
try
{
var stream = sheet.Stream;
while(!stream.TryReadEOF())
{
var data = (DBean)type.Apply(ExcelStreamDataCreator.Ins, stream);
datas.Add(new Record(data, sheet.RawUrl, null));
}
}
catch (DataCreateException dce)
{
dce.OriginDataLocation = sheet.RawUrl;
throw;
}
catch (Exception e)
{
throw new Exception($"sheet:{sheet.Name}", e);
}
}
return datas;
}
public override Record ReadOne(TBean type)
{
throw new Exception($"excel不支持单例读取模式");
}
}
}

View File

@ -1,5 +1,4 @@
using DocumentFormat.OpenXml.EMMA;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -16,7 +15,6 @@ namespace Luban.Job.Cfg.DataSources.Excel
public string Type { get; set; }
public string Desc { get; set; }
public string Groups { get; set; }
}
class RawSheetTableDefInfo

View File

@ -12,7 +12,7 @@ using System.Linq;
namespace Luban.Job.Cfg.DataSources.Excel
{
class RowColumnSheet
class Sheet
{
private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger();
@ -22,7 +22,7 @@ namespace Luban.Job.Cfg.DataSources.Excel
public List<(string Tag, TitleRow Row)> Rows { get; } = new();
public RowColumnSheet(string rawUrl, string name)
public Sheet(string rawUrl, string name)
{
this.RawUrl = rawUrl;
this.Name = name;
@ -42,7 +42,7 @@ namespace Luban.Job.Cfg.DataSources.Excel
{
foreach (var row in cells)
{
if (IsBlankRow(row, title))
if (IsBlankRow(row, title.FromIndex, title.ToIndex))
{
continue;
}
@ -188,15 +188,6 @@ namespace Luban.Job.Cfg.DataSources.Excel
return Rows;
}
public static bool IsBlankRow(List<Cell> row, Title title)
{
if (title.SubTitleList.Count == 0)
{
return IsBlankRow(row, title.FromIndex, title.ToIndex);
}
return title.SubTitleList.All(t => IsBlankRow(row, t));
}
public static bool IsBlankRow(List<Cell> row, int fromIndex, int toIndex)
{
for (int i = Math.Max(1, fromIndex), n = Math.Min(toIndex, row.Count - 1); i <= n; i++)

View File

@ -87,7 +87,6 @@ namespace Luban.Job.Cfg.DataSources.Excel
"desc",
"comment",
"column",
"group",
};
private const char s_sep = '#';
@ -451,10 +450,6 @@ namespace Luban.Job.Cfg.DataSources.Excel
{
return IsRowTagEqual(row, "##type");
}
private static bool IsGroupRow(List<Cell> row)
{
return IsRowTagEqual(row, "##group");
}
private static bool IsHeaderRow(List<Cell> row)
{
@ -582,7 +577,7 @@ namespace Luban.Job.Cfg.DataSources.Excel
{
descRow = cells.Count > 1 ? cells.Skip(1).FirstOrDefault(row => IsRowTagEqual(row, "##")) : null;
}
List<Cell> groupRow = cells.Find(row => IsGroupRow(row));
var fields = new Dictionary<string, FieldInfo>();
foreach (var subTitle in title.SubTitleList)
{
@ -622,7 +617,6 @@ namespace Luban.Job.Cfg.DataSources.Excel
Name = subTitle.Name,
Tags = subTitle.Tags,
Type = typeRow[subTitle.FromIndex].Value?.ToString() ?? "",
Groups = groupRow?[subTitle.FromIndex].Value?.ToString() ?? "",
Desc = desc,
});
}

View File

@ -1,37 +0,0 @@
using Bright.Collections;
using ExcelDataReader;
using Luban.Job.Cfg.DataCreators;
using Luban.Job.Cfg.Datas;
using Luban.Job.Cfg.Utils;
using Luban.Job.Common.Types;
using Luban.Job.Common.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Luban.Job.Cfg.DataSources.Excel
{
class StreamSheet
{
private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger();
public string Name { get; }
public string RawUrl { get; }
public ExcelStream Stream { get; private set; }
public StreamSheet(string rawUrl, string name)
{
this.RawUrl = rawUrl;
this.Name = name;
}
public void Load(RawSheet rawSheet)
{
Title title = rawSheet.Title;
Stream = new ExcelStream(rawSheet.Cells, 1, title.ToIndex, "", "");
}
}
}

View File

@ -75,11 +75,11 @@ namespace Luban.Job.Cfg.DataSources.Excel
{
if (Row != null)
{
return RowColumnSheet.IsBlankRow(Row, SelfTitle.FromIndex, SelfTitle.ToIndex);
return Sheet.IsBlankRow(Row, SelfTitle.FromIndex, SelfTitle.ToIndex);
}
if (Rows != null)
{
return RowColumnSheet.IsBlankRow(Rows[0], SelfTitle.FromIndex, SelfTitle.ToIndex);
return Sheet.IsBlankRow(Rows[0], SelfTitle.FromIndex, SelfTitle.ToIndex);
}
if (Fields != null)
{
@ -105,6 +105,7 @@ namespace Luban.Job.Cfg.DataSources.Excel
}
}
public bool HasSubFields => Fields != null || Elements != null;
public TitleRow(Title selfTitle, List<Cell> row)

View File

@ -7,7 +7,7 @@ namespace Luban.Job.Cfg.DataVisitors
{
abstract class ToLiteralVisitorBase : IDataFuncVisitor<string>
{
public virtual string Accept(DBool type)
public string Accept(DBool type)
{
return type.Value ? "true" : "false";
}

View File

@ -10,11 +10,6 @@ namespace Luban.Job.Cfg.DataVisitors
{
public static ToPythonLiteralVisitor Ins { get; } = new();
public override string Accept(DBool type)
{
return type.Value ? "True" : "False";
}
public override string Accept(DText type)
{
return $"{{\"{DText.KEY_NAME}\":\"{type.Key}\",\"{DText.TEXT_NAME}\":\"{DataUtil.EscapeString(type.TextOfCurrentAssembly)}\"}}";
@ -99,7 +94,7 @@ namespace Luban.Job.Cfg.DataVisitors
x.Append(',');
}
++index;
x.Append(e.Key.Apply(this));
x.Append('"').Append(e.Key.ToString()).Append('"');
x.Append(':');
x.Append(e.Value.Apply(this));
}

View File

@ -11,7 +11,7 @@ namespace Luban.Job.Cfg.Datas
public DateTime Time { get; }
//public int UnixTime { get; }
private readonly long _localTime;
private readonly int _localTime;
public override string TypeName => "datetime";
@ -21,7 +21,7 @@ namespace Luban.Job.Cfg.Datas
this.Time = time;
// time.Kind == DateTimeKind.Unspecified
// DateTimeOffset°ÑËüµ±×÷Local´¦Àí
this._localTime = (long)new DateTimeOffset(TimeZoneInfo.ConvertTime(time, TimeZoneUtil.DefaultTimeZone, TimeZoneInfo.Utc)).ToUnixTimeSeconds();
this._localTime = (int)new DateTimeOffset(TimeZoneInfo.ConvertTime(time, TimeZoneUtil.DefaultTimeZone, TimeZoneInfo.Utc)).ToUnixTimeSeconds();
}
public override bool Equals(object obj)
@ -48,7 +48,7 @@ namespace Luban.Job.Cfg.Datas
return DataUtil.FormatDateTime(Time);
}
public long GetUnixTime(TimeZoneInfo asTimeZone)
public int GetUnixTime(TimeZoneInfo asTimeZone)
{
if (asTimeZone == null || asTimeZone == TimeZoneInfo.Local)
{
@ -57,11 +57,11 @@ namespace Luban.Job.Cfg.Datas
else
{
var destDateTime = TimeZoneInfo.ConvertTime(Time, asTimeZone, TimeZoneInfo.Utc);
return (long)new DateTimeOffset(destDateTime).ToUnixTimeSeconds();
return (int)new DateTimeOffset(destDateTime).ToUnixTimeSeconds();
}
}
public long UnixTimeOfCurrentAssembly => GetUnixTime(DefAssembly.LocalAssebmly.TimeZone);
public int UnixTimeOfCurrentAssembly => GetUnixTime(DefAssembly.LocalAssebmly.TimeZone);
public override void Apply<T>(IDataActionVisitor<T> visitor, T x)
{

View File

@ -236,7 +236,7 @@ namespace Luban.Job.Cfg.Defs
return mode;
}
private readonly List<string> _tableOptionalAttrs = new List<string> { "index", "mode", "group", "patch_input", "comment", "define_from_file", "output", "options" };
private readonly List<string> _tableOptionalAttrs = new List<string> { "index", "mode", "group", "patch_input", "comment", "define_from_file", "output" };
private readonly List<string> _tableRequireAttrs = new List<string> { "name", "value", "input" };
private void AddTable(string defineFile, XElement e)
@ -254,12 +254,11 @@ namespace Luban.Job.Cfg.Defs
string mode = XmlUtil.GetOptionalAttribute(e, "mode");
string tags = XmlUtil.GetOptionalAttribute(e, "tags");
string output = XmlUtil.GetOptionalAttribute(e, "output");
string options = XmlUtil.GetOptionalAttribute(e, "options");
AddTable(defineFile, name, module, valueType, index, mode, group, comment, defineFromFile, input, patchInput, tags, output, options);
AddTable(defineFile, name, module, valueType, index, mode, group, comment, defineFromFile, input, patchInput, tags, output);
}
private void AddTable(string defineFile, string name, string module, string valueType, string index, string mode, string group,
string comment, bool defineFromExcel, string input, string patchInput, string tags, string outputFileName, string options)
string comment, bool defineFromExcel, string input, string patchInput, string tags, string outputFileName)
{
var p = new Table()
{
@ -273,7 +272,6 @@ namespace Luban.Job.Cfg.Defs
Mode = ConvertMode(defineFile, name, mode, index),
Tags = tags,
OutputFile = outputFileName,
Options = options,
};
if (string.IsNullOrWhiteSpace(name))
{
@ -320,43 +318,20 @@ namespace Luban.Job.Cfg.Defs
RawSheetTableDefInfo tableDefInfo;
if (!ExcelTableValueTypeDefInfoCacheManager.Instance.TryGetTableDefInfo(file.MD5, file.SheetName, out tableDefInfo))
{
var source = new ExcelRowColumnDataSource();
var source = new ExcelDataSource();
var stream = new MemoryStream(await this.Agent.GetFromCacheOrReadAllBytesAsync(file.ActualFile, file.MD5));
tableDefInfo = source.LoadTableDefInfo(file.OriginFile, file.SheetName, stream);
ExcelTableValueTypeDefInfoCacheManager.Instance.AddTableDefInfoToCache(file.MD5, file.SheetName, tableDefInfo);
}
var (valueType, tags) = DefUtil.ParseType(table.ValueType);
var ns = TypeUtil.GetNamespace(valueType);
string valueTypeNamespace = string.IsNullOrEmpty(ns) ? table.Namespace : ns;
string valueTypeName = TypeUtil.GetName(valueType);
Bean parentBean = null;
if (tags.TryGetValue("parent", out string parentType))
{
var parentNs = TypeUtil.GetNamespace(parentType);
string parentNamespace = string.IsNullOrEmpty(parentNs) ? table.Namespace : parentNs;
string parentName = TypeUtil.GetName(parentType);
parentType = string.Join(".", parentNamespace, parentName);
parentBean = _beans.FirstOrDefault(x => x.FullName == parentType);
}
var cb = new CfgBean() { Namespace = valueTypeNamespace, Name = valueTypeName, Comment = "", Parent = parentType };
if (parentBean != null)
{
foreach (var parentField in parentBean.Fields)
{
if (!tableDefInfo.FieldInfos.Any(x => x.Key == parentField.Name && x.Value.Type == parentField.Type))
{
throw new Exception($"table:'{table.Name}' file:{file.OriginFile} title:缺失父类字段:'{parentField.Type} {parentField.Name}'");
}
}
}
var ns = TypeUtil.GetNamespace(table.ValueType);
string valueTypeNamespace = string.IsNullOrEmpty(ns) ? table.Namespace : ns;
string valueTypeName = TypeUtil.GetName(table.ValueType);
var cb = new CfgBean() { Namespace = valueTypeNamespace, Name = valueTypeName, Comment = "" };
foreach (var (name, f) in tableDefInfo.FieldInfos)
{
if (parentBean != null && parentBean.Fields.Any(x => x.Name == name && x.Type == f.Type))
{
continue;
}
var cf = new CfgField() { Name = name, Id = 0 };
string[] attrs = f.Type.Trim().Split('&').Select(s => s.Trim()).ToArray();
@ -367,7 +342,9 @@ namespace Luban.Job.Cfg.Defs
}
cf.Comment = f.Desc;
cf.Type = attrs[0];
for (int i = 1; i < attrs.Length; i++)
{
var pair = attrs[i].Split('=', 2);
@ -384,7 +361,6 @@ namespace Luban.Job.Cfg.Defs
case "path":
case "range":
case "sep":
case "regex":
{
throw new Exception($"table:'{table.Name}' file:{file.OriginFile} title:'{name}' attr:'{attrName}' 属于type的属性必须用#分割,尝试'{cf.Type}#{attrs[i]}'");
}
@ -410,11 +386,6 @@ namespace Luban.Job.Cfg.Defs
}
}
if (!string.IsNullOrEmpty(f.Groups))
{
cf.Groups = f.Groups.Split(',').Select(s => s.Trim()).Where(s => !string.IsNullOrWhiteSpace(s)).ToList();
}
cb.Fields.Add(cf);
}
return cb;
@ -465,7 +436,6 @@ namespace Luban.Job.Cfg.Defs
new CfgField() { Name = "output", Type = "string" },
new CfgField() { Name = "patch_input", Type = "string" },
new CfgField() { Name = "tags", Type = "string" },
new CfgField() { Name = "options", Type = "string" },
}
})
{
@ -478,10 +448,10 @@ namespace Luban.Job.Cfg.Defs
foreach (var file in inputFileInfos)
{
var source = new ExcelRowColumnDataSource();
var source = new ExcelDataSource();
var bytes = await this.Agent.GetFromCacheOrReadAllBytesAsync(file.ActualFile, file.MD5);
(var actualFile, var sheetName) = FileUtil.SplitFileAndSheetName(FileUtil.Standardize(file.OriginFile));
var records = DataLoaderUtil.LoadCfgRecords(tableRecordType, actualFile, sheetName, bytes, true, null);
var records = DataLoaderUtil.LoadCfgRecords(tableRecordType, actualFile, sheetName, bytes, true);
foreach (var r in records)
{
DBean data = r.Data;
@ -503,8 +473,7 @@ namespace Luban.Job.Cfg.Defs
string patchInput = (data.GetField("patch_input") as DString).Value.Trim();
string tags = (data.GetField("tags") as DString).Value.Trim();
string outputFile = (data.GetField("output") as DString).Value.Trim();
string options = (data.GetField("options") as DString).Value.Trim();
AddTable(file.OriginFile, name, module, valueType, index, mode, group, comment, isDefineFromExcel, inputFile, patchInput, tags, outputFile, options);
AddTable(file.OriginFile, name, module, valueType, index, mode, group, comment, isDefineFromExcel, inputFile, patchInput, tags, outputFile);
};
}
}
@ -578,10 +547,10 @@ namespace Luban.Job.Cfg.Defs
foreach (var file in inputFileInfos)
{
var source = new ExcelRowColumnDataSource();
var source = new ExcelDataSource();
var bytes = await this.Agent.GetFromCacheOrReadAllBytesAsync(file.ActualFile, file.MD5);
(var actualFile, var sheetName) = FileUtil.SplitFileAndSheetName(FileUtil.Standardize(file.OriginFile));
var records = DataLoaderUtil.LoadCfgRecords(tableRecordType, actualFile, sheetName, bytes, true, null);
var records = DataLoaderUtil.LoadCfgRecords(tableRecordType, actualFile, sheetName, bytes, true);
foreach (var r in records)
{
@ -674,7 +643,6 @@ namespace Luban.Job.Cfg.Defs
new CfgField() { Name = "full_name", Type = "string" },
new CfgField() {Name = "parent", Type = "string" },
new CfgField() { Name = "sep", Type = "string" },
new CfgField() { Name = "alias", Type = "string" },
new CfgField() { Name = "comment", Type = "string" },
new CfgField() { Name = "tags", Type = "string" },
new CfgField() { Name = "fields", Type = "list,__FieldInfo__" },
@ -691,9 +659,9 @@ namespace Luban.Job.Cfg.Defs
foreach (var file in inputFileInfos)
{
var source = new ExcelRowColumnDataSource();
var source = new ExcelDataSource();
var bytes = await this.Agent.GetFromCacheOrReadAllBytesAsync(file.ActualFile, file.MD5);
var records = DataLoaderUtil.LoadCfgRecords(tableRecordType, file.OriginFile, file.SheetName, bytes, true, null);
var records = DataLoaderUtil.LoadCfgRecords(tableRecordType, file.OriginFile, null, bytes, true);
foreach (var r in records)
{
@ -709,7 +677,6 @@ namespace Luban.Job.Cfg.Defs
string parent = (data.GetField("parent") as DString).Value.Trim();
string sep = (data.GetField("sep") as DString).Value.Trim();
string alias = (data.GetField("alias") as DString).Value.Trim();
string comment = (data.GetField("comment") as DString).Value.Trim();
string tags = (data.GetField("tags") as DString).Value.Trim();
DList fields = data.GetField("fields") as DList;
@ -718,7 +685,6 @@ namespace Luban.Job.Cfg.Defs
Name = name,
Namespace = module,
Sep = sep,
Alias = alias,
Comment = comment,
Tags = tags,
Parent = parent,

View File

@ -24,7 +24,6 @@ namespace Luban.Job.Cfg.Defs
public Service CfgTargetService { get; private set; }
private readonly string _patchName;
private readonly List<string> _excludeTags;
public Patch TargetPatch { get; private set; }
@ -35,8 +34,6 @@ namespace Luban.Job.Cfg.Defs
public string TableManagerName => CfgTargetService.Manager;
public List<string> ExcludeTags => _excludeTags;
public DefAssembly(string patchName, TimeZoneInfo timezone, List<string> excludeTags, IAgent agent)
{
this._patchName = patchName;
@ -62,8 +59,7 @@ namespace Luban.Job.Cfg.Defs
private readonly ConcurrentDictionary<string, TableDataInfo> _recordsByTables = new();
public Dictionary<string, DefTable> CfgTablesByName { get; } = new();
public Dictionary<string, DefTable> CfgTablesByName = new();
public Dictionary<string, DefTable> CfgTablesByFullName { get; } = new Dictionary<string, DefTable>();
public RawTextTable RawTextTable { get; } = new RawTextTable();
@ -166,12 +162,12 @@ namespace Luban.Job.Cfg.Defs
public List<DefTable> GetAllTables()
{
return TypeList.Where(t => t is DefTable).Cast<DefTable>().ToList();
return Types.Values.Where(t => t is DefTable).Cast<DefTable>().ToList();
}
public List<DefTable> GetExportTables()
{
return TypeList.Where(t => t is DefTable ct
return Types.Values.Where(t => t is DefTable ct
&& !_outputExcludeTables.Contains(t.FullName)
&& (_outputIncludeTables.Contains(t.FullName) || (_overrideOutputTables == null ? ct.NeedExport : _overrideOutputTables.Contains(ct.FullName)))
).Select(t => (DefTable)t).ToList();
@ -313,12 +309,12 @@ namespace Luban.Job.Cfg.Defs
_cfgServices.AddRange(defines.Services);
foreach (var type in TypeList)
foreach (var type in Types.Values)
{
type.AssemblyBase = this;
}
foreach (var type in TypeList)
foreach (var type in Types.Values)
{
try
{
@ -332,7 +328,7 @@ namespace Luban.Job.Cfg.Defs
throw;
}
}
foreach (var type in TypeList)
foreach (var type in Types.Values)
{
try
{
@ -348,7 +344,7 @@ namespace Luban.Job.Cfg.Defs
}
}
foreach (var type in TypeList)
foreach (var type in Types.Values)
{
try
{

View File

@ -23,7 +23,6 @@ namespace Luban.Job.Cfg.Defs
public const string LUA_TYPE_NAME_KEY = "_type_";
public const string EXCEL_TYPE_NAME_KEY = "$type";
public const string EXCEL_VALUE_NAME_KEY = "$value";
public string JsonTypeNameKey => JSON_TYPE_NAME_KEY;
@ -160,7 +159,21 @@ namespace Luban.Job.Cfg.Defs
public override void PreCompile()
{
base.PreCompile();
if (!string.IsNullOrEmpty(Parent))
{
if ((ParentDefType = (DefBean)AssemblyBase.GetDefType(Namespace, Parent)) == null)
{
throw new Exception($"bean:'{FullName}' parent:'{Parent}' not exist");
}
if (ParentDefType.Children == null)
{
ParentDefType.Children = new List<DefBeanBase>();
}
ParentDefType.Children.Add(this);
}
CollectHierarchyFields(HierarchyFields);
this.ExportFields = this.Fields.Select(f => (DefField)f).Where(f => f.NeedExport).ToList();
this.HierarchyExportFields = this.HierarchyFields.Select(f => (DefField)f).Where(f => f.NeedExport).ToList();
}

View File

@ -63,9 +63,8 @@ namespace Luban.Job.Cfg.Defs
{
return Ref.GenRef;
}
// 特殊处理, 目前只有c#和java支持.而这个属性已经被多种语言模板引用了,故单独处理一下
if (DefAssemblyBase.LocalAssebmly.CurrentLanguage != Common.ELanguage.CS
&& DefAssemblyBase.LocalAssebmly.CurrentLanguage != Common.ELanguage.JAVA)
// 特殊处理, 目前只有c#支持.而这个属性已经被多种语言模板引用了,故单独处理一下
if (DefAssemblyBase.LocalAssebmly.CurrentLanguage != Common.ELanguage.CS)
{
return false;
}
@ -74,7 +73,7 @@ namespace Luban.Job.Cfg.Defs
}
public bool HasRecursiveRef => (CType is TBean tb && HostType.AssemblyBase.GetExternalTypeMapper(tb) == null)
|| (CType.ElementType is TBean eb && HostType.AssemblyBase.GetExternalTypeMapper(eb) == null);
|| CType.ElementType?.IsBean == true;
public string CsRefTypeName => RefType.Apply(CsDefineTypeName.Ins);
@ -110,18 +109,8 @@ namespace Luban.Job.Cfg.Defs
{
get
{
if (Ref != null)
{
return $"{RefType.Apply(JavaDefineTypeName.Ins)} {RefVarName};";
}
else if (ElementRef != null)
{
return $"{ElementRefType.Apply(JavaDefineTypeName.Ins)} {RefVarName};";
}
else
{
throw new NotSupportedException();
}
var table = Assembly.GetCfgTable(Ref.FirstTable);
return $"{table.ValueTType.Apply(JavaDefineTypeName.Ins)} {RefVarName};";
}
}

View File

@ -1,5 +1,4 @@
using Bright.Collections;
using Luban.Job.Cfg.DataSources.Excel;
using Luban.Job.Cfg.RawDefs;
using Luban.Job.Cfg.TypeVisitors;
using Luban.Job.Common.Types;
@ -29,26 +28,8 @@ namespace Luban.Job.Cfg.Defs
Comment = b.Comment;
Tags = DefUtil.ParseAttrs(b.Tags);
_outputFile = b.OutputFile;
ParseOptions(b.Options);
}
private void ParseOptions(string optionsStr)
{
foreach(var kvStr in optionsStr.Split('|', ';', ','))
{
if (string.IsNullOrWhiteSpace(kvStr))
{
continue;
}
string[] entry = kvStr.Split('=');
if (entry.Length != 2)
{
throw new Exception($"table:{FullName} options:'{optionsStr}' invalid");
}
Options[entry[0]] = entry[1];
}
}
public string Index { get; private set; }
@ -56,8 +37,6 @@ namespace Luban.Job.Cfg.Defs
public ETableMode Mode { get; }
public Dictionary<string, string> Options { get; } = new Dictionary<string, string>();
public bool IsMapTable => Mode == ETableMode.MAP;
public bool IsOneValueTable => Mode == ETableMode.ONE;
@ -86,8 +65,6 @@ namespace Luban.Job.Cfg.Defs
public bool IsUnionIndex { get; private set; }
public bool MultiKey { get; private set; }
public List<IndexInfo> IndexList { get; } = new();
public bool NeedExport => Assembly.NeedExport(this.Groups);
@ -113,7 +90,7 @@ namespace Luban.Job.Cfg.Defs
}
}
if ((ValueTType = (TBean)ass.CreateType(Namespace, ValueType, false)) == null)
if ((ValueTType = (TBean)ass.CreateType(Namespace, ValueType)) == null)
{
throw new Exception($"table:'{FullName}' 的 value类型:'{ValueType}' 不存在");
}
@ -164,11 +141,8 @@ namespace Luban.Job.Cfg.Defs
{
if (ValueTType.GetBeanAs<DefBean>().TryGetField(idx, out var f, out var i))
{
if (IndexField == null)
{
IndexField = f;
IndexFieldIdIndex = i;
}
IndexField = f;
IndexFieldIdIndex = i;
this.IndexList.Add(new IndexInfo(f.CType, f, i));
}
else
@ -178,7 +152,6 @@ namespace Luban.Job.Cfg.Defs
}
// 如果不是 union index, 每个key必须唯一否则 (key1,..,key n)唯一
IsUnionIndex = IndexList.Count > 1 && !Index.Contains(',');
MultiKey = IndexList.Count > 1 && Index.Contains(',');
break;
}
default: throw new Exception($"unknown mode:'{Mode}'");

View File

@ -44,19 +44,13 @@ namespace Luban.Job.Cfg.Defs
var overrideRecords = new HashSet<Record>();
foreach (var r in mainRecords)
{
if (recordIndex.TryAdd(r, index))
{
index++;
}
recordIndex.Add(r, index++);
}
if (patchRecords != null)
{
foreach (var r in patchRecords)
{
if (recordIndex.TryAdd(r, index))
{
index++;
}
recordIndex.Add(r, index++);
}
}

View File

@ -8,7 +8,7 @@ namespace Luban.Job.Cfg
[Option('s', "service", Required = true, HelpText = "service")]
public string Service { get; set; }
[Option("gen_types", Required = true, HelpText = "code_cs_bin,code_cs_dotnet_json,code_cs_unity_json,code_cs_unity_editor_json,code_lua_bin,code_java_bin,code_java_json,code_go_bin,code_go_json,code_cpp_bin,code_cpp_ue_editor_json,code_python2_json,code_python3_json,code_typescript_bin,code_typescript_json,code_rust_json,code_protobuf,code_template,code_flatbuffers,code_gdscript_json,data_bin,data_bidx,data_lua,data_json,data_json2,data_json_monolithic,data_bson,data_yaml,data_xml,data_resources,data_template,data_protobuf_bin,data_protobuf_json,data_flatbuffers_json,convert_json,convert_lua,convert_xlsx . can be multi")]
[Option("gen_types", Required = true, HelpText = "code_cs_bin,code_cs_dotnet_json,code_cs_unity_json,code_cs_unity_editor_json,code_lua_bin,code_java_bin,code_java_json,code_go_bin,code_go_json,code_cpp_bin,code_cpp_ue_editor_json,code_python2_json,code_python3_json,code_typescript_bin,code_typescript_json,code_rust_json,code_protobuf,code_template,code_flatbuffers,data_bin,data_lua,data_json,data_json2,data_json_monolithic,data_yaml,data_xml,data_resources,data_template,data_protobuf_bin,data_protobuf_json,data_flatbuffers_json,convert_json,convert_lua,convert_xlsx . can be multi")]
public string GenType { get; set; }
[Option("input_data_dir", Required = true, HelpText = "input data dir")]

View File

@ -8,10 +8,8 @@ using System.Threading.Tasks;
namespace Luban.Job.Cfg.Generate
{
[Render("data_bin")]
[Render("data_bidx")]
[Render("data_json")]
[Render("data_json2")]
[Render("data_bson")]
[Render("data_lua")]
[Render("data_xml")]
[Render("data_yaml")]

View File

@ -45,7 +45,7 @@ namespace Luban.Job.Cfg.Generate
foreach (var subTitle in title.SubTitleList)
{
string titleAndTags = subTitle.Tags.Count == 0 ? subTitle.Name : subTitle.Name + "#" + string.Join('#', subTitle.Tags.Select(e => $"{e.Key}={e.Value}"));
string titleAndTags = subTitle.Tags.Count == 0 ? subTitle.Name : subTitle.Name + "&" + string.Join('&', subTitle.Tags.Select(e => $"{e.Key}={e.Value}"));
titleRow[subTitle.FromIndex] = titleAndTags;
}
dataRangeArray.Add(titleRow);
@ -58,7 +58,7 @@ namespace Luban.Job.Cfg.Generate
foreach (var subTitle in title.SubTitleList)
{
string typeAndTags = valueType.Bean.TryGetField(subTitle.Name, out var f, out _) ?
(f.CType.Tags.Count == 0 ? f.CType.Apply(CsDefineTypeName.Ins) : f.CType.Apply(CsDefineTypeName.Ins) + "#" + string.Join('#', f.CType.Tags.Select(e => $"({e.Key}={e.Value})")))
(f.CType.Tags.Count == 0 ? f.CType.Apply(CsDefineTypeName.Ins) : f.CType.Apply(CsDefineTypeName.Ins) + "&" + string.Join('&', f.CType.Tags.Select(e => $"{e.Key}={e.Value}")))
: "";
typeRow[subTitle.FromIndex] = typeAndTags;
}

View File

@ -1,39 +0,0 @@
using Luban.Job.Cfg.Defs;
using Luban.Job.Common.Generate;
using Luban.Job.Common.Tpl;
using Luban.Job.Common.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Luban.Job.Cfg.Generate
{
[Render("code_gdscript_json")]
internal class GDScriptCodeJsonRender : TemplateCodeRenderBase
{
protected override string RenderTemplateDir => "gdscript_json";
public override void Render(GenContext ctx)
{
ctx.Render = this;
ctx.Lan = Common.ELanguage.GDSCRIPT;
DefAssembly.LocalAssebmly.CurrentLanguage = ctx.Lan;
var lines = new List<string>(10000);
static void PreContent(List<string> fileContent)
{
//fileContent.Add(PythonStringTemplates.ImportTython3Enum);
//fileContent.Add(PythonStringTemplates.PythonVectorTypes);
fileContent.Add(StringTemplateManager.Ins.GetTemplateString("config/gdscript_json/header"));
}
GenerateCodeMonolithic(ctx,
System.IO.Path.Combine(ctx.GenArgs.OutputCodeDir, RenderFileUtil.GetFileOrDefault(ctx.GenArgs.OutputCodeMonolithicFile, "types.gd")),
lines,
PreContent,
null);
}
}
}

View File

@ -23,7 +23,7 @@ namespace Luban.Job.Cfg.Generate
{
allJsonTask.Add(Task.Run(() =>
{
return System.Text.Encoding.UTF8.GetString((byte[])DataExporterUtil.ToOutputData(c, ctx.Assembly.GetTableExportDataList(c), "data_json2"));
return (string)DataExporterUtil.ToOutputData(c, ctx.Assembly.GetTableExportDataList(c), "data_json2");
}));
}

View File

@ -67,33 +67,33 @@ namespace Luban.Job.Cfg
}
if (genTypes.Contains("data_resources") && string.IsNullOrWhiteSpace(options.OutputDataResourceListFile))
{
errMsg = "--output:data:resource_list_file missing";
errMsg = "--output_data_resource_list_file missing";
return false;
}
if (genTypes.Contains("data_json_monolithic") && string.IsNullOrWhiteSpace(options.OutputDataJsonMonolithicFile))
if (genTypes.Contains("output_data_json_monolithic_file") && string.IsNullOrWhiteSpace(options.OutputDataJsonMonolithicFile))
{
errMsg = "--output:data:json_monolithic_file missing";
errMsg = "--output_data_json_monolithic_file missing";
return false;
}
if (string.IsNullOrWhiteSpace(options.L10nInputTextTableFiles) ^ string.IsNullOrWhiteSpace(options.L10nOutputNotTranslatedTextFile))
{
errMsg = "--l10n:input_text_files should be used with --l10n:output_not_translated_text_file";
errMsg = "--input_l10n_text_files must be provided with --output_l10n_not_translated_text_file";
return false;
}
if (genTypes.Contains("data_template") ^ !string.IsNullOrWhiteSpace(options.TemplateDataFile))
{
errMsg = "gen_types data_template should be used with --template:data:file";
errMsg = "gen_types data_template should use with --template:data:file";
return false;
}
if (genTypes.Contains("convert_template") ^ !string.IsNullOrWhiteSpace(options.TemplateConvertFile))
{
errMsg = "gen_types convert_template should be used with --template:convert:file";
errMsg = "gen_types convert_template should use with --template:convert:file";
return false;
}
if (genTypes.Contains("code_template") ^ !string.IsNullOrWhiteSpace(options.TemplateCodeDir))
{
errMsg = "gen_types code_template should be used with --template:code:dir";
errMsg = "gen_types code_template should use with --template:code:dir";
return false;
}
}

View File

@ -1,4 +1,3 @@
using Luban.Job.Cfg.DataSources.Excel;
using System.Collections.Generic;
namespace Luban.Job.Cfg.RawDefs
@ -35,8 +34,6 @@ namespace Luban.Job.Cfg.RawDefs
public ETableMode Mode { get; set; }
public string Options { get; set; }
public string Comment { get; set; }
public string Tags { get; set; }

View File

@ -1,7 +1,6 @@
using Luban.Job.Cfg.Datas;
using Luban.Job.Cfg.Defs;
using Luban.Job.Cfg.Utils;
using Luban.Job.Common.Utils;
using Scriban;
using System.Collections.Generic;
@ -11,7 +10,7 @@ namespace Luban.Job.Cfg
{
public static string RenderCode(this Template template, object model, Dictionary<string, object> extraModels = null)
{
var ctx = TemplateUtil.CreateDefaultTemplateContext();
var ctx = new TemplateContext();
var env = new TTypeTemplateExtends
{
["x"] = model,
@ -30,7 +29,8 @@ namespace Luban.Job.Cfg
public static string RenderDatas(this Template template, DefTable table, List<DBean> exportDatas, Dictionary<string, object> extraModels = null)
{
var ctx = TemplateUtil.CreateDefaultTemplateContext();
var ctx = new TemplateContext();
var env = new DTypeTemplateExtends
{
["table"] = table,
@ -51,7 +51,8 @@ namespace Luban.Job.Cfg
public static string RenderData(this Template template, DefTable table, DBean data, Dictionary<string, object> extraModels = null)
{
var ctx = TemplateUtil.CreateDefaultTemplateContext();
var ctx = new TemplateContext();
var env = new DTypeTemplateExtends
{
["table"] = table,

View File

@ -120,7 +120,7 @@ namespace Luban.Job.Cfg.TypeVisitors
public string Accept(TDateTime type, string bufName, string fieldName)
{
return $"if(!{bufName}.readLong({fieldName})) return false;";
return $"if(!{bufName}.readInt({fieldName})) return false;";
}
}
}

View File

@ -1,156 +1,127 @@
using Luban.Job.Cfg.Datas;
using Luban.Job.Common.Types;
using Luban.Job.Common.TypeVisitors;
using Luban.Job.Common.Utils;
using System;
namespace Luban.Job.Cfg.TypeVisitors
{
class CsJsonDeserialize : ITypeFuncVisitor<string, string, int, string>
class CsJsonDeserialize : ITypeFuncVisitor<string, string, string>
{
public static CsJsonDeserialize Ins { get; } = new();
public string Accept(TBool type, string json, string x, int depth)
public string Accept(TBool type, string json, string x)
{
return $"{x} = {json}.GetBoolean();";
}
public string Accept(TByte type, string json, string x, int depth)
public string Accept(TByte type, string json, string x)
{
return $"{x} = {json}.GetByte();";
}
public string Accept(TShort type, string json, string x, int depth)
public string Accept(TShort type, string json, string x)
{
return $"{x} = {json}.GetInt16();";
}
public string Accept(TFshort type, string json, string x, int depth)
public string Accept(TFshort type, string json, string x)
{
return $"{x} = {json}.GetInt16();";
}
public string Accept(TInt type, string json, string x, int depth)
public string Accept(TInt type, string json, string x)
{
return $"{x} = {json}.GetInt32();";
}
public string Accept(TFint type, string json, string x, int depth)
public string Accept(TFint type, string json, string x)
{
return $"{x} = {json}.GetInt32();";
}
public string Accept(TLong type, string json, string x, int depth)
public string Accept(TLong type, string json, string x)
{
return $"{x} = {json}.GetInt64();";
}
public string Accept(TFlong type, string json, string x, int depth)
public string Accept(TFlong type, string json, string x)
{
return $"{x} = {json}.GetInt64();";
}
public string Accept(TFloat type, string json, string x, int depth)
public string Accept(TFloat type, string json, string x)
{
return $"{x} = {json}.GetSingle();";
}
public string Accept(TDouble type, string json, string x, int depth)
public string Accept(TDouble type, string json, string x)
{
return $"{x} = {json}.GetDouble();";
}
public string Accept(TEnum type, string json, string x, int depth)
public string Accept(TEnum type, string json, string x)
{
return $"{x} = ({type.CsUnderingDefineType()}){json}.GetInt32();";
}
public string Accept(TString type, string json, string x, int depth)
public string Accept(TString type, string json, string x)
{
return $"{x} = {json}.GetString();";
}
public string Accept(TBytes type, string json, string x, int depth)
public string Accept(TBytes type, string json, string x)
{
throw new NotSupportedException();
}
public string Accept(TText type, string json, string x, int depth)
public string Accept(TText type, string json, string x)
{
return $"{x}{TText.L10N_FIELD_SUFFIX} = {json}.GetProperty(\"{DText.KEY_NAME}\").GetString();{x} = {json}.GetProperty(\"{DText.TEXT_NAME}\").GetString();";
}
public string Accept(TBean type, string json, string x, int depth)
public string Accept(TBean type, string json, string x)
{
string src = $"{type.Bean.FullName}.Deserialize{type.Bean.Name}({json})";
return $"{x} = {ExternalTypeUtil.CsCloneToExternal(type.Bean.FullName, src)};";
return $"{x} = {type.CsUnderingDefineType()}.Deserialize{type.Bean.Name}({json});";
}
public string Accept(TArray type, string json, string x, int depth)
public string Accept(TArray type, string json, string x)
{
string _n = $"_n{depth}";
string __e = $"__e{depth}";
string __v = $"__v{depth}";
string __json = $"__json{depth}";
string __index = $"__index{depth}";
string typeStr = $"{type.ElementType.Apply(CsDefineTypeName.Ins)}[{_n}]";
if (type.Dimension > 1)
{
if (type.FinalElementType == null)
{
throw new System.Exception("¶àάÊý×éûÓÐÔªËØÀàÐÍ");
}
typeStr = $"{type.FinalElementType.Apply(CsUnderingDefineTypeName.Ins)}[{_n}]";
for (int i = 0; i < type.Dimension - 1; i++)
{
typeStr += "[]";
}
}
return $"{{ var {__json} = {json}; int {_n} = {__json}.GetArrayLength(); {x} = new {typeStr}; int {__index}=0; foreach(JsonElement {__e} in {__json}.EnumerateArray()) {{ {type.ElementType.CsUnderingDefineType()} {__v}; {type.ElementType.Apply(this, $"{__e}", $"{__v}", depth + 1)} {x}[{__index}++] = {__v}; }} }}";
return $"{{ var _json0 = {json}; int _n = _json0.GetArrayLength(); {x} = new {type.ElementType.CsUnderingDefineType()}[_n]; int _index=0; foreach(JsonElement __e in _json0.EnumerateArray()) {{ {type.ElementType.CsUnderingDefineType()} __v; {type.ElementType.Apply(this, "__e", "__v")} {x}[_index++] = __v; }} }}";
}
public string Accept(TList type, string json, string x, int depth)
public string Accept(TList type, string json, string x)
{
string __e = $"__e{depth}";
string __v = $"__v{depth}";
string __json = $"__json{depth}";
return $"{{ var {__json} = {json}; {x} = new {type.CsUnderingDefineType()}({__json}.GetArrayLength()); foreach(JsonElement {__e} in {__json}.EnumerateArray()) {{ {type.ElementType.CsUnderingDefineType()} {__v}; {type.ElementType.Apply(this, $"{__e}", $"{__v}", depth + 1)} {x}.Add({__v}); }} }}";
return $"{{ var _json0 = {json}; {x} = new {type.CsUnderingDefineType()}(_json0.GetArrayLength()); foreach(JsonElement __e in _json0.EnumerateArray()) {{ {type.ElementType.CsUnderingDefineType()} __v; {type.ElementType.Apply(this, "__e", "__v")} {x}.Add(__v); }} }}";
}
public string Accept(TSet type, string json, string x, int depth)
public string Accept(TSet type, string json, string x)
{
string __e = $"__e{depth}";
string __v = $"__v{depth}";
string __json = $"__json{depth}";
return $"{{ var {__json} = {json}; {x} = new {type.CsUnderingDefineType()}({__json}.GetArrayLength()); foreach(JsonElement {__e} in {__json}.EnumerateArray()) {{ {type.ElementType.CsUnderingDefineType()} {__v}; {type.ElementType.Apply(this, $"{__e}", $"{__v}", depth + 1)} {x}.Add({__v}); }} }}";
return $"{{ var _json0 = {json}; {x} = new {type.CsUnderingDefineType()}(_json0.GetArrayLength()); foreach(JsonElement __e in _json0.EnumerateArray()) {{ {type.ElementType.CsUnderingDefineType()} __v; {type.ElementType.Apply(this, "__e", "__v")} {x}.Add(__v); }} }}";
}
public string Accept(TMap type, string json, string x, int depth)
public string Accept(TMap type, string json, string x)
{
string __e = $"__e{depth}";
string __k = $"_k{depth}";
string __v = $"_v{depth}";
string __json = $"__json{depth}";
return @$"{{ var {__json} = {json}; {x} = new {type.CsUnderingDefineType()}({__json}.GetArrayLength()); foreach(JsonElement {__e} in {__json}.EnumerateArray()) {{ {type.KeyType.CsUnderingDefineType()} {__k}; {type.KeyType.Apply(this, $"{__e}[0]", __k,depth + 1)} {type.ValueType.CsUnderingDefineType()} {__v}; {type.ValueType.Apply(this, $"{__e}[1]", __v, depth + 1)} {x}.Add({__k}, {__v}); }} }}";
return @$"{{ var _json0 = {json}; {x} = new {type.CsUnderingDefineType()}(_json0.GetArrayLength()); foreach(JsonElement __e in _json0.EnumerateArray()) {{ {type.KeyType.CsUnderingDefineType()} __k; {type.KeyType.Apply(this, "__e[0]", "__k")} {type.ValueType.CsUnderingDefineType()} __v; {type.ValueType.Apply(this, "__e[1]", "__v")} {x}.Add(__k, __v); }} }}";
}
public string Accept(TVector2 type, string json, string x, int depth)
public string Accept(TVector2 type, string json, string x)
{
return $"{{ var _json0 = {json}; float __x; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"x\")", "__x", depth) } float __y; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"y\")", "__y", depth) } {x} = new {type.Apply(CsDefineTypeName.Ins)}(__x, __y); }}";
return $"{{ var _json0 = {json}; float __x; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"x\")", "__x") } float __y; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"y\")", "__y") } {x} = new {type.Apply(CsDefineTypeName.Ins)}(__x, __y); }}";
}
public string Accept(TVector3 type, string json, string x, int depth)
public string Accept(TVector3 type, string json, string x)
{
return $"{{ var _json0 = {json}; float __x; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"x\")", "__x", depth) } float __y; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"y\")", "__y", depth) } float __z; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"z\")", "__z", depth) } {x} = new {type.Apply(CsDefineTypeName.Ins)}(__x, __y,__z); }}";
return $"{{ var _json0 = {json}; float __x; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"x\")", "__x") } float __y; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"y\")", "__y") } float __z; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"z\")", "__z") } {x} = new {type.Apply(CsDefineTypeName.Ins)}(__x, __y,__z); }}";
}
public string Accept(TVector4 type, string json, string x, int depth)
public string Accept(TVector4 type, string json, string x)
{
return $"{{ var _json0 = {json}; float __x; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"x\")", "__x", depth) } float __y; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"y\")", "__y", depth) } float __z; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"z\")", "__z", depth) } float __w; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"w\")", "__w", depth) } {x} = new {type.Apply(CsDefineTypeName.Ins)}(__x, __y, __z, __w); }}";
return $"{{ var _json0 = {json}; float __x; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"x\")", "__x") } float __y; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"y\")", "__y") } float __z; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"z\")", "__z") } float __w; {TFloat.Ins.Apply(this, "_json0.GetProperty(\"w\")", "__w") } {x} = new {type.Apply(CsDefineTypeName.Ins)}(__x, __y, __z, __w); }}";
}
public string Accept(TDateTime type, string json, string x, int depth)
public string Accept(TDateTime type, string json, string x)
{
return $"{x} = {json}.GetInt64();";
return $"{x} = {json}.GetInt32();";
}
}
}

View File

@ -1,162 +1,132 @@
using Luban.Job.Cfg.Datas;
using Luban.Job.Common.Types;
using Luban.Job.Common.TypeVisitors;
using Luban.Job.Common.Utils;
using System;
namespace Luban.Job.Cfg.TypeVisitors
{
class CsUnityJsonDeserialize : ITypeFuncVisitor<string, string, int, string>
class CsUnityJsonDeserialize : ITypeFuncVisitor<string, string, string>
{
public static CsUnityJsonDeserialize Ins { get; } = new();
public string Accept(TBool type, string json, string x, int depth)
public string Accept(TBool type, string json, string x)
{
return $"{{ if(!{json}.IsBoolean) {{ throw new SerializationException(); }} {x} = {json}; }}";
}
public string Accept(TByte type, string json, string x, int depth)
public string Accept(TByte type, string json, string x)
{
return $"{{ if(!{json}.IsNumber) {{ throw new SerializationException(); }} {x} = {json}; }}";
}
public string Accept(TShort type, string json, string x, int depth)
public string Accept(TShort type, string json, string x)
{
return $"{{ if(!{json}.IsNumber) {{ throw new SerializationException(); }} {x} = {json}; }}";
}
public string Accept(TFshort type, string json, string x, int depth)
public string Accept(TFshort type, string json, string x)
{
return $"{{ if(!{json}.IsNumber) {{ throw new SerializationException(); }} {x} = {json}; }}";
}
public string Accept(TInt type, string json, string x, int depth)
public string Accept(TInt type, string json, string x)
{
return $"{{ if(!{json}.IsNumber) {{ throw new SerializationException(); }} {x} = {json}; }}";
}
public string Accept(TFint type, string json, string x, int depth)
public string Accept(TFint type, string json, string x)
{
return $"{{ if(!{json}.IsNumber) {{ throw new SerializationException(); }} {x} = {json}; }}";
}
public string Accept(TLong type, string json, string x, int depth)
public string Accept(TLong type, string json, string x)
{
return $"{{ if(!{json}.IsNumber) {{ throw new SerializationException(); }} {x} = {json}; }}";
}
public string Accept(TFlong type, string json, string x, int depth)
public string Accept(TFlong type, string json, string x)
{
return $"{{ if(!{json}.IsNumber) {{ throw new SerializationException(); }} {x} = {json}; }}";
}
public string Accept(TFloat type, string json, string x, int depth)
public string Accept(TFloat type, string json, string x)
{
return $"{{ if(!{json}.IsNumber) {{ throw new SerializationException(); }} {x} = {json}; }}";
}
public string Accept(TDouble type, string json, string x, int depth)
public string Accept(TDouble type, string json, string x)
{
return $"{{ if(!{json}.IsNumber) {{ throw new SerializationException(); }} {x} = {json}; }}";
}
public string Accept(TEnum type, string json, string x, int depth)
public string Accept(TEnum type, string json, string x)
{
return $"{{ if(!{json}.IsNumber) {{ throw new SerializationException(); }} {x} = ({type.CsUnderingDefineType()}){json}.AsInt; }}";
}
public string Accept(TString type, string json, string x, int depth)
public string Accept(TString type, string json, string x)
{
return $"{{ if(!{json}.IsString) {{ throw new SerializationException(); }} {x} = {json}; }}";
}
public string Accept(TBytes type, string json, string x, int depth)
public string Accept(TBytes type, string json, string x)
{
throw new NotSupportedException();
}
public string Accept(TText type, string json, string x, int depth)
public string Accept(TText type, string json, string x)
{
return $"{{ if(!{json}[\"{DText.KEY_NAME}\"].IsString) {{ throw new SerializationException(); }} {x}{TText.L10N_FIELD_SUFFIX} = {json}[\"{DText.KEY_NAME}\"]; if(!{json}[\"{DText.TEXT_NAME}\"].IsString) {{ throw new SerializationException(); }} {x} = {json}[\"{DText.TEXT_NAME}\"]; }}";
}
public string Accept(TBean type, string json, string x, int depth)
public string Accept(TBean type, string json, string x)
{
string src = $"{type.Bean.FullName}.Deserialize{type.Bean.Name}({json})";
return $"{{ if(!{json}.IsObject) {{ throw new SerializationException(); }} {x} = {ExternalTypeUtil.CsCloneToExternal(type.Bean.FullName, src)}; }}";
return $"{{ if(!{json}.IsObject) {{ throw new SerializationException(); }} {x} = {type.CsUnderingDefineType()}.Deserialize{type.Bean.Name}({json}); }}";
}
public string Accept(TArray type, string json, string x, int depth)
public string Accept(TArray type, string json, string x)
{
string _n = $"_n{depth}";
string __e = $"__e{depth}";
string __v = $"__v{depth}";
string __json = $"__json{depth}";
string __index = $"__index{depth}";
string tempJsonName = __json;
string typeStr = $"{type.ElementType.Apply(CsDefineTypeName.Ins)}[{_n}]";
if (type.Dimension > 1)
{
if (type.FinalElementType == null)
{
throw new System.Exception("¶àάÊý×éûÓÐÔªËØÀàÐÍ");
}
typeStr = $"{type.FinalElementType.Apply(CsUnderingDefineTypeName.Ins)}[{_n}]";
for (int i = 0; i < type.Dimension - 1; i++)
{
typeStr += "[]";
}
}
return $"{{ var {tempJsonName} = {json}; if(!{tempJsonName}.IsArray) {{ throw new SerializationException(); }} int {_n} = {tempJsonName}.Count; {x} = new {typeStr}; int {__index}=0; foreach(JSONNode {__e} in {tempJsonName}.Children) {{ {type.ElementType.CsUnderingDefineType()} {__v}; {type.ElementType.Apply(this, __e, __v, depth + 1)} {x}[{__index}++] = {__v}; }} }}";
string tempJsonName = $"_json1";
return $"{{ var {tempJsonName} = {json}; if(!{tempJsonName}.IsArray) {{ throw new SerializationException(); }} int _n = {tempJsonName}.Count; {x} = new {type.ElementType.CsUnderingDefineType()}[_n]; int _index=0; foreach(JSONNode __e in {tempJsonName}.Children) {{ {type.ElementType.CsUnderingDefineType()} __v; {type.ElementType.Apply(this, "__e", "__v")} {x}[_index++] = __v; }} }}";
}
public string Accept(TList type, string json, string x, int depth)
public string Accept(TList type, string json, string x)
{
string __e = $"__e{depth}";
string __v = $"__v{depth}";
string __json = $"__json{depth}";
string tempJsonName = __json;
return $"{{ var {tempJsonName} = {json}; if(!{tempJsonName}.IsArray) {{ throw new SerializationException(); }} {x} = new {type.CsUnderingDefineType()}({tempJsonName}.Count); foreach(JSONNode {__e} in {tempJsonName}.Children) {{ {type.ElementType.CsUnderingDefineType()} {__v}; {type.ElementType.Apply(this, __e, __v, depth + 1)} {x}.Add({__v}); }} }}";
string tempJsonName = $"_json1";
return $"{{ var {tempJsonName} = {json}; if(!{tempJsonName}.IsArray) {{ throw new SerializationException(); }} {x} = new {type.CsUnderingDefineType()}({tempJsonName}.Count); foreach(JSONNode __e in {tempJsonName}.Children) {{ {type.ElementType.CsUnderingDefineType()} __v; {type.ElementType.Apply(this, "__e", "__v")} {x}.Add(__v); }} }}";
}
public string Accept(TSet type, string json, string x, int depth)
public string Accept(TSet type, string json, string x)
{
string __e = $"__e{depth}";
string __v = $"__v{depth}";
string __json = $"__json{depth}";
string tempJsonName = __json;
return $"{{ var {tempJsonName} = {json}; if(!{tempJsonName}.IsArray) {{ throw new SerializationException(); }} {x} = new {type.CsUnderingDefineType()}(/*{tempJsonName}.Count*/); foreach(JSONNode {__e} in {tempJsonName}.Children) {{ {type.ElementType.CsUnderingDefineType()} {__v}; {type.ElementType.Apply(this, __e, __v, depth + 1)} {x}.Add({__v}); }} }}";
string tempJsonName = $"_json1";
return $"{{ var {tempJsonName} = {json}; if(!{tempJsonName}.IsArray) {{ throw new SerializationException(); }} {x} = new {type.CsUnderingDefineType()}(/*{tempJsonName}.Count*/); foreach(JSONNode __e in {tempJsonName}.Children) {{ {type.ElementType.CsUnderingDefineType()} __v; {type.ElementType.Apply(this, "__e", "__v")} {x}.Add(__v); }} }}";
}
public string Accept(TMap type, string json, string x, int depth)
public string Accept(TMap type, string json, string x)
{
string __e = $"__e{depth}";
string __k = $"_k{depth}";
string __v = $"_v{depth}";
string __json = $"__json{depth}";
string tempJsonName = __json;
return @$"{{ var {tempJsonName} = {json}; if(!{tempJsonName}.IsArray) {{ throw new SerializationException(); }} {x} = new {type.CsUnderingDefineType()}({tempJsonName}.Count); foreach(JSONNode {__e} in {tempJsonName}.Children) {{ {type.KeyType.CsUnderingDefineType()} {__k}; {type.KeyType.Apply(this, $"{__e}[0]", __k, depth + 1)} {type.ValueType.CsUnderingDefineType()} { __v}; {type.ValueType.Apply(this, $"{__e}[1]", __v, depth + 1)} {x}.Add({__k}, { __v}); }} }}";
string tempJsonName = $"_json1";
return @$"{{ var {tempJsonName} = {json}; if(!{tempJsonName}.IsArray) {{ throw new SerializationException(); }} {x} = new {type.CsUnderingDefineType()}({tempJsonName}.Count); foreach(JSONNode __e in {tempJsonName}.Children) {{ {type.KeyType.CsUnderingDefineType()} __k; {type.KeyType.Apply(this, "__e[0]", "__k")} {type.ValueType.CsUnderingDefineType()} __v; {type.ValueType.Apply(this, "__e[1]", "__v")} {x}.Add(__k, __v); }} }}";
}
public string Accept(TVector2 type, string json, string x, int depth)
public string Accept(TVector2 type, string json, string x)
{
string tempJsonName = $"_json2";
return $"{{ var {tempJsonName} = {json}; if(!{tempJsonName}.IsObject) {{ throw new SerializationException(); }} float __x; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"x\"]", "__x", depth) } float __y; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"y\"]", "__y", depth) } {x} = new {type.Apply(CsDefineTypeName.Ins)}(__x, __y); }}";
return $"{{ var {tempJsonName} = {json}; if(!{tempJsonName}.IsObject) {{ throw new SerializationException(); }} float __x; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"x\"]", "__x") } float __y; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"y\"]", "__y") } {x} = new {type.Apply(CsDefineTypeName.Ins)}(__x, __y); }}";
}
public string Accept(TVector3 type, string json, string x, int depth)
public string Accept(TVector3 type, string json, string x)
{
string tempJsonName = $"_json2";
return $"{{ var {tempJsonName} = {json}; if(!{tempJsonName}.IsObject) {{ throw new SerializationException(); }} float __x; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"x\"]", "__x", depth) } float __y; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"y\"]", "__y", depth) } float __z; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"z\"]", "__z", depth) } {x} = new {type.Apply(CsDefineTypeName.Ins)}(__x, __y,__z); }}";
return $"{{ var {tempJsonName} = {json}; if(!{tempJsonName}.IsObject) {{ throw new SerializationException(); }} float __x; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"x\"]", "__x") } float __y; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"y\"]", "__y") } float __z; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"z\"]", "__z") } {x} = new {type.Apply(CsDefineTypeName.Ins)}(__x, __y,__z); }}";
}
public string Accept(TVector4 type, string json, string x, int depth)
public string Accept(TVector4 type, string json, string x)
{
string tempJsonName = $"_json2";
return $"{{ var {tempJsonName} = {json}; if(!{tempJsonName}.IsObject) {{ throw new SerializationException(); }} float __x; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"x\"]", "__x", depth) } float __y; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"y\"]", "__y", depth) } float __z; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"z\"]", "__z", depth) } float __w; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"w\"]", "__w", depth) } {x} = new {type.Apply(CsDefineTypeName.Ins)}(__x, __y, __z, __w); }}";
return $"{{ var {tempJsonName} = {json}; if(!{tempJsonName}.IsObject) {{ throw new SerializationException(); }} float __x; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"x\"]", "__x") } float __y; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"y\"]", "__y") } float __z; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"z\"]", "__z") } float __w; {TFloat.Ins.Apply(this, $"{tempJsonName}[\"w\"]", "__w") } {x} = new {type.Apply(CsDefineTypeName.Ins)}(__x, __y, __z, __w); }}";
}
public string Accept(TDateTime type, string json, string x, int depth)
public string Accept(TDateTime type, string json, string x)
{
return $"{{ if(!{json}.IsNumber) {{ throw new SerializationException(); }} {x} = {json}; }}";
}

View File

@ -1,159 +0,0 @@
using Luban.Job.Cfg.Datas;
using Luban.Job.Common.Types;
using Luban.Job.Common.TypeVisitors;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Luban.Job.Cfg.TypeVisitors
{
class GDScriptUnderingDeserializeVisitor : ITypeFuncVisitor<string, string, string>
{
public static GDScriptUnderingDeserializeVisitor Ins { get; } = new();
public string Accept(TBool type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TByte type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TShort type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TFshort type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TInt type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TFint type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TLong type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TFlong type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TFloat type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TDouble type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TEnum type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TString type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TBytes type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName}";
}
public string Accept(TText type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName}['{DText.TEXT_NAME}']";
}
public string Accept(TBean type, string jsonVarName, string fieldName)
{
if (type.Bean.IsAbstractType)
{
return $"{fieldName} = {type.Bean.GDScriptFullName}.from_json({jsonVarName})";
}
else
{
return $"{fieldName} = {type.Bean.GDScriptFullName}.new({jsonVarName})";
}
}
public string Accept(TArray type, string jsonVarName, string fieldName)
{
if (type.Apply(SimpleJsonTypeVisitor.Ins))
{
return $"{fieldName} = {jsonVarName}";
}
else
{
return $"{fieldName} = []\n for _ele in {jsonVarName}:\n var {type.ElementType.Apply(this, "_ele", "_e")};\n {fieldName}.append(_e)";
}
}
public string Accept(TList type, string jsonVarName, string fieldName)
{
if (type.Apply(SimpleJsonTypeVisitor.Ins))
{
return $"{fieldName} = {jsonVarName}";
}
else
{
return $"{fieldName} = []\n for _ele in {jsonVarName}:\n var {type.ElementType.Apply(this, "_ele", "_e")};\n {fieldName}.append(_e)";
}
}
public string Accept(TSet type, string jsonVarName, string fieldName)
{
if (type.Apply(SimpleJsonTypeVisitor.Ins))
{
return $"{fieldName} = {jsonVarName}";
}
else
{
return $"{fieldName} = set()\n for _ele in {jsonVarName}:\n var {type.ElementType.Apply(this, "_ele", "_e")};\n {fieldName}.add(_e)";
}
}
public string Accept(TMap type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {{}}\n for _v in {jsonVarName}:\n {fieldName}[_v[0]] =_v[1]";
}
public string Accept(TVector2 type, string jsonVarName, string fieldName)
{
return $"{fieldName} = Vector2({jsonVarName}['x'], {jsonVarName}['y'])";
}
public string Accept(TVector3 type, string jsonVarName, string fieldName)
{
return $"{fieldName} = Vector3({jsonVarName}['x'], {jsonVarName}['y'], {jsonVarName}['z'])";
}
public string Accept(TVector4 type, string jsonVarName, string fieldName)
{
return $"{fieldName} = Vector3({jsonVarName}['x'], {jsonVarName}['y'], {jsonVarName}['z'])";
}
public string Accept(TDateTime type, string jsonVarName, string fieldName)
{
return $"{fieldName} = {jsonVarName}";
}
}
}

View File

@ -5,81 +5,81 @@ using System;
namespace Luban.Job.Cfg.TypeVisitors
{
class JavaJsonDeserialize : ITypeFuncVisitor<string, string, int, string>
class JavaJsonDeserialize : ITypeFuncVisitor<string, string, string>
{
public static JavaJsonDeserialize Ins { get; } = new();
public string Accept(TBool type, string json, string x, int depth)
public string Accept(TBool type, string json, string x)
{
return $"{x} = {json}.getAsBoolean();";
}
public string Accept(TByte type, string json, string x, int depth)
public string Accept(TByte type, string json, string x)
{
return $"{x} = {json}.getAsByte();";
}
public string Accept(TShort type, string json, string x, int depth)
public string Accept(TShort type, string json, string x)
{
return $"{x} = {json}.getAsShort();";
}
public string Accept(TFshort type, string json, string x, int depth)
public string Accept(TFshort type, string json, string x)
{
return $"{x} = {json}.getAsShort();";
}
public string Accept(TInt type, string json, string x, int depth)
public string Accept(TInt type, string json, string x)
{
return $"{x} = {json}.getAsInt();";
}
public string Accept(TFint type, string json, string x, int depth)
public string Accept(TFint type, string json, string x)
{
return $"{x} = {json}.getAsInt();";
}
public string Accept(TLong type, string json, string x, int depth)
public string Accept(TLong type, string json, string x)
{
return $"{x} = {json}.getAsLong();";
}
public string Accept(TFlong type, string json, string x, int depth)
public string Accept(TFlong type, string json, string x)
{
return $"{x} = {json}.getAsLong();";
}
public string Accept(TFloat type, string json, string x, int depth)
public string Accept(TFloat type, string json, string x)
{
return $"{x} = {json}.getAsFloat();";
}
public string Accept(TDouble type, string json, string x, int depth)
public string Accept(TDouble type, string json, string x)
{
return $"{x} = {json}.getAsDouble();";
}
public string Accept(TEnum type, string json, string x, int depth)
public string Accept(TEnum type, string json, string x)
{
return $"{x} = {json}.getAsInt();";
return $"{x} = {type.DefineEnum.FullNameWithTopModule}.valueOf({json}.getAsInt());";
}
public string Accept(TString type, string json, string x, int depth)
public string Accept(TString type, string json, string x)
{
return $"{x} = {json}.getAsString();";
}
public string Accept(TBytes type, string json, string x, int depth)
public string Accept(TBytes type, string json, string x)
{
throw new NotSupportedException();
}
public string Accept(TText type, string json, string x, int depth)
public string Accept(TText type, string json, string x)
{
return $"{json}.getAsJsonObject().get(\"{DText.KEY_NAME}\").getAsString(); {x} = {json}.getAsJsonObject().get(\"{DText.TEXT_NAME}\").getAsString();";
}
public string Accept(TBean type, string json, string x, int depth)
public string Accept(TBean type, string json, string x)
{
if (type.IsDynamic)
{
@ -91,68 +91,44 @@ namespace Luban.Job.Cfg.TypeVisitors
}
}
public string Accept(TArray type, string json, string x, int depth)
public string Accept(TArray type, string json, string x)
{
string __n = $"__n{depth}";
string __e = $"__e{depth}";
string __v = $"__v{depth}";
string __index = $"__index{depth}";
string typeStr = $"{type.ElementType.Apply(JavaDefineTypeName.Ins)}[{__n}]";
if (type.Dimension > 1)
{
if (type.FinalElementType == null)
{
throw new System.Exception("多维数组没有元素类型");
}
typeStr = $"{type.FinalElementType.Apply(JavaDefineTypeName.Ins)}[{__n}]";
for (int i = 0; i < type.Dimension - 1; i++)
{
typeStr += "[]";
}
}
return $"{{ com.google.gson.JsonArray _json{depth}_ = {json}.getAsJsonArray(); int {__n} = _json{depth}_.size(); {x} = new {typeStr}; int {__index}=0; for(JsonElement {__e} : _json{depth}_) {{ {type.ElementType.Apply(JavaDefineTypeName.Ins)} {__v}; {type.ElementType.Apply(this, $"{__e}", $"{__v}", depth + 1)} {x}[{__index}++] = {__v}; }} }}";
return $"{{ com.google.gson.JsonArray _json0_ = {json}.getAsJsonArray(); int _n = _json0_.size(); {x} = new {type.ElementType.Apply(JavaDefineTypeName.Ins)}[_n]; int _index=0; for(JsonElement __e : _json0_) {{ {type.ElementType.Apply(JavaDefineTypeName.Ins)} __v; {type.ElementType.Apply(this, "__e", "__v")} {x}[_index++] = __v; }} }}";
}
public string Accept(TList type, string json, string x, int depth)
public string Accept(TList type, string json, string x)
{
string __e = $"_e{depth}";
string __v = $"_v{depth}";
return $"{{ com.google.gson.JsonArray _json{depth}_ = {json}.getAsJsonArray(); {x} = new {type.Apply(JavaDefineTypeName.Ins)}(_json{depth}_.size()); for(JsonElement {__e} : _json{depth}_) {{ {type.ElementType.Apply(JavaDefineTypeName.Ins)} {__v}; {type.ElementType.Apply(this, __e, __v, depth + 1)} {x}.add({__v}); }} }}";
return $"{{ com.google.gson.JsonArray _json0_ = {json}.getAsJsonArray(); {x} = new {type.Apply(JavaDefineTypeName.Ins)}(_json0_.size()); for(JsonElement __e : _json0_) {{ {type.ElementType.Apply(JavaDefineTypeName.Ins)} __v; {type.ElementType.Apply(this, "__e", "__v")} {x}.add(__v); }} }}";
}
public string Accept(TSet type, string json, string x, int depth)
public string Accept(TSet type, string json, string x)
{
string __e = $"_e{depth}";
string __v = $"_v{depth}";
return $"{{ com.google.gson.JsonArray _json{depth}_ = {json}.getAsJsonArray(); {x} = new {type.Apply(JavaDefineTypeName.Ins)}(_json{depth}_.size()); for(JsonElement {__e} : _json{depth}_) {{ {type.ElementType.Apply(JavaDefineTypeName.Ins)} {__v}; {type.ElementType.Apply(this, __e, __v, depth + 1)} {x}.add({__v}); }} }}";
return $"{{ com.google.gson.JsonArray _json0_ = {json}.getAsJsonArray(); {x} = new {type.Apply(JavaDefineTypeName.Ins)}(_json0_.size()); for(JsonElement __e : _json0_) {{ {type.ElementType.Apply(JavaDefineTypeName.Ins)} __v; {type.ElementType.Apply(this, "__e", "__v")} {x}.add(__v); }} }}";
}
public string Accept(TMap type, string json, string x, int depth)
public string Accept(TMap type, string json, string x)
{
string __e = $"_e{depth}";
string __k = $"_k{depth}";
string __v = $"_v{depth}";
return @$"{{ com.google.gson.JsonArray _json{depth}_ = {json}.getAsJsonArray(); {x} = new {type.Apply(JavaDefineTypeName.Ins)}(_json{depth}_.size()); for(JsonElement {__e} : _json{depth}_) {{ {type.KeyType.Apply(JavaDefineTypeName.Ins)} {__k}; {type.KeyType.Apply(this, $"{__e}.getAsJsonArray().get(0)", __k, depth + 1)} {type.ValueType.Apply(JavaDefineTypeName.Ins)} {__v}; {type.ValueType.Apply(this, $"{__e}.getAsJsonArray().get(1)", __v, depth + 1)} {x}.put({__k}, {__v}); }} }}";
return @$"{{ com.google.gson.JsonArray _json0_ = {json}.getAsJsonArray(); {x} = new {type.Apply(JavaDefineTypeName.Ins)}(_json0_.size()); for(JsonElement __e : _json0_) {{ {type.KeyType.Apply(JavaDefineTypeName.Ins)} __k; {type.KeyType.Apply(this, "__e.getAsJsonArray().get(0)", "__k")} {type.ValueType.Apply(JavaDefineTypeName.Ins)} __v; {type.ValueType.Apply(this, "__e.getAsJsonArray().get(1)", "__v")} {x}.put(__k, __v); }} }}";
}
public string Accept(TVector2 type, string json, string x, int depth)
public string Accept(TVector2 type, string json, string x)
{
return $"{{ com.google.gson.JsonObject _json{depth}_ = {json}.getAsJsonObject(); float __x; {TFloat.Ins.Apply(this, $"_json{depth}_.get(\"x\")", "__x", depth)} float __y; {TFloat.Ins.Apply(this, $"_json{depth}_.get(\"y\")", "__y", depth)} {x} = new {type.Apply(JavaDefineTypeName.Ins)}(__x, __y); }}";
return $"{{ com.google.gson.JsonObject _json0_ = {json}.getAsJsonObject(); float __x; {TFloat.Ins.Apply(this, "_json0_.get(\"x\")", "__x") } float __y; {TFloat.Ins.Apply(this, "_json0_.get(\"y\")", "__y") } {x} = new {type.Apply(JavaDefineTypeName.Ins)}(__x, __y); }}";
}
public string Accept(TVector3 type, string json, string x, int depth)
public string Accept(TVector3 type, string json, string x)
{
return $"{{ com.google.gson.JsonObject _json{depth}_ = {json}.getAsJsonObject(); float __x; {TFloat.Ins.Apply(this, $"_json{depth}_.get(\"x\")", "__x", depth)} float __y; {TFloat.Ins.Apply(this, $"_json{depth}_.get(\"y\")", "__y", depth)} float __z; {TFloat.Ins.Apply(this, $"_json{depth}_.get(\"z\")", "__z", depth)} {x} = new {type.Apply(JavaDefineTypeName.Ins)}(__x, __y,__z); }}";
return $"{{ com.google.gson.JsonObject _json0_ = {json}.getAsJsonObject(); float __x; {TFloat.Ins.Apply(this, "_json0_.get(\"x\")", "__x") } float __y; {TFloat.Ins.Apply(this, "_json0_.get(\"y\")", "__y") } float __z; {TFloat.Ins.Apply(this, "_json0_.get(\"z\")", "__z") } {x} = new {type.Apply(JavaDefineTypeName.Ins)}(__x, __y,__z); }}";
}
public string Accept(TVector4 type, string json, string x, int depth)
public string Accept(TVector4 type, string json, string x)
{
return $"{{ com.google.gson.JsonObject _json{depth}_ = {json}.getAsJsonObject(); float __x; {TFloat.Ins.Apply(this, $"_json{depth}_.get(\"x\")", "__x", depth)} float __y; {TFloat.Ins.Apply(this, $"_json{depth}_.get(\"y\")", "__y", depth)} float __z; {TFloat.Ins.Apply(this, $"_json{depth}_.get(\"z\")", "__z", depth)} float __w; {TFloat.Ins.Apply(this, $"_json{depth}_.get(\"w\")", "__w", depth)} {x} = new {type.Apply(JavaDefineTypeName.Ins)}(__x, __y, __z, __w); }}";
return $"{{ com.google.gson.JsonObject _json0_ = {json}.getAsJsonObject(); float __x; {TFloat.Ins.Apply(this, "_json0_.get(\"x\")", "__x") } float __y; {TFloat.Ins.Apply(this, "_json0_.get(\"y\")", "__y") } float __z; {TFloat.Ins.Apply(this, "_json0_.get(\"z\")", "__z") } float __w; {TFloat.Ins.Apply(this, "_json0_.get(\"w\")", "__w") } {x} = new {type.Apply(JavaDefineTypeName.Ins)}(__x, __y, __z, __w); }}";
}
public string Accept(TDateTime type, string json, string x, int depth)
public string Accept(TDateTime type, string json, string x)
{
return $"{x} = {json}.getAsLong();";
return $"{x} = {json}.getAsInt();";
}
}
}

View File

@ -59,7 +59,7 @@ namespace Luban.Job.Cfg.TypeVisitors
public string Accept(TEnum type, string bufName, string fieldName)
{
return $"{fieldName} = {bufName}.readInt();";
return $"{fieldName} = {type.DefineEnum.FullNameWithTopModule}.valueOf({bufName}.readInt());";
}
public string Accept(TString type, string bufName, string fieldName)
@ -127,7 +127,7 @@ namespace Luban.Job.Cfg.TypeVisitors
public string Accept(TDateTime type, string bufName, string fieldName)
{
return $"{fieldName} = {bufName}.readLong();";
return $"{fieldName} = {bufName}.readInt();";
}
}
}

View File

@ -125,7 +125,7 @@ namespace Luban.Job.Cfg.TypeVisitors
public string Accept(TDateTime type, string jsonVarName)
{
return AsType(jsonVarName, "i64");
return AsType(jsonVarName, "i32");
}
}
}

View File

@ -122,7 +122,7 @@ namespace Luban.Job.Cfg.TypeVisitors
public string Accept(TDateTime type)
{
return "int64";
return "int32";
}
}
}

View File

@ -11,7 +11,6 @@ using Luban.Job.Common.Tpl;
using Luban.Job.Common.Types;
using Luban.Job.Common.Utils;
using MessagePack;
using Newtonsoft.Json.Bson;
using Scriban;
using System;
using System.Collections.Generic;
@ -44,14 +43,6 @@ namespace Luban.Job.Cfg.Utils
ThreadLocalTemporalByteBufPool.Free(buf);
return bytes;
}
case "data_bidx":
{
var buf = ThreadLocalTemporalByteBufPool.Alloc(1024 * 1024);
BinaryIndexExportor.Ins.WriteList(table, records, buf);
var bytes = buf.CopyData();
ThreadLocalTemporalByteBufPool.Free(buf);
return bytes;
}
case "data_json":
case "data_json2":
{
@ -88,14 +79,6 @@ namespace Luban.Job.Cfg.Utils
tw.Flush();
return DataUtil.StreamToBytes(ms);
}
case "data_bson":
{
var ss = new MemoryStream();
var bsonWriter = new BsonDataWriter(ss);
BsonExportor.Ins.WriteAsArray(records, bsonWriter);
bsonWriter.Flush();
return DataUtil.StreamToBytes(ss);
}
case "data_xml":
{
var xwSetting = new XmlWriterSettings() { Indent = true };

View File

@ -4,7 +4,6 @@ using Luban.Job.Cfg.Cache;
using Luban.Job.Cfg.DataCreators;
using Luban.Job.Cfg.Datas;
using Luban.Job.Cfg.DataSources;
using Luban.Job.Cfg.DataSources.Excel;
using Luban.Job.Cfg.Defs;
using Luban.Job.Common.Types;
using Luban.Job.Common.Utils;
@ -96,7 +95,7 @@ namespace Luban.Job.Cfg.Utils
file.OriginFile,
file.SheetName,
await agent.GetFromCacheOrReadAllBytesAsync(file.ActualFile, file.MD5),
IsMultiRecordFile(file.ActualFile, file.SheetName), table.Options);
IsMultiRecordFile(file.ActualFile, file.SheetName));
FileRecordCacheManager.Ins.AddCacheLoadedRecords(table, file.MD5, file.SheetName, res);
@ -189,10 +188,10 @@ namespace Luban.Job.Cfg.Utils
await Task.WhenAll(genDataTasks.ToArray());
}
public static List<Record> LoadCfgRecords(TBean recordType, string originFile, string sheetName, byte[] content, bool multiRecord, Dictionary<string, string> options)
public static List<Record> LoadCfgRecords(TBean recordType, string originFile, string sheetName, byte[] content, bool multiRecord)
{
// (md5,sheet,multiRecord,exportTestData) -> (valuetype, List<(datas)>)
var dataSource = DataSourceFactory.Create(originFile, sheetName, options, new MemoryStream(content));
var dataSource = DataSourceFactory.Create(originFile, sheetName, new MemoryStream(content));
try
{
if (multiRecord)

View File

@ -1,5 +1,4 @@
using Luban.Common.Utils;
using Luban.Job.Cfg.DataCreators;
using Luban.Job.Cfg.Datas;
using Luban.Job.Cfg.DataSources;
using Luban.Job.Cfg.Defs;
@ -30,7 +29,7 @@ namespace Luban.Job.Cfg.Utils
var values = SplitVectorString(x);
if (values.Length != 2)
{
throw new Exception($"'{x}' 不是合法vector2类型数据");
throw new Exception($"'{x}' 不是合法vector2类型数据");
}
return new DVector2(new System.Numerics.Vector2(float.Parse(values[0]), float.Parse(values[1])));
@ -41,7 +40,7 @@ namespace Luban.Job.Cfg.Utils
var values = SplitVectorString(x);
if (values.Length != 3)
{
throw new Exception($"'{x}' 不是合法vector3类型数据");
throw new Exception($"'{x}' 不是合法vector3类型数据");
}
return new DVector3(new System.Numerics.Vector3(float.Parse(values[0]), float.Parse(values[1]), float.Parse(values[2])));
@ -52,7 +51,7 @@ namespace Luban.Job.Cfg.Utils
var values = SplitVectorString(x);
if (values.Length != 4)
{
throw new Exception($"'{x}' 不是合法vector4类型数据");
throw new Exception($"'{x}' 不是合法vector4类型数据");
}
return new DVector4(new System.Numerics.Vector4(float.Parse(values[0]), float.Parse(values[1]), float.Parse(values[2]), float.Parse(values[3])));
}
@ -112,10 +111,6 @@ namespace Luban.Job.Cfg.Utils
{
return s.Replace("\\", "\\\\").Replace("\"", "\\\"");
}
public static string UnEscapeString(string s)
{
return s.Replace("\\\"", "\"").Replace("\\\"", "\"");
}
public static string EscapeLuaStringWithQuote(string s)
{
@ -168,11 +163,11 @@ namespace Luban.Job.Cfg.Utils
{
if (key == null || text == null)
{
throw new Exception("text的key或text属性不能为null");
throw new Exception("text的key或text属性不能为null");
}
if (key == "" && text != "")
{
throw new Exception($"text key为空, 但text:'{text}'不为空");
throw new Exception($"text key为空, 但text:'{text}'不为空");
}
}
@ -248,37 +243,20 @@ namespace Luban.Job.Cfg.Utils
{
if (string.IsNullOrEmpty(subType))
{
throw new Exception($"module:'{bean.Namespace}' 多态数据type不能为空");
throw new Exception($"module:'{bean.Namespace}' 多态数据type不能为空");
}
DefBean defType = bean.GetHierarchyChildren().Cast<DefBean>().Where(c => c.Alias == subType || c.Name == subType || c.FullName == subType).FirstOrDefault();
if (defType == null)
{
throw new Exception($"module:'{bean.Namespace}' type:'{subType}' 不是合法类型");
throw new Exception($"module:'{bean.Namespace}' type:'{subType}' 不是合法类型");
}
if (defType.IsAbstractType)
{
throw new Exception($"module:'{bean.Namespace}' type:'{subType}' 是抽象类. 不能创建实例");
throw new Exception($"module:'{bean.Namespace}' type:'{subType}' 是抽象类. 不能创建实例");
}
return defType;
}
public static bool ParseExcelBool(string s)
{
s = s.ToLower().Trim();
switch (s)
{
case "true":
case "1":
case "y":
case "yes": return true;
case "false":
case "0":
case "n":
case "no": return false;
default: throw new InvalidExcelDataException($"{s} 不是 bool 类型的值 (true|1|y|yes 或 false|0|n|no)");
}
}
//public static string Data2String(DType data)
//{
// var s = new StringBuilder();

View File

@ -5,7 +5,6 @@ using Luban.Job.Common.Types;
using Luban.Job.Common.TypeVisitors;
using System;
using System.Linq;
using JavaDeserializeVisitor = Luban.Job.Cfg.TypeVisitors.JavaDeserializeVisitor;
namespace Luban.Job.Cfg.Utils
{
@ -30,11 +29,11 @@ namespace Luban.Job.Cfg.Utils
{
if (type.IsNullable)
{
return $"{{ if ({bufName}.TryGetProperty(\"{jsonFieldName}\", out var _j) && _j.ValueKind != JsonValueKind.Null) {{ {type.Apply(TypeVisitors.CsJsonDeserialize.Ins, "_j", fieldName, 0)} }} else {{ {fieldName} = null; }} }}";
return $"{{ if ({bufName}.TryGetProperty(\"{jsonFieldName}\", out var _j) && _j.ValueKind != JsonValueKind.Null) {{ {type.Apply(TypeVisitors.CsJsonDeserialize.Ins, "_j", fieldName)} }} else {{ {fieldName} = null; }} }}";
}
else
{
return type.Apply(TypeVisitors.CsJsonDeserialize.Ins, $"{bufName}.GetProperty(\"{jsonFieldName}\")", fieldName, 0);
return type.Apply(TypeVisitors.CsJsonDeserialize.Ins, $"{bufName}.GetProperty(\"{jsonFieldName}\")", fieldName);
}
}
@ -47,11 +46,11 @@ namespace Luban.Job.Cfg.Utils
{
if (type.IsNullable)
{
return $"{{ var _j = {bufName}[\"{jsonFieldName}\"]; if (_j.Tag != JSONNodeType.None && _j.Tag != JSONNodeType.NullValue) {{ {type.Apply(TypeVisitors.CsUnityJsonDeserialize.Ins, "_j", fieldName, 0)} }} else {{ {fieldName} = null; }} }}";
return $"{{ var _j = {bufName}[\"{jsonFieldName}\"]; if (_j.Tag != JSONNodeType.None && _j.Tag != JSONNodeType.NullValue) {{ {type.Apply(TypeVisitors.CsUnityJsonDeserialize.Ins, "_j", fieldName)} }} else {{ {fieldName} = null; }} }}";
}
else
{
return type.Apply(TypeVisitors.CsUnityJsonDeserialize.Ins, $"{bufName}[\"{jsonFieldName}\"]", fieldName, 0);
return type.Apply(TypeVisitors.CsUnityJsonDeserialize.Ins, $"{bufName}[\"{jsonFieldName}\"]", fieldName);
}
}
@ -86,16 +85,16 @@ namespace Luban.Job.Cfg.Utils
{
case TArray:
{
return $@"{{ int __n = {name}.Length; {table.FullName} __table = ({table.FullName})_tables[""{tableName}""]; this.{refVarName} = new {table.ValueTType.Apply(CsDefineTypeName.Ins)}[__n]; for(int i = 0 ; i < __n ; i++) {{ this.{refVarName}[i] = __table.GetOrDefault({name}[i]); }} }}";
return $@"{{ int __n = {name}.Length; {table.FullName} __table = ({table.FullName})_tables[""{ tableName}""]; this.{refVarName} = new {table.ValueTType.Apply(CsDefineTypeName.Ins)}[__n]; for(int i = 0 ; i < __n ; i++) {{ this.{refVarName}[i] = __table.GetOrDefault({name}[i]); }} }}";
}
case TList:
case TSet:
{
return $@"{{ {table.FullName} __table = ({table.FullName})_tables[""{tableName}""]; this.{refVarName} = new {field.ElementRefType.Apply(CsDefineTypeName.Ins)}(); foreach(var __e in {name}) {{ this.{refVarName}.Add(__table.GetOrDefault(__e)); }} }}";
return $@"{{ {table.FullName} __table = ({table.FullName})_tables[""{ tableName}""]; this.{refVarName} = new {field.ElementRefType.Apply(CsDefineTypeName.Ins)}(); foreach(var __e in {name}) {{ this.{refVarName}.Add(__table.GetOrDefault(__e)); }} }}";
}
case TMap:
{
return $@"{{ {table.FullName} __table = ({table.FullName})_tables[""{tableName}""]; this.{refVarName} = new {field.ElementRefType.Apply(CsDefineTypeName.Ins)}(); foreach(var __e in {name}) {{ this.{refVarName}.Add(__e.Key, __table.GetOrDefault(__e.Value)); }} }}";
return $@"{{ {table.FullName} __table = ({table.FullName})_tables[""{ tableName}""]; this.{refVarName} = new {field.ElementRefType.Apply(CsDefineTypeName.Ins)}(); foreach(var __e in {name}) {{ this.{refVarName}.Add(__e.Key, __table.GetOrDefault(__e.Value)); }} }}";
}
default: throw new NotSupportedException($"type:'{field.CType.TypeName}' not support ref");
}
@ -111,11 +110,11 @@ namespace Luban.Job.Cfg.Utils
{
if (type.IsNullable)
{
return $"{{ if ({jsonName}.has(\"{jsonFieldName}\") && !{jsonName}.get(\"{jsonFieldName}\").isJsonNull()) {{ {type.Apply(TypeVisitors.JavaJsonDeserialize.Ins, $"{jsonName}.get(\"{jsonFieldName}\")", fieldName, 0)} }} else {{ {fieldName} = null; }} }}";
return $"{{ if ({jsonName}.has(\"{jsonFieldName}\") && !{jsonName}.get(\"{jsonFieldName}\").isJsonNull()) {{ {type.Apply(TypeVisitors.JavaJsonDeserialize.Ins, $"{jsonName}.get(\"{jsonFieldName}\")", fieldName)} }} else {{ {fieldName} = null; }} }}";
}
else
{
return type.Apply(TypeVisitors.JavaJsonDeserialize.Ins, $"{jsonName}.get(\"{jsonFieldName}\")", fieldName, 0);
return type.Apply(TypeVisitors.JavaJsonDeserialize.Ins, $"{jsonName}.get(\"{jsonFieldName}\")", fieldName);
}
}
@ -128,41 +127,15 @@ namespace Luban.Job.Cfg.Utils
{
var refVarName = field.RefVarName;
var name = field.ConventionName;
if (field.Ref != null)
var tableName = field.Ref.FirstTable;
var table = field.Assembly.GetCfgTable(field.Ref.FirstTable);
if (field.IsNullable)
{
var tableName = field.Ref.FirstTable;
var table = field.Assembly.GetCfgTable(tableName);
if (field.IsNullable)
{
return $"this.{refVarName} = this.{name} != null ? (({table.FullNameWithTopModule})_tables.get(\"{tableName}\")).get({name}) : null;";
}
else
{
return $"this.{refVarName} = (({table.FullNameWithTopModule})_tables.get(\"{tableName}\")).get({name});";
}
return $"this.{refVarName} = this.{name} != null ? (({table.FullNameWithTopModule})_tables.get(\"{tableName}\")).get({name}) : null;";
}
else
{
var tableName = field.ElementRef.FirstTable;
var table = field.Assembly.GetCfgTable(tableName);
switch (field.CType)
{
case TArray:
{
return $@"{{ int __n = {name}.length; {table.FullNameWithTopModule} __table = ({table.FullNameWithTopModule})_tables.get(""{tableName}""); this.{refVarName} = new {table.ValueTType.Apply(JavaDefineTypeName.Ins)}[__n]; for(int i = 0 ; i < __n ; i++) {{ this.{refVarName}[i] = __table.get({name}[i]); }} }}";
}
case TList:
case TSet:
{
return $@"{{ {table.FullNameWithTopModule} __table = ({table.FullNameWithTopModule})_tables.get(""{tableName}""); this.{refVarName} = new {field.ElementRefType.Apply(JavaDefineTypeName.Ins)}(); for({field.CType.ElementType.TypeName} __e : {name}) {{ this.{refVarName}.add(__table.get(__e)); }} }}";
}
case TMap map:
{
return $@"{{ {table.FullNameWithTopModule} __table = ({table.FullNameWithTopModule})_tables.get(""{tableName}""); this.{refVarName} = new {field.ElementRefType.Apply(JavaDefineTypeName.Ins)}(); for(java.util.Map.Entry<{map.KeyType.Apply(JavaBoxDefineTypeName.Ins)}, {map.ValueType.Apply(JavaBoxDefineTypeName.Ins)}> __e : {name}.entrySet()) {{ {map.KeyType.TypeName} __eKey = __e.getKey(); {map.ValueType.TypeName} __eValue = __e.getValue(); this.{refVarName}.put(__eKey, __table.get(__eValue)); }} }}";
}
default: throw new NotSupportedException($"type:'{field.CType.TypeName}' not support ref");
}
return $"this.{refVarName} = (({table.FullNameWithTopModule})_tables.get(\"{tableName}\")).get({name});";
}
}
@ -252,30 +225,6 @@ namespace Luban.Job.Cfg.Utils
}
}
public static string GdscriptDeserializeValue(string fieldName, string jsonVarName, TType type)
{
if (type.IsNullable)
{
return $"if {jsonVarName} != None: {type.Apply(GDScriptUnderingDeserializeVisitor.Ins, jsonVarName, fieldName)}";
}
else
{
return type.Apply(GDScriptUnderingDeserializeVisitor.Ins, jsonVarName, fieldName);
}
}
public static string GdscriptDeserializeField(string fieldName, string jsonVarName, string jsonFieldName, TType type)
{
if (type.IsNullable)
{
return $"if {jsonVarName}.get('{jsonFieldName}') != null: {type.Apply(GDScriptUnderingDeserializeVisitor.Ins, $"{jsonVarName}['{jsonFieldName}']", fieldName)}";
}
else
{
return type.Apply(GDScriptUnderingDeserializeVisitor.Ins, $"{jsonVarName}['{jsonFieldName}']", fieldName);
}
}
public static string DefineTextKeyField(DefField field, string lan)
{
switch (lan)
@ -317,7 +266,7 @@ namespace Luban.Job.Cfg.Utils
public static string CsUnityEditorJsonLoad(string jsonName, string fieldName, TType type)
{
return $"{type.Apply(CsEditorJsonLoad.Ins, jsonName, fieldName)}";
return $"{type.Apply(CsEditorJsonLoad.Ins, jsonName, fieldName)}";
}
public static string CsUnityEditorJsonSave(string jsonName, string jsonFieldName, string fieldName, TType type)

View File

@ -1,145 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Luban.Job.Cfg.Validators
{
internal class Range
{
private readonly string _str;
private long? _min;
private long? _max;
private double? _mind;
private double? _maxd;
private bool _includeMinBound;
private bool _includeMaxBound;
public Range(string strRange)
{
_str = strRange.Trim();
}
public string RawStr => _str;
private bool TryParse(string s, ref long? x)
{
s = s.Trim();
if (string.IsNullOrEmpty(s))
{
x = null;
return true;
}
else if (long.TryParse(s, out var v))
{
x = v;
return true;
}
else
{
return false;
}
}
private bool TryParse(string s, ref double? x)
{
s = s.Trim();
if (string.IsNullOrEmpty(s))
{
x = null;
return true;
}
else if (double.TryParse(s, out var v))
{
x = v;
return true;
}
else
{
return false;
}
}
public void Compile()
{
void ThrowError()
{
throw new Exception($"range定义不合法");
}
if (long.TryParse(_str, out long value))
{
// size=xxxx
_min = _max = value;
_mind = _maxd = value;
_includeMinBound = _includeMaxBound = true;
return;
}
if (_str.Length <= 2)
{
ThrowError();
}
switch (_str[0])
{
case '[': _includeMinBound = true; break;
case '(': _includeMinBound = false; break;
default: ThrowError(); break;
}
switch (_str[^1])
{
case ']': _includeMaxBound = true; break;
case ')': _includeMaxBound = false; break;
default: ThrowError(); break;
}
var pars = _str[1..^1].Split(',');
if (pars.Length != 2)
{
ThrowError();
}
bool p1 = TryParse(pars[0], ref _min);
bool p2 = TryParse(pars[0], ref _mind);
bool p3 = TryParse(pars[1], ref _max);
bool p4 = TryParse(pars[1], ref _maxd);
if ((!p1 && !p2) || (!p3 && !p4))
{
ThrowError();
}
}
public bool CheckInLongRange(long x)
{
if (_min is long m && (_includeMinBound ? m > x : m >= x))
{
return false;
}
if (_max is long n && (_includeMaxBound ? n < x : n <= x))
{
return false;
}
return true;
}
public bool CheckInDoubleRange(double x)
{
if (_mind is double m && (_includeMinBound ? m > x : m >= x))
{
return false;
}
if (_maxd is double n && (_includeMaxBound ? n < x : n <= x))
{
return false;
}
return true;
}
}
}

View File

@ -11,17 +11,128 @@ namespace Luban.Job.Cfg.Validators
{
public TType Type { get; }
private Range _range;
private readonly string _str;
private long? _min;
private long? _max;
private double? _mind;
private double? _maxd;
private bool _includeMinBound;
private bool _includeMaxBound;
public RangeValidator(TType type, string strRange)
{
Type = type;
_range = new Range(strRange);
_str = strRange.Trim();
}
private bool TryParse(string s, ref long? x)
{
s = s.Trim();
if (string.IsNullOrEmpty(s))
{
x = null;
return true;
}
else if (long.TryParse(s, out var v))
{
x = v;
return true;
}
else
{
return false;
}
}
private bool TryParse(string s, ref double? x)
{
s = s.Trim();
if (string.IsNullOrEmpty(s))
{
x = null;
return true;
}
else if (double.TryParse(s, out var v))
{
x = v;
return true;
}
else
{
return false;
}
}
public void Compile(DefFieldBase def)
{
_range.Compile();
void ThrowError()
{
throw new Exception($"结构:{ def.HostType.FullName } 字段: { def.Name} range 定义:{_str} 不合法");
}
if (_str.Length <= 2)
{
ThrowError();
}
switch (_str[0])
{
case '[': _includeMinBound = true; break;
case '(': _includeMinBound = false; break;
default: ThrowError(); break;
}
switch (_str[^1])
{
case ']': _includeMaxBound = true; break;
case ')': _includeMaxBound = false; break;
default: ThrowError(); break;
}
var pars = _str[1..^1].Split(',');
if (pars.Length != 2)
{
ThrowError();
}
bool p1 = TryParse(pars[0], ref _min);
bool p2 = TryParse(pars[0], ref _mind);
bool p3 = TryParse(pars[1], ref _max);
bool p4 = TryParse(pars[1], ref _maxd);
if ((!p1 && !p2) || (!p3 && !p4))
{
ThrowError();
}
}
private bool CheckInLongRange(long x)
{
if (_min is long m && (_includeMinBound ? m > x : m >= x))
{
return false;
}
if (_max is long n && (_includeMaxBound ? n < x : n <= x))
{
return false;
}
return true;
}
private bool CheckInDoubleRange(double x)
{
if (_mind is double m && (_includeMinBound ? m > x : m >= x))
{
return false;
}
if (_maxd is double n && (_includeMaxBound ? n < x : n <= x))
{
return false;
}
return true;
}
public string Source => ValidatorContext.CurrentVisitor.CurrentValidateRecord.Source;
@ -31,7 +142,7 @@ namespace Luban.Job.Cfg.Validators
var assembly = ctx.Assembly;
void LogError()
{
assembly.Agent.Error("记录 {0}:{1} (来自文件:{2}) 不在范围:{3}内", ValidatorContext.CurrentRecordPath, data, Source, _range.RawStr);
assembly.Agent.Error("记录 {0}:{1} (来自文件:{2}) 不在范围:{3}内", ValidatorContext.CurrentRecordPath, data, Source, _str);
}
if (type.IsNullable && data == null)
@ -43,7 +154,7 @@ namespace Luban.Job.Cfg.Validators
{
case DByte b:
{
if (!_range.CheckInLongRange(b.Value))
if (!CheckInLongRange(b.Value))
{
LogError();
return;
@ -52,7 +163,7 @@ namespace Luban.Job.Cfg.Validators
}
case DFshort s:
{
if (!_range.CheckInLongRange(s.Value))
if (!CheckInLongRange(s.Value))
{
LogError();
return;
@ -61,7 +172,7 @@ namespace Luban.Job.Cfg.Validators
}
case DShort s:
{
if (!_range.CheckInLongRange(s.Value))
if (!CheckInLongRange(s.Value))
{
LogError();
return;
@ -70,7 +181,7 @@ namespace Luban.Job.Cfg.Validators
}
case DInt i:
{
if (!_range.CheckInLongRange(i.Value))
if (!CheckInLongRange(i.Value))
{
LogError();
return;
@ -79,7 +190,7 @@ namespace Luban.Job.Cfg.Validators
}
case DFint i:
{
if (!_range.CheckInLongRange(i.Value))
if (!CheckInLongRange(i.Value))
{
LogError();
return;
@ -88,7 +199,7 @@ namespace Luban.Job.Cfg.Validators
}
case DLong l:
{
if (!_range.CheckInLongRange(l.Value))
if (!CheckInLongRange(l.Value))
{
LogError();
return;
@ -97,7 +208,7 @@ namespace Luban.Job.Cfg.Validators
}
case DFlong fl:
{
if (!_range.CheckInLongRange(fl.Value))
if (!CheckInLongRange(fl.Value))
{
LogError();
return;
@ -106,7 +217,7 @@ namespace Luban.Job.Cfg.Validators
}
case DFloat ff:
{
if (!_range.CheckInDoubleRange(ff.Value))
if (!CheckInDoubleRange(ff.Value))
{
LogError();
return;
@ -115,7 +226,7 @@ namespace Luban.Job.Cfg.Validators
}
case DDouble dd:
{
if (!_range.CheckInDoubleRange(dd.Value))
if (!CheckInDoubleRange(dd.Value))
{
LogError();
return;

View File

@ -1,5 +1,4 @@
using Luban.Job.Cfg.Datas;
using Luban.Job.Cfg.DataSources;
using Luban.Job.Cfg.DataVisitors;
using Luban.Job.Cfg.Defs;
using Luban.Job.Cfg.RawDefs;
@ -59,14 +58,8 @@ namespace Luban.Job.Cfg.Validators
case ETableMode.MAP:
{
var recordMap = assembly.GetTableDataInfo(defTable).FinalRecordMap;
if (recordMap.TryGetValue(key, out Record rec))
if (recordMap.ContainsKey(key))
{
if (!rec.IsNotFiltered(assembly.ExcludeTags))
{
string locationFile = ValidatorContext.CurrentVisitor.CurrentValidateRecord.Source;
assembly.Agent.Error("记录 {0} = {1} (来自文件:{2}) 在引用表:{3} 中存在,但导出时被过滤了",
ValidatorContext.CurrentRecordPath, key, locationFile, defTable.FullName);
}
return;
}
break;
@ -74,14 +67,8 @@ namespace Luban.Job.Cfg.Validators
case ETableMode.LIST:
{
var recordMap = assembly.GetTableDataInfo(defTable).FinalRecordMapByIndexs[field];
if (recordMap.TryGetValue(key, out Record rec))
if (recordMap.ContainsKey(key))
{
if (!rec.IsNotFiltered(assembly.ExcludeTags))
{
string locationFile = ValidatorContext.CurrentVisitor.CurrentValidateRecord.Source;
assembly.Agent.Error("记录 {0} = {1} (来自文件:{2}) 在引用表:{3} 中存在,但导出时被过滤了",
ValidatorContext.CurrentRecordPath, key, locationFile, defTable.FullName);
}
return;
}
break;
@ -194,23 +181,23 @@ namespace Luban.Job.Cfg.Validators
//}
if (ct.IsOneValueTable)
{
if (string.IsNullOrEmpty(indexName))
if (string.IsNullOrEmpty(fieldName))
{
throw new Exception($"结构:{hostTypeName} 字段:{fieldName} ref:{actualTable} 是singleton表索引字段不能为空");
}
else
{
if (!ct.ValueTType.Bean.TryGetField(indexName, out var indexField, out _))
if (!ct.ValueTType.Bean.TryGetField(fieldName, out var indexField, out _))
{
throw new Exception($"结构:{hostTypeName} 字段:{fieldName} ref:{actualTable} value_type:{ct.ValueTType.Bean.FullName} 未包含索引字段:{indexName}");
throw new Exception($"结构:{hostTypeName} 字段:{fieldName} ref:{actualTable} value_type:{ct.ValueTType.Bean.FullName} 未包含索引字段:{fieldName}");
}
if (!(indexField.CType is TMap tmap))
{
throw new Exception($"结构:{hostTypeName} 字段:{fieldName} ref:{actualTable} value_type:{ct.ValueTType.Bean.FullName} 索引字段:{indexName} type:{indexField.CType.TypeName} 不是map类型");
throw new Exception($"结构:{hostTypeName} 字段:{fieldName} ref:{actualTable} value_type:{ct.ValueTType.Bean.FullName} 索引字段:{fieldName} type:{indexField.CType.TypeName} 不是map类型");
}
if (tmap.KeyType.TypeName != Type.TypeName)
{
throw new Exception($"结构:{hostTypeName} 字段:{fieldName} 类型:'{Type.TypeName}' 与被引用的表:{actualTable} value_type:{ct.ValueTType.Bean.FullName} 索引字段:{indexName} key_type:{tmap.KeyType.TypeName} 不一致");
throw new Exception($"结构:{hostTypeName} 字段:{fieldName} 类型:'{Type.TypeName}' 与被引用的表:{actualTable} value_type:{ct.ValueTType.Bean.FullName} 索引字段:{fieldName} key_type:{tmap.KeyType.TypeName} 不一致");
}
}
}

View File

@ -1,121 +0,0 @@
using Luban.Job.Cfg.Datas;
using Luban.Job.Cfg.Utils;
using Luban.Job.Common.Defs;
using Luban.Job.Common.Types;
using System;
using System.Text.RegularExpressions;
namespace Luban.Job.Cfg.Validators
{
[Validator("regex")]
class RegexValidator : IValidator
{
public TType Type { get; }
private Regex _regex;
public string Source => ValidatorContext.CurrentVisitor.CurrentValidateRecord.Source;
public RegexValidator(TType type, string strRegex)
{
Type = type;
_regex = new Regex(DataUtil.UnEscapeString(strRegex), RegexOptions.Compiled);
}
public void Compile(DefFieldBase def)
{
switch (Type)
{
case TBean:
throw new Exception($"regex检查器不支持检查Bean类型{Type.TypeName}");
}
}
public void Validate(ValidatorContext ctx, TType type, DType data)
{
Validate(ctx, type.IsNullable, data);
}
private void Validate(ValidatorContext ctx, bool nullable, DType data)
{
var assembly = ctx.Assembly;
void Check(string str)
{
var match = _regex.Match(str);
if (!match.Success)
{
assembly.Agent.Error($"记录 {ValidatorContext.CurrentRecordPath}:{data} (来自文件:{Source}) 不符合正则表达式:'{_regex}'");
}
}
if (nullable && data == null)
{
return;
}
switch (data)
{
case DList dList:
{
foreach (var d in dList.Datas)
{
Validate(ctx, nullable, d);
}
break;
}
case DArray dArray:
{
foreach (var d in dArray.Datas)
{
Validate(ctx, nullable, d);
}
break;
}
case DSet dSet:
{
foreach (var d in dSet.Datas)
{
Validate(ctx, nullable, d);
}
break;
}
case DMap dMap:
{
foreach (var d in dMap.Datas.Values)
{
Validate(ctx, nullable, d);
}
break;
}
case DVector2 dVector2:
{
Check(dVector2.Value.X.ToString());
Check(dVector2.Value.Y.ToString());
break;
}
case DVector3 dVector3:
{
Check(dVector3.Value.X.ToString());
Check(dVector3.Value.Y.ToString());
Check(dVector3.Value.Z.ToString());
break;
}
case DVector4 dVector4:
{
Check(dVector4.Value.X.ToString());
Check(dVector4.Value.Y.ToString());
Check(dVector4.Value.Z.ToString());
Check(dVector4.Value.W.ToString());
break;
}
case DText dText:
{
Check(dText.RawValue);
break;
}
default:
Check(data.ToString());
break;
}
}
}
}

View File

@ -12,16 +12,16 @@ namespace Luban.Job.Cfg.Validators
[Validator("size")]
internal class SizeValidator : IValidator
{
private Range _range;
private readonly int _size;
public SizeValidator(TType type, string rule)
{
_range = new Range(rule);
this._size = int.Parse(rule);
}
public void Compile(DefFieldBase def)
{
_range.Compile();
}
private static string Source => ValidatorContext.CurrentVisitor.CurrentValidateRecord.Source;
@ -31,7 +31,7 @@ namespace Luban.Job.Cfg.Validators
var assembly = ctx.Assembly;
void LogError(int size)
{
assembly.Agent.Error("记录 {0}:{1} (来自文件:{2}) size:{3},但要求为 {4} ", ValidatorContext.CurrentRecordPath, data, Source, size, _range.RawStr);
assembly.Agent.Error("记录 {0}:{1} (来自文件:{2}) size:{3},但要求为 {4} ", ValidatorContext.CurrentRecordPath, data, Source, size, _size);
}
if (type.IsNullable && data == null)
@ -43,7 +43,7 @@ namespace Luban.Job.Cfg.Validators
{
case DArray b:
{
if (!_range.CheckInLongRange(b.Datas.Count))
if (b.Datas.Count != _size)
{
LogError(b.Datas.Count);
return;
@ -52,7 +52,7 @@ namespace Luban.Job.Cfg.Validators
}
case DList b:
{
if (!_range.CheckInLongRange(b.Datas.Count))
if (b.Datas.Count != _size)
{
LogError(b.Datas.Count);
return;
@ -61,7 +61,7 @@ namespace Luban.Job.Cfg.Validators
}
case DSet b:
{
if (!_range.CheckInLongRange(b.Datas.Count))
if (b.Datas.Count != _size)
{
LogError(b.Datas.Count);
return;
@ -70,7 +70,7 @@ namespace Luban.Job.Cfg.Validators
}
case DMap b:
{
if (!_range.CheckInLongRange(b.Datas.Count))
if (b.Datas.Count != _size)
{
LogError(b.Datas.Count);
return;

View File

@ -1,5 +1,4 @@
using Luban.Job.Cfg.Datas;
using Luban.Job.Cfg.DataSources.Excel;
using Luban.Job.Cfg.Defs;
using Luban.Job.Cfg.RawDefs;
using Luban.Job.Cfg.Utils;
@ -66,7 +65,7 @@ namespace Luban.Job.Cfg.l10n
public void LoadFromFile(string fileName, byte[] bytes)
{
var records = DataLoaderUtil.LoadCfgRecords(_textRowType, fileName, null, bytes, true, null);
var records = DataLoaderUtil.LoadCfgRecords(_textRowType, fileName, null, bytes, true);
foreach (var r in records)
{
//s_logger.Info("== read text:{}", r.Data);

View File

@ -34,9 +34,7 @@ namespace Luban.Job.Common.Defs
public Dictionary<string, DefTypeBase> Types { get; } = new Dictionary<string, DefTypeBase>();
public List<DefTypeBase> TypeList { get; } = new List<DefTypeBase>();
private readonly Dictionary<string, DefTypeBase> _notCaseSenseTypes = new();
private readonly Dictionary<string, DefTypeBase> _notCaseSenseTypes = new ();
private readonly HashSet<string> _namespaces = new();
@ -196,7 +194,6 @@ namespace Luban.Job.Common.Defs
}
Types.Add(fullName, type);
TypeList.Add(type);
}
public DefTypeBase GetDefType(string fullName)
@ -276,9 +273,8 @@ namespace Luban.Job.Common.Defs
return Types.Values.Where(v => typeof(T).IsAssignableFrom(v.GetType())).Select(v => (T)v).ToList();
}
public TType CreateType(string module, string type, bool containerElementType)
public TType CreateType(string module, string type)
{
type = DefUtil.TrimBracePairs(type);
int sepIndex = DefUtil.IndexOfBaseTypeEnd(type);
if (sepIndex > 0)
{
@ -289,11 +285,11 @@ namespace Luban.Job.Common.Defs
}
else
{
return CreateNotContainerType(module, type, containerElementType);
return CreateNotContainerType(module, type);
}
}
protected TType CreateNotContainerType(string module, string rawType, bool containerElementType)
protected TType CreateNotContainerType(string module, string rawType)
{
bool nullable;
// 去掉 rawType 两侧的匹配的 ()
@ -306,10 +302,6 @@ namespace Luban.Job.Common.Defs
{
throw new Exception($"not support nullable type:'{module}.{type}'");
}
if (containerElementType)
{
throw new Exception($"container element type can't be nullable type:'{module}.{type}'");
}
nullable = true;
type = type.Substring(0, type.Length - 1);
}
@ -348,17 +340,17 @@ namespace Luban.Job.Common.Defs
case "time":
case "datetime": return SupportDatetimeType ? TDateTime.Create(nullable, tags) : throw new NotSupportedException($"只有配置支持datetime数据类型");
default:
{
var dtype = GetDefTType(module, type, nullable, tags);
if (dtype != null)
{
var dtype = GetDefTType(module, type, nullable, tags);
if (dtype != null)
{
return dtype;
}
else
{
throw new ArgumentException($"invalid type. module:'{module}' type:'{type}'");
}
return dtype;
}
else
{
throw new ArgumentException($"invalid type. module:'{module}' type:'{type}'");
}
}
}
}
@ -370,33 +362,22 @@ namespace Luban.Job.Common.Defs
throw new ArgumentException($"invalid map element type:'{keyValueType}'");
}
return TMap.Create(false, tags,
CreateNotContainerType(module, keyValueType.Substring(0, typeSepIndex).Trim(), true),
CreateType(module, keyValueType.Substring(typeSepIndex + 1).Trim(), true), isTreeMap);
CreateNotContainerType(module, keyValueType.Substring(0, typeSepIndex).Trim()),
CreateNotContainerType(module, keyValueType.Substring(typeSepIndex + 1).Trim()), isTreeMap);
}
protected TType CreateContainerType(string module, string containerType, Dictionary<string, string> containerTags, string elementType)
{
switch (containerType)
{
case "array":
{
return TArray.Create(false, containerTags, CreateType(module, elementType, true));
}
case "list": return TList.Create(false, containerTags, CreateType(module, elementType, true), true);
case "set":
{
TType type = CreateType(module, elementType, true);
if (type.IsCollection)
{
throw new Exception("set的元素不支持容器类型");
}
return TSet.Create(false, containerTags, type, false);
}
case "array": return TArray.Create(false, containerTags, CreateNotContainerType(module, elementType));
case "list": return TList.Create(false, containerTags, CreateNotContainerType(module, elementType), true);
case "set": return TSet.Create(false, containerTags, CreateNotContainerType(module, elementType), false);
case "map": return CreateMapType(module, containerTags, elementType, false);
default:
{
throw new ArgumentException($"invalid container type. module:'{module}' container:'{containerType}' element:'{elementType}'");
}
{
throw new ArgumentException($"invalid container type. module:'{module}' container:'{containerType}' element:'{elementType}'");
}
}
}
}

View File

@ -154,9 +154,9 @@ namespace Luban.Job.Common.Defs
fields.AddRange(Fields);
}
private void SetUpParentRecursively()
public override void PreCompile()
{
if (ParentDefType == null && !string.IsNullOrEmpty(Parent))
if (!string.IsNullOrEmpty(Parent))
{
if ((ParentDefType = (DefBeanBase)AssemblyBase.GetDefType(Namespace, Parent)) == null)
{
@ -167,13 +167,8 @@ namespace Luban.Job.Common.Defs
ParentDefType.Children = new List<DefBeanBase>();
}
ParentDefType.Children.Add(this);
ParentDefType.SetUpParentRecursively();
}
}
public override void PreCompile()
{
SetUpParentRecursively();
CollectHierarchyFields(HierarchyFields);
}

View File

@ -33,25 +33,24 @@ namespace Luban.Job.Common.Defs
case NamingConvention.UnderScores: cn = TypeUtil.ToUnderScores(Name); break;
case NamingConvention.Invalid: throw new Exception($"invalid NamingConvention");
case NamingConvention.LanguangeRecommend:
{
switch (curLan)
{
switch (curLan)
{
case ELanguage.INVALID: throw new Exception($"not set current language. can't get recommend naming convention name");
case ELanguage.CS: cn = TypeUtil.ToPascalCase(Name); break;
case ELanguage.JAVA: cn = TypeUtil.ToCamelCase(Name); break;
case ELanguage.GO: cn = TypeUtil.ToPascalCase(Name); break;
case ELanguage.CPP: cn = TypeUtil.ToCamelCase(Name); break;
case ELanguage.LUA: cn = TypeUtil.ToUnderScores(Name); break;
case ELanguage.JAVASCRIPT: cn = TypeUtil.ToCamelCase(Name); break;
case ELanguage.TYPESCRIPT: cn = TypeUtil.ToCamelCase(Name); break;
case ELanguage.PYTHON: cn = TypeUtil.ToUnderScores(Name); break;
case ELanguage.GDSCRIPT: cn = TypeUtil.ToUnderScores(Name); break;
case ELanguage.RUST: cn = TypeUtil.ToUnderScores(Name); break;
case ELanguage.PROTOBUF: cn = Name; break;
default: throw new Exception($"unknown language:{curLan}");
}
break;
case ELanguage.INVALID: throw new Exception($"not set current language. can't get recommend naming convention name");
case ELanguage.CS: cn = TypeUtil.ToPascalCase(Name); break;
case ELanguage.JAVA: cn = TypeUtil.ToCamelCase(Name); break;
case ELanguage.GO: cn = TypeUtil.ToPascalCase(Name); break;
case ELanguage.CPP: cn = TypeUtil.ToCamelCase(Name); break;
case ELanguage.LUA: cn = TypeUtil.ToUnderScores(Name); break;
case ELanguage.JAVASCRIPT: cn = TypeUtil.ToCamelCase(Name); break;
case ELanguage.TYPESCRIPT: cn = TypeUtil.ToCamelCase(Name); break;
case ELanguage.PYTHON: cn = TypeUtil.ToUnderScores(Name); break;
case ELanguage.RUST: cn = TypeUtil.ToUnderScores(Name); break;
case ELanguage.PROTOBUF: cn = Name; break;
default: throw new Exception($"unknown language:{curLan}");
}
break;
}
default: throw new Exception($"unknown NamingConvention:{AssemblyBase.NamingConventionBeanMember}");
}
if (curLan == ELanguage.RUST)
@ -117,7 +116,7 @@ namespace Luban.Job.Common.Defs
try
{
CType = AssemblyBase.CreateType(HostType.Namespace, Type, false);
CType = AssemblyBase.CreateType(HostType.Namespace, Type);
}
catch (Exception e)
{
@ -132,21 +131,21 @@ namespace Luban.Job.Common.Defs
switch (CType)
{
case TArray t:
{
if (t.ElementType is TBean e && !e.IsDynamic && e.Bean.HierarchyFields.Count == 0)
{
if (t.ElementType is TBean e && !e.IsDynamic && e.Bean.HierarchyFields.Count == 0)
{
throw new Exception($"container element type:'{e.Bean.FullName}' can't be empty bean");
}
break;
throw new Exception($"container element type:'{e.Bean.FullName}' can't be empty bean");
}
break;
}
case TList t:
{
if (t.ElementType is TBean e && !e.IsDynamic && e.Bean.HierarchyFields.Count == 0)
{
if (t.ElementType is TBean e && !e.IsDynamic && e.Bean.HierarchyFields.Count == 0)
{
throw new Exception($"container element type:'{e.Bean.FullName}' can't be empty bean");
}
break;
throw new Exception($"container element type:'{e.Bean.FullName}' can't be empty bean");
}
break;
}
}
}

View File

@ -53,8 +53,6 @@ namespace Luban.Job.Common.Defs
public string PyFullName => TypeUtil.MakePyFullName(Namespace, Name);
public string GDScriptFullName => TypeUtil.MakeGDScriptFullName(Namespace, Name);
public string RustFullName => TypeUtil.MakeRustFullName(Namespace, Name);
public string PbFullName => TypeUtil.MakePbFullName(Namespace, Name);

View File

@ -87,11 +87,6 @@ namespace Luban.Job.Common.Defs
return type.Apply(CppDefineTypeName.Ins);
}
public static string GdscriptDefineType(TType type)
{
return type.Apply(GDScriptDefineTypeName.Ins);
}
public static string CppConstValue(TType type, string value)
{
return type.Apply(CsConstValueVisitor.Ins, value);
@ -195,6 +190,7 @@ namespace Luban.Job.Common.Defs
return type.Apply(ErlangDefineTypeNameVisitor.Ins);
}
public static string GoDefineType(TType type)
{
return type.Apply(GoTypeNameVisitor.Ins);
@ -318,28 +314,5 @@ namespace Luban.Job.Common.Defs
{
return type is TDateTime && !type.IsNullable && ExternalTypeUtil.GetExternalTypeMappfer("datetime") == null;
}
public static string CsStartNameSpaceGrace(string np)
{
if (string.IsNullOrEmpty(np))
{
return string.Empty;
}
else
{
return $"namespace {np}\n{{";
}
}
public static string CsEndNameSpaceGrace(string np)
{
if (string.IsNullOrEmpty(np))
{
return string.Empty;
}
else
{
return "}";
}
}
}
}

View File

@ -15,6 +15,5 @@ namespace Luban.Job.Common
RUST,
PROTOBUF,
FLATBUFFERS,
GDSCRIPT,
}
}

View File

@ -5,15 +5,16 @@ namespace Luban.Job.Common.TypeVisitors
public class CsDeserializeVisitor : DecoratorFuncVisitor<string, string, string>
{
public static CsDeserializeVisitor Ins { get; } = new CsDeserializeVisitor();
public override string DoAccept(TType type, string bufName, string fieldName)
{
if (type.IsNullable)
{
return $"if({bufName}.ReadBool()){{ {type.Apply(CsUnderingDeserializeVisitor.Ins, bufName, fieldName, 0)} }} else {{ {fieldName} = null; }}";
return $"if({bufName}.ReadBool()){{ {type.Apply(CsUnderingDeserializeVisitor.Ins, bufName, fieldName)} }} else {{ {fieldName} = null; }}";
}
else
{
return type.Apply(CsUnderingDeserializeVisitor.Ins, bufName, fieldName, 0);
return type.Apply(CsUnderingDeserializeVisitor.Ins, bufName, fieldName);
}
}

View File

@ -152,7 +152,7 @@ namespace Luban.Job.Common.TypeVisitors
{
return mapper.TargetTypeName;
}
return "long";
return "int";
}
}
}

View File

@ -4,155 +4,130 @@ using Luban.Job.Common.Utils;
namespace Luban.Job.Common.TypeVisitors
{
class CsUnderingDeserializeVisitor : ITypeFuncVisitor<string, string, int, string>
class CsUnderingDeserializeVisitor : ITypeFuncVisitor<string, string, string>
{
public static CsUnderingDeserializeVisitor Ins { get; } = new CsUnderingDeserializeVisitor();
public string Accept(TBool type, string bufName, string fieldName, int depth)
public string Accept(TBool type, string bufName, string fieldName)
{
return $"{fieldName} = {bufName}.ReadBool();";
}
public string Accept(TByte type, string bufName, string fieldName, int depth)
public string Accept(TByte type, string bufName, string fieldName)
{
return $"{fieldName} = {bufName}.ReadByte();";
}
public string Accept(TShort type, string bufName, string fieldName, int depth)
public string Accept(TShort type, string bufName, string fieldName)
{
return $"{fieldName} = {bufName}.ReadShort();";
}
public string Accept(TFshort type, string bufName, string fieldName, int depth)
public string Accept(TFshort type, string bufName, string fieldName)
{
return $"{fieldName} = {bufName}.ReadFshort();";
}
public string Accept(TInt type, string bufName, string fieldName, int depth)
public string Accept(TInt type, string bufName, string fieldName)
{
return $"{fieldName} = {bufName}.ReadInt();";
}
public string Accept(TFint type, string bufName, string fieldName, int depth)
public string Accept(TFint type, string bufName, string fieldName)
{
return $"{fieldName} = {bufName}.ReadFint();";
}
public string Accept(TLong type, string bufName, string fieldName, int depth)
public string Accept(TLong type, string bufName, string fieldName)
{
return $"{fieldName} = {bufName}.ReadLong();";
}
public string Accept(TFlong type, string bufName, string fieldName, int depth)
public string Accept(TFlong type, string bufName, string fieldName)
{
return $"{fieldName} = {bufName}.ReadFlong();";
}
public string Accept(TFloat type, string bufName, string fieldName, int depth)
public string Accept(TFloat type, string bufName, string fieldName)
{
return $"{fieldName} = {bufName}.ReadFloat();";
}
public string Accept(TDouble type, string bufName, string fieldName, int depth)
public string Accept(TDouble type, string bufName, string fieldName)
{
return $"{fieldName} = {bufName}.ReadDouble();";
}
public string Accept(TEnum type, string bufName, string fieldName, int depth)
public string Accept(TEnum type, string bufName, string fieldName)
{
return $"{fieldName} = ({ type.Apply(CsUnderingDefineTypeName.Ins)}){bufName}.ReadInt();";
}
public string Accept(TString type, string bufName, string fieldName, int depth)
public string Accept(TString type, string bufName, string fieldName)
{
return $"{fieldName} = {bufName}.ReadString();";
}
public string Accept(TBytes type, string bufName, string fieldName, int depth)
public string Accept(TBytes type, string bufName, string fieldName)
{
return $"{fieldName} = {bufName}.ReadBytes();";
}
public string Accept(TText type, string bufName, string fieldName, int depth)
public string Accept(TText type, string bufName, string fieldName)
{
return $"{fieldName}{TText.L10N_FIELD_SUFFIX} = {bufName}.ReadString(); {fieldName} = {bufName}.ReadString();";
}
public string Accept(TBean type, string bufName, string fieldName, int depth)
public string Accept(TBean type, string bufName, string fieldName)
{
string src = $"{type.Bean.FullName}.Deserialize{type.Bean.Name}({bufName})";
return $"{fieldName} = {ExternalTypeUtil.CsCloneToExternal(type.Bean.FullName, src)};";
}
public string Accept(TArray type, string bufName, string fieldName, int depth)
public string Accept(TArray type, string bufName, string fieldName)
{
string __n = $"__n{depth}";
string __e = $"__e{depth}";
string __index = $"__index{depth}";
string typeStr = $"{type.ElementType.Apply(CsDefineTypeName.Ins)}[{__n}]";
if (type.Dimension > 1)
{
if (type.FinalElementType == null)
{
throw new System.Exception("¶àάÊý×éûÓÐÔªËØÀàÐÍ");
}
typeStr = $"{type.FinalElementType.Apply(CsUnderingDefineTypeName.Ins)}[{__n}]";
for (int i = 0; i < type.Dimension - 1; i++)
{
typeStr += "[]";
}
}
return $"{{int {__n} = System.Math.Min({bufName}.ReadSize(), {bufName}.Size);{fieldName} = new {typeStr};for(var {__index} = 0 ; {__index} < {__n} ; {__index}++) {{ {type.ElementType.Apply(CsDefineTypeName.Ins)} {__e};{type.ElementType.Apply(this, bufName, $"{__e}", depth + 1)} {fieldName}[{__index}] = {__e};}}}}";
return $"{{int n = System.Math.Min({bufName}.ReadSize(), {bufName}.Size);{fieldName} = new {type.ElementType.Apply(CsDefineTypeName.Ins)}[n];for(var i = 0 ; i < n ; i++) {{ {type.ElementType.Apply(CsDefineTypeName.Ins)} _e;{type.ElementType.Apply(this, bufName, "_e")} {fieldName}[i] = _e;}}}}";
}
public string Accept(TList type, string bufName, string fieldName, int depth)
public string Accept(TList type, string bufName, string fieldName)
{
string n = $"n{depth}";
string _e = $"_e{depth}";
string i = $"i{depth}";
return $"{{int {n} = System.Math.Min({bufName}.ReadSize(), {bufName}.Size);{fieldName} = new {type.Apply(CsDefineTypeName.Ins)}({n});for(var {i} = 0 ; {i} < {n} ; {i}++) {{ {type.ElementType.Apply(CsDefineTypeName.Ins)} {_e}; {type.ElementType.Apply(this, bufName, $"{_e}", depth + 1)} {fieldName}.Add({_e});}}}}";
return $"{{int n = System.Math.Min({bufName}.ReadSize(), {bufName}.Size);{fieldName} = new {type.Apply(CsDefineTypeName.Ins)}(n);for(var i = 0 ; i < n ; i++) {{ {type.ElementType.Apply(CsDefineTypeName.Ins)} _e; {type.ElementType.Apply(this, bufName, "_e")} {fieldName}.Add(_e);}}}}";
}
public string Accept(TSet type, string bufName, string fieldName, int depth)
public string Accept(TSet type, string bufName, string fieldName)
{
string n = $"n{depth}";
string _e = $"_e{depth}";
string i = $"i{depth}";
return $"{{int {n} = System.Math.Min({bufName}.ReadSize(), {bufName}.Size);{fieldName} = new {type.Apply(CsDefineTypeName.Ins)}(/*{n} * 3 / 2*/);for(var {i} = 0 ; {i} < {n} ; {i}++) {{ {type.ElementType.Apply(CsDefineTypeName.Ins)} {_e}; {type.ElementType.Apply(this, bufName, $"{_e}", +1)} {fieldName}.Add({_e});}}}}";
return $"{{int n = System.Math.Min({bufName}.ReadSize(), {bufName}.Size);{fieldName} = new {type.Apply(CsDefineTypeName.Ins)}(/*n * 3 / 2*/);for(var i = 0 ; i < n ; i++) {{ {type.ElementType.Apply(CsDefineTypeName.Ins)} _e; {type.ElementType.Apply(this, bufName, "_e")} {fieldName}.Add(_e);}}}}";
}
public string Accept(TMap type, string bufName, string fieldName, int depth)
public string Accept(TMap type, string bufName, string fieldName)
{
string n = $"n{depth}";
string _k = $"_k{depth}";
string _v = $"_v{depth}";
string i = $"i{depth}";
return $"{{int {n} = System.Math.Min({bufName}.ReadSize(), {bufName}.Size);{fieldName} = new {type.Apply(CsDefineTypeName.Ins)}({n} * 3 / 2);for(var {i} = 0 ; {i} < {n} ; {i}++) {{ {type.KeyType.Apply(CsDefineTypeName.Ins)} {_k}; {type.KeyType.Apply(this, bufName, _k, depth + 1)} {type.ValueType.Apply(CsDefineTypeName.Ins)} {_v}; {type.ValueType.Apply(this, bufName, _v, depth + 1)} {fieldName}.Add({_k}, {_v});}}}}";
return $"{{int n = System.Math.Min({bufName}.ReadSize(), {bufName}.Size);{fieldName} = new {type.Apply(CsDefineTypeName.Ins)}(n * 3 / 2);for(var i = 0 ; i < n ; i++) {{ {type.KeyType.Apply(CsDefineTypeName.Ins)} _k; {type.KeyType.Apply(this, bufName, "_k")} {type.ValueType.Apply(CsDefineTypeName.Ins)} _v; {type.ValueType.Apply(this, bufName, "_v")} {fieldName}.Add(_k, _v);}}}}";
}
public static string VectorName => (DefAssemblyBase.IsUseUnityVectors ? "UnityVector" : "Vector");
public string Accept(TVector2 type, string bufName, string fieldName, int depth)
public string Accept(TVector2 type, string bufName, string fieldName)
{
string src = $"{bufName}.Read{VectorName}2()";
return $"{fieldName} = {ExternalTypeUtil.CsCloneToExternal("vector2", src)};";
}
public string Accept(TVector3 type, string bufName, string fieldName, int depth)
public string Accept(TVector3 type, string bufName, string fieldName)
{
string src = $"{bufName}.Read{VectorName}3()";
return $"{fieldName} = {ExternalTypeUtil.CsCloneToExternal("vector3", src)};";
}
public string Accept(TVector4 type, string bufName, string fieldName, int depth)
public string Accept(TVector4 type, string bufName, string fieldName)
{
string src = $"{bufName}.Read{VectorName}4()";
return $"{fieldName} = {ExternalTypeUtil.CsCloneToExternal("vector4", src)};";
}
public string Accept(TDateTime type, string bufName, string fieldName, int depth)
public string Accept(TDateTime type, string bufName, string fieldName)
{
string src = $"{bufName}.ReadLong()";
string src = $"{bufName}.ReadInt()";
return $"{fieldName} = {ExternalTypeUtil.CsCloneToExternal("datetime", src)};";
}
}

View File

@ -122,7 +122,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type, string bufName, string fieldName)
{
return $"{bufName}.WriteLong({fieldName});";
return $"{bufName}.WriteInt({fieldName});";
}
}
}

View File

@ -98,7 +98,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type)
{
return "int64";
return "int32";
}
public string Accept(TBean type)

View File

@ -1,43 +0,0 @@
using Luban.Job.Common.Types;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Luban.Job.Common.TypeVisitors
{
public class GDScriptDefineTypeName : DecoratorFuncVisitor<string>
{
public static PyDefineTypeName Ins { get; } = new PyDefineTypeName();
public override string DoAccept(TType type)
{
throw new System.NotSupportedException();
}
public override string Accept(TEnum type)
{
return type.DefineEnum.GDScriptFullName;
}
public override string Accept(TBean type)
{
return type.Bean.GDScriptFullName;
}
public override string Accept(TVector2 type)
{
return "Vector2";
}
public override string Accept(TVector3 type)
{
return "Vector3";
}
public override string Accept(TVector4 type)
{
return "Vector4";
}
}
}

View File

@ -94,7 +94,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type, string fieldName, string bufName, string err)
{
return $"{{ if {fieldName}, {err} = {bufName}.ReadLong(); {err} != nil {{ {err} = errors.New(\"{fieldName} error\"); return }} }}";
return $"{{ if {fieldName}, {err} = {bufName}.ReadInt(); {err} != nil {{ {err} = errors.New(\"{fieldName} error\"); return }} }}";
}
public string Accept(TBean type, string fieldName, string bufName, string err)

View File

@ -94,7 +94,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type, string fieldName, string bufName)
{
return $"{bufName}.WriteLong({fieldName})";
return $"{bufName}.WriteInt({fieldName})";
}
public string Accept(TBean type, string fieldName, string bufName)

View File

@ -119,7 +119,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type)
{
return "int64";
return "int32";
}
}
}

View File

@ -58,12 +58,6 @@ namespace Luban.Job.Common.TypeVisitors
public override string Accept(TDateTime type)
{
return "Long";
}
public override string Accept(TEnum type)
{
//return type.DefineEnum.FullNameWithTopModule;
return "Integer";
}
}

View File

@ -56,10 +56,9 @@ namespace Luban.Job.Common.TypeVisitors
return type.IsNullable ? "Double" : "double";
}
public virtual string Accept(TEnum type)
public string Accept(TEnum type)
{
//return type.DefineEnum.FullNameWithTopModule;
return type.IsNullable ? "Integer" : "int";
return type.DefineEnum.FullNameWithTopModule;
}
public string Accept(TString type)
@ -119,7 +118,7 @@ namespace Luban.Job.Common.TypeVisitors
public virtual string Accept(TDateTime type)
{
return type.IsNullable ? "Long" : "long";
return type.IsNullable ? "Integer" : "int";
}
}
}

View File

@ -1,22 +0,0 @@
using Luban.Job.Common.Types;
using Luban.Job.Common.TypeVisitors;
namespace Luban.Job.Common.TypeVisitors
{
public class JavaDeserializeVisitor : DecoratorFuncVisitor<string, string, string>
{
public static JavaDeserializeVisitor Ins { get; } = new JavaDeserializeVisitor();
public override string DoAccept(TType type, string bufName, string fieldName)
{
if (type.IsNullable)
{
return $"if({bufName}.readBool()){{ {type.Apply(JavaUnderingDeserializeVisitor.Ins, bufName, fieldName, 0)} }} else {{ {fieldName} = null; }}";
}
else
{
return type.Apply(JavaUnderingDeserializeVisitor.Ins, bufName, fieldName, 0);
}
}
}
}

View File

@ -1,21 +0,0 @@
using Luban.Job.Common.Types;
namespace Luban.Job.Common.TypeVisitors
{
public class JavaSerializeVisitor : DecoratorFuncVisitor<string, string, string>
{
public static JavaSerializeVisitor Ins { get; } = new JavaSerializeVisitor();
public override string DoAccept(TType type, string bufName, string fieldName)
{
if (type.IsNullable)
{
return $"{{ if ({fieldName} != null){{ {bufName}.writeBool(true); {type.Apply(JavaUnderingSerializeVisitor.Ins, bufName, fieldName)} }} else {{ {bufName}.writeBool(false); }} }}";
}
else
{
return type.Apply(JavaUnderingSerializeVisitor.Ins, bufName, fieldName);
}
}
}
}

View File

@ -1,155 +0,0 @@
using Luban.Job.Common.Types;
using Luban.Job.Common.TypeVisitors;
namespace Luban.Job.Common.TypeVisitors
{
class JavaUnderingDeserializeVisitor : ITypeFuncVisitor<string, string, int, string>
{
public static JavaUnderingDeserializeVisitor Ins { get; } = new JavaUnderingDeserializeVisitor();
public string Accept(TBool type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {bufName}.readBool();";
}
public string Accept(TByte type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {bufName}.readByte();";
}
public string Accept(TShort type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {bufName}.readShort();";
}
public string Accept(TFshort type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {bufName}.readFshort();";
}
public string Accept(TInt type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {bufName}.readInt();";
}
public string Accept(TFint type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {bufName}.readFint();";
}
public string Accept(TLong type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {bufName}.readLong();";
}
public string Accept(TFlong type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {bufName}.readFlong();";
}
public string Accept(TFloat type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {bufName}.readFloat();";
}
public string Accept(TDouble type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {bufName}.readDouble();";
}
public string Accept(TEnum type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {bufName}.readInt();";
}
public string Accept(TString type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {bufName}.readString();";
}
public string Accept(TBytes type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {bufName}.readBytes();";
}
public string Accept(TText type, string bufName, string fieldName, int depth)
{
return $"{bufName}.readString(); {fieldName} = {bufName}.readString();";
}
public string Accept(TBean type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {type.Bean.FullNameWithTopModule}.deserialize{type.Bean.Name}({bufName});";
}
public string Accept(TArray type, string bufName, string fieldName, int depth)
{
string __n = $"__n{depth}";
string __e = $"__e{depth}";
string __v = $"__v{depth}";
string __i = $"__i{depth}";
string typeStr = $"{type.ElementType.Apply(CsDefineTypeName.Ins)}[{__n}]";
if (type.Dimension > 1)
{
if (type.FinalElementType == null)
{
throw new System.Exception("多维数组没有元素类型");
}
typeStr = $"{type.FinalElementType.Apply(CsUnderingDefineTypeName.Ins)}[{__n}]";
for (int i = 0; i < type.Dimension - 1; i++)
{
typeStr += "[]";
}
}
return $"{{int {__n} = Math.min({bufName}.readSize(), {bufName}.size());{fieldName} = new {type.ElementType.Apply(JavaDefineTypeName.Ins)}[{__n}];for(int {__i} = 0 ; {__i} < {__n} ; {__i}++) {{ {type.ElementType.Apply(JavaDefineTypeName.Ins)} {__e};{type.ElementType.Apply(this, bufName, __e, depth + 1)} {fieldName}[{__i}] = {__e};}}}}";
}
public string Accept(TList type, string bufName, string fieldName, int depth)
{
string __n = $"__n{depth}";
string __e = $"__e{depth}";
string __v = $"__v{depth}";
string __i = $"__i{depth}";
return $"{{int {__n} = Math.min({bufName}.readSize(), {bufName}.size());{fieldName} = new {type.Apply(JavaDefineTypeName.Ins)}({__n});for(int {__i} = 0 ; {__i} < {__n} ; {__i}++) {{ {type.ElementType.Apply(JavaBoxDefineTypeName.Ins)} {__e}; {type.ElementType.Apply(this, bufName, __e, depth + 1)} {fieldName}.add({__e});}}}}";
}
public string Accept(TSet type, string bufName, string fieldName, int depth)
{
string __n = $"__n{depth}";
string __e = $"__e{depth}";
string __v = $"__v{depth}";
string __i = $"__i{depth}";
return $"{{int {__n} = Math.min({bufName}.readSize(), {bufName}.size());{fieldName} = new {type.Apply(JavaDefineTypeName.Ins)}({__n} * 3 / 2);for(int {__i} = 0 ; {__i} < {__n} ; {__i}++) {{ {type.ElementType.Apply(JavaBoxDefineTypeName.Ins)} {__e}; {type.ElementType.Apply(this, bufName, __e, depth + 1)} {fieldName}.add({__e});}}}}";
}
public string Accept(TMap type, string bufName, string fieldName, int depth)
{
string __n = $"__n{depth}";
string __k = $"__k{depth}";
string __v = $"__v{depth}";
string __i = $"__i{depth}";
return $"{{int {__n} = Math.min({bufName}.readSize(), {bufName}.size());{fieldName} = new {type.Apply(JavaDefineTypeName.Ins)}({__n} * 3 / 2);for(int {__i} = 0 ; {__i} < {__n} ; {__i}++) {{ {type.KeyType.Apply(JavaBoxDefineTypeName.Ins)} {__k}; {type.KeyType.Apply(this, bufName, __k, depth + 1)} {type.ValueType.Apply(JavaBoxDefineTypeName.Ins)} {__v}; {type.ValueType.Apply(this, bufName, __v, depth + 1)} {fieldName}.put({__k}, {__v});}}}}";
}
public string Accept(TVector2 type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {bufName}.readVector2();";
}
public string Accept(TVector3 type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {bufName}.readVector3();";
}
public string Accept(TVector4 type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {bufName}.readVector4();";
}
public string Accept(TDateTime type, string bufName, string fieldName, int depth)
{
return $"{fieldName} = {bufName}.readLong();";
}
}
}

View File

@ -1,128 +0,0 @@
using Luban.Job.Common.Defs;
using Luban.Job.Common.Types;
namespace Luban.Job.Common.TypeVisitors
{
class JavaUnderingSerializeVisitor : ITypeFuncVisitor<string, string, string>
{
public static JavaUnderingSerializeVisitor Ins { get; } = new JavaUnderingSerializeVisitor();
public string Accept(TBool type, string bufName, string fieldName)
{
return $"{bufName}.writeBool({fieldName});";
}
public string Accept(TByte type, string bufName, string fieldName)
{
return $"{bufName}.writeByte({fieldName});";
}
public string Accept(TShort type, string bufName, string fieldName)
{
return $"{bufName}.writeShort({fieldName});";
}
public string Accept(TFshort type, string bufName, string fieldName)
{
return $"{bufName}.writeFshort({fieldName});";
}
public string Accept(TInt type, string bufName, string fieldName)
{
return $"{bufName}.writeInt({fieldName});";
}
public string Accept(TFint type, string bufName, string fieldName)
{
return $"{bufName}.writeFint({fieldName});";
}
public string Accept(TLong type, string bufName, string fieldName)
{
return $"{bufName}.writeLong({fieldName});";
}
public string Accept(TFlong type, string bufName, string fieldName)
{
return $"{bufName}.writeFlong({fieldName});";
}
public string Accept(TFloat type, string bufName, string fieldName)
{
return $"{bufName}.writeFloat({fieldName});";
}
public string Accept(TDouble type, string bufName, string fieldName)
{
return $"{bufName}.writeDouble({fieldName});";
}
public string Accept(TEnum type, string bufName, string fieldName)
{
return $"{bufName}.writeInt((int){fieldName});";
}
public string Accept(TString type, string bufName, string fieldName)
{
return $"{bufName}.writeString({fieldName});";
}
public string Accept(TBytes type, string bufName, string fieldName)
{
return $"{bufName}.writeBytes({fieldName});";
}
public string Accept(TText type, string bufName, string fieldName)
{
return $"{bufName}.writeString({fieldName});";
}
public string Accept(TBean type, string bufName, string fieldName)
{
return $"{type.Bean.FullNameWithTopModule}.serialize{type.Bean.Name}({bufName}, {fieldName});";
}
public string Accept(TArray type, string bufName, string fieldName)
{
return $"{{ {bufName}.writeSize({fieldName}.length); for({type.ElementType.Apply(JavaBoxDefineTypeName.Ins)} _e : {fieldName}) {{ {type.ElementType.Apply(this, bufName, "_e")} }} }}";
}
public string Accept(TList type, string bufName, string fieldName)
{
return $"{{ {bufName}.writeSize({fieldName}.size()); for({type.ElementType.Apply(JavaBoxDefineTypeName.Ins)} _e : {fieldName}) {{ {type.ElementType.Apply(this, bufName, "_e")} }} }}";
}
public string Accept(TSet type, string bufName, string fieldName)
{
return $"{{ {bufName}.writeSize({fieldName}.size()); for({type.ElementType.Apply(JavaBoxDefineTypeName.Ins)} _e : {fieldName}) {{ {type.ElementType.Apply(this, bufName, "_e")} }} }}";
}
public string Accept(TMap type, string bufName, string fieldName)
{
return $"{{ {bufName}.writeSize({fieldName}.size()); for(java.util.Map.Entry<{type.KeyType.Apply(JavaBoxDefineTypeName.Ins)},{type.ValueType.Apply(JavaBoxDefineTypeName.Ins)}> _e : {fieldName}.entrySet()) {{ {type.KeyType.Apply(this, bufName, "_e.getKey()")} {type.ValueType.Apply(this, bufName, "_e.getValue()")} }} }}";
}
public static string VectorName => "Vector";
public string Accept(TVector2 type, string bufName, string fieldName)
{
return $"{bufName}.write{VectorName}2({fieldName});";
}
public string Accept(TVector3 type, string bufName, string fieldName)
{
return $"{bufName}.write{VectorName}3({fieldName});";
}
public string Accept(TVector4 type, string bufName, string fieldName)
{
return $"{bufName}.write{VectorName}4({fieldName});";
}
public string Accept(TDateTime type, string bufName, string fieldName)
{
return $"{bufName}.writeLong({fieldName});";
}
}
}

View File

@ -8,57 +8,57 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TBool type)
{
return "boolean";
return "bool";
}
public string Accept(TByte type)
{
return "integer";
return "byte";
}
public string Accept(TShort type)
{
return "integer";
return "short";
}
public string Accept(TFshort type)
{
return "integer";
return "short";
}
public string Accept(TInt type)
{
return "integer";
return "int";
}
public string Accept(TFint type)
{
return "integer";
return "int";
}
public string Accept(TLong type)
{
return "integer";
return "long";
}
public string Accept(TFlong type)
{
return "integer";
return "long";
}
public string Accept(TFloat type)
{
return "number";
return "float";
}
public string Accept(TDouble type)
{
return "number";
return "double";
}
public string Accept(TEnum type)
{
return "integer";
return type.DefineEnum.FullName;
}
public string Accept(TString type)
@ -103,22 +103,22 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TVector2 type)
{
return "{x:number,y:number}";
return "vector2";
}
public string Accept(TVector3 type)
{
return "{x:number,y:number,z:number}";
return "vector3";
}
public string Accept(TVector4 type)
{
return "{x:number,y:number,z:number,w:number}";
return "vector4";
}
public string Accept(TDateTime type)
{
return "integer";
return "int";
}
}
}

View File

@ -118,7 +118,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type)
{
return "readLong";
return "readInt";
}
}
}

View File

@ -118,7 +118,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type)
{
return "writeLong";
return "writeInt";
}
}
}

View File

@ -98,7 +98,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type)
{
return "int64";
return "int32";
}
public string Accept(TBean type)

View File

@ -118,7 +118,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type)
{
return "i64";
return "i32";
}
}
}

View File

@ -118,7 +118,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type)
{
return "LONG";
return "INT";
}
}
}

View File

@ -166,7 +166,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type, string bufVarName, string fieldName)
{
return $"{fieldName} = {bufVarName}.ReadLongAsNumber()";
return $"{fieldName} = {bufVarName}.ReadInt()";
}
}
}

View File

@ -93,7 +93,7 @@ namespace Luban.Job.Common.TypeVisitors
public string Accept(TDateTime type, string bufVarName, string fieldName)
{
return $"{bufVarName}.WriteLong({fieldName})";
return $"{bufVarName}.WriteInt({fieldName})";
}
public virtual string Accept(TBean type, string bufVarName, string fieldName)

View File

@ -15,21 +15,10 @@ namespace Luban.Job.Common.Types
public override TType ElementType { get; }
public override string TypeName => "array";
public int Dimension { get; } = 1;
public TType FinalElementType { get; protected set; }
private TArray(bool isNullable, Dictionary<string, string> tags, TType elementType) : base(isNullable, tags)
{
ElementType = elementType;
if (ElementType.TypeName == "array")
{
Dimension = (ElementType as TArray).Dimension + 1;
FinalElementType = (ElementType as TArray).FinalElementType;
}
else
{
FinalElementType = elementType;
}
}
public override bool TryParseFrom(string s)

View File

@ -20,8 +20,6 @@ namespace Luban.Job.Common.Types
public abstract string TypeName { get; }
public int CollectionLevel { get; set; }
public bool HasTag(string attrName)
{
return Tags != null && Tags.ContainsKey(attrName);

View File

@ -81,7 +81,7 @@ namespace Luban.Job.Common.Utils
{
++braceDepth;
}
else if (c == ')' || c == ']' || c == '}')
else if (c == ')' || c == ')' || c == '}')
{
--braceDepth;
}
@ -119,7 +119,7 @@ namespace Luban.Job.Common.Utils
{
++braceDepth;
}
else if (c == ')' || c == ']' || c == '}')
else if (c == ')' || c == ')' || c == '}')
{
--braceDepth;
}
@ -137,44 +137,6 @@ namespace Luban.Job.Common.Utils
}
public static string TrimBracePairs(string rawType)
{
while (rawType.Length > 0 && rawType[0] == '(')
{
int braceDepth = 0;
int level1Left = -1;
int level1Right = -1;
for (int i = 0; i < rawType.Length; i++)
{
if (rawType[i] == '(')
{
braceDepth++;
if (level1Left < 0)
{
level1Left = i;
}
}
if (rawType[i] == ')')
{
braceDepth--;
if (level1Right < 0 && braceDepth == 0)
{
level1Right = i;
break;
}
}
}
if (level1Left >= 0 && level1Right == rawType.Length - 1)
{
rawType = rawType.Substring(1, rawType.Length - 2);
}
else
{
break;
}
}
return rawType;
}
public static string TrimBracePairs2(string rawType, bool soft = false)
{
while (rawType.Length > 0 && rawType[0] == '(')
{
@ -184,14 +146,7 @@ namespace Luban.Job.Common.Utils
}
else
{
if (soft)
{
return rawType;
}
else
{
throw new Exception($"type:{rawType} brace not match");
}
throw new Exception($"type:{rawType} brace not match");
}
}
return rawType;
@ -245,7 +200,7 @@ namespace Luban.Job.Common.Utils
return (typeStr, attrs);
}
public static bool ParseOrientation(string value)
public static bool ParseOrientation(string value)
{
switch (value.Trim())
{
@ -255,9 +210,9 @@ namespace Luban.Job.Common.Utils
case "c":
case "column": return false;
default:
{
throw new Exception($"orientation 属性值只能为row|r|column|c");
}
{
throw new Exception($"orientation 属性值只能为row|r|column|c");
}
}
}
@ -310,8 +265,7 @@ namespace Luban.Job.Common.Utils
case ELanguage.PYTHON:
case ELanguage.RUST:
case ELanguage.PROTOBUF:
case ELanguage.GDSCRIPT:
return System.Web.HttpUtility.HtmlEncode(comment).Replace("\n", "<br/>");
return System.Web.HttpUtility.HtmlEncode(comment).Replace("\n", "<br/>");
default: throw new Exception($"unknown language:{curLan}");
}
}
@ -337,7 +291,6 @@ namespace Luban.Job.Common.Utils
case "rust": return ELanguage.RUST;
case "pb":
case "protobuf": return ELanguage.PROTOBUF;
case "gdscript": return ELanguage.GDSCRIPT;
default: throw new ArgumentException($"parse lan:'{lan}' fail");
}
}

View File

@ -29,13 +29,6 @@ namespace Luban.Job.Common.Utils
the code is regenerated.
</auto-generated>
'''
";
const string AUTO_GENERATE_GDScript= @"# <auto-generated>
# This code was generated by a tool.
# Changes to this file may cause incorrect behavior and will be lost if
# the code is regenerated.
# </auto-generated>
";
public static string ConcatAutoGenerationHeader(string txt, ELanguage lan)
@ -44,7 +37,6 @@ namespace Luban.Job.Common.Utils
{
case ELanguage.LUA: return AUTO_GENERATE_LUA + txt;
case ELanguage.PYTHON: return AUTO_GENERATE_PYTHON + txt;
case ELanguage.GDSCRIPT: return AUTO_GENERATE_GDScript + txt;
default: return AUTO_GENERATE_C_LIKE + txt;
}
}
@ -55,7 +47,6 @@ namespace Luban.Job.Common.Utils
{
case ELanguage.LUA: return AUTO_GENERATE_LUA;
case ELanguage.PYTHON: return AUTO_GENERATE_PYTHON;
case ELanguage.GDSCRIPT: return AUTO_GENERATE_GDScript;
default: return AUTO_GENERATE_C_LIKE;
}
}

View File

@ -19,9 +19,9 @@ namespace Luban.Job.Common.Utils
case ELanguage.TYPESCRIPT: return fullName.Replace('.', '/') + ".ts";
case ELanguage.RUST: return fullName.Replace('.', '_') + ".rs";
case ELanguage.PROTOBUF: return fullName.Replace('.', '_') + ".pb";
case ELanguage.GDSCRIPT: return fullName.Replace('.', '_') + ".gd";
default: throw new NotSupportedException();
}
}
public static string GetCsDefTypePath(string fullName)
@ -44,6 +44,7 @@ namespace Luban.Job.Common.Utils
return fullName.Replace('.', '_');
}
public static string GetCppDefTypeCppFilePath(string fullName)
{
return fullName + ".cpp";
@ -72,7 +73,6 @@ namespace Luban.Job.Common.Utils
{ "erlang", ELanguage.ERLANG },
{ "rust", ELanguage.RUST },
{ "protobuf", ELanguage.PROTOBUF },
{ "gdscript", ELanguage.GDSCRIPT },
};
public static ELanguage GetLanguage(string genType)
@ -103,7 +103,6 @@ namespace Luban.Job.Common.Utils
ELanguage.RUST => "rust",
ELanguage.PROTOBUF => "protobuf",
ELanguage.FLATBUFFERS => "flatbuffers",
ELanguage.GDSCRIPT => "gdscript",
_ => throw new Exception($"not support common template dir for lan:{lan}"),
};
}
@ -111,10 +110,8 @@ namespace Luban.Job.Common.Utils
private static readonly Dictionary<string, string> s_name2Suxxifx = new()
{
{ "json", "json" },
{ "bson", "bson" },
{ "lua", "lua" },
{ "bin", "bytes" },
{ "bidx", "bytes" },
{ "xml", "xml" },
{ "yaml", "yml" },
{ "yml", "yml" },

View File

@ -1,21 +0,0 @@
using Scriban;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Luban.Job.Common.Utils
{
public static class TemplateUtil
{
public static TemplateContext CreateDefaultTemplateContext()
{
return new TemplateContext()
{
LoopLimit = 0,
NewLine = "\n",
};
}
}
}

View File

@ -48,12 +48,12 @@ namespace Luban.Job.Db.Defs
AddType(new DefTable(p));
}
foreach (var type in TypeList)
foreach (var type in Types.Values)
{
type.AssemblyBase = this;
}
foreach (var type in TypeList)
foreach (var type in Types.Values)
{
try
{
@ -67,7 +67,7 @@ namespace Luban.Job.Db.Defs
throw;
}
}
foreach (var type in TypeList)
foreach (var type in Types.Values)
{
try
{
@ -82,7 +82,7 @@ namespace Luban.Job.Db.Defs
throw;
}
}
foreach (var type in TypeList)
foreach (var type in Types.Values)
{
try
{
@ -101,7 +101,7 @@ namespace Luban.Job.Db.Defs
public List<DefTypeBase> GetExportTypes()
{
return TypeList;
return Types.Values.ToList();
}
}
}

View File

@ -40,7 +40,7 @@ namespace Luban.Job.Db.Defs
ass.AddDbTable(this);
if ((KeyTType = ass.CreateType(Namespace, KeyType, false)) == null)
if ((KeyTType = ass.CreateType(Namespace, KeyType)) == null)
{
throw new Exception($"table:{FullName} key:{KeyType} 类型不合法");
}
@ -50,7 +50,7 @@ namespace Luban.Job.Db.Defs
throw new Exception($"table:{FullName} key:{KeyTType} 不支持。只支持long与string类型");
}
if ((ValueTType = (TBean)ass.CreateType(Namespace, ValueType, false)) == null)
if ((ValueTType = (TBean)ass.CreateType(Namespace, ValueType)) == null)
{
throw new Exception($"table:{FullName} value:{ValueType} 类型不合法");
}

View File

@ -23,7 +23,7 @@ namespace Luban.Job.Db.Generate
public string Render(DefEnum e)
{
var template = StringTemplateManager.Ins.GetTemplate("common/cs/enum");
var result = template.RenderCode(e);
var result = template.Render(e);
return result;
}

View File

@ -23,7 +23,7 @@ namespace Luban.Job.Db.Generate
public string Render(DefEnum e)
{
var template = StringTemplateManager.Ins.GetTemplate("common/cs/enum");
var result = template.RenderCode(e);
var result = template.Render(e);
return result;
}

View File

@ -99,7 +99,7 @@ namespace Luban.Job.Db
case "cs":
{
ass.CurrentLanguage = ELanguage.CS;
var render = new SyncCsRender();
var render = new AsyncCsRender();
foreach (var c in ass.Types.Values)
{
tasks.Add(Task.Run(() =>

View File

@ -1,4 +1,3 @@
using Luban.Job.Common.Utils;
using Luban.Job.Db.Defs;
using Scriban;
using System.Collections.Generic;
@ -9,7 +8,7 @@ namespace Luban.Job.Db
{
public static string RenderCode(this Template template, object model, Dictionary<string, object> extraModels = null)
{
var ctx = TemplateUtil.CreateDefaultTemplateContext();
var ctx = new TemplateContext();
var env = new TTypeTemplateExtends
{
["x"] = model

View File

@ -151,7 +151,7 @@ namespace Luban.Job.Db.TypeVisitors
public string Accept(TDateTime type, string bufName, string fieldName)
{
return $"{fieldName} = {bufName}.ReadLong();";
return $"{fieldName} = {bufName}.ReadInt();";
}
}
}

View File

@ -150,9 +150,9 @@ namespace Luban.Job.Db.TypeVisitors
return $"{bufName}.WriteVector4({fieldName});";
}
public string Accept(TDateTime type, string bufName, string fieldName)
public string Accept(TDateTime type, string x, string y)
{
return $"{bufName}.WriteLong({fieldName});";
throw new NotImplementedException();
}
}
}

View File

@ -25,7 +25,7 @@ namespace Luban.Job.Db.TypeVisitors
public override string Accept(TMap type)
{
return $"BrightDB.Transaction.Collections.{(type.ValueType is TBean ? "PMap2" : "PMap1")}<{type.KeyType.Apply(this)}, {type.ValueType.Apply(this)}>";
return $"BrightDB.Transaction.Collections.{(type.ValueType is TBean ? " PMap2" : "PMap1")}<{type.KeyType.Apply(this)}, {type.ValueType.Apply(this)}>";
}
}
}

View File

@ -128,7 +128,7 @@ namespace Luban.Job.Db.TypeVisitors
public string Accept(TDateTime type)
{
return "Bright.Common.SerializationUtil.DeserializeLong";
return "Bright.Common.SerializationUtil.DeserializeInt";
}
}
}

Some files were not shown because too many files have changed in this diff Show More