### Example XML Data Structure Source: https://luban.doc.code-philosophy.com/docs/intro/3.x/manual/otherdatasource Demonstrates a sample XML structure representing various data types such as booleans, integers, floats, strings, nested elements, and collections (lists and key-value pairs). It illustrates how different data structures are serialized into XML. ```XML true 4 128 1 112233445566 1.3 1112232.43123 yf 1 C 1 2 1 2 1 2 210 330 1 true 2 false 1 2 ``` -------------------------------- ### Example YAML Data Structure Source: https://luban.doc.code-philosophy.com/docs/intro/3.x/manual/otherdatasource Illustrates a sample YAML structure, highlighting its similarity to JSON and specific features like set, map, and polymorphic bean types using the '$type' attribute. It shows how various data types and complex structures are represented in YAML. ```YAML x1: true x2: 3 x3: 128 x4: 40 x5: 11223344 x6: 1.2 x7: 1.23432 x10: hq x12: x1: 10 x13: B x14: $type: DemoD2 x1: 1 x2: 2 t1: '1970-01-01 00:00:00' k1: - 1 - 2 k2: - 2 - 3 k8: - - 2 - 2 - - 4 - 10 k9: - y1: 1 y2: true - y1: 2 y2: false k15: - $type: DemoD2 x1: 1 x2: 2 ``` -------------------------------- ### Lite Data Format Examples for Luban Source: https://luban.doc.code-philosophy.com/docs/intro/manual/otherdatasource Demonstrates Luban's unique Lite text-based data format, which is more concise than JSON as it omits field names. It shows both single-line and multi-line representations, along with notes on whitespace handling, string escaping, and container/bean syntax. ```lite { 1122, false, 2, 128, 112233445566, 1.3, 1122, yf, {1}, D, {DemoD2,1,3}, 1970-01-01 00:00:00, {1,2}, {2,3}, {{2,10},{3,12}}, {{1,true},{2,false}}, {{DemoD2,1,3}}} ``` ```lite { 1122, false, 2, 128, 112233445566, 1.3, 1122, yf, {1}, D, {DemoD2,1,3}, 1970-01-01 00:00:00, {1,2}, {2,3}, {{2,10},{3,12}}, {{1,true},{2,false}}, {{DemoD2,1,3}} } ``` -------------------------------- ### Example Lua Data Source Configuration for Luban Source: https://luban.doc.code-philosophy.com/docs/intro/1.x/manual/datasource Shows a Lua file structure for Luban data sources. It highlights Lua-specific syntax for tables, including set and map representations, and polymorphic beans using the '_type_' property. Note the 'return' keyword at the beginning, as Lua files are loaded as scripts. ```Lua return { x1 = false, x2 = 2, x3 = 128, x4 = 1122, x5 = 112233445566, x6 = 1.3, x7 = 1122, x10 = "yf", t1 = {key="/key/ab1", text="apple"}, x12 = {x1=1}, x13 = "D", x14 = { _type_="DemoD2", x1 = 1, x2=3}, v2 = {x= 1,y = 2}, v3 = {x=0.1, y= 0.2,z=0.3}, v4 = {x=1,y=2,z=3.5,w=4}, t1 = "1970-01-01 00:00:00", k1 = {1,2}, k2 = {2,3}, k8 = {[2]=10,[3]=12}, k9 = { {y1=1,y2=true}, {y1=10,y2=false} }, k15 = { { _type_="DemoD2", x1 = 1, x2=3} }, } ``` -------------------------------- ### Access and Use Specific Luban Configuration Table in C# Source: https://luban.doc.code-philosophy.com/docs/intro/3.x/beginner/loadinruntime After loading 'cfg.Tables', this C# example shows how to access a specific configuration table (e.g., 'TbReward') and retrieve an entry by its ID. It then prints the retrieved reward information to the console. Note that field names are automatically converted to C# style (e.g., boo_bar to BooBar). ```C# cfg.demo.Reward reward = tables.TbReward.Get(1001); Console.WriteLine("reward:{0}", reward); ``` -------------------------------- ### Generate Unity C# JSON Data with Luban Source: https://luban.doc.code-philosophy.com/docs/intro/3.x/manual/commandtools This Batch script illustrates using Luban to generate C# code and JSON data for a Unity project. It sets up the Luban DLL, configuration root, output directories, and path validation, similar to the binary generation example, but targets JSON output. ```Batch set WORKSPACE=..\..\n set GEN_CLIENT=%WORKSPACE%\Tools\Luban\Luban.dll set CONF_ROOT=%WORKSPACE%\DataTables dotnet %GEN_CLIENT% ^ -t all ^ -c cs-simple-json ^ -d json ^^ --conf %CONF_ROOT%\luban.conf ^ -x outputCodeDir=Assets/Gen ^ -x outputDataDir=..\GenerateDatas\json ^ -x pathValidator.rootDir=D:\workspace2\luban_examples\Projects\Csharp_Unity_bin ^ -x l10n.textProviderFile=*@D:\workspace2\luban_examples\DataTables\Datas\l10n\texts.json ``` -------------------------------- ### YAML Data Format Example for Luban Source: https://luban.doc.code-philosophy.com/docs/intro/manual/otherdatasource Illustrates the YAML data structure as used in Luban, highlighting its similarity to JSON and specific features like set, map, and polymorphic bean types. It also notes that both `.yaml` and `.yml` file extensions are recognized. ```yaml x1: true x2: 3 x3: 128 x4: 40 x5: 11223344 x6: 1.2 x7: 1.23432 x10: hq x12: x1: 10 x13: B x14: $type: DemoD2 x1: 1 x2: 2 t1: '1970-01-01 00:00:00' k1: - 1 - 2 k2: - 2 - 3 k8: - - 2 - 2 - - 4 - 10 k9: - y1: 1 y2: true - y1: 2 y2: false k15: - $type: DemoD2 x1: 1 x2: 2 ``` -------------------------------- ### XML Sub-definition File Structure Source: https://luban.doc.code-philosophy.com/docs/intro/1.x/manual/define Illustrates the basic structure of an XML sub-definition file, which can contain module, bean, enum, and table definitions. This snippet provides a typical example of how these elements are nested within a module. ```XML ``` -------------------------------- ### Example YAML Data Source Configuration for Luban Source: https://luban.doc.code-philosophy.com/docs/intro/1.x/manual/datasource Provides a YAML file structure for Luban data sources. It showcases the YAML syntax for different data types, including scalars, nested objects, and lists, and how polymorphic beans are defined using the '$type' property, similar to JSON. ```YAML x1: true x2: 3 x3: 128 x4: 40 x5: 11223344 x6: 1.2 x7: 1.23432 x10: hq x12: x1: 10 x13: B x14: $type: DemoD2 x1: 1 x2: 2 s1: key: "/key32" text: aabbcc22 v2: x: 1 y: 2 v3: x: 1.1 y: 2.2 z: 3.4 v4: x: 10.1 y: 11.2 z: 12.3 w: 13.4 t1: '1970-01-01 00:00:00' k1: - 1 - 2 k2: - 2 - 3 k8: - - 2 - 2 - - 4 - 10 k9: - y1: 1 y2: true - y1: 2 y2: false k15: - $type: DemoD2 x1: 1 x2: 2 ``` -------------------------------- ### XML Data Format Example for Luban Source: https://luban.doc.code-philosophy.com/docs/intro/manual/otherdatasource Demonstrates the structure of data in XML format, including various data types like booleans, numbers, strings, nested elements, and collections (lists and maps) as used in Luban configurations. ```xml true 4 128 1 112233445566 1.3 1112232.43123 yf 1 C 1 2 1 2 1 2 210 330 1 true 2 false 1 2 ``` -------------------------------- ### Example XML Data Source Configuration for Luban Source: https://luban.doc.code-philosophy.com/docs/intro/1.x/manual/datasource Presents an XML file structure for Luban data sources. It demonstrates how various data types, including primitive types, nested elements, arrays, and polymorphic beans (using the 'type' attribute), are represented in XML for Luban. ```XML true 4 128 1 112233445566 1.3 1112232.43123 yf 1 C 1 2 1,2 1.2,2.3,3.4 1.2,2.2,3.2,4.3 1970-01-01 00:00:00 1 2 1 2 210 330 1 true 2 false 1 2 ``` -------------------------------- ### XML Enum Definition with Attributes Source: https://luban.doc.code-philosophy.com/docs/intro/1.x/manual/define Provides examples of defining enumerations in XML, including basic enum members and advanced attributes. It illustrates how to specify enum names, aliases, values, and flags for bitwise operations, along with tags and comments for code generation. ```XML ``` ```APIDOC enum Attributes: name: string (Required) Description: The enumeration name. Its namespace is the full namespace of the current module (including parent modules). flags: boolean (Optional) Description: Whether it is a bit flag type. Defaults to false. If set to 1 or true, configuration data allows syntax like 'READ|WRITE'. tags: string (Optional) Description: Tags in "key1=value2#key2=value2#..." format. Primarily used with custom template generation. unique: boolean (Optional) Description: Whether enum values must be unique. Defaults to true. comment: string (Optional) Description: Comment for the enum. If non-empty, it will be included in the generated code. enum.var Attributes: name: string (Required) Description: The enumeration member name. alias: string (Optional) Description: An alias for the enum member. Planners can use aliases for convenience. value: string (Optional) Description: The enum value. If not specified, it defaults to the previous enum item's value + 1. For the first item, it defaults to 0. tags: string (Optional) Description: Tags for the enum member. Primarily used with custom template generation. comment: string (Optional) Description: Comment for the enum member. If non-empty, it will be included when generating enum items. If empty and an alias is defined, the alias will be used as the comment. ``` -------------------------------- ### Typical XML Definition File Structure Source: https://luban.doc.code-philosophy.com/docs/intro/manual/defaultschemacollector This XML snippet illustrates the typical structure of a Luban definition file, showcasing the use of `module`, `enum`, `bean`, `table`, and `refgroup` elements to define data structures, enumerations, and table configurations. It includes examples of nested modules, type mappings, and various attribute usages. ```XML
``` -------------------------------- ### XML Bean Definition - Normal Structure Source: https://luban.doc.code-philosophy.com/docs/intro/1.x/manual/define Defines a standard structure type (bean) in XML, which must contain at least one field. This example shows how to define fields with various attributes such as type, reference to other tables, resource paths, and custom tags. ```XML ``` ```APIDOC bean Attributes: name: string (Required) Description: The structure name. Cannot contain namespaces (e.g., 'abc.Item' is not allowed). parent: string (Optional) Description: The inherited parent class name. Defaults to empty. Can inherit types from other modules, in which case the parent must be specified with its full name. sep: string (Optional) Description: Specifies that the structure is filled in composite mode from an Excel data source. For example, if 'MyIntVector3' has x, y, z fields, 'sep=","' means the input string will be split by ',' into three integers. bean.var Attributes: name: string (Required) Description: The field name. Recommended format is 'xx_yy_zz'. Some names are reserved keywords in certain languages (e.g., 'base', 'end', 'if') and should be avoided to prevent compilation errors. type: string (Required) Description: The type name of the field. Refer to the 'Type Definition' section for details. group: string (Optional) Description: The group(s) the field belongs to. Can be multiple, comma-separated. Each value must be one of the groups defined in 'root.xml'. If empty, the field belongs to all groups. Refer to the 'Group Export' section for details. ref: string (Optional) Description: A table reference. Points to a full table name or a 'refgroup'. Used to validate if this field is a valid ID for a specific table, preventing data entry errors. Refer to the 'processor' section for details. path: string (Optional) Description: A resource reference. Points to a resource name. Used to validate if this field points to a valid resource, preventing runtime errors. Refer to the 'processor' section for details. tag: string (Optional) Description: Field tags in 'tag="tag1=xxx#tag2=bb#tag3=ccc"' format. Used to add custom tags to fields, primarily for special handling during custom code generation. Refer to the 'Defining Tags' section for details. ``` -------------------------------- ### Example JSON Data Source Configuration for Luban Source: https://luban.doc.code-philosophy.com/docs/intro/1.x/manual/datasource Illustrates a typical JSON file structure used as a data source for Luban. It demonstrates various data types including booleans, numbers, strings, nested objects, arrays, and polymorphic beans using the '$type' property, as well as specific formats for text and map types. ```JSON { "x1":true, "x2":3, "x3":128, "x4":1, "x5":11223344, "x6":1.2, "x7":1.23432, "x10":"hq", "t1": {"key":"/key/xx1","text":"apple"}, "x12": { "x1":10}, "x13":"B", "x14":{"$type": "DemoD2", "x1":1, "x2":2}, "v2":{"x":1, "y":2}, "v3":{"x":1.1, "y":2.2, "z":3.4}, "v4":{"x":10.1, "y":11.2, "z":12.3, "w":13.4}, "t1":"1970-01-01 00:00:00", "k1":[1,2], "k2":[2,3], "k7":[2,3], "k8":[[2,2],[4,10]], "k9":[{"y1":1, "y2":true},{"y1":2, "y2":false}], "k15":[{"$type": "DemoD2", "x1":1, "x2":2}] } ``` -------------------------------- ### Example Lua Data for DemoType2 Single Record Source: https://luban.doc.code-philosophy.com/docs/intro/manual/otherdatasource This Lua snippet shows how to represent a single record of 'DemoType2' data. It illustrates Lua-specific features like the 'return' keyword, set format, map format (supporting non-string keys directly), and polymorphic bean types (using '_type_' property). ```Lua return { x1 = false, x2 = 2, x3 = 128, x4 = 1122, x5 = 112233445566, x6 = 1.3, x7 = 1122, x10 = "yf", x12 = {x1=1}, x13 = "D", x14 = { _type_="DemoD2", x1 = 1, x2=3}, t1 = "1970-01-01 00:00:00", k1 = {1,2}, k2 = {2,3}, k8 = {[2]=10,[3]=12}, k9 = { {y1=1,y2=true}, {y1=10,y2=false} }, k15 = { { _type_="DemoD2", x1 = 1, x2=3} }, } ``` -------------------------------- ### Luban Composite File Configuration Example (XML) Source: https://luban.doc.code-philosophy.com/docs/intro/manual/otherdatasource Illustrates how to define bean structures and table mappings in XML for Luban's composite file format. This allows reading multiple records or specific fields from a single JSON file, similar to how Excel data sources are handled. ```xml
``` -------------------------------- ### Example JSON Data for DemoType2 Single Record Source: https://luban.doc.code-philosophy.com/docs/intro/manual/otherdatasource This JSON snippet demonstrates how to represent a single record of 'DemoType2' data. It highlights the specific JSON formats for set, map (using array of key-value pairs), and polymorphic bean types (using '$type' property to specify the concrete type). ```JSON { "x1":true, "x2":3, "x3":128, "x4":1, "x5":11223344, "x6":1.2, "x7":1.23432, "x10":"hq", "x12": { "x1":10}, "x13":"B", "x14":{"$type": "DemoD2", "x1":1, "x2":2}, "t1":"1970-01-01 00:00:00", "k1":[1,2], "k2":[2,3], "k7":[2,3], "k8":[[2,2],[4,10]], "k9":[{"y1":1, "y2":true},{"y1":2, "y2":false}], "k15":[{"$type": "DemoD2", "x1":1, "x2":2}] } ``` -------------------------------- ### Luban.Client.dll Command-Line Parameters Source: https://luban.doc.code-philosophy.com/docs/intro/1.x/manual/commandtools This snippet demonstrates the general command-line syntax for `Luban.Client.dll` and provides a detailed explanation of each parameter, including host, port, job type, log level, cache meta file, watch directories, and help options. ```Shell dotnet Luban.Client.dll [-h ] [-p ] [-l ] [-c ] [-w ] [-h ] -j cfg -- 参数介绍: -h,--host 可选参数。 luban-server的地址。默认为 127.0.0.1 -p,--port 可选参数。 luban-server的端口。默认为 8899 -j,--job 必选参数。 生成类型。目前支持的生成类型有: cfg,proto,db。 生成配置请取cfg。 -l,--loglevel 可选参数。 日志级别。默认为INFO。有效值有: TRACE,DEBUG,INFO,WARN,ERROR,FATAL,OFF -c,--cachemetafile 可选参数。 meta缓存文件名。 默认为 .cache.meta -w,--watch 可选参数。 监测目录或者目录列表,以逗号';'分隔。当开启此选项后,生成结束后不会退出程序,而是进入自动生成模式。 监听到目标目录发生变化后,自动重新运行生成。省去改动后手动运行生成脚本的麻烦。 --generateonly 可选参数。 仅生成。不从服务器下载生成结果。可以用于检查服务器是否能成功生成。 -h,--help 可选参数。 显示帮助信息 -- 必选参数。 从此参数起,便是 不同job的特有选项 ``` -------------------------------- ### Load All Luban Configuration Tables in C# Source: https://luban.doc.code-philosophy.com/docs/intro/3.x/beginner/loadinruntime This C# snippet demonstrates how to load all configuration tables using a single line of code. It expects a 'gameConfDir' pointing to the output data directory and uses 'JSON.Parse' to read and parse JSON files. This operation is typically performed once during game initialization. ```C# string gameConfDir = ""; // 替换为gen.bat中outputDataDir指向的目录 var tables = new cfg.Tables(file => JSON.Parse(File.ReadAllText($"{gameConfDir}/{file}.json"))); ``` -------------------------------- ### Luban.Client.dll cfg Job-Specific Options Source: https://luban.doc.code-philosophy.com/docs/intro/1.x/manual/commandtools This section outlines the specific command-line options available when running `Luban.Client.dll` with the `cfg` job type. It covers essential parameters like define file, input/output directories, various `gen_types` for code and data generation, validation, data export settings, custom templates, naming conventions, localization parameters, and language-specific configurations for TypeScript, C#, and Go. ```APIDOC cfg的介绍: -d,--define_file 必选参数。 根定义文件名。 --input_data_dir 必选参数。 配置数据文件根目录。 --input:convert:dir 可选参数。 执行json、lua、xlsx之类数据格式转换时,提供的数据源,覆盖table中默认的input参数。 -c,--output_code_dir 可选参数。 生成代码文件的目录。 -s,--service 必选参数。生成分组目标。一般来说,会定义client,server,editor等好几个目标,不同目标的生成内容不同。 --gen_types 必选参数。生成任务类型。既可以是生成代码也可以是生成数据或者其他。 目前支持的有 code_cs_bin,code_cs_unity_bin,code_cs_dotnet_json,code_cs_unity_json, code_cs_unity_editor_json,code_lua_bin,code_java_bin,code_go_bin, code_go_json,code_cpp_bin,code_cpp_ue_editor_json,code_python27_json, code_python3_json, code_gdscript_json, code_typescript_bin,code_typescript_json,code_rust_json, code_protobuf2,code_protobuf3,code_template,code_flatbuffers, data_bin,data_bidx,data_lua,data_json,data_json_monolithic,data_bson,data_yaml, data_template,data_protobuf_bin,data_protobuf_json,data_flatbuffers_json, convert_json,convert_lua,convert_xlsx,convert_template --validate_root_dir . 可选参数。 配置path检查的根目录。 --output_data_dir 可选参数。 导出的数据文件的目录。只生成代码时可不指定。 --output:data:compact_json 可选参数。默认导出的json格式为对齐后的优雅格式,使用此参数后导出紧凑的不带空格和换行的格式。 --output:data:file_extension 可选参数。 导出数据文件的后缀。默认按照生成类型自动选择。 --output:exclude_tags 可选参数。导出时排除包含这些tag的数据 --output:tables 可选参数。手动指定导出哪些表。覆盖group中设置 --output:include_tables 可选参数。除了group中设置外,额外新增表。 --output:exclude_tables 可选参数。排除group中指定的表。 --output:convert:file_extension 可选参数。 convert数据文件的后缀。默认按照模板名猜测。 --template:code:dir 可选参数。自定义额外代码模板的目录名 --template:data:file