├── .editorconfig ├── .gitattributes ├── .github ├── FUNDING.yml └── workflows │ └── sync_gitee.yml ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── README_EN.md ├── docs ├── _config.yml ├── images │ ├── Client_Server.png │ ├── adv │ │ ├── def_01.png │ │ ├── def_02.png │ │ ├── def_03.png │ │ ├── def_04.png │ │ ├── def_05.png │ │ ├── def_06.png │ │ ├── def_07.png │ │ ├── def_08.png │ │ ├── def_09.png │ │ ├── def_10.png │ │ ├── def_11.png │ │ ├── def_12.png │ │ ├── def_13.png │ │ ├── def_14.png │ │ ├── def_15.png │ │ ├── def_16.png │ │ ├── def_17.png │ │ ├── def_18.png │ │ ├── def_19.png │ │ ├── def_20.png │ │ ├── def_21.png │ │ ├── def_22.png │ │ ├── def_23.png │ │ ├── def_24.png │ │ ├── def_25.png │ │ ├── def_26.png │ │ ├── def_27.png │ │ ├── def_28.png │ │ ├── def_29.png │ │ ├── def_30.png │ │ ├── def_31.png │ │ ├── def_32.png │ │ ├── def_33.png │ │ ├── def_34.png │ │ ├── def_35.png │ │ ├── def_36.png │ │ ├── def_37.png │ │ ├── def_38.png │ │ ├── def_39.png │ │ ├── def_40.png │ │ ├── def_41.png │ │ ├── def_42.png │ │ ├── def_43.png │ │ ├── def_44.png │ │ ├── def_45.png │ │ ├── def_46.png │ │ ├── def_47.png │ │ ├── def_48.png │ │ ├── def_49.png │ │ └── def_50.png │ ├── cases │ │ ├── bean.jpg │ │ ├── bean2.jpg │ │ ├── collection.jpg │ │ ├── enum.jpg │ │ ├── ignorefield.jpg │ │ ├── l10n_text.jpg │ │ ├── multileveltitle.jpg │ │ ├── multiline.jpg │ │ ├── nullable.jpg │ │ ├── primitive_type.jpg │ │ ├── quickstart_reward.jpg │ │ ├── quickstart_table.jpg │ │ ├── sep_bean.jpg │ │ ├── sep_container1.jpg │ │ ├── sep_container2.jpg │ │ ├── simple1.jpg │ │ ├── singleton.jpg │ │ ├── singleton2.jpg │ │ ├── stream.jpg │ │ ├── table_list_indep_key.jpg │ │ ├── table_list_not_key.jpg │ │ ├── table_list_union_key.jpg │ │ ├── tag.jpg │ │ ├── tag2.jpg │ │ ├── title_dynamic_bean.jpg │ │ ├── title_enum.jpg │ │ ├── title_map.jpg │ │ └── titlelimit.jpg │ ├── docusaurus-social-card.jpg │ ├── docusaurus.png │ ├── dots_release.png │ ├── easy.svg │ ├── efficient.svg │ ├── excel_bean.jpg │ ├── excel_enum.jpg │ ├── excel_table.jpg │ ├── favicon.ico │ ├── favicon.png │ ├── flying-seagull.jpg │ ├── icon.png │ ├── install │ │ ├── install_01.png │ │ ├── install_02.png │ │ ├── install_03.png │ │ ├── install_04.png │ │ ├── install_05.png │ │ ├── install_06.png │ │ ├── install_07.png │ │ ├── install_08.png │ │ ├── install_09.png │ │ └── install_10.png │ ├── logo.png │ ├── logo.svg │ ├── luban_edit_tool.png │ ├── more.png │ ├── other.png │ ├── panda-waving.png │ ├── pipeline.jpg │ ├── process.jpg │ ├── python.png │ ├── reliable-dark.svg │ ├── reliable.svg │ ├── ui.png │ ├── undraw_docusaurus_mountain.svg │ ├── undraw_docusaurus_react.svg │ ├── undraw_docusaurus_tree.svg │ ├── web.png │ ├── weixin.jpg │ └── zhifubao.jpg └── sponsor │ ├── weixin.JPG │ └── zhifubao.JPG ├── scripts ├── format.bat └── format.sh └── src ├── .dockerignore ├── .editorconfig ├── Luban.Bson ├── AssemblyInfo.cs ├── BsonDataTarget.cs ├── BsonDataVisitor.cs └── Luban.Bson.csproj ├── Luban.CSharp ├── AssemblyInfo.cs ├── CodeTarget │ ├── CsharpBinCodeTarget.cs │ ├── CsharpCodeTargetBase.cs │ ├── CsharpDotnetJsonCodeTarget.cs │ ├── CsharpEditorJsonCodeTarget.cs │ ├── CsharpNewtonSoftJsonCodeTarget.cs │ └── CsharpSimpleJsonCodeTarget.cs ├── ConstStrings.cs ├── Luban.CSharp.csproj ├── TemplateExtensions │ ├── CsharpBinTemplateExtension.cs │ ├── CsharpDotNetJsonTemplateExtension.cs │ ├── CsharpEditorJsonTemplateExtension.cs │ ├── CsharpNewtonSoftJsonTemplateExtension.cs │ ├── CsharpSimpleJsonTemplateExtension.cs │ └── CsharpTemplateExtension.cs ├── Templates │ ├── common │ │ └── cs │ │ │ └── enum.sbn │ ├── cs-bin │ │ ├── bean.sbn │ │ ├── table.sbn │ │ └── tables.sbn │ ├── cs-dotnet-json │ │ ├── bean.sbn │ │ ├── table.sbn │ │ └── tables.sbn │ ├── cs-editor-json │ │ ├── bean.sbn │ │ └── enum.sbn │ ├── cs-newtonsoft-json │ │ ├── bean.sbn │ │ ├── table.sbn │ │ └── tables.sbn │ └── cs-simple-json │ │ ├── bean.sbn │ │ ├── table.sbn │ │ └── tables.sbn ├── TypeUtil.cs └── TypeVisitors │ ├── BinaryDeserializeVisitor.cs │ ├── BinaryUnderlyingDeserializeVisitor.cs │ ├── ConstValueVisitor.cs │ ├── CtorDefaultValueVisitor.cs │ ├── DataToStringVisitor.cs │ ├── DeclaringCollectionRefNameVisitor.cs │ ├── DeclaringTypeNameVisitor.cs │ ├── DotNetJsonDeserializeVisitor.cs │ ├── EditorDeclaringTypeNameVisitor.cs │ ├── EditorInitValueVisitor.cs │ ├── EditorIsRawNullableTypeVisitor.cs │ ├── EditorJsonLoad.cs │ ├── EditorJsonSave.cs │ ├── EditorJsonSaveUnderlying.cs │ ├── EditorJsonSaveUnderlying2.cs │ ├── EditorNeedInitVisitor.cs │ ├── EditorUnderlyingTypeNameVisitor.cs │ ├── IsRawNullableTypeVisitor.cs │ ├── NeedInitFieldVisitor.cs │ ├── NewtonSoftJsonDeserializeVisitor.cs │ ├── RecursiveResolveVisitor.cs │ ├── SimpleJsonDeserializeVisitor.cs │ ├── StringDeserializeVisitor.cs │ └── UnderlyingDeclaringTypeNameVisitor.cs ├── Luban.Core ├── AssemblyInfo.cs ├── BuiltinOptionNames.cs ├── CodeFormat │ ├── CodeFormatManager.cs │ ├── CodeStyleAttribute.cs │ ├── CodeStyles │ │ ├── CodeStyleBase.cs │ │ ├── ConfigurableCodeStyle.cs │ │ └── OverlayCodeStyle.cs │ ├── ICodeStyle.cs │ ├── INamingConventionFormatter.cs │ ├── NamingConventionAttribute.cs │ └── NamingConventionFormatters │ │ ├── CamelCaseFormatter.cs │ │ ├── NoneFormatter.cs │ │ ├── PascalCaseFormatter.cs │ │ ├── SnakeCaseFormatter.cs │ │ └── UpperCaseFormatter.cs ├── CodeTarget │ ├── AllInOneTemplateCodeTargetBase.cs │ ├── CodeTargetAttribute.cs │ ├── CodeTargetBase.cs │ ├── CodeTargetManager.cs │ ├── CodeWriter.cs │ ├── CommonFileHeaders.cs │ ├── ICodeTarget.cs │ ├── NameLocation.cs │ └── TemplateCodeTargetBase.cs ├── CustomBehaviour │ ├── BehaviourBaseAttribute.cs │ ├── CustomBehaviourManager.cs │ ├── ICustomBehaviour.cs │ └── IPriorityBehaviour.cs ├── DataLoader │ ├── DataCreateException.cs │ ├── DataLoaderAttribute.cs │ ├── DataLoaderBase.cs │ ├── DataLoaderManager.cs │ ├── FieldNames.cs │ └── IDataLoader.cs ├── DataTarget │ ├── DataExporterAttribute.cs │ ├── DataExporterBase.cs │ ├── DataTargetAttribute.cs │ ├── DataTargetBase.cs │ ├── DataTargetManager.cs │ ├── IDataExporter.cs │ └── IDataTarget.cs ├── DataTransformer │ ├── DataTransfomerBase.cs │ ├── DataTransformerAttribute.cs │ └── IDataTransformer.cs ├── DataVisitors │ ├── DataActionHelpVisitor.cs │ ├── DataActionHelpVisitor2.cs │ ├── IDataActionVisitor.cs │ ├── IDataActionVisitor2.cs │ ├── IDataFuncVisitor.cs │ ├── IDataFuncVisitor2.cs │ ├── IsDefaultValueVisitor.cs │ ├── IsSimpleLiteralDataVisitor.cs │ ├── TableVisitor.cs │ ├── ToLiteralVisitorBase.cs │ ├── ToStringVisitor.cs │ └── ToStringVisitor2.cs ├── Datas │ ├── DArray.cs │ ├── DBean.cs │ ├── DBool.cs │ ├── DByte.cs │ ├── DDateTime.cs │ ├── DDouble.cs │ ├── DEnum.cs │ ├── DFloat.cs │ ├── DInt.cs │ ├── DList.cs │ ├── DLong.cs │ ├── DMap.cs │ ├── DSet.cs │ ├── DShort.cs │ ├── DString.cs │ └── DType.cs ├── Defs │ ├── DefAssembly.cs │ ├── DefBean.cs │ ├── DefEnum.cs │ ├── DefField.cs │ ├── DefRefGroup.cs │ ├── DefTable.cs │ ├── DefTypeBase.cs │ ├── LoadDefException.cs │ ├── Record.cs │ ├── TableDataInfo.cs │ └── TableMode.cs ├── EnvManager.cs ├── GenerationContext.cs ├── GlobalConfigLoader.cs ├── IGenerationContext.cs ├── L10N │ ├── ITextProvider.cs │ ├── L10NManager.cs │ └── TextProviderAttribute.cs ├── Luban.Core.csproj ├── OutputFile.cs ├── OutputFileManifest.cs ├── OutputSaver │ ├── IOutputSaver.cs │ ├── LocalFileSaver.cs │ ├── NullSaver.cs │ ├── OutputSaverAttribute.cs │ ├── OutputSaverBase.cs │ └── OutputSaverManager.cs ├── Pipeline │ ├── DefaultPipeline.cs │ ├── IPipeline.cs │ ├── PipelineArguments.cs │ ├── PipelineAttribute.cs │ └── PipelineManager.cs ├── PostProcess │ ├── IPostProcess.cs │ ├── PostProcessAttribute.cs │ ├── PostProcessBase.cs │ └── PostProcessManager.cs ├── RawDefs │ ├── RawAssembly.cs │ ├── RawBean.cs │ ├── RawEnum.cs │ ├── RawField.cs │ ├── RawGroup.cs │ ├── RawRefGroup.cs │ ├── RawTable.cs │ ├── RawTarget.cs │ └── TypeMapper.cs ├── RegisterBehaviourAttribute.cs ├── Schema │ ├── BeanSchemaLoaderAttribute.cs │ ├── IBeanSchemaLoader.cs │ ├── IConfigLoader.cs │ ├── ISchemaCollector.cs │ ├── ISchemaLoader.cs │ ├── ITableImporter.cs │ ├── LubanConfig.cs │ ├── SchemaCollectorAttribute.cs │ ├── SchemaCollectorBase.cs │ ├── SchemaFileInfo.cs │ ├── SchemaLoaderAttribute.cs │ ├── SchemaLoaderBase.cs │ ├── SchemaManager.cs │ └── TableImporterAttribute.cs ├── Serialization │ ├── BeanBase.cs │ ├── ByteBuf.cs │ ├── ByteBufPool.cs │ ├── EUnmarshalError.cs │ ├── FieldTag.cs │ ├── ISerializable.cs │ ├── ITypeId.cs │ ├── SerializationException.cs │ └── ThreadLocalTemporalByteBufPool.cs ├── SimpleLauncher.cs ├── TemplateExtensions │ ├── ContextTemplateExtension.cs │ └── TypeTemplateExtension.cs ├── Tmpl │ └── TemplateManager.cs ├── TypeVisitors │ ├── AllFalseVisitor.cs │ ├── AllTrueVisitor.cs │ ├── DecoratorActionVisitor.cs │ ├── DecoratorFuncVisitor.cs │ ├── DeepCompareTypeDefine.cs │ ├── ITypeActionVisitor.cs │ ├── ITypeFuncVisitor.cs │ ├── IsValidTableKeyTypeVisitor.cs │ ├── RawDefineTypeNameVisitor.cs │ ├── RefTypeVisitor.cs │ └── TypeActionVisitorAdaptor.cs ├── Types │ ├── TArray.cs │ ├── TBean.cs │ ├── TBool.cs │ ├── TByte.cs │ ├── TDateTime.cs │ ├── TDouble.cs │ ├── TEnum.cs │ ├── TFloat.cs │ ├── TInt.cs │ ├── TList.cs │ ├── TLong.cs │ ├── TMap.cs │ ├── TSet.cs │ ├── TShort.cs │ ├── TString.cs │ └── TType.cs ├── Utils │ ├── AtomicLong.cs │ ├── CollectionExtensions.cs │ ├── DataExtensions.cs │ ├── DataUtil.cs │ ├── DefExtensions.cs │ ├── DefUtil.cs │ ├── ExceptionUtil.cs │ ├── ExternalTypeUtil.cs │ ├── FileCleaner.cs │ ├── FileUtil.cs │ ├── ListEqualityComparer.cs │ ├── LoadXmlException.cs │ ├── StringUtil.cs │ ├── TemplateUtil.cs │ ├── TimeUtil.cs │ ├── TimeZoneUtil.cs │ ├── TypeUtil.cs │ └── XmlUtil.cs └── Validator │ ├── DataValidatorBase.cs │ ├── DataValidatorContext.cs │ ├── DataValidatorVisitor.cs │ ├── IDataValidator.cs │ ├── ITableValidator.cs │ ├── ValidatorAttribute.cs │ ├── ValidatorManager.cs │ └── ValidatorType.cs ├── Luban.Cpp ├── AssemblyInfo.cs ├── CodeTarget │ ├── CppBinRawptrCodeTarget.cs │ ├── CppBinSharedptrCodeTarget.cs │ └── CppCodeTargetBase.cs ├── Luban.Cpp.csproj ├── TemplateExtensions │ ├── CppRawptrBinTemplateExtension.cs │ ├── CppSharedptrBinTemplateExtension.cs │ └── CppTemplateExtension.cs ├── Templates │ ├── common │ │ └── cpp │ │ │ └── enum.sbn │ ├── cpp-rawptr-bin │ │ ├── bean.sbn │ │ ├── schema_cpp.sbn │ │ ├── schema_h.sbn │ │ ├── table.sbn │ │ └── tables.sbn │ └── cpp-sharedptr-bin │ │ ├── bean.sbn │ │ ├── schema_cpp.sbn │ │ ├── schema_h.sbn │ │ ├── table.sbn │ │ └── tables.sbn └── TypeVisitors │ ├── CppRawptrDeclaringTypeNameVisitor.cs │ ├── CppRawptrDeserializeVisitor.cs │ ├── CppRawptrUnderlyingDeclaringTypeNameVisitor.cs │ ├── CppRawptrUnderlyingDeserializeVisitor.cs │ ├── CppSharedPtrUnderlyingDeclaringTypeNameVisitor.cs │ ├── CppSharedptrDeclaringTypeNameVisitor.cs │ ├── CppSharedptrDeserializeVisitor.cs │ ├── CppSharedptrUnderlyingDeserializeVisitor.cs │ ├── CppUnderlyingDeclaringTypeNameVisitor.cs │ └── CppUnderlyingDeserializeVisitorBase.cs ├── Luban.Dart ├── AssemblyInfo.cs ├── CodeTarget │ ├── DartCodeTargetBase.cs │ └── DartJsonCodeTarget.cs ├── Luban.Dart.csproj ├── TemplateExtensions │ ├── DartCommonTemplateExtension.cs │ └── DartJsonTemplateExtension.cs ├── Templates │ ├── common │ │ └── dart │ │ │ └── enum.sbn │ └── dart-json │ │ ├── bean.sbn │ │ ├── table.sbn │ │ └── tables.sbn └── TypeVisitors │ ├── DartDeclaringBoxTypeNameVisitor.cs │ ├── DartDeclaringTypeNameVisitor.cs │ ├── DeclaringCollectionRefNameVisitor.cs │ └── JsonUnderlyingDeserializeVisitor.cs ├── Luban.DataLoader.Builtin ├── AssemblyInfo.cs ├── DataVisitors │ ├── ExcelStreamDataCreator.cs │ ├── InvalidExcelDataException.cs │ ├── JsonDataCreator.cs │ ├── LiteStreamDataCreator.cs │ ├── LuaDataCreator.cs │ ├── SheetDataCreator.cs │ ├── StringDataCreator.cs │ ├── UnityAssetDataCreator.cs │ ├── XmlDataCreator.cs │ └── YamlDataCreator.cs ├── Excel │ ├── Cell.cs │ ├── DataParser │ │ ├── DataParserFactory.cs │ │ ├── IDataParser.cs │ │ ├── JsonParser.cs │ │ ├── LiteParser.cs │ │ ├── LubParser.cs │ │ ├── StreamParser.cs │ │ └── TextParserBase.cs │ ├── ExcelRowColumnDataSource.cs │ ├── ExcelStream.cs │ ├── RawSheet.cs │ ├── RawSheetTableDefInfo.cs │ ├── RowColumnSheet.cs │ ├── SheetLoadUtil.cs │ ├── StreamSheet.cs │ ├── Title.cs │ └── TitleRow.cs ├── Json │ └── JsonDataSource.cs ├── Lite │ ├── LiteDataSource.cs │ └── LiteStream.cs ├── Lua │ └── LuaDataSource.cs ├── Luban.DataLoader.Builtin.csproj ├── UnityAsset │ └── UnityAssetDataSource.cs ├── Utils │ └── LoadDataUtil.cs ├── Xml │ └── XmlDataSource.cs └── Yaml │ └── YamlDataLoader.cs ├── Luban.DataTarget.Builtin ├── AssemblyInfo.cs ├── Binary │ ├── BinaryDataTarget.cs │ ├── BinaryDataVisitor.cs │ ├── BinaryIndexExportor.cs │ └── BinaryRecordOffsetDataTarget.cs ├── DefaultDataExporter.cs ├── Json │ ├── Json2DataTarget.cs │ ├── Json2DataVisitor.cs │ ├── JsonConvertTarget.cs │ ├── JsonConvertor.cs │ ├── JsonDataTarget.cs │ ├── JsonDataVisitor.cs │ ├── SimpleJsonTypeVisitor.cs │ ├── ToJsonLiteralVisitor.cs │ └── ToJsonPropertyNameVisitor.cs ├── Luban.DataTarget.Builtin.csproj ├── NullDataExporter.cs ├── Res │ ├── ResDataVisitor.cs │ └── ResourceInfo.cs ├── Xml │ ├── ToXmlLiteralVisitor.cs │ ├── XmlDataTarget.cs │ └── XmlDataVisitor.cs └── Yaml │ ├── YamlDataTarget.cs │ └── YamlDataVisitor.cs ├── Luban.DataValidator.Builtin ├── AssemblyInfo.cs ├── Collection │ ├── IndexValidator.cs │ └── SizeValidator.cs ├── Luban.DataValidator.Builtin.csproj ├── Misc │ └── NotDefaultValueValidator.cs ├── Path │ ├── IPathPattern.cs │ ├── PathValidator.cs │ ├── RegexPattern.cs │ ├── SimpleReplacePattern.cs │ ├── Ue4ResourcePattern.cs │ └── UnityAddressablePattern.cs ├── Range │ ├── DoubleRange.cs │ ├── LongRange.cs │ └── RangeValidator.cs ├── Ref │ └── RefValidator.cs ├── Set │ ├── LongDataSet.cs │ ├── SetValidator.cs │ └── StringDataSet.cs └── Str │ └── RegexValidator.cs ├── Luban.FlatBuffers ├── AssemblyInfo.cs ├── CodeTarget │ └── FlatBuffersSchemaTarget.cs ├── DataTarget │ └── FlatBuffersDataTarget.cs ├── DataVisitors │ └── FlatBuffersJsonDataVisitor.cs ├── Luban.FlatBuffers.csproj ├── TemplateExtensions │ └── FlatBuffersTemplateExtension.cs ├── Templates │ └── flatbuffers │ │ └── schema.sbn └── TypeVisitors │ ├── CollectMapKeyValueEntriesVisitor.cs │ ├── FlatBuffersTypeNameVisitor.cs │ └── IsFlatBuffersScalarTypeVisitor.cs ├── Luban.Gdscript ├── AssemblyInfo.cs ├── CodeTarget │ ├── GdscriptCodeTargetBase.cs │ └── GdscriptJsonCodeTarget.cs ├── Luban.Gdscript.csproj ├── TemplateExtensions │ ├── GdscriptCommonTemplateExtension.cs │ └── GdscriptJsonTemplateExtension.cs ├── Templates │ └── gdscript-json │ │ └── schema.sbn └── TypeVisitors │ ├── DeclaringTypeNameVisitor.cs │ └── UnderlyingDeserializeVisitor.cs ├── Luban.Golang ├── AssemblyInfo.cs ├── CodeTarget │ ├── GoBinCodeTarget.cs │ ├── GoCodeTargetBase.cs │ └── GoJsonCodeTarget.cs ├── Luban.Golang.csproj ├── TemplateExtensions │ ├── GoBinTemplateExtension.cs │ ├── GoCommonTemplateExtension.cs │ └── GoJsonTemplateExtension.cs ├── Templates │ ├── common │ │ └── go │ │ │ └── enum.sbn │ ├── go-bin │ │ ├── bean.sbn │ │ ├── table.sbn │ │ └── tables.sbn │ └── go-json │ │ ├── bean.sbn │ │ ├── table.sbn │ │ └── tables.sbn └── TypeVisitors │ ├── BinImport.cs │ ├── BinUnderlyingDeserializeVisitor.cs │ ├── DeclaringTypeNameVisitor.cs │ ├── DeserializeBinVisitor.cs │ ├── DeserializeJsonFieldVisitor.cs │ ├── DeserializeJsonUnderingVisitor.cs │ ├── DeserializeJsonVisitor.cs │ ├── IsPointerTypeVisitor.cs │ ├── JsonImport.cs │ └── UnderlyingDeclaringTypeNameVisitor.cs ├── Luban.Java ├── AssemblyInfo.cs ├── CodeTarget │ ├── JavaBinCodeTarget.cs │ ├── JavaCodeTargetBase.cs │ └── JavaJsonCodeTarget.cs ├── Luban.Java.csproj ├── TemplateExtensions │ ├── JavaBinTemplateExtension.cs │ ├── JavaCommonTemplateExtension.cs │ └── JavaJsonTemplateExtension.cs ├── Templates │ ├── common │ │ └── java │ │ │ └── enum.sbn │ ├── java-bin │ │ ├── bean.sbn │ │ ├── table.sbn │ │ └── tables.sbn │ └── java-json │ │ ├── bean.sbn │ │ ├── table.sbn │ │ └── tables.sbn └── TypeVisitors │ ├── JavaBinDeserializeVisitor.cs │ ├── JavaBinUnderlyingDeserializeVisitor.cs │ ├── JavaDeclaringBoxTypeNameVisitor.cs │ ├── JavaDeclaringTypeNameVisitor.cs │ └── JavaJsonUnderlyingDeserializeVisitor.cs ├── Luban.L10N ├── AssemblyInfo.cs ├── DataTarget │ ├── TextKeyCollection.cs │ ├── TextKeyListCollectorVisitor.cs │ └── TextKeyListDataTarget.cs ├── DefaultTextProvider.cs ├── Luban.L10N.csproj ├── TextKeyToValueTransformer.cs └── TextValidator.cs ├── Luban.Lua ├── AssemblyInfo.cs ├── CodeTarget │ ├── LuaBinCodeTarget.cs │ ├── LuaCodeTargetBase.cs │ └── LuaLuaCodeTarget.cs ├── DataTarget │ └── LuaDataTarget.cs ├── DataVisitors │ └── ToLuaLiteralVisitor.cs ├── Luban.Lua.csproj ├── TemplateExtensions │ ├── LuaBinTemplateExtension.cs │ └── LuaCommonTemplateExtension.cs ├── Templates │ ├── lua-bin │ │ └── schema.sbn │ └── lua-lua │ │ └── schema.sbn └── TypVisitors │ ├── LuaCommentTypeVisitor.cs │ ├── LuaDeserializeMethodNameVisitor.cs │ ├── LuaUnderlyingDeserializeVisitor.cs │ └── LuaValueOrDefaultVisitor.cs ├── Luban.MsgPack ├── AssemblyInfo.cs ├── Luban.MsgPack.csproj ├── MsgPackDataTarget.cs └── MsgPackDataVisitor.cs ├── Luban.PHP ├── AssemblyInfo.cs ├── CodeTarget │ ├── PHPCodeTargetBase.cs │ └── PHPJsonCodeTarget.cs ├── Luban.PHP.csproj ├── TemplateExtensions │ ├── PHPCommonTemplateExtension.cs │ └── PHPJsonTemplateExtension.cs ├── Templates │ ├── common │ │ └── php │ │ │ └── enum.sbn │ └── php-json │ │ └── schema.sbn └── TypeVisitors │ ├── JsonDeserializeVisitor.cs │ └── JsonUnderlyingDeserializeVisitor.cs ├── Luban.Protobuf ├── AssemblyInfo.cs ├── CodeTarget │ ├── CSharpProtobuf2CodeTarget.cs │ ├── CSharpProtobuf3CodeTarget.cs │ ├── CSharpProtobufCodeTargetBase.cs │ ├── Protobuf2SchemaTarget.cs │ ├── Protobuf3SchemaTarget.cs │ └── ProtobufSchemaTargetBase.cs ├── DataTarget │ ├── Protobuf2BinDataTarget.cs │ ├── Protobuf2JsonDataTarget.cs │ ├── Protobuf3BinDataTarget.cs │ └── Protobuf3JsonDataTarget.cs ├── DataVisitors │ ├── Protobuf2JsonDataVisitor.cs │ ├── Protobuf3JsonDataVisitor.cs │ ├── ProtobufBinDataVisitor.cs │ └── ProtobufWireTypeVisitor.cs ├── Luban.Protobuf.csproj ├── TemplateExtensions │ ├── CsharpProtobufTemplateExtension.cs │ ├── Protobuf2TemplateExtension.cs │ ├── Protobuf3TemplateExtension.cs │ └── ProtobufCommonTemplateExtension.cs ├── Templates │ ├── cs_pb │ │ └── tables.sbn │ └── pb │ │ └── schema.sbn └── TypeVisitors │ ├── IsProtobufPackedType.cs │ └── ProtobufTypeNameVisitor.cs ├── Luban.Python ├── AssemblyInfo.cs ├── CodeTarget │ ├── Python2JsonCodeTarget.cs │ └── PythonCodeTargetBase.cs ├── DataVisitors │ └── ToPythonLiteralVisitor.cs ├── Luban.Python.csproj ├── TemplateExtensions │ └── PythonCommonTemplateExtension.cs ├── Templates │ └── python-json │ │ └── schema.sbn └── TypeVisitors │ ├── DeclaringTypeNameVisitor.cs │ └── JsonUnderlyingDeserializeVisitor.cs ├── Luban.Rust ├── AssemblyInfo.cs ├── CodeTarget │ ├── RustBinCodeTarget.cs │ ├── RustCodeTargetBase.cs │ └── RustJsonCodeTarget.cs ├── ConstantStrings.cs ├── Luban.Rust.csproj ├── TemplateExtensions │ ├── RustBinTemplateExtension.cs │ ├── RustCommonTemplateExtension.cs │ └── RustJsonTemplateExtension.cs ├── Templates │ ├── common │ │ └── rs │ │ │ └── macros │ │ │ ├── Cargo.toml.sbn │ │ │ └── src │ │ │ └── lib.rs.sbn │ ├── rust-bin │ │ ├── lib.sbn │ │ ├── mod.sbn │ │ └── toml.sbn │ └── rust-json │ │ ├── lib.sbn │ │ ├── mod.sbn │ │ └── toml.sbn └── TypeVisitors │ ├── BinaryUnderlyingDeserializeVisitor.cs │ ├── RustDeclaringBoxTypeNameVisitor.cs │ ├── RustDeclaringTypeNameVisitor.cs │ └── RustJsonUnderlyingDeserializeVisitor.cs ├── Luban.Schema.Builtin ├── AssemblyInfo.cs ├── AutoTableImporter.cs ├── BeanSchemaFromExcelHeaderLoader.cs ├── DefaultSchemaCollector.cs ├── DefaultTableImporter.cs ├── ExcelSchemaLoader.cs ├── Luban.Schema.Builtin.csproj ├── SchemaLoaderUtil.cs ├── XmlSchemaLoader.cs └── XmlSchemaUtil.cs ├── Luban.Typescript ├── AssemblyInfo.cs ├── CodeTarget │ ├── TypescriptBinCodeTarget.cs │ ├── TypescriptCodeTargetBase.cs │ ├── TypescriptJsonCodeTarget.cs │ └── TypescriptProtobufCodeTarget.cs ├── Luban.Typescript.csproj ├── TemplateExtensions │ ├── TypescriptBinTemplateExtension.cs │ ├── TypescriptCommonTemplateExtension.cs │ └── TypescriptJsonTemplateExtension.cs ├── Templates │ ├── common │ │ └── ts │ │ │ └── enum.sbn │ ├── typescript-bin │ │ └── schema.sbn │ ├── typescript-json │ │ └── schema.sbn │ └── typescript-protobuf │ │ └── schema.sbn └── TypeVisitors │ ├── BinDeserializeVisitor.cs │ ├── BinUnderingDeserializeVisitor.cs │ ├── BinUnderingDeserializeVisitorBase.cs │ ├── DeclaringTypeNameVisitor.cs │ ├── JsonDeserializeVisitor.cs │ ├── JsonUnderlyingDeserializeVisitor.cs │ └── UnderlyingDeclaringTypeNameVisitor.cs ├── Luban.sln ├── Luban.sln.DotSettings ├── Luban ├── .editorconfig ├── Luban.csproj ├── Program.cs ├── Utils │ ├── ConsoleUtil.cs │ └── DirectoryWatcher.cs └── nlog.xml └── nuget.config /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # [pirunxi] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: walon 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: ['https://raw.githubusercontent.com/focus-creative-games/luban/main/docs/sponsor/weixin.JPG','https://raw.githubusercontent.com/focus-creative-games/luban/main/docs/sponsor/zhifubao.JPG'] 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: csharp 2 | solution: src/Luban.sln 3 | 4 | mono: none 5 | dotnet: 6.0 6 | script: 7 | - cd src 8 | - dotnet restore Luban.sln 9 | - dotnet build Luban.sln -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Code Philosophy Technology Ltd. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-slate -------------------------------------------------------------------------------- /docs/images/Client_Server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/Client_Server.png -------------------------------------------------------------------------------- /docs/images/adv/def_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_01.png -------------------------------------------------------------------------------- /docs/images/adv/def_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_02.png -------------------------------------------------------------------------------- /docs/images/adv/def_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_03.png -------------------------------------------------------------------------------- /docs/images/adv/def_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_04.png -------------------------------------------------------------------------------- /docs/images/adv/def_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_05.png -------------------------------------------------------------------------------- /docs/images/adv/def_06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_06.png -------------------------------------------------------------------------------- /docs/images/adv/def_07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_07.png -------------------------------------------------------------------------------- /docs/images/adv/def_08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_08.png -------------------------------------------------------------------------------- /docs/images/adv/def_09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_09.png -------------------------------------------------------------------------------- /docs/images/adv/def_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_10.png -------------------------------------------------------------------------------- /docs/images/adv/def_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_11.png -------------------------------------------------------------------------------- /docs/images/adv/def_12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_12.png -------------------------------------------------------------------------------- /docs/images/adv/def_13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_13.png -------------------------------------------------------------------------------- /docs/images/adv/def_14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_14.png -------------------------------------------------------------------------------- /docs/images/adv/def_15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_15.png -------------------------------------------------------------------------------- /docs/images/adv/def_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_16.png -------------------------------------------------------------------------------- /docs/images/adv/def_17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_17.png -------------------------------------------------------------------------------- /docs/images/adv/def_18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_18.png -------------------------------------------------------------------------------- /docs/images/adv/def_19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_19.png -------------------------------------------------------------------------------- /docs/images/adv/def_20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_20.png -------------------------------------------------------------------------------- /docs/images/adv/def_21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_21.png -------------------------------------------------------------------------------- /docs/images/adv/def_22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_22.png -------------------------------------------------------------------------------- /docs/images/adv/def_23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_23.png -------------------------------------------------------------------------------- /docs/images/adv/def_24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_24.png -------------------------------------------------------------------------------- /docs/images/adv/def_25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_25.png -------------------------------------------------------------------------------- /docs/images/adv/def_26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_26.png -------------------------------------------------------------------------------- /docs/images/adv/def_27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_27.png -------------------------------------------------------------------------------- /docs/images/adv/def_28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_28.png -------------------------------------------------------------------------------- /docs/images/adv/def_29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_29.png -------------------------------------------------------------------------------- /docs/images/adv/def_30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_30.png -------------------------------------------------------------------------------- /docs/images/adv/def_31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_31.png -------------------------------------------------------------------------------- /docs/images/adv/def_32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_32.png -------------------------------------------------------------------------------- /docs/images/adv/def_33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_33.png -------------------------------------------------------------------------------- /docs/images/adv/def_34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_34.png -------------------------------------------------------------------------------- /docs/images/adv/def_35.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_35.png -------------------------------------------------------------------------------- /docs/images/adv/def_36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_36.png -------------------------------------------------------------------------------- /docs/images/adv/def_37.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_37.png -------------------------------------------------------------------------------- /docs/images/adv/def_38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_38.png -------------------------------------------------------------------------------- /docs/images/adv/def_39.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_39.png -------------------------------------------------------------------------------- /docs/images/adv/def_40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_40.png -------------------------------------------------------------------------------- /docs/images/adv/def_41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_41.png -------------------------------------------------------------------------------- /docs/images/adv/def_42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_42.png -------------------------------------------------------------------------------- /docs/images/adv/def_43.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_43.png -------------------------------------------------------------------------------- /docs/images/adv/def_44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_44.png -------------------------------------------------------------------------------- /docs/images/adv/def_45.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_45.png -------------------------------------------------------------------------------- /docs/images/adv/def_46.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_46.png -------------------------------------------------------------------------------- /docs/images/adv/def_47.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_47.png -------------------------------------------------------------------------------- /docs/images/adv/def_48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_48.png -------------------------------------------------------------------------------- /docs/images/adv/def_49.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_49.png -------------------------------------------------------------------------------- /docs/images/adv/def_50.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/adv/def_50.png -------------------------------------------------------------------------------- /docs/images/cases/bean.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/bean.jpg -------------------------------------------------------------------------------- /docs/images/cases/bean2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/bean2.jpg -------------------------------------------------------------------------------- /docs/images/cases/collection.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/collection.jpg -------------------------------------------------------------------------------- /docs/images/cases/enum.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/enum.jpg -------------------------------------------------------------------------------- /docs/images/cases/ignorefield.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/ignorefield.jpg -------------------------------------------------------------------------------- /docs/images/cases/l10n_text.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/l10n_text.jpg -------------------------------------------------------------------------------- /docs/images/cases/multileveltitle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/multileveltitle.jpg -------------------------------------------------------------------------------- /docs/images/cases/multiline.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/multiline.jpg -------------------------------------------------------------------------------- /docs/images/cases/nullable.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/nullable.jpg -------------------------------------------------------------------------------- /docs/images/cases/primitive_type.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/primitive_type.jpg -------------------------------------------------------------------------------- /docs/images/cases/quickstart_reward.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/quickstart_reward.jpg -------------------------------------------------------------------------------- /docs/images/cases/quickstart_table.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/quickstart_table.jpg -------------------------------------------------------------------------------- /docs/images/cases/sep_bean.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/sep_bean.jpg -------------------------------------------------------------------------------- /docs/images/cases/sep_container1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/sep_container1.jpg -------------------------------------------------------------------------------- /docs/images/cases/sep_container2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/sep_container2.jpg -------------------------------------------------------------------------------- /docs/images/cases/simple1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/simple1.jpg -------------------------------------------------------------------------------- /docs/images/cases/singleton.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/singleton.jpg -------------------------------------------------------------------------------- /docs/images/cases/singleton2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/singleton2.jpg -------------------------------------------------------------------------------- /docs/images/cases/stream.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/stream.jpg -------------------------------------------------------------------------------- /docs/images/cases/table_list_indep_key.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/table_list_indep_key.jpg -------------------------------------------------------------------------------- /docs/images/cases/table_list_not_key.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/table_list_not_key.jpg -------------------------------------------------------------------------------- /docs/images/cases/table_list_union_key.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/table_list_union_key.jpg -------------------------------------------------------------------------------- /docs/images/cases/tag.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/tag.jpg -------------------------------------------------------------------------------- /docs/images/cases/tag2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/tag2.jpg -------------------------------------------------------------------------------- /docs/images/cases/title_dynamic_bean.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/title_dynamic_bean.jpg -------------------------------------------------------------------------------- /docs/images/cases/title_enum.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/title_enum.jpg -------------------------------------------------------------------------------- /docs/images/cases/title_map.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/title_map.jpg -------------------------------------------------------------------------------- /docs/images/cases/titlelimit.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/cases/titlelimit.jpg -------------------------------------------------------------------------------- /docs/images/docusaurus-social-card.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/docusaurus-social-card.jpg -------------------------------------------------------------------------------- /docs/images/docusaurus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/docusaurus.png -------------------------------------------------------------------------------- /docs/images/dots_release.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/dots_release.png -------------------------------------------------------------------------------- /docs/images/excel_bean.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/excel_bean.jpg -------------------------------------------------------------------------------- /docs/images/excel_enum.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/excel_enum.jpg -------------------------------------------------------------------------------- /docs/images/excel_table.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/excel_table.jpg -------------------------------------------------------------------------------- /docs/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/favicon.ico -------------------------------------------------------------------------------- /docs/images/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/favicon.png -------------------------------------------------------------------------------- /docs/images/flying-seagull.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/flying-seagull.jpg -------------------------------------------------------------------------------- /docs/images/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/icon.png -------------------------------------------------------------------------------- /docs/images/install/install_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/install/install_01.png -------------------------------------------------------------------------------- /docs/images/install/install_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/install/install_02.png -------------------------------------------------------------------------------- /docs/images/install/install_03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/install/install_03.png -------------------------------------------------------------------------------- /docs/images/install/install_04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/install/install_04.png -------------------------------------------------------------------------------- /docs/images/install/install_05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/install/install_05.png -------------------------------------------------------------------------------- /docs/images/install/install_06.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/install/install_06.png -------------------------------------------------------------------------------- /docs/images/install/install_07.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/install/install_07.png -------------------------------------------------------------------------------- /docs/images/install/install_08.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/install/install_08.png -------------------------------------------------------------------------------- /docs/images/install/install_09.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/install/install_09.png -------------------------------------------------------------------------------- /docs/images/install/install_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/install/install_10.png -------------------------------------------------------------------------------- /docs/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/logo.png -------------------------------------------------------------------------------- /docs/images/luban_edit_tool.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/luban_edit_tool.png -------------------------------------------------------------------------------- /docs/images/more.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/more.png -------------------------------------------------------------------------------- /docs/images/other.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/other.png -------------------------------------------------------------------------------- /docs/images/panda-waving.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/panda-waving.png -------------------------------------------------------------------------------- /docs/images/pipeline.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/pipeline.jpg -------------------------------------------------------------------------------- /docs/images/process.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/process.jpg -------------------------------------------------------------------------------- /docs/images/python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/python.png -------------------------------------------------------------------------------- /docs/images/ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/ui.png -------------------------------------------------------------------------------- /docs/images/web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/web.png -------------------------------------------------------------------------------- /docs/images/weixin.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/weixin.jpg -------------------------------------------------------------------------------- /docs/images/zhifubao.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/images/zhifubao.jpg -------------------------------------------------------------------------------- /docs/sponsor/weixin.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/sponsor/weixin.JPG -------------------------------------------------------------------------------- /docs/sponsor/zhifubao.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/focus-creative-games/luban/b2ed13dbdc94d76e05b870422ac18ce6bbafd56c/docs/sponsor/zhifubao.JPG -------------------------------------------------------------------------------- /scripts/format.bat: -------------------------------------------------------------------------------- 1 | cd ../src 2 | dotnet format --severity error -v n 3 | -------------------------------------------------------------------------------- /scripts/format.sh: -------------------------------------------------------------------------------- 1 | cd ../src 2 | dotnet format --severity error -v n 3 | -------------------------------------------------------------------------------- /src/.dockerignore: -------------------------------------------------------------------------------- 1 | **/bin/ 2 | **/obj/ 3 | /lubanAssistant/ 4 | /packages/ 5 | /TestResults/ 6 | LubanTools.sln 7 | -------------------------------------------------------------------------------- /src/Luban.Bson/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.Bson/BsonDataTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.DataTarget; 2 | using Luban.Defs; 3 | using Luban.Utils; 4 | using Newtonsoft.Json.Bson; 5 | 6 | namespace Luban.Bson; 7 | 8 | [DataTarget("bson")] 9 | public class BsonDataTarget : DataTargetBase 10 | { 11 | protected override string DefaultOutputFileExt => "bson"; 12 | 13 | 14 | private void WriteAsArray(List datas, BsonDataWriter x) 15 | { 16 | x.WriteStartArray(); 17 | foreach (var d in datas) 18 | { 19 | d.Data.Apply(BsonDataVisitor.Ins, x); 20 | } 21 | x.WriteEndArray(); 22 | } 23 | 24 | public override OutputFile ExportTable(DefTable table, List records) 25 | { 26 | var ss = new MemoryStream(); 27 | var bsonWriter = new BsonDataWriter(ss); 28 | WriteAsArray(records, bsonWriter); 29 | bsonWriter.Flush(); 30 | return CreateOutputFile($"{table.OutputDataFile}.{OutputFileExt}", DataUtil.StreamToBytes(ss)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Luban.Bson/Luban.Bson.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | disable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/Luban.CSharp/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.CSharp/CodeTarget/CsharpBinCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.CSharp.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.CSharp.CodeTarget; 6 | 7 | [CodeTarget("cs-bin")] 8 | public class CsharpBinCodeTarget : CsharpCodeTargetBase 9 | { 10 | protected override void OnCreateTemplateContext(TemplateContext ctx) 11 | { 12 | base.OnCreateTemplateContext(ctx); 13 | ctx.PushGlobal(new CsharpBinTemplateExtension()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.CSharp/CodeTarget/CsharpDotnetJsonCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.CSharp.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.CSharp.CodeTarget; 6 | 7 | [CodeTarget("cs-dotnet-json")] 8 | public class CsharpDotnetJsonCodeTarget : CsharpCodeTargetBase 9 | { 10 | 11 | protected override void OnCreateTemplateContext(TemplateContext ctx) 12 | { 13 | base.OnCreateTemplateContext(ctx); 14 | ctx.PushGlobal(new CsharpDotNetJsonTemplateExtension()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Luban.CSharp/CodeTarget/CsharpNewtonSoftJsonCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.CSharp.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.CSharp.CodeTarget; 6 | 7 | [CodeTarget("cs-newtonsoft-json")] 8 | public class CsharpNewtonSoftJsonCodeTarget : CsharpCodeTargetBase 9 | { 10 | protected override void OnCreateTemplateContext(TemplateContext ctx) 11 | { 12 | base.OnCreateTemplateContext(ctx); 13 | ctx.PushGlobal(new CsharpNewtonSoftJsonTemplateExtension()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.CSharp/CodeTarget/CsharpSimpleJsonCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.CSharp.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.CSharp.CodeTarget; 6 | 7 | [CodeTarget("cs-simple-json")] 8 | public class CsharpSimpleJsonCodeTarget : CsharpCodeTargetBase 9 | { 10 | 11 | protected override void OnCreateTemplateContext(TemplateContext ctx) 12 | { 13 | base.OnCreateTemplateContext(ctx); 14 | ctx.PushGlobal(new CsharpSimpleJsonTemplateExtension()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Luban.CSharp/ConstStrings.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.CSharp; 2 | 3 | public static class ConstStrings 4 | { 5 | public const string ListTypeName = "System.Collections.Generic.List"; 6 | public const string HashSetTypeName = "System.Collections.Generic.HashSet"; 7 | public const string HashMapTypeName = "System.Collections.Generic.Dictionary"; 8 | } 9 | -------------------------------------------------------------------------------- /src/Luban.CSharp/TemplateExtensions/CsharpBinTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.CSharp.TypeVisitors; 2 | using Luban.Types; 3 | using Scriban.Runtime; 4 | 5 | namespace Luban.CSharp.TemplateExtensions; 6 | 7 | public class CsharpBinTemplateExtension : ScriptObject 8 | { 9 | public static string Deserialize(string bufName, string fieldName, TType type) 10 | { 11 | return type.Apply(BinaryDeserializeVisitor.Ins, bufName, fieldName); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Luban.CSharp/TemplateExtensions/CsharpNewtonSoftJsonTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.CSharp.TypeVisitors; 2 | using Luban.Types; 3 | using Scriban.Runtime; 4 | namespace Luban.CSharp.TemplateExtensions; 5 | 6 | internal class CsharpNewtonSoftJsonTemplateExtension : ScriptObject 7 | { 8 | public static string Deserialize(string fieldName, string jsonVar, TType type) 9 | { 10 | return type.Apply(NewtonSoftJsonDeserializeVisitor.Ins, jsonVar, fieldName, 0); 11 | } 12 | 13 | public static string DeserializeField(string fieldName, string jsonVar, string jsonFieldName, TType type) 14 | { 15 | if (type.IsNullable) 16 | { 17 | return $"{{if ({jsonVar}.TryGetValue(\"{jsonFieldName}\", out var _j)) {{ {type.Apply(NewtonSoftJsonDeserializeVisitor.Ins, "_j", fieldName, 0)} }} else {{ {fieldName} = null; }} }}"; 18 | } 19 | else 20 | { 21 | return type.Apply(NewtonSoftJsonDeserializeVisitor.Ins, $"{jsonVar}.GetValue(\"{jsonFieldName}\")", fieldName, 0); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Luban.CSharp/Templates/common/cs/enum.sbn: -------------------------------------------------------------------------------- 1 | {{~ 2 | comment = __enum.comment 3 | items = __enum.items 4 | ~}} 5 | 6 | 7 | {{namespace_with_grace_begin __namespace_with_top_module}} 8 | {{~if comment != '' ~}} 9 | /// 10 | /// {{escape_comment comment}} 11 | /// 12 | {{~end~}} 13 | {{~if __enum.is_flags~}} 14 | [System.Flags] 15 | {{~end~}} 16 | public enum {{__name}} 17 | { 18 | {{~ for item in items ~}} 19 | {{~if item.comment != '' ~}} 20 | /// 21 | /// {{escape_comment item.comment_or_alias}} 22 | /// 23 | {{~end~}} 24 | {{format_enum_item_name __code_style item.name}} = {{item.value}}, 25 | {{~end~}} 26 | } 27 | 28 | {{namespace_with_grace_end __namespace_with_top_module}} 29 | -------------------------------------------------------------------------------- /src/Luban.CSharp/Templates/cs-bin/tables.sbn: -------------------------------------------------------------------------------- 1 | using Luban; 2 | 3 | {{namespace_with_grace_begin __namespace}} 4 | public partial class {{__name}} 5 | { 6 | {{~for table in __tables ~}} 7 | {{~if table.comment != '' ~}} 8 | /// 9 | /// {{escape_comment table.comment}} 10 | /// 11 | {{~end~}} 12 | public {{table.full_name}} {{format_property_name __code_style table.name}} {get; } 13 | {{~end~}} 14 | 15 | public {{__name}}(System.Func loader) 16 | { 17 | {{~for table in __tables ~}} 18 | {{format_property_name __code_style table.name}} = new {{table.full_name}}(loader("{{table.output_data_file}}")); 19 | {{~end~}} 20 | ResolveRef(); 21 | } 22 | 23 | private void ResolveRef() 24 | { 25 | {{~for table in __tables ~}} 26 | {{format_property_name __code_style table.name}}.ResolveRef(this); 27 | {{~end~}} 28 | } 29 | } 30 | 31 | {{namespace_with_grace_end __namespace}} -------------------------------------------------------------------------------- /src/Luban.CSharp/Templates/cs-dotnet-json/tables.sbn: -------------------------------------------------------------------------------- 1 | using Luban; 2 | using System.Text.Json; 3 | 4 | {{namespace_with_grace_begin __namespace}} 5 | public partial class {{__name}} 6 | { 7 | {{~for table in __tables ~}} 8 | {{~if table.comment != '' ~}} 9 | /// 10 | /// {{escape_comment table.comment}} 11 | /// 12 | {{~end~}} 13 | public {{table.full_name}} {{format_property_name __code_style table.name}} {get; } 14 | {{~end~}} 15 | 16 | public {{__name}}(System.Func loader) 17 | { 18 | {{~for table in __tables ~}} 19 | {{format_property_name __code_style table.name}} = new {{table.full_name}}(loader("{{table.output_data_file}}")); 20 | {{~end~}} 21 | ResolveRef(); 22 | } 23 | 24 | private void ResolveRef() 25 | { 26 | {{~for table in __tables ~}} 27 | {{format_property_name __code_style table.name}}.ResolveRef(this); 28 | {{~end~}} 29 | } 30 | } 31 | 32 | {{namespace_with_grace_end __namespace}} -------------------------------------------------------------------------------- /src/Luban.CSharp/Templates/cs-newtonsoft-json/tables.sbn: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Linq; 2 | 3 | {{namespace_with_grace_begin __namespace}} 4 | public partial class {{__name}} 5 | { 6 | {{~for table in __tables ~}} 7 | {{~if table.comment != '' ~}} 8 | /// 9 | /// {{escape_comment table.comment}} 10 | /// 11 | {{~end~}} 12 | public {{table.full_name}} {{format_property_name __code_style table.name}} {get; } 13 | {{~end~}} 14 | 15 | 16 | public {{__name}}(System.Func loader) 17 | { 18 | {{~for table in __tables ~}} 19 | {{format_property_name __code_style table.name}} = new {{table.full_name}}(loader("{{table.output_data_file}}")); 20 | {{~end~}} 21 | ResolveRef(); 22 | } 23 | 24 | private void ResolveRef() 25 | { 26 | {{~for table in __tables ~}} 27 | {{format_property_name __code_style table.name}}.ResolveRef(this); 28 | {{~end~}} 29 | } 30 | } 31 | 32 | {{namespace_with_grace_end __namespace}} 33 | -------------------------------------------------------------------------------- /src/Luban.CSharp/Templates/cs-simple-json/tables.sbn: -------------------------------------------------------------------------------- 1 | using Luban; 2 | using SimpleJSON; 3 | 4 | {{namespace_with_grace_begin __namespace}} 5 | public partial class {{__name}} 6 | { 7 | {{~for table in __tables ~}} 8 | {{~if table.comment != '' ~}} 9 | /// 10 | /// {{escape_comment table.comment}} 11 | /// 12 | {{~end~}} 13 | public {{table.full_name}} {{format_property_name __code_style table.name}} {get; } 14 | {{~end~}} 15 | 16 | public {{__name}}(System.Func loader) 17 | { 18 | {{~for table in __tables ~}} 19 | {{format_property_name __code_style table.name}} = new {{table.full_name}}(loader("{{table.output_data_file}}")); 20 | {{~end~}} 21 | ResolveRef(); 22 | } 23 | 24 | private void ResolveRef() 25 | { 26 | {{~for table in __tables ~}} 27 | {{format_property_name __code_style table.name}}.ResolveRef(this); 28 | {{~end~}} 29 | } 30 | } 31 | 32 | {{namespace_with_grace_end __namespace}} -------------------------------------------------------------------------------- /src/Luban.CSharp/TypeUtil.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Luban.CSharp; 9 | 10 | public static class CSharpUtil 11 | { 12 | public static string GetFullNameWithGlobalQualifier(DefTypeBase type) 13 | { 14 | return $"global::{type.FullNameWithTopModule}"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Luban.CSharp/TypeVisitors/BinaryDeserializeVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.CSharp.TypeVisitors; 5 | 6 | public class BinaryDeserializeVisitor : DecoratorFuncVisitor 7 | { 8 | public static BinaryDeserializeVisitor Ins { get; } = new(); 9 | 10 | public override string DoAccept(TType type, string bufName, string fieldName) 11 | { 12 | if (type.IsNullable) 13 | { 14 | return $"if({bufName}.ReadBool()){{ {type.Apply(BinaryUnderlyingDeserializeVisitor.Ins, bufName, fieldName, 0)} }} else {{ {fieldName} = null; }}"; 15 | } 16 | else 17 | { 18 | return type.Apply(BinaryUnderlyingDeserializeVisitor.Ins, bufName, fieldName, 0); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Luban.CSharp/TypeVisitors/DataToStringVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.CSharp.TypeVisitors; 5 | 6 | public class DataToStringVisitor : DecoratorFuncVisitor 7 | { 8 | public static DataToStringVisitor Ins { get; } = new(); 9 | 10 | public override string DoAccept(TType type, string fieldName) 11 | { 12 | return fieldName; 13 | } 14 | 15 | public override string Accept(TArray type, string fieldName) 16 | { 17 | return $"Luban.StringUtil.CollectionToString({fieldName})"; 18 | } 19 | 20 | public override string Accept(TList type, string fieldName) 21 | { 22 | return $"Luban.StringUtil.CollectionToString({fieldName})"; 23 | } 24 | 25 | public override string Accept(TSet type, string fieldName) 26 | { 27 | return $"Luban.StringUtil.CollectionToString({fieldName})"; 28 | } 29 | 30 | public override string Accept(TMap type, string fieldName) 31 | { 32 | return $"Luban.StringUtil.CollectionToString({fieldName})"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Luban.CSharp/TypeVisitors/EditorDeclaringTypeNameVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.CSharp.TypeVisitors; 5 | 6 | public class EditorDeclaringTypeNameVisitor : DeclaringTypeNameVisitor 7 | { 8 | public new static EditorDeclaringTypeNameVisitor Ins { get; } = new(); 9 | 10 | protected override ITypeFuncVisitor UnderlyingVisitor => EditorUnderlyingTypeNameVisitor.Ins; 11 | 12 | public override string Accept(TDateTime type) 13 | { 14 | return "string"; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Luban.CSharp/TypeVisitors/EditorIsRawNullableTypeVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.CSharp.TypeVisitors; 5 | 6 | public class EditorIsRawNullableTypeVisitor : IsRawNullableTypeVisitor 7 | { 8 | public new static EditorIsRawNullableTypeVisitor Ins { get; } = new(); 9 | 10 | public override bool Accept(TBean type) 11 | { 12 | return true; 13 | } 14 | 15 | public override bool Accept(TDateTime type) 16 | { 17 | return true; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Luban.CSharp/TypeVisitors/EditorJsonSave.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.CSharp.TypeVisitors; 5 | 6 | class EditorJsonSave : DecoratorFuncVisitor 7 | { 8 | public static EditorJsonSave Ins { get; } = new(); 9 | 10 | public override string DoAccept(TType type, string jsonName, string jsonFieldName, string value, int depth) 11 | { 12 | return $"{type.Apply(EditorJsonSaveUnderlying.Ins, jsonName, jsonFieldName, (!type.IsNullable || type.Apply(EditorIsRawNullableTypeVisitor.Ins) ? value : $"{value}.Value"), depth)}"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Luban.CSharp/TypeVisitors/EditorNeedInitVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | 3 | namespace Luban.CSharp.TypeVisitors; 4 | 5 | public class EditorNeedInitVisitor : NeedInitFieldVisitor 6 | { 7 | public new static EditorNeedInitVisitor Ins { get; } = new(); 8 | 9 | public override bool Accept(TEnum type) 10 | { 11 | return true; 12 | } 13 | 14 | public override bool Accept(TDateTime type) 15 | { 16 | return true; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Luban.CSharp/TypeVisitors/EditorUnderlyingTypeNameVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | 3 | namespace Luban.CSharp.TypeVisitors; 4 | 5 | public class EditorUnderlyingTypeNameVisitor : UnderlyingDeclaringTypeNameVisitor 6 | { 7 | public new static EditorUnderlyingTypeNameVisitor Ins { get; } = new(); 8 | 9 | public override string Accept(TDateTime type) 10 | { 11 | return "string"; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Luban.CSharp/TypeVisitors/IsRawNullableTypeVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.CSharp.TypeVisitors; 5 | 6 | public class IsRawNullableTypeVisitor : AllFalseVisitor 7 | { 8 | public static IsRawNullableTypeVisitor Ins { get; } = new(); 9 | 10 | public override bool Accept(TString type) 11 | { 12 | return true; 13 | } 14 | 15 | public override bool Accept(TArray type) 16 | { 17 | return true; 18 | } 19 | 20 | public override bool Accept(TList type) 21 | { 22 | return true; 23 | } 24 | 25 | public override bool Accept(TSet type) 26 | { 27 | return true; 28 | } 29 | 30 | public override bool Accept(TMap type) 31 | { 32 | return true; 33 | } 34 | 35 | public override bool Accept(TBean type) 36 | { 37 | return !type.DefBean.IsValueType; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Luban.CSharp/TypeVisitors/NeedInitFieldVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.CSharp.TypeVisitors; 5 | 6 | public class NeedInitFieldVisitor : AllFalseVisitor 7 | { 8 | public static NeedInitFieldVisitor Ins { get; } = new(); 9 | 10 | public override bool Accept(TString type) 11 | { 12 | return true; 13 | } 14 | 15 | public override bool Accept(TArray type) 16 | { 17 | return true; 18 | } 19 | 20 | public override bool Accept(TList type) 21 | { 22 | return true; 23 | } 24 | 25 | public override bool Accept(TSet type) 26 | { 27 | return true; 28 | } 29 | 30 | public override bool Accept(TMap type) 31 | { 32 | return true; 33 | } 34 | 35 | public override bool Accept(TBean type) 36 | { 37 | return !type.IsDynamic; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Luban.Core/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.Core/CodeFormat/CodeStyleAttribute.cs: -------------------------------------------------------------------------------- 1 | using Luban.CustomBehaviour; 2 | 3 | namespace Luban.CodeFormat; 4 | 5 | [AttributeUsage(AttributeTargets.Class)] 6 | public class CodeStyleAttribute : BehaviourBaseAttribute 7 | { 8 | public CodeStyleAttribute(string name) : base(name) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Luban.Core/CodeFormat/CodeStyles/CodeStyleBase.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.CodeFormat.CodeStyles; 2 | 3 | public abstract class CodeStyleBase : ICodeStyle 4 | { 5 | public abstract string FormatNamespace(string ns); 6 | public abstract string FormatType(string typeName); 7 | public abstract string FormatMethod(string methodName); 8 | 9 | public virtual string FormatProperty(string propertyName) 10 | { 11 | return FormatMethod(propertyName); 12 | } 13 | 14 | public abstract string FormatField(string fieldName); 15 | 16 | public abstract string FormatEnumItemName(string enumItemName); 17 | } 18 | -------------------------------------------------------------------------------- /src/Luban.Core/CodeFormat/ICodeStyle.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.CodeFormat; 2 | 3 | public interface ICodeStyle 4 | { 5 | string FormatNamespace(string ns); 6 | 7 | string FormatType(string typeName); 8 | 9 | string FormatMethod(string methodName); 10 | 11 | string FormatProperty(string propertyName); 12 | 13 | string FormatField(string fieldName); 14 | 15 | string FormatEnumItemName(string enumItemName); 16 | } 17 | -------------------------------------------------------------------------------- /src/Luban.Core/CodeFormat/INamingConventionFormatter.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.CodeFormat; 2 | 3 | public interface INamingConventionFormatter 4 | { 5 | string FormatName(string name); 6 | } 7 | -------------------------------------------------------------------------------- /src/Luban.Core/CodeFormat/NamingConventionAttribute.cs: -------------------------------------------------------------------------------- 1 | using Luban.CustomBehaviour; 2 | 3 | namespace Luban.CodeFormat; 4 | 5 | [AttributeUsage(AttributeTargets.Class)] 6 | public class NamingConventionAttribute : BehaviourBaseAttribute 7 | { 8 | public NamingConventionAttribute(string name) : base(name) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Luban.Core/CodeFormat/NamingConventionFormatters/CamelCaseFormatter.cs: -------------------------------------------------------------------------------- 1 | using Luban.Utils; 2 | 3 | namespace Luban.CodeFormat.NamingConventionFormatters; 4 | 5 | [NamingConvention("camel")] 6 | public class CamelCaseFormatter : INamingConventionFormatter 7 | { 8 | public string FormatName(string fieldName) 9 | { 10 | return TypeUtil.ToCamelCase(fieldName); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Luban.Core/CodeFormat/NamingConventionFormatters/NoneFormatter.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.CodeFormat.NamingConventionFormatters; 2 | 3 | [NamingConvention("none")] 4 | public class NoneFormatter : INamingConventionFormatter 5 | { 6 | public string FormatName(string name) 7 | { 8 | return name; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Luban.Core/CodeFormat/NamingConventionFormatters/PascalCaseFormatter.cs: -------------------------------------------------------------------------------- 1 | using Luban.Utils; 2 | 3 | namespace Luban.CodeFormat.NamingConventionFormatters; 4 | 5 | [NamingConvention("pascal")] 6 | public class PascalCaseFormatter : INamingConventionFormatter 7 | { 8 | public string FormatName(string name) 9 | { 10 | return TypeUtil.ToPascalCase(name); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Luban.Core/CodeFormat/NamingConventionFormatters/SnakeCaseFormatter.cs: -------------------------------------------------------------------------------- 1 | using Luban.Utils; 2 | 3 | namespace Luban.CodeFormat.NamingConventionFormatters; 4 | 5 | [NamingConvention("snake")] 6 | public class SnakeCaseFormatter : INamingConventionFormatter 7 | { 8 | public string FormatName(string name) 9 | { 10 | return TypeUtil.ToUnderScores(name); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Luban.Core/CodeFormat/NamingConventionFormatters/UpperCaseFormatter.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.CodeFormat.NamingConventionFormatters; 2 | 3 | [NamingConvention("upper")] 4 | public class UpperCaseFormatter : INamingConventionFormatter 5 | { 6 | public string FormatName(string name) 7 | { 8 | return name.ToUpperInvariant(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/Luban.Core/CodeTarget/CodeTargetAttribute.cs: -------------------------------------------------------------------------------- 1 | using Luban.CustomBehaviour; 2 | 3 | namespace Luban.CodeTarget; 4 | 5 | [AttributeUsage(AttributeTargets.Class, Inherited = false)] 6 | public class CodeTargetAttribute : BehaviourBaseAttribute 7 | { 8 | public CodeTargetAttribute(string name) : base(name) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Luban.Core/CodeTarget/CodeTargetManager.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using Luban.CustomBehaviour; 3 | 4 | namespace Luban.CodeTarget; 5 | 6 | public class CodeTargetManager 7 | { 8 | public static CodeTargetManager Ins { get; } = new(); 9 | 10 | public void Init() 11 | { 12 | 13 | } 14 | 15 | public ICodeTarget CreateCodeTarget(string name) 16 | { 17 | return CustomBehaviourManager.Ins.CreateBehaviour(name); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Luban.Core/CodeTarget/CodeWriter.cs: -------------------------------------------------------------------------------- 1 | using Luban.Utils; 2 | using System.Text; 3 | 4 | namespace Luban.CodeTarget; 5 | 6 | public class CodeWriter 7 | { 8 | private readonly List _lines; 9 | 10 | public CodeWriter(int lineCapacity = 1000) 11 | { 12 | _lines = new List(lineCapacity); 13 | } 14 | 15 | public void Write(string line) 16 | { 17 | _lines.Add(line); 18 | } 19 | 20 | public string ToResult(string header) 21 | { 22 | var sb = new StringBuilder(100 * 1024); 23 | if (!string.IsNullOrEmpty(header)) 24 | { 25 | sb.AppendLine(header); 26 | } 27 | foreach (var line in _lines) 28 | { 29 | sb.AppendLine(line); 30 | } 31 | return sb.ToString(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Luban.Core/CodeTarget/ICodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | using System.Text; 3 | 4 | namespace Luban.CodeTarget; 5 | 6 | public interface ICodeTarget 7 | { 8 | string Name { get; } 9 | 10 | void ValidateDefinition(GenerationContext ctx); 11 | 12 | void Handle(GenerationContext ctx, OutputFileManifest manifest); 13 | 14 | string FileHeader { get; } 15 | 16 | Encoding FileEncoding { get; } 17 | 18 | string GetPathFromFullName(string fullName); 19 | 20 | void GenerateTables(GenerationContext ctx, List tables, CodeWriter writer); 21 | 22 | void GenerateTable(GenerationContext ctx, DefTable table, CodeWriter writer); 23 | 24 | void GenerateBean(GenerationContext ctx, DefBean bean, CodeWriter writer); 25 | 26 | void GenerateEnum(GenerationContext ctx, DefEnum @enum, CodeWriter writer); 27 | } 28 | -------------------------------------------------------------------------------- /src/Luban.Core/CodeTarget/NameLocation.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.CodeTarget; 2 | 3 | public enum NameLocation 4 | { 5 | TableName, 6 | BeanName, 7 | EnumName, 8 | BeanFieldName, 9 | EnumItemName, 10 | } 11 | -------------------------------------------------------------------------------- /src/Luban.Core/CustomBehaviour/BehaviourBaseAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.CustomBehaviour; 2 | 3 | public abstract class BehaviourBaseAttribute : Attribute, ICustomBehaviour 4 | { 5 | public string Name { get; } 6 | 7 | public int Priority { get; set; } 8 | 9 | protected BehaviourBaseAttribute(string name) 10 | { 11 | Name = name; 12 | Priority = 0; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Luban.Core/CustomBehaviour/ICustomBehaviour.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.CustomBehaviour; 2 | 3 | public interface ICustomBehaviour 4 | { 5 | public string Name { get; } 6 | 7 | int Priority { get; } 8 | } 9 | -------------------------------------------------------------------------------- /src/Luban.Core/CustomBehaviour/IPriorityBehaviour.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.CustomBehaviour; 2 | 3 | public interface IPriorityBehaviour 4 | { 5 | int Priority { get; } 6 | } 7 | -------------------------------------------------------------------------------- /src/Luban.Core/DataLoader/DataLoaderAttribute.cs: -------------------------------------------------------------------------------- 1 | using Luban.CustomBehaviour; 2 | 3 | namespace Luban.DataLoader; 4 | 5 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] 6 | public class DataLoaderAttribute : BehaviourBaseAttribute 7 | { 8 | public DataLoaderAttribute(string name) : base(name) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Luban.Core/DataLoader/DataLoaderBase.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | using Luban.Types; 3 | 4 | namespace Luban.DataLoader; 5 | 6 | public abstract class DataLoaderBase : IDataLoader 7 | { 8 | public string RawUrl { get; protected set; } 9 | 10 | public abstract Record ReadOne(TBean type); 11 | 12 | public abstract List ReadMulti(TBean type); 13 | 14 | public abstract void Load(string rawUrl, string sheetName, Stream stream); 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Core/DataLoader/FieldNames.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.DataLoader; 2 | 3 | public static class FieldNames 4 | { 5 | public const string FallbackTypeNameKey = "__type__"; 6 | 7 | public const string BeanNullType = "null"; 8 | 9 | public const string BeanNotNullType = "{}"; 10 | 11 | public const string JsonTypeNameKey = "$type"; 12 | 13 | public const string XmlTypeNameKey = "type"; 14 | 15 | public const string LuaTypeNameKey = "_type_"; 16 | 17 | public const string ExcelTypeNameKey = "$type"; 18 | public const string ExcelValueNameKey = "$value"; 19 | 20 | public const string ExcelMapKey = "$key"; 21 | 22 | public const string TagKey = "__tag__"; 23 | } 24 | -------------------------------------------------------------------------------- /src/Luban.Core/DataLoader/IDataLoader.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | using Luban.Types; 3 | 4 | namespace Luban.DataLoader; 5 | 6 | public interface IDataLoader 7 | { 8 | string RawUrl { get; } 9 | 10 | Record ReadOne(TBean type); 11 | 12 | List ReadMulti(TBean type); 13 | 14 | void Load(string rawUrl, string subAsset, Stream stream); 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Core/DataTarget/DataExporterAttribute.cs: -------------------------------------------------------------------------------- 1 | using Luban.CustomBehaviour; 2 | 3 | namespace Luban.DataTarget; 4 | 5 | [AttributeUsage(AttributeTargets.Class)] 6 | public class DataExporterAttribute : BehaviourBaseAttribute 7 | { 8 | 9 | public DataExporterAttribute(string name) : base(name) 10 | { 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Luban.Core/DataTarget/DataTargetAttribute.cs: -------------------------------------------------------------------------------- 1 | using Luban.CustomBehaviour; 2 | 3 | namespace Luban.DataTarget; 4 | 5 | [AttributeUsage(AttributeTargets.Class)] 6 | public class DataTargetAttribute : BehaviourBaseAttribute 7 | { 8 | public DataTargetAttribute(string name) : base(name) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Luban.Core/DataTarget/DataTargetManager.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using Luban.CustomBehaviour; 3 | using Luban.Validator; 4 | 5 | namespace Luban.DataTarget; 6 | 7 | public class DataTargetManager 8 | { 9 | public static DataTargetManager Ins { get; } = new(); 10 | 11 | public void Init() 12 | { 13 | 14 | } 15 | 16 | public IDataExporter CreateDataExporter(string name) 17 | { 18 | return CustomBehaviourManager.Ins.CreateBehaviour(name); 19 | } 20 | 21 | public IDataTarget CreateDataTarget(string name) 22 | { 23 | return CustomBehaviourManager.Ins.CreateBehaviour(name); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Luban.Core/DataTarget/IDataExporter.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace Luban.DataTarget; 3 | 4 | public interface IDataExporter 5 | { 6 | void Handle(GenerationContext ctx, IDataTarget dataTarget, OutputFileManifest manifest); 7 | } 8 | -------------------------------------------------------------------------------- /src/Luban.Core/DataTarget/IDataTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | using System.Text; 3 | 4 | namespace Luban.DataTarget; 5 | 6 | public enum AggregationType 7 | { 8 | Table, 9 | Tables, 10 | Record, 11 | Other, 12 | } 13 | 14 | public interface IDataTarget 15 | { 16 | AggregationType AggregationType { get; } 17 | 18 | Encoding FileEncoding { get; } 19 | 20 | bool ExportAllRecords { get; } 21 | 22 | OutputFile ExportTable(DefTable table, List records); 23 | 24 | OutputFile ExportTables(List tables); 25 | 26 | OutputFile ExportRecord(DefTable table, Record record); 27 | } 28 | -------------------------------------------------------------------------------- /src/Luban.Core/DataTransformer/DataTransformerAttribute.cs: -------------------------------------------------------------------------------- 1 | using Luban.CustomBehaviour; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Luban.DataTransformer; 9 | 10 | [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] 11 | public class DataTransformerAttribute : BehaviourBaseAttribute 12 | { 13 | public DataTransformerAttribute(string name) : base(name) 14 | { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Luban.Core/DataTransformer/IDataTransformer.cs: -------------------------------------------------------------------------------- 1 | using Luban.Datas; 2 | using Luban.Types; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Luban.DataTransformer; 10 | 11 | public interface IDataTransformer 12 | { 13 | DType Transform(DType originalData, TType type); 14 | } 15 | -------------------------------------------------------------------------------- /src/Luban.Core/DataVisitors/ToStringVisitor2.cs: -------------------------------------------------------------------------------- 1 | using Luban.Datas; 2 | using Luban.Utils; 3 | 4 | namespace Luban.DataVisitors; 5 | 6 | public class ToStringVisitor2 : ToStringVisitor 7 | { 8 | public new static ToStringVisitor2 Ins { get; } = new(); 9 | 10 | public override string Accept(DString type) 11 | { 12 | return DataUtil.EscapeString(type.Value); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Luban.Core/Defs/DefRefGroup.cs: -------------------------------------------------------------------------------- 1 | using Luban.RawDefs; 2 | 3 | namespace Luban.Defs; 4 | 5 | public class DefRefGroup 6 | { 7 | public string Name { get; } 8 | 9 | public List Refs { get; } 10 | 11 | public DefRefGroup(RawRefGroup group) 12 | { 13 | this.Name = group.Name; 14 | this.Refs = group.Refs; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Luban.Core/Defs/LoadDefException.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace Luban.Defs; 4 | 5 | public class LoadDefException : Exception 6 | { 7 | public LoadDefException() 8 | { 9 | } 10 | 11 | public LoadDefException(string message) : base(message) 12 | { 13 | } 14 | 15 | public LoadDefException(string message, Exception innerException) : base(message, innerException) 16 | { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Luban.Core/Defs/Record.cs: -------------------------------------------------------------------------------- 1 | using Luban.Datas; 2 | 3 | namespace Luban.Defs; 4 | 5 | public class Record 6 | { 7 | public int AutoIndex { get; set; } 8 | 9 | public DBean Data { get; set; } 10 | 11 | public string Source { get; } 12 | 13 | public List Tags { get; } 14 | 15 | public bool IsNotFiltered(List includeTags, List excludeTags) 16 | { 17 | if (Tags == null || Tags.Count == 0) 18 | { 19 | return true; 20 | } 21 | if (includeTags != null && includeTags.Count > 0) 22 | { 23 | return Tags.Any(includeTags.Contains); 24 | } 25 | return !Tags.Any(excludeTags.Contains); 26 | } 27 | 28 | public Record(DBean data, string source, List tags) 29 | { 30 | Data = data; 31 | Source = source; 32 | Tags = tags; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Luban.Core/Defs/TableMode.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Defs; 2 | 3 | public enum TableMode 4 | { 5 | ONE, 6 | MAP, 7 | LIST, 8 | } 9 | -------------------------------------------------------------------------------- /src/Luban.Core/IGenerationContext.cs: -------------------------------------------------------------------------------- 1 | namespace Luban; 2 | 3 | // public interface IGenerationContext 4 | // { 5 | // public static IGenerationContext Ins { get; set; } 6 | // 7 | // bool NeedExport(List groups); 8 | // 9 | // string TopModule { get; } 10 | // 11 | // public GenerationArguments Arguments { get; } 12 | // } 13 | -------------------------------------------------------------------------------- /src/Luban.Core/L10N/ITextProvider.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.L10N; 2 | 3 | public interface ITextProvider 4 | { 5 | void Load(); 6 | 7 | void ProcessDatas(); 8 | 9 | bool IsValidKey(string key); 10 | 11 | bool TryGetText(string key, out string text); 12 | 13 | void AddUnknownKey(string key); 14 | 15 | bool ConvertTextKeyToValue { get; } 16 | } 17 | -------------------------------------------------------------------------------- /src/Luban.Core/L10N/L10NManager.cs: -------------------------------------------------------------------------------- 1 | using Luban.CustomBehaviour; 2 | 3 | namespace Luban.L10N; 4 | 5 | public class L10NManager 6 | { 7 | public static L10NManager Ins { get; } = new(); 8 | 9 | public void Init() 10 | { 11 | 12 | } 13 | 14 | public ITextProvider CreateTextProvider(string name) 15 | { 16 | return CustomBehaviourManager.Ins.CreateBehaviour(name); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Luban.Core/L10N/TextProviderAttribute.cs: -------------------------------------------------------------------------------- 1 | using Luban.CustomBehaviour; 2 | 3 | namespace Luban.L10N; 4 | 5 | [AttributeUsage(AttributeTargets.Class)] 6 | public class TextProviderAttribute : BehaviourBaseAttribute 7 | { 8 | public TextProviderAttribute(string name) : base(name) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Luban.Core/OutputFile.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | 3 | namespace Luban; 4 | 5 | public class OutputFile 6 | { 7 | public string File { get; init; } 8 | 9 | /// 10 | /// Data type: string or byte[] 11 | /// 12 | public object Content { get; init; } 13 | 14 | public Encoding Encoding { get; set; } = Encoding.UTF8; 15 | 16 | public byte[] GetContentBytes() 17 | { 18 | if (Content is byte[] bytes) 19 | { 20 | return bytes; 21 | } 22 | return this.Encoding.GetBytes((string)Content); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Luban.Core/OutputFileManifest.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | 3 | namespace Luban; 4 | 5 | public enum OutputType 6 | { 7 | Code, 8 | Data, 9 | } 10 | 11 | public class OutputFileManifest 12 | { 13 | public string TargetName { get; } 14 | 15 | public OutputType OutputType { get; } 16 | 17 | private readonly List _dataFiles = new(); 18 | 19 | public IReadOnlyList DataFiles => _dataFiles; 20 | 21 | public OutputFileManifest(string targetName, OutputType outputType) 22 | { 23 | TargetName = targetName; 24 | OutputType = outputType; 25 | } 26 | 27 | public void AddFile(OutputFile file) 28 | { 29 | lock (this) 30 | { 31 | _dataFiles.Add(file); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Luban.Core/OutputSaver/IOutputSaver.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.OutputSaver; 2 | 3 | public interface IOutputSaver 4 | { 5 | string Name { get; } 6 | 7 | void Save(OutputFileManifest outputFileManifest); 8 | 9 | void SaveFile(OutputFileManifest fileManifest, string outputDir, OutputFile outputFile); 10 | } 11 | -------------------------------------------------------------------------------- /src/Luban.Core/OutputSaver/NullSaver.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.OutputSaver; 2 | 3 | [OutputSaver("null")] 4 | public class NullSaver : OutputSaverBase 5 | { 6 | public override void Save(OutputFileManifest outputFileManifest) 7 | { 8 | 9 | } 10 | 11 | public override void SaveFile(OutputFileManifest fileManifest, string outputDir, OutputFile outputFile) 12 | { 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Core/OutputSaver/OutputSaverAttribute.cs: -------------------------------------------------------------------------------- 1 | using Luban.CustomBehaviour; 2 | 3 | namespace Luban.OutputSaver; 4 | 5 | [AttributeUsage(AttributeTargets.Class)] 6 | public class OutputSaverAttribute : BehaviourBaseAttribute 7 | { 8 | public OutputSaverAttribute(string name) : base(name) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Luban.Core/OutputSaver/OutputSaverManager.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using Luban.CustomBehaviour; 3 | 4 | namespace Luban.OutputSaver; 5 | 6 | public class OutputSaverManager 7 | { 8 | public static OutputSaverManager Ins { get; } = new(); 9 | 10 | public void Init() 11 | { 12 | 13 | } 14 | 15 | public IOutputSaver GetOutputSaver(string name) 16 | { 17 | return CustomBehaviourManager.Ins.CreateBehaviour(name); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Luban.Core/Pipeline/IPipeline.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | using Luban.RawDefs; 3 | 4 | namespace Luban.Pipeline; 5 | 6 | public interface IPipeline 7 | { 8 | void Run(PipelineArguments args); 9 | } 10 | -------------------------------------------------------------------------------- /src/Luban.Core/Pipeline/PipelineArguments.cs: -------------------------------------------------------------------------------- 1 | using Luban.Schema; 2 | 3 | namespace Luban.Pipeline; 4 | 5 | public class PipelineArguments 6 | { 7 | public string Target { get; set; } 8 | 9 | public bool ForceLoadTableDatas { get; set; } 10 | 11 | public List IncludeTags { get; set; } 12 | 13 | public List ExcludeTags { get; set; } 14 | 15 | public List CodeTargets { get; set; } 16 | 17 | public List DataTargets { get; set; } 18 | 19 | public string SchemaCollector { get; set; } 20 | 21 | public LubanConfig Config { get; set; } 22 | 23 | public List OutputTables { get; set; } 24 | 25 | public string TimeZone { get; set; } 26 | 27 | public Dictionary CustomArgs { get; set; } 28 | 29 | public Dictionary Variants { get; set; } 30 | } 31 | -------------------------------------------------------------------------------- /src/Luban.Core/Pipeline/PipelineAttribute.cs: -------------------------------------------------------------------------------- 1 | using Luban.CustomBehaviour; 2 | 3 | namespace Luban.Pipeline; 4 | 5 | [AttributeUsage(AttributeTargets.Class)] 6 | public class PipelineAttribute : BehaviourBaseAttribute 7 | { 8 | public PipelineAttribute(string name) : base(name) 9 | { 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Luban.Core/Pipeline/PipelineManager.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using Luban.CustomBehaviour; 3 | 4 | namespace Luban.Pipeline; 5 | 6 | public class PipelineManager 7 | { 8 | public static PipelineManager Ins { get; } = new(); 9 | 10 | public void Init() 11 | { 12 | 13 | } 14 | 15 | public IPipeline CreatePipeline(string name) 16 | { 17 | return CustomBehaviourManager.Ins.CreateBehaviour(name); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Luban.Core/PostProcess/IPostProcess.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.PostProcess; 2 | 3 | public interface IPostProcess 4 | { 5 | void PostProcess(OutputFileManifest oldOutputFileManifest, OutputFileManifest newOutputFileManifest); 6 | void PostProcess(OutputFileManifest oldOutputFileManifest, OutputFileManifest newOutputFileManifest, OutputFile outputFile); 7 | } 8 | -------------------------------------------------------------------------------- /src/Luban.Core/PostProcess/PostProcessAttribute.cs: -------------------------------------------------------------------------------- 1 | using Luban.CustomBehaviour; 2 | 3 | namespace Luban.PostProcess; 4 | 5 | [Flags] 6 | public enum TargetFileType 7 | { 8 | None = 0, 9 | Code = 0x1, 10 | DataExport = 0x2, 11 | DataConvert = 0x4, 12 | } 13 | 14 | public class PostProcessAttribute : BehaviourBaseAttribute 15 | { 16 | public TargetFileType TargetFileType { get; } 17 | 18 | public PostProcessAttribute(string name, TargetFileType targetFileType) : base(name) 19 | { 20 | TargetFileType = targetFileType; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Luban.Core/PostProcess/PostProcessBase.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.PostProcess; 2 | 3 | public abstract class PostProcessBase : IPostProcess 4 | { 5 | public virtual void PostProcess(OutputFileManifest oldOutputFileManifest, OutputFileManifest newOutputFileManifest) 6 | { 7 | foreach (var outputFile in oldOutputFileManifest.DataFiles) 8 | { 9 | PostProcess(oldOutputFileManifest, newOutputFileManifest, outputFile); 10 | } 11 | } 12 | 13 | public abstract void PostProcess(OutputFileManifest oldOutputFileManifest, OutputFileManifest newOutputFileManifest, 14 | OutputFile outputFile); 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Core/PostProcess/PostProcessManager.cs: -------------------------------------------------------------------------------- 1 | using Luban.CustomBehaviour; 2 | 3 | namespace Luban.PostProcess; 4 | 5 | public class PostProcessManager 6 | { 7 | public static PostProcessManager Ins { get; } = new(); 8 | 9 | public void Init() 10 | { 11 | 12 | } 13 | 14 | public IPostProcess GetPostProcess(string name) 15 | { 16 | return CustomBehaviourManager.Ins.CreateBehaviour(name); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Luban.Core/RawDefs/RawAssembly.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.RawDefs; 2 | 3 | public class RawAssembly 4 | { 5 | public List Beans { get; set; } = new(); 6 | 7 | public List Enums { get; set; } = new(); 8 | 9 | public List Tables { get; set; } = new(); 10 | 11 | public List Groups { get; set; } = new(); 12 | 13 | public List Targets { get; set; } = new(); 14 | 15 | public List RefGroups { get; set; } = new(); 16 | } 17 | -------------------------------------------------------------------------------- /src/Luban.Core/RawDefs/RawBean.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.RawDefs; 2 | 3 | public class RawBean 4 | { 5 | public string Namespace { get; set; } 6 | 7 | public string Name { get; set; } 8 | 9 | public string FullName => Namespace.Length > 0 ? Namespace + "." + Name : Name; 10 | 11 | public string Parent { get; set; } 12 | 13 | public bool IsValueType { get; set; } 14 | 15 | public string Comment { get; set; } 16 | 17 | public Dictionary Tags { get; set; } 18 | 19 | public string Alias { get; set; } 20 | 21 | public string Sep { get; set; } 22 | 23 | public List Groups { get; set; } 24 | 25 | public List Fields { get; set; } 26 | 27 | public List TypeMappers { get; set; } 28 | } 29 | -------------------------------------------------------------------------------- /src/Luban.Core/RawDefs/RawEnum.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.RawDefs; 2 | 3 | public class EnumItem 4 | { 5 | public string Name { get; set; } 6 | 7 | public string Alias { get; set; } 8 | 9 | public string Value { get; set; } 10 | 11 | public string Comment { get; set; } 12 | 13 | public Dictionary Tags { get; set; } 14 | } 15 | 16 | public class RawEnum 17 | { 18 | public string Namespace { get; set; } 19 | 20 | public string Name { get; set; } 21 | 22 | public string FullName => Namespace.Length > 0 ? Namespace + "." + Name : Name; 23 | 24 | public bool IsFlags { get; set; } 25 | 26 | public bool IsUniqueItemId { get; set; } 27 | 28 | public string Comment { get; set; } 29 | 30 | public Dictionary Tags { get; set; } 31 | 32 | public List Items { get; set; } 33 | 34 | public List Groups { get; set; } 35 | 36 | public List TypeMappers { get; set; } 37 | } 38 | -------------------------------------------------------------------------------- /src/Luban.Core/RawDefs/RawField.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.RawDefs; 2 | 3 | public class RawField 4 | { 5 | public string Name { get; set; } 6 | 7 | public string Alias { get; set; } 8 | 9 | public string Type { get; set; } 10 | 11 | public string Comment { get; set; } 12 | 13 | public Dictionary Tags { get; set; } 14 | 15 | public List Variants { get; set; } 16 | 17 | public bool NotNameValidation { get; set; } 18 | 19 | public List Groups { get; set; } 20 | } 21 | -------------------------------------------------------------------------------- /src/Luban.Core/RawDefs/RawGroup.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.RawDefs; 2 | 3 | public class RawGroup 4 | { 5 | public bool IsDefault { get; set; } 6 | 7 | public List Names { get; set; } 8 | } 9 | -------------------------------------------------------------------------------- /src/Luban.Core/RawDefs/RawRefGroup.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.RawDefs; 2 | 3 | public class RawRefGroup 4 | { 5 | public string Name { get; set; } 6 | 7 | public List Refs { get; set; } 8 | } 9 | -------------------------------------------------------------------------------- /src/Luban.Core/RawDefs/RawTable.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | 3 | namespace Luban.RawDefs; 4 | 5 | public class RawTable 6 | { 7 | public string Namespace { get; set; } 8 | 9 | public string Name { get; set; } 10 | 11 | public string Index { get; set; } 12 | 13 | public string ValueType { get; set; } 14 | 15 | public bool ReadSchemaFromFile { get; set; } 16 | 17 | public TableMode Mode { get; set; } 18 | 19 | public string Comment { get; set; } 20 | 21 | public Dictionary Tags { get; set; } 22 | 23 | public List Groups { get; set; } = new(); 24 | 25 | public List InputFiles { get; set; } = new(); 26 | 27 | public string OutputFile { get; set; } 28 | } 29 | -------------------------------------------------------------------------------- /src/Luban.Core/RawDefs/RawTarget.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.RawDefs; 2 | 3 | public class RawTarget 4 | { 5 | public string Name { get; set; } 6 | 7 | public string Manager { get; set; } 8 | 9 | public string TopModule { get; set; } 10 | 11 | public List Groups { get; set; } = new(); 12 | } 13 | -------------------------------------------------------------------------------- /src/Luban.Core/RawDefs/TypeMapper.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.RawDefs; 2 | 3 | public class TypeMapper 4 | { 5 | public List Targets { get; set; } 6 | 7 | public List CodeTargets { get; set; } 8 | 9 | public Dictionary Options { get; set; } 10 | } 11 | -------------------------------------------------------------------------------- /src/Luban.Core/RegisterBehaviourAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace Luban; 2 | 3 | [AttributeUsage(AttributeTargets.Assembly)] 4 | public class RegisterBehaviourAttribute : Attribute 5 | { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/Luban.Core/Schema/BeanSchemaLoaderAttribute.cs: -------------------------------------------------------------------------------- 1 | using Luban.CustomBehaviour; 2 | 3 | namespace Luban.Schema; 4 | 5 | [AttributeUsage(AttributeTargets.Class, Inherited = false)] 6 | public class BeanSchemaLoaderAttribute : BehaviourBaseAttribute 7 | { 8 | public BeanSchemaLoaderAttribute(string name) : base(name) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Luban.Core/Schema/IBeanSchemaLoader.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | using Luban.RawDefs; 3 | 4 | namespace Luban.Schema; 5 | 6 | public interface IBeanSchemaLoader 7 | { 8 | RawBean Load(string fileName, string beanFullName, RawTable table); 9 | } 10 | -------------------------------------------------------------------------------- /src/Luban.Core/Schema/IConfigLoader.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Schema; 2 | 3 | public interface IConfigLoader 4 | { 5 | LubanConfig Load(string fileName); 6 | } 7 | -------------------------------------------------------------------------------- /src/Luban.Core/Schema/ISchemaCollector.cs: -------------------------------------------------------------------------------- 1 | using Luban.RawDefs; 2 | 3 | namespace Luban.Schema; 4 | 5 | public interface ISchemaCollector 6 | { 7 | void Load(LubanConfig config); 8 | 9 | RawAssembly CreateRawAssembly(); 10 | 11 | void Add(RawTable table); 12 | 13 | void Add(RawBean bean); 14 | 15 | void Add(RawEnum @enum); 16 | 17 | void Add(RawRefGroup refGroup); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/Luban.Core/Schema/ISchemaLoader.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Schema; 2 | 3 | public interface ISchemaLoader 4 | { 5 | string Type { get; set; } 6 | 7 | ISchemaCollector Collector { get; set; } 8 | 9 | void Load(string fileName); 10 | } 11 | -------------------------------------------------------------------------------- /src/Luban.Core/Schema/ITableImporter.cs: -------------------------------------------------------------------------------- 1 | using Luban.RawDefs; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Luban.Schema; 9 | 10 | public interface ITableImporter 11 | { 12 | List LoadImportTables(); 13 | } 14 | -------------------------------------------------------------------------------- /src/Luban.Core/Schema/LubanConfig.cs: -------------------------------------------------------------------------------- 1 | using Luban.RawDefs; 2 | 3 | namespace Luban.Schema; 4 | 5 | public class LubanConfig 6 | { 7 | public string ConfigFileName { get; set; } 8 | public List Groups { get; set; } 9 | 10 | public List Targets { get; set; } 11 | 12 | public List Imports { get; set; } 13 | 14 | public List Xargs { get; set; } 15 | 16 | public string InputDataDir { get; set; } 17 | } 18 | -------------------------------------------------------------------------------- /src/Luban.Core/Schema/SchemaCollectorAttribute.cs: -------------------------------------------------------------------------------- 1 | using Luban.CustomBehaviour; 2 | 3 | namespace Luban.Schema; 4 | 5 | [AttributeUsage(AttributeTargets.Class)] 6 | public class SchemaCollectorAttribute : BehaviourBaseAttribute 7 | { 8 | public SchemaCollectorAttribute(string name) : base(name) 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Luban.Core/Schema/SchemaFileInfo.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Schema; 2 | 3 | public class SchemaFileInfo 4 | { 5 | public string FileName { get; set; } 6 | 7 | public string Type { get; set; } 8 | } 9 | -------------------------------------------------------------------------------- /src/Luban.Core/Schema/SchemaLoaderAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Schema; 2 | 3 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] 4 | public class SchemaLoaderAttribute : System.Attribute 5 | { 6 | public string Type { get; } 7 | 8 | public string[] ExtNames { get; } 9 | 10 | public int Priority { get; set; } 11 | 12 | public SchemaLoaderAttribute(string type, params string[] extNames) 13 | { 14 | Type = type; 15 | ExtNames = extNames; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Luban.Core/Schema/SchemaLoaderBase.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Schema; 2 | 3 | public abstract class SchemaLoaderBase : ISchemaLoader 4 | { 5 | public string Type { get; set; } 6 | 7 | public ISchemaCollector Collector { get; set; } 8 | 9 | public abstract void Load(string fileName); 10 | } 11 | -------------------------------------------------------------------------------- /src/Luban.Core/Schema/TableImporterAttribute.cs: -------------------------------------------------------------------------------- 1 | using Luban.CustomBehaviour; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Luban.Schema; 9 | 10 | [AttributeUsage(AttributeTargets.Class)] 11 | public class TableImporterAttribute : BehaviourBaseAttribute 12 | { 13 | public TableImporterAttribute(string name) : base(name) 14 | { 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Luban.Core/Serialization/BeanBase.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Serialization; 2 | 3 | public abstract class BeanBase : ITypeId, ISerializable 4 | { 5 | public abstract int GetTypeId(); 6 | 7 | public abstract void Serialize(ByteBuf os); 8 | 9 | public abstract void Deserialize(ByteBuf os); 10 | } 11 | -------------------------------------------------------------------------------- /src/Luban.Core/Serialization/ByteBufPool.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Serialization; 2 | 3 | public class ByteBufPool 4 | { 5 | private readonly Stack _bufs = new(); 6 | private readonly int _maxCacheNum; 7 | 8 | private readonly Action _freeAction; 9 | 10 | public ByteBufPool(int maxCacheNum) 11 | { 12 | _maxCacheNum = maxCacheNum; 13 | _freeAction = this.Free; 14 | } 15 | 16 | public ByteBuf Alloc(int? hintSize) 17 | { 18 | if (_bufs.TryPop(out var b)) 19 | { 20 | return b; 21 | } 22 | else 23 | { 24 | return new ByteBuf(hintSize ?? 64, this._freeAction); 25 | } 26 | } 27 | 28 | public void Free(ByteBuf buf) 29 | { 30 | buf.Clear(); 31 | if (_bufs.Count < _maxCacheNum) 32 | { 33 | _bufs.Push(buf); 34 | } 35 | } 36 | 37 | public Stack GetByteBufsForTest() => _bufs; 38 | } 39 | -------------------------------------------------------------------------------- /src/Luban.Core/Serialization/EUnmarshalError.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Serialization; 2 | 3 | public enum EDeserializeError 4 | { 5 | OK, 6 | NOT_ENOUGH, 7 | EXCEED_SIZE, 8 | // UNMARSHAL_ERR, 9 | } 10 | -------------------------------------------------------------------------------- /src/Luban.Core/Serialization/FieldTag.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Serialization; 2 | 3 | // 把 int,long,string,bool 调整到最小 4 | // 这样 marshal compatible write(field_id << tag_shift | tag_id) < 2^7 能在一个字节 5 | // 内序列化, 优化序列化最终大小 6 | #pragma warning disable CA1720 // 标识符包含类型名称 7 | public static class FieldTag 8 | { 9 | public const int 10 | INT = 0, 11 | LONG = 1, 12 | STRING = 2, 13 | BOOL = 3, 14 | 15 | BYTE = 4, 16 | SHORT = 5, 17 | FSHORT = 6, 18 | FINT = 7, 19 | FLONG = 8, 20 | FLOAT = 9, 21 | DOUBLE = 10, 22 | BYTES = 11, 23 | ARRAY = 12, 24 | LIST = 13, 25 | SET = 14, 26 | MAP = 15, 27 | BEAN = 16, 28 | TEXT = 17, 29 | VECTOR2 = 18, 30 | VECTOR3 = 19, 31 | VECTOR4 = 20, 32 | DYNAMIC_BEAN = 21, 33 | 34 | NOT_USE = 22; 35 | 36 | 37 | public const int TAG_SHIFT = 5; 38 | public const int TAG_MASK = (1 << TAG_SHIFT) - 1; 39 | } 40 | #pragma warning restore CA1720 // 标识符包含类型名称 41 | -------------------------------------------------------------------------------- /src/Luban.Core/Serialization/ISerializable.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Serialization; 2 | 3 | /// 4 | /// 非兼容binary序列化 5 | /// 6 | public interface ISerializable 7 | { 8 | void Serialize(ByteBuf os); 9 | 10 | void Deserialize(ByteBuf os); 11 | } 12 | -------------------------------------------------------------------------------- /src/Luban.Core/Serialization/ITypeId.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Serialization; 2 | 3 | public interface ITypeId 4 | { 5 | int GetTypeId(); 6 | } 7 | -------------------------------------------------------------------------------- /src/Luban.Core/Serialization/SerializationException.cs: -------------------------------------------------------------------------------- 1 | #define CPU_SUPPORT_MEMORY_NOT_ALIGN //CPU 是否支持读取非对齐内存 2 | 3 | 4 | 5 | 6 | /// 7 | /// TODO 8 | /// 1. 整理代码 9 | /// 2. 优化序列化 (像这样 data[endPos + 1] = (byte)(x >> 8) 挨个字节赋值总感觉很低效,能优化吗) 10 | /// 11 | 12 | 13 | namespace Luban.Serialization; 14 | 15 | public class SerializationException : Exception 16 | { 17 | public SerializationException() { } 18 | public SerializationException(string msg) : base(msg) { } 19 | 20 | public SerializationException(string message, Exception innerException) : base(message, innerException) 21 | { 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Luban.Core/TemplateExtensions/ContextTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Scriban.Runtime; 2 | 3 | namespace Luban.TemplateExtensions; 4 | 5 | public class ContextTemplateExtension : ScriptObject 6 | { 7 | 8 | 9 | public static bool HasTag(dynamic obj, string attrName) 10 | { 11 | return obj.HasTag(attrName); 12 | } 13 | 14 | public static string GetTag(dynamic obj, string attrName) 15 | { 16 | return obj.GetTag(attrName); 17 | } 18 | 19 | public static bool HasOption(string name) 20 | { 21 | return EnvManager.Current.HasOptionRaw(name); 22 | } 23 | 24 | public static string GetOption(string name) 25 | { 26 | return EnvManager.Current.GetOptionRaw(name); 27 | } 28 | 29 | public static string GetOptionOrDefault(string name, string defaultValue) 30 | { 31 | return EnvManager.Current.GetOptionOrDefaultRaw(name, defaultValue); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Luban.Core/TypeVisitors/AllFalseVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | 3 | namespace Luban.TypeVisitors; 4 | 5 | public abstract class AllFalseVisitor : DecoratorFuncVisitor 6 | { 7 | public override bool DoAccept(TType type) 8 | { 9 | return false; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Luban.Core/TypeVisitors/AllTrueVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | 3 | namespace Luban.TypeVisitors; 4 | 5 | public abstract class AllTrueVisitor : DecoratorFuncVisitor 6 | { 7 | public override bool DoAccept(TType type) 8 | { 9 | return true; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/Luban.Core/TypeVisitors/IsValidTableKeyTypeVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | 3 | namespace Luban.TypeVisitors; 4 | 5 | class IsValidTableKeyTypeVisitor : AllTrueVisitor 6 | { 7 | public static IsValidTableKeyTypeVisitor Ins { get; } = new(); 8 | 9 | public override bool Accept(TDateTime type) 10 | { 11 | return false; 12 | } 13 | 14 | public override bool Accept(TBean type) 15 | { 16 | return false; 17 | } 18 | 19 | public override bool Accept(TArray type) 20 | { 21 | return false; 22 | } 23 | 24 | public override bool Accept(TList type) 25 | { 26 | return false; 27 | } 28 | 29 | public override bool Accept(TSet type) 30 | { 31 | return false; 32 | } 33 | 34 | public override bool Accept(TMap type) 35 | { 36 | return false; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Luban.Core/Utils/AtomicLong.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Utils; 2 | 3 | public class AtomicLong 4 | { 5 | private long _value; 6 | public AtomicLong(long initValue = 0) 7 | { 8 | _value = initValue; 9 | } 10 | 11 | public long IncrementAndGet() 12 | { 13 | return Interlocked.Add(ref _value, 1); 14 | } 15 | 16 | public long AddAndGet(long step) 17 | { 18 | return Interlocked.Add(ref _value, step); 19 | } 20 | 21 | public long GetAndAdd(long step) 22 | { 23 | return Interlocked.Add(ref _value, step); 24 | } 25 | 26 | public long Value { get => Interlocked.Read(ref _value); set => Interlocked.Exchange(ref _value, value); } 27 | 28 | 29 | public override string ToString() 30 | { 31 | return _value.ToString(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Luban.Core/Utils/CollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Utils; 2 | 3 | public static class CollectionExtensions 4 | { 5 | public static void AddAll(this Dictionary resultDic, Dictionary addDic) where K : notnull 6 | { 7 | foreach (var e in addDic) 8 | { 9 | resultDic[e.Key] = e.Value; 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Luban.Core/Utils/DataExtensions.cs: -------------------------------------------------------------------------------- 1 | using Luban.Datas; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Luban.Utils; 9 | 10 | public static class DataExtensions 11 | { 12 | public static long UnixTimeOfCurrentContext(this DDateTime dateTime) 13 | { 14 | return dateTime.GetUnixTime(GenerationContext.Current.TimeZone); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Luban.Core/Utils/ExceptionUtil.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Utils; 2 | 3 | public static class ExceptionUtil 4 | { 5 | public static string ExtractMessage(Exception e) 6 | { 7 | var lines = new List(); 8 | do 9 | { 10 | lines.Add("===> " + e.Message); 11 | e = e.InnerException; 12 | } while (e != null); 13 | 14 | return string.Join('\n', lines); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Luban.Core/Utils/ListEqualityComparer.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics.CodeAnalysis; 2 | 3 | namespace Luban.Utils; 4 | 5 | public class ListEqualityComparer : IEqualityComparer> 6 | { 7 | public static ListEqualityComparer Default { get; } = new(); 8 | 9 | public bool Equals(List x, List y) 10 | { 11 | return x.Count == y.Count && System.Linq.Enumerable.SequenceEqual(x, y); 12 | } 13 | 14 | public int GetHashCode([DisallowNull] List obj) 15 | { 16 | int hash = 17; 17 | foreach (T x in obj) 18 | { 19 | hash = hash * 23 + x.GetHashCode(); 20 | } 21 | return hash; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Luban.Core/Utils/LoadXmlException.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace Luban.Utils; 4 | 5 | public class LoadXmlException : Exception 6 | { 7 | public LoadXmlException() 8 | { 9 | } 10 | 11 | public LoadXmlException(string message) : base(message) 12 | { 13 | } 14 | 15 | public LoadXmlException(string message, Exception innerException) : base(message, innerException) 16 | { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Luban.Core/Utils/StringUtil.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Specialized; 2 | 3 | namespace Luban.Utils; 4 | 5 | public static class StringUtil 6 | { 7 | public static string CollectionToString(IEnumerable collection) 8 | { 9 | return string.Join(",", collection); 10 | } 11 | 12 | public static string RepeatString(string str, int count) 13 | { 14 | return count == 0 ? "" : string.Concat(Enumerable.Repeat(str, count)); 15 | } 16 | 17 | public static string RepeatSpaceAsTab(int count) 18 | { 19 | return count == 0 ? "" : string.Concat(Enumerable.Repeat(" ", count)); 20 | } 21 | 22 | public static string GetLineEnding(string endings) 23 | { 24 | switch (endings) 25 | { 26 | case "": 27 | return Environment.NewLine; 28 | case "crlf": 29 | return "\r\n"; 30 | case "lf": 31 | return "\n"; 32 | case "cr": 33 | return "\r"; 34 | default: 35 | throw new Exception($"unknown line ending: {endings}"); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Luban.Core/Utils/TemplateUtil.cs: -------------------------------------------------------------------------------- 1 | using Scriban; 2 | 3 | namespace Luban.Utils; 4 | 5 | public static class TemplateUtil 6 | { 7 | public static TemplateContext CreateDefaultTemplateContext() 8 | { 9 | return new TemplateContext() 10 | { 11 | LoopLimit = 0, 12 | NewLine = "\n", 13 | }; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Core/Utils/TimeUtil.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Utils; 2 | 3 | public static class TimeUtil 4 | { 5 | public static int Now => (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; 6 | 7 | public static long NowMillis => (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds; 8 | } 9 | -------------------------------------------------------------------------------- /src/Luban.Core/Validator/DataValidatorBase.cs: -------------------------------------------------------------------------------- 1 | using Luban.Datas; 2 | using Luban.Defs; 3 | using Luban.Types; 4 | 5 | namespace Luban.Validator; 6 | 7 | public abstract class DataValidatorBase : IDataValidator 8 | { 9 | public string Args { get; set; } 10 | 11 | public abstract void Compile(DefField field, TType type); 12 | 13 | public abstract void Validate(DataValidatorContext ctx, TType type, DType data); 14 | 15 | protected static string Source => DataValidatorContext.CurrentVisitor.CurrentValidateRecord.Source; 16 | 17 | protected static string RecordPath => DataValidatorContext.CurrentRecordPath; 18 | } 19 | -------------------------------------------------------------------------------- /src/Luban.Core/Validator/IDataValidator.cs: -------------------------------------------------------------------------------- 1 | using Luban.Datas; 2 | using Luban.Defs; 3 | using Luban.Types; 4 | 5 | namespace Luban.Validator; 6 | 7 | public interface IDataValidator 8 | { 9 | string Args { get; set; } 10 | 11 | void Compile(DefField owner, TType type); 12 | 13 | void Validate(DataValidatorContext ctx, TType type, DType data); 14 | } 15 | -------------------------------------------------------------------------------- /src/Luban.Core/Validator/ITableValidator.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | 3 | namespace Luban.Validator; 4 | 5 | public interface ITableValidator 6 | { 7 | void Validate(DefTable table, List records); 8 | } 9 | -------------------------------------------------------------------------------- /src/Luban.Core/Validator/ValidatorAttribute.cs: -------------------------------------------------------------------------------- 1 | using Luban.CustomBehaviour; 2 | 3 | namespace Luban.Validator; 4 | 5 | [AttributeUsage(AttributeTargets.Class)] 6 | public class ValidatorAttribute : BehaviourBaseAttribute 7 | { 8 | public ValidatorType Type { get; } 9 | 10 | public ValidatorAttribute(string name, ValidatorType type = ValidatorType.Data) : base(name) 11 | { 12 | this.Type = type; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Luban.Core/Validator/ValidatorType.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Validator; 2 | 3 | public enum ValidatorType 4 | { 5 | Data, 6 | Table, 7 | } 8 | -------------------------------------------------------------------------------- /src/Luban.Cpp/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.Cpp/CodeTarget/CppBinRawptrCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Cpp.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.Cpp.CodeTarget; 6 | 7 | [CodeTarget("cpp-rawptr-bin")] 8 | public class CppBinRawptrCodeTarget : CppCodeTargetBase 9 | { 10 | protected override void OnCreateTemplateContext(TemplateContext ctx) 11 | { 12 | base.OnCreateTemplateContext(ctx); 13 | ctx.PushGlobal(new CppRawptrBinTemplateExtension()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Cpp/CodeTarget/CppBinSharedptrCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Cpp.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.Cpp.CodeTarget; 6 | 7 | [CodeTarget("cpp-sharedptr-bin")] 8 | public class CppBinSharedptrCodeTarget : CppCodeTargetBase 9 | { 10 | protected override void OnCreateTemplateContext(TemplateContext ctx) 11 | { 12 | base.OnCreateTemplateContext(ctx); 13 | ctx.PushGlobal(new CppSharedptrBinTemplateExtension()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Cpp/TemplateExtensions/CppRawptrBinTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.Cpp.TypeVisitors; 2 | using Luban.Types; 3 | using Scriban.Runtime; 4 | 5 | namespace Luban.Cpp.TemplateExtensions; 6 | 7 | public class CppRawptrBinTemplateExtension : ScriptObject 8 | { 9 | public static string Deserialize(string bufName, string fieldName, TType type) 10 | { 11 | return type.Apply(CppRawptrDeserializeVisitor.Ins, bufName, fieldName, 0); 12 | } 13 | 14 | public static string DeclaringTypeName(TType type) 15 | { 16 | return type.Apply(CppRawptrDeclaringTypeNameVisitor.Ins); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Luban.Cpp/TemplateExtensions/CppSharedptrBinTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.Cpp.TypeVisitors; 2 | using Luban.Types; 3 | using Scriban.Runtime; 4 | 5 | namespace Luban.Cpp.TemplateExtensions; 6 | 7 | public class CppSharedptrBinTemplateExtension : ScriptObject 8 | { 9 | public static string Deserialize(string bufName, string fieldName, TType type) 10 | { 11 | return type.Apply(CppSharedptrDeserializeVisitor.Ins, bufName, fieldName,0); 12 | } 13 | 14 | public static string DeclaringTypeName(TType type) 15 | { 16 | return type.Apply(CppSharedptrDeclaringTypeNameVisitor.Ins); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Luban.Cpp/Templates/common/cpp/enum.sbn: -------------------------------------------------------------------------------- 1 | {{~ 2 | comment = __enum.comment 3 | items = __enum.items 4 | ~}} 5 | {{namespace_with_grace_begin __namespace}} 6 | {{~if comment != '' ~}} 7 | /// 8 | /// {{escape_comment comment}} 9 | /// 10 | {{~end~}} 11 | enum class {{__name}} 12 | { 13 | {{~ for item in items ~}} 14 | {{~if item.comment != '' ~}} 15 | /// 16 | /// {{escape_comment item.comment_or_alias}} 17 | /// 18 | {{~end~}} 19 | {{format_enum_item_name __code_style item.name}} = {{item.value}}, 20 | {{~end~}} 21 | }; 22 | 23 | {{namespace_with_grace_end __namespace}} 24 | -------------------------------------------------------------------------------- /src/Luban.Cpp/Templates/cpp-rawptr-bin/bean.sbn: -------------------------------------------------------------------------------- 1 | {{namespace_with_grace_begin __namespace}} 2 | 3 | {{~if __this.comment != '' ~}} 4 | /** 5 | * {{escape_comment __this.comment}} 6 | */ 7 | {{~end~}} 8 | struct {{__name}} : public{{if __parent_def_type}} {{make_cpp_name __parent_def_type.full_name}} {{else}} luban::CfgBean {{end}} 9 | { 10 | static bool deserialize{{__name}}(::luban::ByteBuf& _buf, {{__name}}*& _out); 11 | 12 | virtual ~{{__name}}() {} 13 | 14 | bool deserialize(::luban::ByteBuf& _buf); 15 | 16 | {{~ for field in __export_fields ~}} 17 | {{~if field.comment != '' ~}} 18 | /** 19 | * {{escape_comment field.comment}} 20 | */ 21 | {{~end~}} 22 | {{declaring_type_name field.ctype}} {{format_field_name __code_style field.name}}; 23 | {{~end~}} 24 | 25 | {{~if !__this.is_abstract_type~}} 26 | static constexpr int __ID__ = {{__this.id}}; 27 | 28 | int getTypeId() const override { return __ID__; } 29 | {{~end~}} 30 | }; 31 | 32 | {{namespace_with_grace_end __namespace}} 33 | -------------------------------------------------------------------------------- /src/Luban.Cpp/Templates/cpp-rawptr-bin/schema_h.sbn: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #include "CfgBean.h" 6 | 7 | {{namespace_with_grace_begin __top_module}} 8 | 9 | {{__enum_codes~}} 10 | 11 | {{~for b in __beans~}} 12 | {{namespace_with_grace_begin b.namespace}} struct {{b.name}}; {{namespace_with_grace_end b.namespace}} 13 | {{~end~}} 14 | 15 | {{~__bean_codes~}} 16 | 17 | {{~__table_codes~}} 18 | 19 | {{__tables_code}} 20 | 21 | {{namespace_with_grace_end __top_module}} 22 | -------------------------------------------------------------------------------- /src/Luban.Cpp/Templates/cpp-rawptr-bin/tables.sbn: -------------------------------------------------------------------------------- 1 | class {{__name}} 2 | { 3 | public: 4 | {{~for table in __tables ~}} 5 | {{~if table.comment != '' ~}} 6 | /** 7 | * {{escape_comment table.comment}} 8 | */ 9 | {{~end~}} 10 | {{make_cpp_name table.full_name}} {{table.name}}; 11 | {{~end~}} 12 | 13 | bool load(::luban::Loader<::luban::ByteBuf> loader) 14 | { 15 | ::luban::ByteBuf buf; 16 | {{~for table in __tables~}} 17 | buf.clear(); 18 | if (!loader(buf, "{{table.output_data_file}}")) return false; 19 | if (!{{table.name}}.load(buf)) return false; 20 | {{~end~}} 21 | return true; 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /src/Luban.Cpp/Templates/cpp-sharedptr-bin/bean.sbn: -------------------------------------------------------------------------------- 1 | {{namespace_with_grace_begin __namespace}} 2 | 3 | {{~if __this.comment != '' ~}} 4 | /** 5 | * {{escape_comment __this.comment}} 6 | */ 7 | {{~end~}} 8 | struct {{__name}} : public{{if __parent_def_type}} {{make_cpp_name __parent_def_type.full_name}} {{else}} luban::CfgBean {{end}} 9 | { 10 | static bool deserialize{{__name}}(::luban::ByteBuf& _buf, ::luban::SharedPtr<{{__name}}>& _out); 11 | 12 | virtual ~{{__name}}() {} 13 | 14 | bool deserialize(::luban::ByteBuf& _buf); 15 | 16 | {{~ for field in __export_fields ~}} 17 | {{~if field.comment != '' ~}} 18 | /** 19 | * {{escape_comment field.comment}} 20 | */ 21 | {{~end~}} 22 | {{declaring_type_name field.ctype}} {{format_field_name __code_style field.name}}; 23 | {{~end~}} 24 | 25 | {{~if !__this.is_abstract_type~}} 26 | static constexpr int __ID__ = {{__this.id}}; 27 | 28 | int getTypeId() const override { return __ID__; } 29 | {{~end~}} 30 | }; 31 | 32 | {{namespace_with_grace_end __namespace}} -------------------------------------------------------------------------------- /src/Luban.Cpp/Templates/cpp-sharedptr-bin/schema_h.sbn: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #include "CfgBean.h" 6 | 7 | {{namespace_with_grace_begin __top_module}} 8 | 9 | {{__enum_codes~}} 10 | 11 | {{~for b in __beans~}} 12 | {{namespace_with_grace_begin b.namespace}} struct {{b.name}}; {{namespace_with_grace_end b.namespace}} 13 | {{~end~}} 14 | 15 | {{~__bean_codes~}} 16 | 17 | {{~__table_codes~}} 18 | 19 | {{__tables_code}} 20 | 21 | {{namespace_with_grace_end __top_module}} 22 | -------------------------------------------------------------------------------- /src/Luban.Cpp/Templates/cpp-sharedptr-bin/tables.sbn: -------------------------------------------------------------------------------- 1 | class {{__name}} 2 | { 3 | public: 4 | {{~for table in __tables ~}} 5 | {{~if table.comment != '' ~}} 6 | /** 7 | * {{escape_comment table.comment}} 8 | */ 9 | {{~end~}} 10 | {{make_cpp_name table.full_name}} {{table.name}}; 11 | {{~end~}} 12 | 13 | bool load(::luban::Loader<::luban::ByteBuf> loader) 14 | { 15 | ::luban::ByteBuf buf; 16 | {{~for table in __tables~}} 17 | buf.clear(); 18 | if (!loader(buf, "{{table.output_data_file}}")) return false; 19 | if (!{{table.name}}.load(buf)) return false; 20 | {{~end~}} 21 | return true; 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /src/Luban.Cpp/TypeVisitors/CppRawptrDeclaringTypeNameVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.Cpp.TypeVisitors; 5 | 6 | public class CppRawptrDeclaringTypeNameVisitor : DecoratorFuncVisitor 7 | { 8 | public static CppRawptrDeclaringTypeNameVisitor Ins { get; } = new CppRawptrDeclaringTypeNameVisitor(); 9 | 10 | public override string DoAccept(TType type) 11 | { 12 | return type.IsNullable && !type.IsBean ? $"{type.Apply(CppRawptrUnderlyingDeclaringTypeNameVisitor.Ins)}*" : type.Apply(CppRawptrUnderlyingDeclaringTypeNameVisitor.Ins); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Luban.Cpp/TypeVisitors/CppRawptrDeserializeVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.Cpp.TypeVisitors; 5 | 6 | public class CppRawptrDeserializeVisitor : DecoratorFuncVisitor 7 | { 8 | public static CppRawptrDeserializeVisitor Ins { get; } = new CppRawptrDeserializeVisitor(); 9 | 10 | public override string DoAccept(TType type, string bufName, string fieldName, int depth) 11 | { 12 | if (type.IsNullable) 13 | { 14 | return $"{{ bool _has_value_; if(!{bufName}.readBool(_has_value_)){{return false;}} if(_has_value_) {{ {fieldName} = {(type.IsBean ? "nullptr" : $"new {type.Apply(CppUnderlyingDeclaringTypeNameVisitor.Ins)}{{}}")}; {type.Apply(CppRawptrUnderlyingDeserializeVisitor.Ins, bufName, type.IsBean ? fieldName : $"*{fieldName}",depth + 1, CppRawptrDeclaringTypeNameVisitor.Ins)} }} else {{ {fieldName} = nullptr; }} }}"; 15 | } 16 | else 17 | { 18 | return type.Apply(CppRawptrUnderlyingDeserializeVisitor.Ins, bufName, fieldName, depth, CppRawptrDeclaringTypeNameVisitor.Ins); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Luban.Cpp/TypeVisitors/CppRawptrUnderlyingDeclaringTypeNameVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Cpp.TemplateExtensions; 2 | using Luban.Types; 3 | 4 | namespace Luban.Cpp.TypeVisitors; 5 | 6 | public class CppRawptrUnderlyingDeclaringTypeNameVisitor : CppUnderlyingDeclaringTypeNameVisitor 7 | { 8 | public new static CppRawptrUnderlyingDeclaringTypeNameVisitor Ins { get; } = new(); 9 | 10 | public override string Accept(TBean type) 11 | { 12 | string typeName = CppTemplateExtension.MakeTypeCppName(type.DefBean); 13 | return $"{typeName}*"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Cpp/TypeVisitors/CppRawptrUnderlyingDeserializeVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Cpp.TemplateExtensions; 2 | using Luban.Types; 3 | using Luban.TypeVisitors; 4 | 5 | namespace Luban.Cpp.TypeVisitors; 6 | 7 | public class CppRawptrUnderlyingDeserializeVisitor : CppUnderlyingDeserializeVisitorBase 8 | { 9 | public static CppRawptrUnderlyingDeserializeVisitor Ins { get; } = new(); 10 | } 11 | -------------------------------------------------------------------------------- /src/Luban.Cpp/TypeVisitors/CppSharedPtrUnderlyingDeclaringTypeNameVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Cpp.TemplateExtensions; 2 | using Luban.Types; 3 | 4 | namespace Luban.Cpp.TypeVisitors; 5 | 6 | public class CppSharedptrUnderlyingDeclaringTypeNameVisitor : CppUnderlyingDeclaringTypeNameVisitor 7 | { 8 | public new static CppSharedptrUnderlyingDeclaringTypeNameVisitor Ins { get; } = new(); 9 | 10 | public override string Accept(TBean type) 11 | { 12 | return $"::luban::SharedPtr<{CppTemplateExtension.MakeTypeCppName(type.DefBean)}>"; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Luban.Cpp/TypeVisitors/CppSharedptrDeclaringTypeNameVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.Cpp.TypeVisitors; 5 | 6 | public class CppSharedptrDeclaringTypeNameVisitor : DecoratorFuncVisitor 7 | { 8 | public static CppSharedptrDeclaringTypeNameVisitor Ins { get; } = new CppSharedptrDeclaringTypeNameVisitor(); 9 | 10 | public override string DoAccept(TType type) 11 | { 12 | return type.IsNullable ? $"::luban::SharedPtr<{type.Apply(CppSharedptrUnderlyingDeclaringTypeNameVisitor.Ins)}>" : type.Apply(CppSharedptrUnderlyingDeclaringTypeNameVisitor.Ins); 13 | } 14 | 15 | public override string Accept(TBean type) 16 | { 17 | return type.Apply(CppSharedptrUnderlyingDeclaringTypeNameVisitor.Ins); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Luban.Cpp/TypeVisitors/CppSharedptrDeserializeVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.Cpp.TypeVisitors; 5 | 6 | public class CppSharedptrDeserializeVisitor : DecoratorFuncVisitor 7 | { 8 | public static CppSharedptrDeserializeVisitor Ins { get; } = new CppSharedptrDeserializeVisitor(); 9 | 10 | public override string DoAccept(TType type, string bufName, string fieldName, int depth) 11 | { 12 | if (type.IsNullable) 13 | { 14 | return $"{{ bool _has_value_; if(!{bufName}.readBool(_has_value_)){{return false;}} if(_has_value_) {{ {fieldName}.reset({(type.IsBean ? "" : $"new {type.Apply(CppUnderlyingDeclaringTypeNameVisitor.Ins)}()")}); {type.Apply(CppSharedptrUnderlyingDeserializeVisitor.Ins, bufName, $"{(type.IsBean ? "" : "*")}{fieldName}",depth+1, CppSharedptrDeclaringTypeNameVisitor.Ins)} }} else {{ {fieldName}.reset(); }} }}"; 15 | } 16 | else 17 | { 18 | return type.Apply(CppSharedptrUnderlyingDeserializeVisitor.Ins, bufName, fieldName, depth ,CppSharedptrDeclaringTypeNameVisitor.Ins); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Luban.Dart/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 |  2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.Dart/CodeTarget/DartJsonCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Dart.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.Dart.CodeTarget; 6 | 7 | [CodeTarget("dart-json")] 8 | class DartJsonCodeTarget : DartCodeTargetBase 9 | { 10 | protected override void OnCreateTemplateContext(TemplateContext ctx) 11 | { 12 | base.OnCreateTemplateContext(ctx); 13 | ctx.PushGlobal(new DartJsonTemplateExtension()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Dart/Luban.Dart.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net8.0 5 | enable 6 | disable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | Always 20 | 21 | 22 | Always 23 | 24 | 25 | Always 26 | 27 | 28 | Always 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/Luban.Dart/TemplateExtensions/DartJsonTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.Dart.TypeVisitors; 2 | using Luban.Types; 3 | using Scriban.Runtime; 4 | 5 | namespace Luban.Dart.TemplateExtensions; 6 | 7 | class DartJsonTemplateExtension : ScriptObject 8 | { 9 | public static string DeserializeField(string fieldName, string jsonVarName, string jsonFieldName, TType type) 10 | { 11 | if (type.IsNullable) 12 | { 13 | return $" if ({jsonVarName}.containsKey('{fieldName}')) {{ {type.Apply(JsonUnderlyingDeserializeVisitor.Ins, 14 | $"{jsonVarName}['{jsonFieldName}']" 15 | , fieldName, 0)}; }} else {{ {fieldName} = null; }}"; 16 | } 17 | else 18 | { 19 | return $"{type.Apply(JsonUnderlyingDeserializeVisitor.Ins, 20 | $"{jsonVarName}['{jsonFieldName}']", 21 | fieldName, 0)};"; 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Luban.Dart/Templates/common/dart/enum.sbn: -------------------------------------------------------------------------------- 1 | {{~if __this.comment != '' ~}} 2 | //{{escape_comment __this.comment}} 3 | {{~end~}} 4 | enum {{__name}} 5 | { 6 | {{~if !has_enum_item __this~}} 7 | empty_placeholder(0); 8 | {{~else~}} 9 | {{~if !__this.has_zero_value_item ~}} 10 | None(0), 11 | {{~end~}} 12 | {{~end~}} 13 | 14 | 15 | {{~ for item in __this.items ~}} 16 | {{~if item.comment_or_alias != '' ~}} 17 | //{{escape_comment item.comment_or_alias}} 18 | {{~end~}} 19 | {{item.name}}({{item.int_value}}) {{is_last_enum_item __this item.int_value ? ';' : ','}} 20 | 21 | {{~end~}} 22 | final int value; 23 | 24 | const {{__name}}(this.value); 25 | 26 | static {{__name}} fromValue(int value) 27 | { 28 | return {{__name}}.values.firstWhere((element) => element.value == value, orElse: () => fromValue(0)); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Luban.Dart/TypeVisitors/DartDeclaringBoxTypeNameVisitor.cs: -------------------------------------------------------------------------------- 1 |  2 | 3 | using Luban.Types; 4 | 5 | namespace Luban.Dart.TypeVisitors; 6 | 7 | class DartDeclaringBoxTypeNameVisitor: DartDeclaringTypeNameVisitor 8 | { 9 | public new static DartDeclaringBoxTypeNameVisitor Ins { get; } = new(); 10 | 11 | public override string Accept(TBool type) 12 | { 13 | return "bool"; 14 | } 15 | 16 | public override string Accept(TByte type) 17 | { 18 | return "int"; 19 | } 20 | 21 | public override string Accept(TShort type) 22 | { 23 | return "int"; 24 | } 25 | 26 | public override string Accept(TInt type) 27 | { 28 | return "int"; 29 | } 30 | 31 | public override string Accept(TLong type) 32 | { 33 | return "int"; 34 | } 35 | 36 | public override string Accept(TFloat type) 37 | { 38 | return "double"; 39 | } 40 | 41 | public override string Accept(TDouble type) 42 | { 43 | return "double"; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Luban.DataLoader.Builtin/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.DataLoader.Builtin/DataVisitors/InvalidExcelDataException.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.Serialization; 2 | 3 | namespace Luban.DataLoader.Builtin.DataVisitors; 4 | 5 | class InvalidExcelDataException : Exception 6 | { 7 | public InvalidExcelDataException() 8 | { 9 | } 10 | 11 | public InvalidExcelDataException(string message) : base(message) 12 | { 13 | } 14 | 15 | public InvalidExcelDataException(string message, Exception innerException) : base(message, innerException) 16 | { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/Luban.DataLoader.Builtin/DataVisitors/UnityAssetDataCreator.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.DataLoader.Builtin.DataVisitors; 2 | 3 | class UnityAssetDataCreator : YamlDataCreator 4 | { 5 | public new static UnityAssetDataCreator Ins = new(); 6 | } 7 | -------------------------------------------------------------------------------- /src/Luban.DataLoader.Builtin/Excel/Cell.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.DataLoader.Builtin.Excel; 2 | 3 | public struct Cell 4 | { 5 | public Cell(int row, int column, object value) 6 | { 7 | this.Row = row; 8 | this.Column = column; 9 | this.Value = value; 10 | } 11 | public int Row { get; } // 从 1 开始 12 | 13 | public int Column { get; } // 从 0 开始,考虑改了它? 14 | 15 | public object Value { get; } 16 | 17 | 18 | private static string ToAlphaString(int column) 19 | { 20 | int h = column / 26; 21 | int n = column % 26; 22 | return $"{(h > 0 ? ((char)('A' + h - 1)).ToString() : "")}{(char)('A' + n)}"; 23 | } 24 | 25 | public override string ToString() 26 | { 27 | return $"[{ToAlphaString(Column)}:{Row + 1}] {Value}"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Luban.DataLoader.Builtin/Excel/RawSheet.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.DataLoader.Builtin.Excel; 2 | 3 | public class RawSheet 4 | { 5 | public Title Title { get; set; } 6 | 7 | public string TableName { get; set; } 8 | 9 | public string SheetName { get; set; } 10 | 11 | public List> Cells { get; set; } 12 | } 13 | -------------------------------------------------------------------------------- /src/Luban.DataLoader.Builtin/Excel/RawSheetTableDefInfo.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.DataLoader.Builtin.Excel; 2 | 3 | public class FieldInfo 4 | { 5 | public string Name { get; set; } 6 | 7 | public Dictionary Tags { get; set; } 8 | 9 | public string Type { get; set; } 10 | 11 | public string Desc { get; set; } 12 | public string Groups { get; set; } 13 | } 14 | 15 | public class RawSheetTableDefInfo 16 | { 17 | public Dictionary FieldInfos { get; set; } 18 | } 19 | -------------------------------------------------------------------------------- /src/Luban.DataLoader.Builtin/Excel/StreamSheet.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.DataLoader.Builtin.Excel; 2 | 3 | class StreamSheet 4 | { 5 | private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger(); 6 | 7 | public string Name { get; } 8 | 9 | public string RawUrl { get; } 10 | 11 | public ExcelStream Stream { get; private set; } 12 | 13 | public StreamSheet(string rawUrl, string name) 14 | { 15 | this.RawUrl = rawUrl; 16 | this.Name = name; 17 | } 18 | 19 | public void Load(RawSheet rawSheet) 20 | { 21 | Title title = rawSheet.Title; 22 | Stream = new ExcelStream(rawSheet.Cells, 1, title.ToIndex, "", ""); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/Luban.DataLoader.Builtin/Xml/XmlDataSource.cs: -------------------------------------------------------------------------------- 1 | using System.Xml.Linq; 2 | using Luban.DataLoader.Builtin.DataVisitors; 3 | using Luban.Datas; 4 | using Luban.Defs; 5 | using Luban.Types; 6 | using Luban.Utils; 7 | 8 | namespace Luban.DataLoader.Builtin.Xml; 9 | 10 | [DataLoader("xml")] 11 | public class XmlDataSource : DataLoaderBase 12 | { 13 | private XElement _doc; 14 | 15 | public override void Load(string rawUrl, string sheetName, Stream stream) 16 | { 17 | RawUrl = rawUrl; 18 | _doc = XElement.Load(stream); 19 | } 20 | 21 | public override List ReadMulti(TBean type) 22 | { 23 | throw new NotSupportedException(); 24 | } 25 | 26 | public override Record ReadOne(TBean type) 27 | { 28 | string tagName = _doc.Element(FieldNames.TagKey)?.Value; 29 | if (DataUtil.IsIgnoreTag(tagName)) 30 | { 31 | return null; 32 | } 33 | var data = (DBean)type.Apply(XmlDataCreator.Ins, _doc, type.DefBean.Assembly); 34 | var tags = DataUtil.ParseTags(tagName); 35 | return new Record(data, RawUrl, tags); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Luban.DataTarget.Builtin/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.DataTarget.Builtin/Binary/BinaryDataTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.DataTarget; 2 | using Luban.Defs; 3 | using Luban.Serialization; 4 | 5 | namespace Luban.DataExporter.Builtin.Binary; 6 | 7 | [DataTarget("bin")] 8 | public class BinaryDataTarget : DataTargetBase 9 | { 10 | protected override string DefaultOutputFileExt => "bytes"; 11 | 12 | private void WriteList(DefTable table, List datas, ByteBuf x) 13 | { 14 | x.WriteSize(datas.Count); 15 | foreach (var d in datas) 16 | { 17 | d.Data.Apply(BinaryDataVisitor.Ins, x); 18 | } 19 | } 20 | 21 | public override OutputFile ExportTable(DefTable table, List records) 22 | { 23 | var bytes = new ByteBuf(); 24 | WriteList(table, records, bytes); 25 | return CreateOutputFile($"{table.OutputDataFile}.{OutputFileExt}", bytes.CopyData()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Luban.DataTarget.Builtin/Binary/BinaryIndexExportor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Datas; 2 | using Luban.Defs; 3 | using Luban.Serialization; 4 | 5 | namespace Luban.DataExporter.Builtin.Binary; 6 | 7 | class BinaryIndexExportor 8 | { 9 | public static BinaryIndexExportor Ins { get; } = new(); 10 | 11 | public void WriteList(DefTable table, List datas, ByteBuf x) 12 | { 13 | x.WriteSize(datas.Count); 14 | var tableDataBuf = new ByteBuf(10 * 1024); 15 | tableDataBuf.WriteSize(datas.Count); 16 | 17 | foreach (var d in datas) 18 | { 19 | int offset = tableDataBuf.Size; 20 | d.Data.Apply(BinaryDataVisitor.Ins, tableDataBuf); 21 | 22 | string keyStr = ""; 23 | foreach (IndexInfo index in table.IndexList) 24 | { 25 | DType key = d.Data.Fields[index.IndexFieldIdIndex]; 26 | key.Apply(BinaryDataVisitor.Ins, x); 27 | keyStr += key.ToString() + ","; 28 | } 29 | x.WriteSize(offset); 30 | Console.WriteLine($"table:{table.Name} key:{keyStr} offset:{offset}"); 31 | } 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Luban.DataTarget.Builtin/DefaultDataExporter.cs: -------------------------------------------------------------------------------- 1 | using Luban.DataTarget; 2 | 3 | namespace Luban.DataExporter.Builtin; 4 | 5 | [DataExporter("default")] 6 | public class DefaultDataExporter : DataExporterBase 7 | { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/Luban.DataTarget.Builtin/Json/Json2DataVisitor.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json; 2 | using Luban.Datas; 3 | 4 | namespace Luban.DataExporter.Builtin.Json; 5 | 6 | class Json2DataVisitor : JsonDataVisitor 7 | { 8 | public static new Json2DataVisitor Ins { get; } = new(); 9 | 10 | public override void Accept(DMap type, Utf8JsonWriter x) 11 | { 12 | x.WriteStartObject(); 13 | foreach (var d in type.DataMap) 14 | { 15 | x.WritePropertyName(d.Key.Apply(ToJsonPropertyNameVisitor.Ins)); 16 | d.Value.Apply(this, x); 17 | } 18 | x.WriteEndObject(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Luban.DataTarget.Builtin/Json/SimpleJsonTypeVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.DataExporter.Builtin.Json; 5 | 6 | public class SimpleJsonTypeVisitor : AllTrueVisitor 7 | { 8 | public static SimpleJsonTypeVisitor Ins { get; } = new(); 9 | 10 | public override bool Accept(TEnum type) 11 | { 12 | return false; 13 | } 14 | 15 | public override bool Accept(TBean type) 16 | { 17 | //return type.Bean.IsNotAbstractType && type.Bean.HierarchyFields.All(f => f.CType.Apply(this)); 18 | return false; 19 | } 20 | 21 | public override bool Accept(TArray type) 22 | { 23 | return type.ElementType.Apply(this); 24 | } 25 | 26 | public override bool Accept(TList type) 27 | { 28 | return type.ElementType.Apply(this); 29 | } 30 | 31 | public override bool Accept(TSet type) 32 | { 33 | return type.ElementType.Apply(this); 34 | } 35 | 36 | public override bool Accept(TMap type) 37 | { 38 | return false; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Luban.DataTarget.Builtin/NullDataExporter.cs: -------------------------------------------------------------------------------- 1 | using Luban.DataTarget; 2 | 3 | namespace Luban.DataExporter.Builtin; 4 | 5 | [DataExporter("null")] 6 | public class NullDataExporter : DataExporterBase 7 | { 8 | public override void Handle(GenerationContext ctx, IDataTarget dataTarget, OutputFileManifest manifest) 9 | { 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Luban.DataTarget.Builtin/Res/ResourceInfo.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.DataExporter.Builtin.Res; 2 | 3 | public class ResourceInfo 4 | { 5 | public string Resource { get; set; } 6 | 7 | public string Tag { get; set; } 8 | } 9 | -------------------------------------------------------------------------------- /src/Luban.DataTarget.Builtin/Xml/ToXmlLiteralVisitor.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using Luban.DataExporter.Builtin.Json; 3 | using Luban.Datas; 4 | using Luban.DataVisitors; 5 | 6 | namespace Luban.DataExporter.Builtin.Xml; 7 | 8 | public class ToXmlLiteralVisitor : ToLiteralVisitorBase 9 | { 10 | public static ToXmlLiteralVisitor Ins { get; } = new(); 11 | 12 | public override string Accept(DBean type) 13 | { 14 | throw new NotSupportedException(); 15 | } 16 | 17 | public override string Accept(DArray type) 18 | { 19 | throw new NotImplementedException(); 20 | } 21 | 22 | public override string Accept(DList type) 23 | { 24 | throw new NotSupportedException(); 25 | } 26 | 27 | public override string Accept(DSet type) 28 | { 29 | throw new NotSupportedException(); 30 | } 31 | 32 | public override string Accept(DMap type) 33 | { 34 | throw new NotSupportedException(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Luban.DataTarget.Builtin/Yaml/YamlDataTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.DataTarget; 2 | using Luban.Defs; 3 | using Luban.Utils; 4 | using System.Text; 5 | using YamlDotNet.RepresentationModel; 6 | 7 | namespace Luban.DataExporter.Builtin.Yaml; 8 | 9 | [DataTarget("yaml")] 10 | public class YamlDataTarget : DataTargetBase 11 | { 12 | protected override string DefaultOutputFileExt => "yml"; 13 | 14 | public YamlNode WriteAsArray(List datas) 15 | { 16 | 17 | var seqNode = new YamlSequenceNode(); 18 | foreach (var d in datas) 19 | { 20 | seqNode.Add(d.Data.Apply(YamlDataVisitor.Ins)); 21 | } 22 | return seqNode; 23 | } 24 | 25 | public override OutputFile ExportTable(DefTable table, List records) 26 | { 27 | var node = WriteAsArray(records); 28 | var ys = new YamlStream(new YamlDocument(node)); 29 | var ms = new MemoryStream(); 30 | var tw = new StreamWriter(ms); 31 | ys.Save(tw, false); 32 | tw.Flush(); 33 | return CreateOutputFile($"{table.OutputDataFile}.{OutputFileExt}", Encoding.UTF8.GetString(DataUtil.StreamToBytes(ms))); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Luban.DataValidator.Builtin/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.DataValidator.Builtin/Luban.DataValidator.Builtin.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | disable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /src/Luban.DataValidator.Builtin/Misc/NotDefaultValueValidator.cs: -------------------------------------------------------------------------------- 1 | using Luban.Datas; 2 | using Luban.DataVisitors; 3 | using Luban.Defs; 4 | using Luban.Types; 5 | using Luban.Validator; 6 | 7 | namespace Luban.DataValidator.Builtin.Misc; 8 | 9 | [Validator("not-default")] 10 | public class NotDefaultValueValidator : DataValidatorBase 11 | { 12 | private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger(); 13 | 14 | public override void Compile(DefField field, TType type) 15 | { 16 | 17 | } 18 | 19 | public override void Validate(DataValidatorContext ctx, TType type, DType data) 20 | { 21 | if (data.Apply(IsDefaultValueVisitor.Ins)) 22 | { 23 | s_logger.Error("记录 {}:{} (来自文件:{}) 是一个默认值", DataValidatorContext.CurrentRecordPath, data, Source); 24 | GenerationContext.Current.LogValidatorFail(this); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Luban.DataValidator.Builtin/Path/IPathPattern.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.DataValidator.Builtin.Path; 2 | 3 | interface IPathPattern 4 | { 5 | bool ExistPath(string rootDir, string subFile); 6 | 7 | bool EmptyAble { get; set; } 8 | } 9 | -------------------------------------------------------------------------------- /src/Luban.DataValidator.Builtin/Path/RegexPattern.cs: -------------------------------------------------------------------------------- 1 | using System.Text.RegularExpressions; 2 | 3 | namespace Luban.DataValidator.Builtin.Path; 4 | 5 | class RegexPattern : IPathPattern 6 | { 7 | private readonly string _replacePattern; 8 | 9 | private readonly Regex _re; 10 | 11 | public bool EmptyAble { get; set; } 12 | 13 | public string Mode => "regex"; 14 | 15 | public RegexPattern(string matchPattern, string replacePattern) 16 | { 17 | _re = new Regex(matchPattern); 18 | _replacePattern = replacePattern; 19 | } 20 | 21 | public bool ExistPath(string rootDir, string subFile) 22 | { 23 | if (!_re.IsMatch(subFile)) 24 | { 25 | return false; 26 | } 27 | var replacePath = _re.Replace(subFile, _replacePattern); 28 | string finalPath = System.IO.Path.Combine(rootDir, replacePath); 29 | return File.Exists(finalPath); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Luban.DataValidator.Builtin/Path/SimpleReplacePattern.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.DataValidator.Builtin.Path; 2 | 3 | class SimpleReplacePattern : IPathPattern 4 | { 5 | private readonly string _prefix; 6 | private readonly string _suffix; 7 | 8 | public bool EmptyAble { get; set; } 9 | 10 | public string Mode => "normal"; 11 | 12 | public SimpleReplacePattern(string prefix, string suffix) 13 | { 14 | _prefix = prefix; 15 | _suffix = suffix; 16 | } 17 | 18 | public bool ExistPath(string rootDir, string subFile) 19 | { 20 | string finalPath = System.IO.Path.Combine(rootDir, _prefix + subFile + _suffix); 21 | return File.Exists(finalPath); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Luban.DataValidator.Builtin/Path/UnityAddressablePattern.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.DataValidator.Builtin.Path; 2 | 3 | class UnityAddressablePattern : IPathPattern 4 | { 5 | public bool EmptyAble { get; set; } 6 | 7 | public UnityAddressablePattern() 8 | { 9 | } 10 | 11 | public bool ExistPath(string rootDir, string subFile) 12 | { 13 | return File.Exists(System.IO.Path.Combine(rootDir, subFile)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.DataValidator.Builtin/Set/LongDataSet.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.DataValidator.Builtin.Set; 2 | 3 | public class LongDataSet 4 | { 5 | private readonly HashSet _values; 6 | 7 | public LongDataSet(string args) 8 | { 9 | _values = args.Split(',').Select(long.Parse).ToHashSet(); 10 | } 11 | 12 | public LongDataSet(IEnumerable args) 13 | { 14 | _values = args.ToHashSet(); 15 | } 16 | 17 | public bool Contains(long value) 18 | { 19 | return _values.Contains(value); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Luban.DataValidator.Builtin/Set/StringDataSet.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.DataValidator.Builtin.Set; 2 | 3 | public class StringDataSet 4 | { 5 | private readonly HashSet _values; 6 | public StringDataSet(string args) 7 | { 8 | _values = args.Split(',').ToHashSet(); 9 | } 10 | 11 | public bool Contains(string value) 12 | { 13 | return _values.Contains(value); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.FlatBuffers/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.FlatBuffers/Luban.FlatBuffers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | disable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Always 17 | 18 | 19 | PreserveNewest 20 | 21 | 22 | Always 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/Luban.FlatBuffers/TemplateExtensions/FlatBuffersTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | using Luban.FlatBuffers.TypeVisitors; 3 | using Luban.Types; 4 | using Luban.Utils; 5 | using Scriban.Runtime; 6 | 7 | namespace Luban.FlatBuffers.TemplateExtensions; 8 | 9 | public class FlatBuffersTemplateExtension : ScriptObject 10 | { 11 | public static string FullName(DefTypeBase type) 12 | { 13 | return TypeUtil.MakeFlatBuffersFullName(type.Namespace, type.Name); 14 | } 15 | 16 | public static string DeclaringTypeName(TType type) 17 | { 18 | return type.Apply(FlatBuffersTypeNameVisitor.Ins); 19 | } 20 | 21 | public static string TypeMetadata(TType type) 22 | { 23 | return type.IsNullable || type.Apply(IsFlatBuffersScalarTypeVisitor.Ins) ? "" : "(required)"; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Luban.FlatBuffers/TypeVisitors/IsFlatBuffersScalarTypeVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.FlatBuffers.TypeVisitors; 5 | 6 | public class IsFlatBuffersScalarTypeVisitor : AllTrueVisitor 7 | { 8 | public static IsFlatBuffersScalarTypeVisitor Ins { get; } = new(); 9 | 10 | public override bool Accept(TBean type) 11 | { 12 | return false; 13 | } 14 | 15 | public override bool Accept(TArray type) 16 | { 17 | return false; 18 | } 19 | 20 | public override bool Accept(TList type) 21 | { 22 | return false; 23 | } 24 | 25 | public override bool Accept(TSet type) 26 | { 27 | return false; 28 | } 29 | 30 | public override bool Accept(TMap type) 31 | { 32 | return false; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Luban.Gdscript/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.Gdscript/CodeTarget/GdscriptJsonCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Gdscript.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.Gdscript.CodeTarget; 6 | 7 | [CodeTarget("gdscript-json")] 8 | public class GdscriptJsonCodeTarget : GdscriptCodeTargetBase 9 | { 10 | protected override void OnCreateTemplateContext(TemplateContext ctx) 11 | { 12 | base.OnCreateTemplateContext(ctx); 13 | ctx.PushGlobal(new GdscriptJsonTemplateExtension()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Gdscript/Luban.Gdscript.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | Always 12 | 13 | 14 | Always 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/Luban.Gdscript/TemplateExtensions/GdscriptCommonTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | using Luban.Gdscript.TypeVisitors; 3 | using Luban.Types; 4 | using Luban.Utils; 5 | using Scriban.Runtime; 6 | 7 | namespace Luban.Gdscript.TemplateExtensions; 8 | 9 | public class GdscriptCommonTemplateExtension : ScriptObject 10 | { 11 | 12 | public static string DeclaringTypeName(TType type) 13 | { 14 | return type.Apply(DeclaringTypeNameVisitor.Ins); 15 | } 16 | 17 | public static string FullName(DefTypeBase type) 18 | { 19 | return TypeUtil.MakeGDScriptFullName(type.Namespace, type.Name); 20 | } 21 | 22 | public static string StrFullName(string fullName) 23 | { 24 | return TypeUtil.ToPascalCase(fullName.Replace(".", "_")); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Luban.Golang/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.Golang/CodeTarget/GoBinCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Golang.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.Golang.CodeTarget; 6 | 7 | [CodeTarget("go-bin")] 8 | public class GoBinCodeTarget : GoCodeTargetBase 9 | { 10 | protected override void OnCreateTemplateContext(TemplateContext ctx) 11 | { 12 | base.OnCreateTemplateContext(ctx); 13 | ctx.PushGlobal(new GoBinTemplateExtension()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Golang/CodeTarget/GoJsonCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Golang.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.Golang.CodeTarget; 6 | 7 | [CodeTarget("go-json")] 8 | public class GoJsonCodeTarget : GoCodeTargetBase 9 | { 10 | protected override void OnCreateTemplateContext(TemplateContext ctx) 11 | { 12 | base.OnCreateTemplateContext(ctx); 13 | ctx.PushGlobal(new GoJsonTemplateExtension()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Golang/TemplateExtensions/GoBinTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | using Luban.Golang.TypeVisitors; 3 | using Luban.Types; 4 | using Scriban.Runtime; 5 | 6 | namespace Luban.Golang.TemplateExtensions; 7 | 8 | public class GoBinTemplateExtension : ScriptObject 9 | { 10 | // public static string Deserialize(string bufName, string fieldName, TType type) 11 | // { 12 | // return type.Apply(GoDeserializeBinVisitor.Ins, bufName, fieldName); 13 | // } 14 | 15 | public static string DeserializeField(TType type, string name, string bufName, string err) 16 | { 17 | return type.Apply(DeserializeBinVisitor.Ins, name, bufName, err, 0); 18 | } 19 | 20 | public static string CollectImport(DefBean bean) 21 | { 22 | var imports = new HashSet(); 23 | if (bean.IsAbstractType || bean.HierarchyExportFields.Count > 0) 24 | { 25 | imports.Add("errors"); 26 | } 27 | return string.Join('\n', imports.Select(im => $"import \"{im}\"")); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Luban.Golang/TemplateExtensions/GoCommonTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | using Luban.Golang.TypeVisitors; 3 | using Luban.Types; 4 | using Luban.Utils; 5 | using Scriban.Runtime; 6 | 7 | namespace Luban.Golang.TemplateExtensions; 8 | 9 | public class GoCommonTemplateExtension : ScriptObject 10 | { 11 | public static string FullName(DefTypeBase bean) 12 | { 13 | return TypeUtil.MakeGoFullName(bean.Namespace, bean.Name); 14 | } 15 | public static string FullNameLowerCase(DefTypeBase bean) 16 | { 17 | return TypeUtil.MakeGoFullName(bean.Namespace, bean.Name).ToLowerInvariant(); 18 | } 19 | 20 | public static string DeclaringTypeName(TType type) 21 | { 22 | return type.Apply(DeclaringTypeNameVisitor.Ins); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/Luban.Golang/Templates/common/go/enum.sbn: -------------------------------------------------------------------------------- 1 | {{~if ___top_module != ''~}} 2 | package {{__top_module}}; 3 | {{~end~}} 4 | 5 | {{~if __this.comment != '' ~}} 6 | /** 7 | * {{escape_comment __this.comment}} 8 | */ 9 | {{~end~}} 10 | const ( 11 | {{~ for item in __this.items ~}} 12 | {{~if item.comment_or_alias != '' ~}} 13 | /** 14 | * {{escape_comment item.comment_or_alias}} 15 | */ 16 | {{~end~}} 17 | {{full_name __this}}_{{item.name}} = {{item.int_value}}; 18 | {{~end~}} 19 | ) 20 | -------------------------------------------------------------------------------- /src/Luban.Golang/Templates/go-bin/tables.sbn: -------------------------------------------------------------------------------- 1 | {{~if __namespace != ''~}} 2 | package {{__namespace}}; 3 | {{~end~}} 4 | 5 | import ( 6 | "{{__luban_module_name}}" 7 | "errors" 8 | ) 9 | 10 | type ByteBufLoader func(string) (*luban.ByteBuf, error) 11 | 12 | type {{__name}} struct { 13 | {{~for table in __tables ~}} 14 | {{table.name}} *{{full_name table}} 15 | {{~end~}} 16 | } 17 | 18 | func NewTables(loader ByteBufLoader) (*{{__name}}, error) { 19 | var err error 20 | var buf *luban.ByteBuf 21 | 22 | tables := &{{__name}}{} 23 | {{~for table in __tables ~}} 24 | if buf, err = loader("{{table.output_data_file}}") ; err != nil { 25 | return nil, err 26 | } 27 | if tables.{{table.name}}, err = New{{full_name table}}(buf) ; err != nil { 28 | return nil, errors.Join(errors.New("failed to load {{table.name}}"), err) 29 | } 30 | {{~end~}} 31 | return tables, nil 32 | } 33 | 34 | -------------------------------------------------------------------------------- /src/Luban.Golang/Templates/go-json/tables.sbn: -------------------------------------------------------------------------------- 1 | {{~if __namespace != ''~}} 2 | package {{__namespace}}; 3 | {{~end~}} 4 | 5 | type JsonLoader func(string) ([]map[string]interface{}, error) 6 | 7 | type {{__name}} struct { 8 | {{~for table in __tables ~}} 9 | {{table.name}} *{{full_name table}} 10 | {{~end~}} 11 | } 12 | 13 | func NewTables(loader JsonLoader) (*{{__name}}, error) { 14 | var err error 15 | var buf []map[string]interface{} 16 | 17 | tables := &{{__name}}{} 18 | {{~for table in __tables ~}} 19 | if buf, err = loader("{{table.output_data_file}}") ; err != nil { 20 | return nil, err 21 | } 22 | if tables.{{table.name}}, err = New{{full_name table}}(buf) ; err != nil { 23 | return nil, err 24 | } 25 | {{~end~}} 26 | return tables, nil 27 | } 28 | 29 | -------------------------------------------------------------------------------- /src/Luban.Golang/TypeVisitors/BinImport.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.Golang.TypeVisitors; 5 | 6 | public class BinImport : DecoratorActionVisitor> 7 | { 8 | public static BinImport Ins { get; } = new(); 9 | 10 | public override void DoAccept(TType type, HashSet x) 11 | { 12 | 13 | } 14 | 15 | public override void Accept(TArray type, HashSet x) 16 | { 17 | type.ElementType.Apply(this, x); 18 | } 19 | 20 | public override void Accept(TList type, HashSet x) 21 | { 22 | type.ElementType.Apply(this, x); 23 | } 24 | 25 | public override void Accept(TSet type, HashSet x) 26 | { 27 | 28 | } 29 | 30 | public override void Accept(TMap type, HashSet x) 31 | { 32 | type.KeyType.Apply(this, x); 33 | type.ValueType.Apply(this, x); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Luban.Golang/TypeVisitors/DeclaringTypeNameVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.Golang.TypeVisitors; 5 | 6 | public class DeclaringTypeNameVisitor : DecoratorFuncVisitor 7 | { 8 | public static DeclaringTypeNameVisitor Ins { get; } = new DeclaringTypeNameVisitor(); 9 | 10 | public override string DoAccept(TType type) 11 | { 12 | var s = type.Apply(UnderlyingDeclaringTypeNameVisitor.Ins); 13 | return type.Apply(IsPointerTypeVisitor.Ins) ? "*" + s : s; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Golang/TypeVisitors/DeserializeBinVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.Golang.TypeVisitors; 5 | 6 | public class DeserializeBinVisitor : DecoratorFuncVisitor 7 | { 8 | public static DeserializeBinVisitor Ins { get; } = new DeserializeBinVisitor(); 9 | 10 | public override string DoAccept(TType type, string fieldName, string bufName, string err, int depth) 11 | { 12 | if (type.IsNullable) 13 | { 14 | return $"{{ var __exists__ bool; if __exists__, {err} = {bufName}.ReadBool(); {err} != nil {{ return }}; if __exists__ {{ var __x__ {type.Apply(UnderlyingDeclaringTypeNameVisitor.Ins)}; {type.Apply(BinUnderlyingDeserializeVisitor.Ins, "__x__", bufName, err, depth + 1)}; {fieldName} = {(type.Apply(IsPointerTypeVisitor.Ins) ? "&" : "")}__x__ }}}}"; 15 | } 16 | else 17 | { 18 | return type.Apply(BinUnderlyingDeserializeVisitor.Ins, fieldName, bufName, err, depth); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Luban.Golang/TypeVisitors/DeserializeJsonVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.Golang.TypeVisitors; 5 | 6 | public class DeserializeJsonVisitor : DecoratorFuncVisitor 7 | { 8 | public static DeserializeJsonVisitor Ins { get; } = new(); 9 | 10 | public override string DoAccept(TType type, string varName, string bufName, int depth) 11 | { 12 | if (type.IsNullable) 13 | { 14 | return $"{{ if {bufName} == nil {{ return }} else {{ var __x{depth}__ {type.Apply(UnderlyingDeclaringTypeNameVisitor.Ins)}; {type.Apply(DeserializeJsonUnderingVisitor.Ins, $"__x{depth}__", bufName, depth)}; {varName} = {(type.Apply(IsPointerTypeVisitor.Ins) ? "&" : "")}__x{depth}__ }}}}"; 15 | } 16 | else 17 | { 18 | return type.Apply(DeserializeJsonUnderingVisitor.Ins, varName, bufName, depth); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Luban.Golang/TypeVisitors/IsPointerTypeVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.Golang.TypeVisitors; 5 | 6 | public class IsPointerTypeVisitor : DecoratorFuncVisitor 7 | { 8 | public static IsPointerTypeVisitor Ins { get; } = new(); 9 | 10 | public override bool DoAccept(TType type) 11 | { 12 | return type.IsNullable; 13 | } 14 | 15 | public override bool Accept(TBean type) 16 | { 17 | return false; 18 | } 19 | 20 | public override bool Accept(TArray type) 21 | { 22 | return false; 23 | } 24 | 25 | public override bool Accept(TList type) 26 | { 27 | return false; 28 | } 29 | 30 | public override bool Accept(TSet type) 31 | { 32 | return false; 33 | } 34 | 35 | public override bool Accept(TMap type) 36 | { 37 | return false; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Luban.Golang/TypeVisitors/JsonImport.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | using Luban.Types; 3 | using Luban.TypeVisitors; 4 | 5 | namespace Luban.Golang.TypeVisitors; 6 | 7 | class JsonImport : DecoratorActionVisitor> 8 | { 9 | public static JsonImport Ins { get; } = new(); 10 | 11 | public override void DoAccept(TType type, HashSet x) 12 | { 13 | x.Add("errors"); 14 | } 15 | 16 | public override void Accept(TArray type, HashSet x) 17 | { 18 | type.ElementType.Apply(this, x); 19 | } 20 | 21 | public override void Accept(TList type, HashSet x) 22 | { 23 | type.ElementType.Apply(this, x); 24 | } 25 | 26 | public override void Accept(TSet type, HashSet x) 27 | { 28 | type.ElementType.Apply(this, x); 29 | } 30 | 31 | public override void Accept(TMap type, HashSet x) 32 | { 33 | type.KeyType.Apply(this, x); 34 | type.ValueType.Apply(this, x); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Luban.Java/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.Java/CodeTarget/JavaBinCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Java.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.Java.CodeTarget; 6 | 7 | [CodeTarget("java-bin")] 8 | public class JavaBinCodeTarget : JavaCodeTargetBase 9 | { 10 | protected override void OnCreateTemplateContext(TemplateContext ctx) 11 | { 12 | base.OnCreateTemplateContext(ctx); 13 | ctx.PushGlobal(new JavaBinTemplateExtension()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Java/CodeTarget/JavaJsonCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Java.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.Java.CodeTarget; 6 | 7 | [CodeTarget("java-json")] 8 | public class JavaJsonCodeTarget : JavaCodeTargetBase 9 | { 10 | protected override void OnCreateTemplateContext(TemplateContext ctx) 11 | { 12 | base.OnCreateTemplateContext(ctx); 13 | ctx.PushGlobal(new JavaJsonTemplateExtension()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Java/TemplateExtensions/JavaBinTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.Java.TypeVisitors; 2 | using Luban.Types; 3 | using Scriban.Runtime; 4 | 5 | namespace Luban.Java.TemplateExtensions; 6 | 7 | public class JavaBinTemplateExtension : ScriptObject 8 | { 9 | public static string Deserialize(string bufName, string fieldName, TType type) 10 | { 11 | return type.Apply(JavaBinDeserializeVisitor.Ins, bufName, fieldName); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Luban.Java/TemplateExtensions/JavaCommonTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | using Luban.Java.TypeVisitors; 3 | using Luban.Types; 4 | using Luban.Utils; 5 | using Scriban.Runtime; 6 | 7 | namespace Luban.Java.TemplateExtensions; 8 | 9 | public class JavaCommonTemplateExtension : ScriptObject 10 | { 11 | public static string DeclaringTypeName(TType type) 12 | { 13 | return type.Apply(JavaDeclaringTypeNameVisitor.Ins); 14 | } 15 | 16 | public static string DeclaringBoxTypeName(TType type) 17 | { 18 | return type.Apply(JavaDeclaringBoxTypeNameVisitor.Ins); 19 | } 20 | 21 | public static string ClassModifier(DefBean type) 22 | { 23 | return type.IsAbstractType ? "abstract" : "final"; 24 | } 25 | 26 | public static string GetterName(string name) 27 | { 28 | return TypeUtil.ToJavaGetterName(name); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Luban.Java/TemplateExtensions/JavaJsonTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.Java.TypeVisitors; 2 | using Luban.Types; 3 | using Scriban.Runtime; 4 | 5 | namespace Luban.Java.TemplateExtensions; 6 | 7 | public class JavaJsonTemplateExtension : ScriptObject 8 | { 9 | public static string Deserialize(string fieldName, string jsonVar, TType type) 10 | { 11 | return type.Apply(JavaJsonUnderlyingDeserializeVisitor.Ins, jsonVar, fieldName, 0); 12 | } 13 | 14 | public static string DeserializeField(string fieldName, string jsonName, string jsonFieldName, TType type) 15 | { 16 | if (type.IsNullable) 17 | { 18 | return $"{{ if ({jsonName}.has(\"{jsonFieldName}\") && !{jsonName}.get(\"{jsonFieldName}\").isJsonNull()) {{ {type.Apply(JavaJsonUnderlyingDeserializeVisitor.Ins, $"{jsonName}.get(\"{jsonFieldName}\")", fieldName, 0)} }} else {{ {fieldName} = null; }} }}"; 19 | } 20 | else 21 | { 22 | return type.Apply(TypeVisitors.JavaJsonUnderlyingDeserializeVisitor.Ins, $"{jsonName}.get(\"{jsonFieldName}\")", fieldName, 0); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Luban.Java/Templates/common/java/enum.sbn: -------------------------------------------------------------------------------- 1 | {{~if __namespace_with_top_module != ''~}} 2 | package {{__namespace_with_top_module}}; 3 | {{~end~}} 4 | 5 | {{~if __this.comment != '' ~}} 6 | /** 7 | * {{escape_comment __this.comment}} 8 | */ 9 | {{~end~}} 10 | public final class {{__name}} { 11 | {{~ for item in __this.items ~}} 12 | {{~if item.comment_or_alias != '' ~}} 13 | /** 14 | * {{escape_comment item.comment_or_alias}} 15 | */ 16 | {{~end~}} 17 | public static final int {{item.name}} = {{item.int_value}}; 18 | {{~end~}} 19 | } 20 | -------------------------------------------------------------------------------- /src/Luban.Java/Templates/java-bin/tables.sbn: -------------------------------------------------------------------------------- 1 | {{~if __namespace != ''~}} 2 | package {{__namespace}}; 3 | {{~end~}} 4 | 5 | import luban.*; 6 | {{~ 7 | func get_table_inner_name 8 | ret '_' + ($0 | string.downcase) 9 | end 10 | ~}} 11 | 12 | public final class {{__name}} 13 | { 14 | public static interface IByteBufLoader { 15 | ByteBuf load(String file) throws java.io.IOException; 16 | } 17 | 18 | {{~for table in __tables 19 | inner_name = get_table_inner_name table.name 20 | ~}} 21 | {{~if table.comment != '' ~}} 22 | /** 23 | * {{escape_comment table.comment}} 24 | */ 25 | {{~end~}} 26 | private final {{table.full_name_with_top_module}} {{inner_name}}; 27 | public {{table.full_name_with_top_module}} get{{table.name}}() { return {{inner_name}}; } 28 | {{~end~}} 29 | 30 | public {{__name}}(IByteBufLoader loader) throws java.io.IOException { 31 | {{~for table in __tables 32 | inner_name = get_table_inner_name table.name 33 | ~}} 34 | {{inner_name}} = new {{table.full_name_with_top_module}}(loader.load("{{table.output_data_file}}")); 35 | {{~end~}} 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/Luban.Java/TypeVisitors/JavaBinDeserializeVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.Java.TypeVisitors; 5 | 6 | public class JavaBinDeserializeVisitor : DecoratorFuncVisitor 7 | { 8 | public static JavaBinDeserializeVisitor Ins { get; } = new(); 9 | 10 | public override string DoAccept(TType type, string bufName, string fieldName) 11 | { 12 | if (type.IsNullable) 13 | { 14 | return $"if({bufName}.readBool()){{ {type.Apply(JavaBinUnderlyingDeserializeVisitor.Ins, bufName, fieldName, 0)} }} else {{ {fieldName} = null; }}"; 15 | } 16 | else 17 | { 18 | return type.Apply(JavaBinUnderlyingDeserializeVisitor.Ins, bufName, fieldName, 0); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Luban.L10N/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.L10N/DataTarget/TextKeyCollection.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.L10N.DataTarget; 2 | 3 | public class TextKeyCollection 4 | { 5 | private readonly HashSet _keys = new(); 6 | 7 | public void AddKey(string key) 8 | { 9 | if (!string.IsNullOrWhiteSpace(key)) 10 | { 11 | _keys.Add(key); 12 | } 13 | } 14 | 15 | public IEnumerable Keys => _keys; 16 | } 17 | -------------------------------------------------------------------------------- /src/Luban.L10N/Luban.L10N.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | disable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /src/Luban.Lua/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.Lua/CodeTarget/LuaBinCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Lua.TemplateExtensions; 3 | using Luban.Tmpl; 4 | using Scriban; 5 | using Scriban.Runtime; 6 | 7 | namespace Luban.Lua.CodeTarget; 8 | 9 | [CodeTarget("lua-bin")] 10 | public class LuaBinCodeTarget : LuaCodeTargetBase 11 | { 12 | protected override void OnCreateTemplateContext(TemplateContext ctx) 13 | { 14 | base.OnCreateTemplateContext(ctx); 15 | ctx.PushGlobal(new LuaBinTemplateExtension()); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/Luban.Lua/CodeTarget/LuaCodeTargetBase.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Lua.TemplateExtensions; 3 | using Luban.Tmpl; 4 | using Scriban; 5 | using Scriban.Runtime; 6 | 7 | namespace Luban.Lua.CodeTarget; 8 | 9 | public abstract class LuaCodeTargetBase : AllInOneTemplateCodeTargetBase 10 | { 11 | public override string FileHeader => CommonFileHeaders.AUTO_GENERATE_LUA; 12 | 13 | protected override string FileSuffixName => "lua"; 14 | 15 | protected override string DefaultOutputFileName => "schema.lua"; 16 | 17 | 18 | private static readonly HashSet s_preservedKeyWords = new() 19 | { 20 | // lua preserved key words 21 | "and", "break", "do", "else", "elseif", "end", "false", "for", "function", "goto", "if", "in", "local", "nil", "not", "or", "repeat", "return", "then", "true", "until", "while" 22 | }; 23 | 24 | protected override IReadOnlySet PreservedKeyWords => s_preservedKeyWords; 25 | 26 | protected override void OnCreateTemplateContext(TemplateContext ctx) 27 | { 28 | ctx.PushGlobal(new LuaCommonTemplateExtension()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Luban.Lua/CodeTarget/LuaLuaCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Defs; 3 | using Scriban; 4 | 5 | namespace Luban.Lua.CodeTarget; 6 | 7 | [CodeTarget("lua-lua")] 8 | public class LuaLuaCodeTarget : LuaCodeTargetBase 9 | { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/Luban.Lua/Luban.Lua.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | Always 20 | 21 | 22 | Always 23 | 24 | 25 | Always 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /src/Luban.Lua/TemplateExtensions/LuaBinTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | using Luban.Lua.TypVisitors; 3 | using Luban.Types; 4 | using Luban.Utils; 5 | using Scriban.Runtime; 6 | 7 | namespace Luban.Lua.TemplateExtensions; 8 | 9 | public class LuaBinTemplateExtension : ScriptObject 10 | { 11 | public static string Deserialize(string bufName, TType type) 12 | { 13 | return type.Apply(LuaUnderlyingDeserializeVisitor.Ins, bufName); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Lua/TemplateExtensions/LuaCommonTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | using Luban.Lua.TypVisitors; 3 | using Luban.Types; 4 | using Luban.Utils; 5 | using Scriban.Runtime; 6 | 7 | namespace Luban.Lua.TemplateExtensions; 8 | 9 | public class LuaCommonTemplateExtension : ScriptObject 10 | { 11 | public static string CommentType(TType type) 12 | { 13 | return type.Apply(LuaCommentTypeVisitor.Ins); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.MsgPack/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.MsgPack/Luban.MsgPack.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | disable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/Luban.MsgPack/MsgPackDataTarget.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using Luban.DataTarget; 3 | using Luban.Defs; 4 | using Luban.Utils; 5 | using MessagePack; 6 | 7 | namespace Luban.MsgPack; 8 | 9 | [DataTarget("msgpack")] 10 | public class MsgPackDataTarget : DataTargetBase 11 | { 12 | protected override string DefaultOutputFileExt => "bytes"; 13 | 14 | 15 | public void WriteList(DefTable table, List records, ref MessagePackWriter writer) 16 | { 17 | writer.WriteArrayHeader(records.Count); 18 | foreach (var record in records) 19 | { 20 | MsgPackDataVisitor.Ins.Accept(record.Data, ref writer); 21 | } 22 | } 23 | 24 | public override OutputFile ExportTable(DefTable table, List records) 25 | { 26 | var ms = new System.Buffers.ArrayBufferWriter(); 27 | var writer = new MessagePackWriter(ms); 28 | WriteList(table, records, ref writer); 29 | writer.Flush(); 30 | return CreateOutputFile($"{table.OutputDataFile}.{OutputFileExt}", ms.WrittenSpan.ToArray()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Luban.PHP/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.PHP/CodeTarget/PHPJsonCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.PHP.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.PHP.CodeTarget; 6 | 7 | [CodeTarget("php-json")] 8 | public class PHPJsonCodeTarget : PHPCodeTargetBase 9 | { 10 | protected override void OnCreateTemplateContext(TemplateContext ctx) 11 | { 12 | base.OnCreateTemplateContext(ctx); 13 | ctx.PushGlobal(new PHPJsonTemplateExtension()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.PHP/TemplateExtensions/PHPCommonTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeFormat; 2 | using Luban.Defs; 3 | using Luban.Types; 4 | using Luban.Utils; 5 | using Scriban.Runtime; 6 | 7 | namespace Luban.PHP.TemplateExtensions; 8 | 9 | public class PHPCommonTemplateExtension : ScriptObject 10 | { 11 | public static string FullName(DefTypeBase type) 12 | { 13 | return TypeUtil.MakePyFullName(type.Namespace, type.Name); 14 | } 15 | 16 | public static string ClassModifier(DefBean bean) 17 | { 18 | return bean.IsAbstractType ? "abstract" : ""; 19 | } 20 | 21 | public static string NamespaceWithGraceBegin(string ns) 22 | { 23 | if (string.IsNullOrEmpty(ns)) 24 | { 25 | return ""; 26 | } 27 | return string.Join("", ns.Split('.').Select(n => $"namespace {n} {{")); 28 | } 29 | 30 | public static string NamespaceWithGraceEnd(string ns) 31 | { 32 | if (string.IsNullOrEmpty(ns)) 33 | { 34 | return ""; 35 | } 36 | return string.Join("", ns.Split('.').Select(n => $"}}")); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Luban.PHP/TemplateExtensions/PHPJsonTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.PHP.TypeVisitors; 2 | using Luban.Types; 3 | using Scriban.Runtime; 4 | 5 | namespace Luban.PHP.TemplateExtensions; 6 | 7 | public class PHPJsonTemplateExtension : ScriptObject 8 | { 9 | public static string Deserialize(string fieldName, string jsonVar, TType type) 10 | { 11 | return type.Apply(JsonDeserializeVisitor.Ins, jsonVar, fieldName, 0); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Luban.PHP/Templates/common/php/enum.sbn: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /src/Luban.PHP/TypeVisitors/JsonDeserializeVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.PHP.TypeVisitors; 5 | 6 | public class JsonDeserializeVisitor : DecoratorFuncVisitor 7 | { 8 | public static JsonDeserializeVisitor Ins { get; } = new(); 9 | 10 | public override string DoAccept(TType type, string jsonFieldName, string fieldName, int depth) 11 | { 12 | if (type.IsNullable) 13 | { 14 | return $"if({jsonFieldName} != null) {{ {type.Apply(JsonUnderlyingDeserializeVisitor.Ins, jsonFieldName, fieldName, depth)}; }} else {{ {fieldName} = null; }}"; 15 | } 16 | else 17 | { 18 | return type.Apply(JsonUnderlyingDeserializeVisitor.Ins, jsonFieldName, fieldName, depth); 19 | } 20 | } 21 | 22 | //public override string Accept(TBean type, string bytebufName, string fieldName) 23 | //{ 24 | // return type.Apply(TypescriptJsonUnderingConstructorVisitor.Ins, bytebufName, fieldName); 25 | //} 26 | } 27 | -------------------------------------------------------------------------------- /src/Luban.Protobuf/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.Protobuf/CodeTarget/CSharpProtobuf2CodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Protobuf.TemplateExtensions; 3 | using Luban.Utils; 4 | using Scriban; 5 | 6 | namespace Luban.Protobuf.CodeTarget; 7 | 8 | [CodeTarget("cs-protobuf2")] 9 | public class CSharpProtobuf2CodeTarget : CSharpProtobufCodeTargetBase 10 | { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/Luban.Protobuf/CodeTarget/CSharpProtobuf3CodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Protobuf.TemplateExtensions; 3 | using Luban.Utils; 4 | using Scriban; 5 | 6 | namespace Luban.Protobuf.CodeTarget; 7 | 8 | [CodeTarget("cs-protobuf3")] 9 | public class CSharpProtobuf3CodeTarget : CSharpProtobufCodeTargetBase 10 | { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/Luban.Protobuf/CodeTarget/Protobuf2SchemaTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Protobuf.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.Protobuf.CodeTarget; 6 | 7 | [CodeTarget("protobuf2")] 8 | public class Protobuf2SchemaTarget : ProtobufSchemaTargetBase 9 | { 10 | protected override string Syntax => "proto2"; 11 | 12 | protected override void OnCreateTemplateContext(TemplateContext ctx) 13 | { 14 | ctx.PushGlobal(new Protobuf2TemplateExtension()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Luban.Protobuf/CodeTarget/Protobuf3SchemaTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Protobuf.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.Protobuf.CodeTarget; 6 | 7 | [CodeTarget("protobuf3")] 8 | public class Protobuf3SchemaTarget : ProtobufSchemaTargetBase 9 | { 10 | protected override string Syntax => "proto3"; 11 | 12 | protected override void OnCreateTemplateContext(TemplateContext ctx) 13 | { 14 | ctx.PushGlobal(new Protobuf3TemplateExtension()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/Luban.Protobuf/DataTarget/Protobuf2BinDataTarget.cs: -------------------------------------------------------------------------------- 1 | using Google.Protobuf; 2 | using Luban.DataTarget; 3 | using Luban.Defs; 4 | using Luban.Protobuf.DataVisitors; 5 | using Luban.Utils; 6 | 7 | namespace Luban.Protobuf.DataTarget; 8 | 9 | [DataTarget("protobuf2-bin")] 10 | public class Protobuf2BinDataTarget : DataTargetBase 11 | { 12 | protected override string DefaultOutputFileExt => "bytes"; 13 | 14 | public void WriteList(DefTable table, List datas, MemoryStream x) 15 | { 16 | var cos = new CodedOutputStream(x); 17 | foreach (var d in datas) 18 | { 19 | cos.WriteTag(1, WireFormat.WireType.LengthDelimited); 20 | d.Data.Apply(ProtobufBinDataVisitor.Ins, cos); 21 | } 22 | cos.Flush(); 23 | } 24 | 25 | public override OutputFile ExportTable(DefTable table, List records) 26 | { 27 | var ss = new MemoryStream(); 28 | WriteList(table, records, ss); 29 | ss.Flush(); 30 | return CreateOutputFile($"{table.OutputDataFile}.{OutputFileExt}", DataUtil.StreamToBytes(ss)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Luban.Protobuf/DataTarget/Protobuf3BinDataTarget.cs: -------------------------------------------------------------------------------- 1 | using Google.Protobuf; 2 | using Luban.DataTarget; 3 | using Luban.Defs; 4 | using Luban.Protobuf.DataVisitors; 5 | using Luban.Utils; 6 | 7 | namespace Luban.Protobuf.DataTarget; 8 | 9 | [DataTarget("protobuf3-bin")] 10 | public class Protobuf3BinDataTarget : Protobuf2BinDataTarget 11 | { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/Luban.Protobuf/DataTarget/Protobuf3JsonDataTarget.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json; 2 | using Luban.DataExporter.Builtin.Json; 3 | using Luban.DataTarget; 4 | using Luban.Defs; 5 | using Luban.Protobuf.DataVisitors; 6 | using Luban.Utils; 7 | 8 | namespace Luban.Protobuf.DataTarget; 9 | 10 | [DataTarget("protobuf3-json")] 11 | public class Protobuf3JsonDataTarget : Protobuf2JsonDataTarget 12 | { 13 | protected override JsonDataVisitor ImplJsonDataVisitor => Protobuf3JsonDataVisitor.Ins; 14 | } 15 | -------------------------------------------------------------------------------- /src/Luban.Protobuf/DataVisitors/Protobuf3JsonDataVisitor.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json; 2 | using Luban.DataExporter.Builtin.Json; 3 | using Luban.Datas; 4 | using Luban.Defs; 5 | using Luban.Protobuf.TypeVisitors; 6 | using Luban.Types; 7 | using Luban.Utils; 8 | 9 | namespace Luban.Protobuf.DataVisitors; 10 | 11 | public class Protobuf3JsonDataVisitor : Protobuf2JsonDataVisitor 12 | { 13 | public static new Protobuf3JsonDataVisitor Ins { get; } = new(); 14 | } 15 | -------------------------------------------------------------------------------- /src/Luban.Protobuf/Luban.Protobuf.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | disable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | Always 21 | 22 | 23 | Always 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/Luban.Protobuf/TemplateExtensions/CsharpProtobufTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Scriban.Runtime; 2 | namespace Luban.Protobuf.TemplateExtensions; 3 | 4 | public class CsharpProtobufTemplateExtension : ScriptObject 5 | { 6 | 7 | public static string NamespaceWithGraceBegin(string ns) 8 | { 9 | if (string.IsNullOrEmpty(ns)) 10 | { 11 | return string.Empty; 12 | } 13 | ns = ns.Substring(0, 1).ToUpper() + ns.Substring(1); 14 | 15 | return $"namespace {ns}\n{{"; 16 | } 17 | 18 | public static string NamespaceWithGraceEnd(string ns) 19 | { 20 | if (string.IsNullOrEmpty(ns)) 21 | { 22 | return string.Empty; 23 | } 24 | return "}"; 25 | } 26 | 27 | public static string ProtoFullName(string typeName) 28 | { 29 | var name = string.Join("", typeName.Split('.')); 30 | 31 | return name.Substring(0, 1).ToUpper() + name.Substring(1); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Luban.Protobuf/TemplateExtensions/Protobuf2TemplateExtension.cs: -------------------------------------------------------------------------------- 1 | 2 | using Luban.CodeFormat; 3 | using Luban.Defs; 4 | using Luban.Protobuf.TypeVisitors; 5 | using Luban.Types; 6 | using Luban.Utils; 7 | using Scriban.Runtime; 8 | 9 | namespace Luban.Protobuf.TemplateExtensions; 10 | 11 | public class Protobuf2TemplateExtension : ScriptObject 12 | { 13 | public static string PreDecorator(TType type) 14 | { 15 | if (type.IsNullable) 16 | { 17 | return "optional"; 18 | } 19 | else if (type.IsCollection) 20 | { 21 | if (type is TMap) 22 | { 23 | return ""; 24 | } 25 | else 26 | { 27 | return "repeated"; 28 | } 29 | } 30 | else 31 | { 32 | return "required"; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Luban.Protobuf/TemplateExtensions/Protobuf3TemplateExtension.cs: -------------------------------------------------------------------------------- 1 | 2 | using Luban.CodeFormat; 3 | using Luban.Defs; 4 | using Luban.Protobuf.TypeVisitors; 5 | using Luban.Types; 6 | using Luban.Utils; 7 | using Scriban.Runtime; 8 | 9 | namespace Luban.Protobuf.TemplateExtensions; 10 | 11 | public class Protobuf3TemplateExtension : ScriptObject 12 | { 13 | public static string PreDecorator(TType type) 14 | { 15 | if (type.IsNullable) 16 | { 17 | return "optional"; 18 | } 19 | else if (type.IsCollection) 20 | { 21 | if (type is TMap) 22 | { 23 | return ""; 24 | } 25 | else 26 | { 27 | return "repeated"; 28 | } 29 | } 30 | else 31 | { 32 | return ""; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Luban.Protobuf/TemplateExtensions/ProtobufCommonTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | 2 | using Luban.CodeFormat; 3 | using Luban.Defs; 4 | using Luban.Protobuf.DataTarget; 5 | using Luban.Protobuf.TypeVisitors; 6 | using Luban.Types; 7 | using Luban.Utils; 8 | using Scriban.Runtime; 9 | 10 | namespace Luban.Protobuf.TemplateExtensions; 11 | 12 | public class ProtobufCommonTemplateExtension : ScriptObject 13 | { 14 | 15 | public static string FullName(DefTypeBase type) 16 | { 17 | return TypeUtil.MakePbFullName(type.Namespace, type.Name); 18 | } 19 | 20 | public static string DeclaringTypeName(TType type) 21 | { 22 | return type.Apply(ProtobufTypeNameVisitor.Ins); 23 | } 24 | 25 | public static string SuffixOptions(TType type) 26 | { 27 | if (type.IsCollection && !(type is TMap)) 28 | { 29 | return $"[packed = {(type.ElementType.Apply(IsProtobufPackedType.Ins) ? "true" : "false")}]"; 30 | } 31 | else 32 | { 33 | return ""; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/Luban.Protobuf/Templates/cs_pb/tables.sbn: -------------------------------------------------------------------------------- 1 | using Google.Protobuf; 2 | using Google.Protobuf.Collections; 3 | using System.Reflection; 4 | 5 | {{namespace_with_grace_begin __namespace}} 6 | public partial class {{__name}} 7 | { 8 | {{~for table in __tables ~}} 9 | {{~if table.comment != '' ~}} 10 | /// 11 | /// {{escape_comment table.comment}} 12 | /// 13 | {{~end~}} 14 | public {{proto_full_name table.full_name}} {{format_property_name __code_style table.name}} { get; } 15 | 16 | {{~end~}} 17 | 18 | public {{__name}}(System.Func loader) 19 | { 20 | {{~for table in __tables ~}} 21 | {{format_property_name __code_style table.name}} = {{proto_full_name table.full_name}}.Parser.ParseFrom(loader("{{table.output_data_file}}")); 22 | {{~end~}} 23 | } 24 | public {{__name}}(System.Func loader) 25 | { 26 | {{~for table in __tables ~}} 27 | {{format_property_name __code_style table.name}} = {{proto_full_name table.full_name}}.Parser.ParseJson(loader("{{table.output_data_file}}")); 28 | {{~end~}} 29 | } 30 | } 31 | 32 | {{namespace_with_grace_end __namespace}} 33 | -------------------------------------------------------------------------------- /src/Luban.Protobuf/Templates/pb/schema.sbn: -------------------------------------------------------------------------------- 1 | syntax = "{{__syntax}}"; 2 | 3 | package {{__namespace}}; 4 | 5 | {{~for enum in __enums 6 | typeName = full_name enum 7 | ~}} 8 | enum {{typeName}} { 9 | {{~if !enum.has_zero_value_item ~}} 10 | {{typeName}}_EMPTY_PLACEHOLDER = 0; 11 | {{~end~}} 12 | {{~for item in enum.items ~}} 13 | {{typeName}}_{{item.name}} = {{item.int_value}}; 14 | {{~end~}} 15 | } 16 | {{~end~}} 17 | 18 | {{~for bean in __beans 19 | typeName = full_name bean 20 | ~}} 21 | message {{typeName}} { 22 | {{~if bean.is_abstract_type ~}} 23 | oneof value { 24 | {{~for c in bean.hierarchy_not_abstract_children~}} 25 | {{full_name c}} {{c.name}} = {{c.auto_id}}; 26 | {{~end~}} 27 | } 28 | {{~else~}} 29 | {{~for f in bean.hierarchy_export_fields ~}} 30 | {{pre_decorator f.ctype}} {{declaring_type_name f.ctype}} {{f.name}} = {{f.auto_id}} {{suffix_options f.ctype}}; 31 | {{~end~}} 32 | {{~end~}} 33 | } 34 | {{~end~}} 35 | 36 | {{~for table in __tables~}} 37 | message {{full_name table}} { 38 | repeated {{declaring_type_name table.value_ttype}} data_list = 1 [packed = false]; 39 | } 40 | {{~end~}} 41 | 42 | -------------------------------------------------------------------------------- /src/Luban.Protobuf/TypeVisitors/IsProtobufPackedType.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.Protobuf.TypeVisitors; 5 | 6 | public class IsProtobufPackedType : AllTrueVisitor 7 | { 8 | public static IsProtobufPackedType Ins { get; } = new(); 9 | 10 | 11 | public override bool Accept(TString type) 12 | { 13 | return false; 14 | } 15 | 16 | public override bool Accept(TEnum type) 17 | { 18 | return false; 19 | } 20 | 21 | public override bool Accept(TBean type) 22 | { 23 | return false; 24 | } 25 | 26 | public override bool Accept(TArray type) 27 | { 28 | return false; 29 | } 30 | 31 | public override bool Accept(TList type) 32 | { 33 | return false; 34 | } 35 | 36 | public override bool Accept(TSet type) 37 | { 38 | return false; 39 | } 40 | 41 | public override bool Accept(TMap type) 42 | { 43 | return false; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Luban.Python/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.Python/CodeTarget/Python2JsonCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Defs; 3 | using Scriban; 4 | 5 | namespace Luban.Python.CodeTarget; 6 | 7 | [CodeTarget("python-json")] 8 | public class Python2JsonCodeTarget : PythonCodeTargetBase 9 | { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/Luban.Python/Luban.Python.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | disable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | PreserveNewest 21 | 22 | 23 | Always 24 | 25 | 26 | Always 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/Luban.Python/TypeVisitors/DeclaringTypeNameVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | using Luban.Utils; 4 | 5 | namespace Luban.Python.TypeVisitors; 6 | 7 | public class DeclaringTypeNameVisitor : DecoratorFuncVisitor 8 | { 9 | public static DeclaringTypeNameVisitor Ins { get; } = new(); 10 | 11 | public override string DoAccept(TType type) 12 | { 13 | throw new System.NotSupportedException(); 14 | } 15 | 16 | public override string Accept(TEnum type) 17 | { 18 | return type.DefEnum.FullName.Replace('.', '_'); 19 | } 20 | 21 | public override string Accept(TBean type) 22 | { 23 | return type.DefBean.FullName.Replace('.', '_'); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Luban.Rust/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.Rust/CodeTarget/RustBinCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.CSharp.TemplateExtensions; 3 | using Luban.Rust.CodeTarget; 4 | using Scriban; 5 | 6 | namespace Luban.CSharp.CodeTarget; 7 | 8 | [CodeTarget("rust-bin")] 9 | public class RustBinCodeTarget : RustCodeTargetBase 10 | { 11 | protected override void OnCreateTemplateContext(TemplateContext ctx) 12 | { 13 | base.OnCreateTemplateContext(ctx); 14 | ctx.PushGlobal(new RustBinTemplateExtension()); 15 | } 16 | } -------------------------------------------------------------------------------- /src/Luban.Rust/CodeTarget/RustJsonCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Rust.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.Rust.CodeTarget; 6 | 7 | [CodeTarget("rust-json")] 8 | public class RustJsonCodeTarget : RustCodeTargetBase 9 | { 10 | protected override void OnCreateTemplateContext(TemplateContext ctx) 11 | { 12 | base.OnCreateTemplateContext(ctx); 13 | ctx.PushGlobal(new RustJsonTemplateExtension()); 14 | } 15 | } -------------------------------------------------------------------------------- /src/Luban.Rust/ConstantStrings.cs: -------------------------------------------------------------------------------- 1 | namespace Luban.Rust; 2 | 3 | public static class ConstantStrings 4 | { 5 | public const string ArrayType = "Vec"; 6 | public const string ListType = "Vec"; 7 | public const string SetType = "std::collections::HashSet"; 8 | public const string MapType = "std::collections::HashMap"; 9 | } -------------------------------------------------------------------------------- /src/Luban.Rust/TemplateExtensions/RustCommonTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.Defs; 2 | using Luban.Rust.TypeVisitors; 3 | using Luban.Types; 4 | using Luban.Utils; 5 | using Scriban.Runtime; 6 | 7 | namespace Luban.Rust.TemplateExtensions; 8 | 9 | public class RustCommonTemplateExtension : ScriptObject 10 | { 11 | public static string DeclaringTypeName(TType type) 12 | { 13 | return type?.Apply(RustDeclaringBoxTypeNameVisitor.Ins) ?? string.Empty; 14 | } 15 | 16 | public static string GetterName(string name) 17 | { 18 | return "get_" + name; 19 | } 20 | 21 | public static string FullName(DefTypeBase type) 22 | { 23 | return $"crate::{type.FullName.Replace(".", "::")}"; 24 | } 25 | 26 | public static string BaseTraitName(DefBean bean) 27 | { 28 | if (!bean.IsAbstractType) return string.Empty; 29 | 30 | var name = $"crate::{bean.FullName.Replace(".", "::")}"; 31 | return name.Insert(name.Length - bean.Name.Length, "T"); 32 | 33 | } 34 | } -------------------------------------------------------------------------------- /src/Luban.Rust/Templates/common/rs/macros/Cargo.toml.sbn: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "macros" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | quote = "1.0.36" 10 | syn = "2.0.60" 11 | proc-macro2 = "1.0.82" 12 | 13 | [lib] 14 | proc-macro = true -------------------------------------------------------------------------------- /src/Luban.Rust/Templates/rust-bin/toml.sbn: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "{{__name}}" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | bitflags = { version = "2.5.x" , features = ["serde"] } 10 | macros = { path = "../macros" } 11 | luban_lib = { path = "../../luban_lib" } -------------------------------------------------------------------------------- /src/Luban.Rust/Templates/rust-json/toml.sbn: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "{{__name}}" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | serde = { version = "1.0.x", features = ["derive"] } 10 | serde_json = "1.0.x" 11 | bitflags = { version = "2.5.x" , features = ["serde"]} 12 | macros = {path = "../macros"} -------------------------------------------------------------------------------- /src/Luban.Rust/TypeVisitors/RustDeclaringBoxTypeNameVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.Rust.TypeVisitors; 5 | 6 | public class RustDeclaringBoxTypeNameVisitor : DecoratorFuncVisitor 7 | { 8 | public static readonly RustDeclaringBoxTypeNameVisitor Ins = new(); 9 | 10 | public override string DoAccept(TType type) 11 | { 12 | var origin = type.Apply(RustDeclaringTypeNameVisitor.Ins); 13 | return type.IsNullable ? $"Option<{origin}>" : origin; 14 | } 15 | } -------------------------------------------------------------------------------- /src/Luban.Schema.Builtin/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.Schema.Builtin/AutoTableImporter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Luban.Schema.Builtin; 8 | 9 | public class AutoTableImporter 10 | { 11 | } 12 | -------------------------------------------------------------------------------- /src/Luban.Typescript/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | 2 | 3 | using Luban; 4 | 5 | [assembly: RegisterBehaviour] 6 | -------------------------------------------------------------------------------- /src/Luban.Typescript/CodeTarget/TypescriptBinCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Typescript.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.Typescript.CodeTarget; 6 | 7 | [CodeTarget("typescript-bin")] 8 | public class TypescriptBinCodeTarget : TypescriptCodeTargetBase 9 | { 10 | protected override void OnCreateTemplateContext(TemplateContext ctx) 11 | { 12 | base.OnCreateTemplateContext(ctx); 13 | ctx.PushGlobal(new TypescriptBinTemplateExtension()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Typescript/CodeTarget/TypescriptJsonCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Typescript.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.Typescript.CodeTarget; 6 | 7 | [CodeTarget("typescript-json")] 8 | public class TypescriptJsonCodeTarget : TypescriptCodeTargetBase 9 | { 10 | protected override void OnCreateTemplateContext(TemplateContext ctx) 11 | { 12 | base.OnCreateTemplateContext(ctx); 13 | ctx.PushGlobal(new TypescriptJsonTemplateExtension()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Typescript/CodeTarget/TypescriptProtobufCodeTarget.cs: -------------------------------------------------------------------------------- 1 | using Luban.CodeTarget; 2 | using Luban.Typescript.TemplateExtensions; 3 | using Scriban; 4 | 5 | namespace Luban.Typescript.CodeTarget; 6 | 7 | [CodeTarget("typescript-protobuf")] 8 | public class TypescriptProtobufCodeTarget : TypescriptCodeTargetBase 9 | { 10 | protected override void OnCreateTemplateContext(TemplateContext ctx) 11 | { 12 | base.OnCreateTemplateContext(ctx); 13 | ctx.PushGlobal(new TypescriptBinTemplateExtension()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Luban.Typescript/TemplateExtensions/TypescriptBinTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Scriban.Runtime; 3 | 4 | namespace Luban.Typescript.TemplateExtensions; 5 | 6 | public class TypescriptBinTemplateExtension : ScriptObject 7 | { 8 | public static string Deserialize(string fieldName, string bufName, TType type) 9 | { 10 | return type.Apply(BinDeserializeVisitor.Ins, bufName, fieldName); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/Luban.Typescript/TemplateExtensions/TypescriptJsonTemplateExtension.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.Typescript.TypeVisitors; 3 | using Scriban.Runtime; 4 | 5 | namespace Luban.Typescript.TemplateExtensions; 6 | 7 | public class TypescriptJsonTemplateExtension : ScriptObject 8 | { 9 | public static string Deserialize(string fieldName, string jsonVar, TType type) 10 | { 11 | return type.Apply(JsonDeserializeVisitor.Ins, jsonVar, fieldName, 0); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/Luban.Typescript/Templates/common/ts/enum.sbn: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /src/Luban.Typescript/Templates/typescript-protobuf/schema.sbn: -------------------------------------------------------------------------------- 1 | import pb from 'pb'; 2 | 3 | type BufLoader = (file: string) => Uint8Array; 4 | 5 | export class {{__name}} { 6 | {{~ for table in __tables ~}} 7 | private _{{table.name}}: pb.cfg.{{table.name}} 8 | {{~if table.comment != '' ~}} 9 | /** 10 | * {{escape_comment table.comment}} 11 | */ 12 | {{~end~}} 13 | get {{table.name}}(): pb.cfg.{{table.name}} { return this._{{table.name}};} 14 | {{~end~}} 15 | 16 | static getTableNames(): string[] { 17 | let names: string[] = []; 18 | {{~for table in __tables ~}} 19 | names.push('{{table.output_data_file}}'); 20 | {{~end~}} 21 | return names; 22 | } 23 | 24 | constructor(loader: BufLoader) { 25 | let buffer: Uint8Array; 26 | {{~for table in __tables ~}} 27 | buffer = loader('{{table.output_data_file}}'); 28 | this._{{table.name}} = pb.cfg.{{table.name}}.decode(buffer, buffer.length); 29 | {{~end~}} 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Luban.Typescript/TypeVisitors/BinDeserializeVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.Typescript.TypeVisitors; 3 | using Luban.TypeVisitors; 4 | 5 | namespace Luban.Typescript.TemplateExtensions; 6 | 7 | class BinDeserializeVisitor : DecoratorFuncVisitor 8 | { 9 | public static BinDeserializeVisitor Ins { get; } = new BinDeserializeVisitor(); 10 | 11 | public override string DoAccept(TType type, string byteBufName, string fieldName) 12 | { 13 | if (type.IsNullable) 14 | { 15 | return $"if({byteBufName}.ReadBool()) {{ {type.Apply(BinUnderingDeserializeVisitor.Ins, byteBufName, fieldName, 0)} }} else {{ {fieldName} = null; }}"; 16 | } 17 | else 18 | { 19 | return type.Apply(BinUnderingDeserializeVisitor.Ins, byteBufName, fieldName, 0); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Luban.Typescript/TypeVisitors/BinUnderingDeserializeVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | 3 | namespace Luban.Typescript.TypeVisitors; 4 | 5 | public class BinUnderingDeserializeVisitor : BinUnderingDeserializeVisitorBase 6 | { 7 | public static BinUnderingDeserializeVisitor Ins { get; } = new BinUnderingDeserializeVisitor(); 8 | 9 | public override string Accept(TBean type, string bufVarName, string fieldName, int depth) 10 | { 11 | if (type.DefBean.IsAbstractType) 12 | { 13 | return $"{fieldName} = {type.DefBean.FullName}.constructorFrom({bufVarName})"; 14 | } 15 | else 16 | { 17 | return $"{fieldName} = new {type.DefBean.FullName}({bufVarName})"; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Luban.Typescript/TypeVisitors/DeclaringTypeNameVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.Typescript.TypeVisitors; 5 | 6 | public class DeclaringTypeNameVisitor : DecoratorFuncVisitor 7 | { 8 | public static DeclaringTypeNameVisitor Ins { get; } = new DeclaringTypeNameVisitor(); 9 | 10 | public override string DoAccept(TType type) 11 | { 12 | return type.IsNullable ? $"{type.Apply(UnderlyingDeclaringTypeNameVisitor.Ins)}|undefined" : type.Apply(UnderlyingDeclaringTypeNameVisitor.Ins); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/Luban.Typescript/TypeVisitors/JsonDeserializeVisitor.cs: -------------------------------------------------------------------------------- 1 | using Luban.Types; 2 | using Luban.TypeVisitors; 3 | 4 | namespace Luban.Typescript.TypeVisitors; 5 | 6 | public class JsonDeserializeVisitor : DecoratorFuncVisitor 7 | { 8 | public static JsonDeserializeVisitor Ins { get; } = new(); 9 | 10 | public override string DoAccept(TType type, string jsonFieldName, string fieldName, int depth) 11 | { 12 | if (type.IsNullable) 13 | { 14 | return $"if({jsonFieldName} != undefined) {{ {type.Apply(JsonUnderlyingDeserializeVisitor.Ins, jsonFieldName, fieldName, depth)} }} else {{ {fieldName} = undefined }}"; 15 | } 16 | else 17 | { 18 | return type.Apply(JsonUnderlyingDeserializeVisitor.Ins, jsonFieldName, fieldName, depth); 19 | } 20 | } 21 | 22 | //public override string Accept(TBean type, string bytebufName, string fieldName) 23 | //{ 24 | // return type.Apply(TypescriptJsonUnderingConstructorVisitor.Ins, bytebufName, fieldName); 25 | //} 26 | } 27 | -------------------------------------------------------------------------------- /src/Luban.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | False -------------------------------------------------------------------------------- /src/Luban/nlog.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 13 | 14 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /src/nuget.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | --------------------------------------------------------------------------------