[new] 增加java对容器ref的支持 (#34)

[new] 增加java对容器ref的支持
main
Carson - 宝鱼 2022-12-14 09:56:04 +08:00 committed by GitHub
parent d0587324f5
commit ba2c5c56e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 12 deletions

View File

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

View File

@ -128,8 +128,11 @@ namespace Luban.Job.Cfg.Utils
{
var refVarName = field.RefVarName;
var name = field.ConventionName;
if (field.Ref != null)
{
var tableName = field.Ref.FirstTable;
var table = field.Assembly.GetCfgTable(field.Ref.FirstTable);
var table = field.Assembly.GetCfgTable(tableName);
if (field.IsNullable)
{
return $"this.{refVarName} = this.{name} != null ? (({table.FullNameWithTopModule})_tables.get(\"{tableName}\")).get({name}) : null;";
@ -139,6 +142,29 @@ namespace Luban.Job.Cfg.Utils
return $"this.{refVarName} = (({table.FullNameWithTopModule})_tables.get(\"{tableName}\")).get({name});";
}
}
else
{
var tableName = field.ElementRef.FirstTable;
var table = field.Assembly.GetCfgTable(tableName);
switch (field.CType)
{
case TArray:
{
return $@"{{ int __n = {name}.length; {table.FullNameWithTopModule} __table = ({table.FullNameWithTopModule})_tables.get(""{tableName}""); this.{refVarName} = new {table.ValueTType.Apply(JavaDefineTypeName.Ins)}[__n]; for(int i = 0 ; i < __n ; i++) {{ this.{refVarName}[i] = __table.get({name}[i]); }} }}";
}
case TList:
case TSet:
{
return $@"{{ {table.FullNameWithTopModule} __table = ({table.FullNameWithTopModule})_tables.get(""{tableName}""); this.{refVarName} = new {field.ElementRefType.Apply(JavaDefineTypeName.Ins)}(); for({field.CType.ElementType.TypeName} __e : {name}) {{ this.{refVarName}.add(__table.get(__e)); }} }}";
}
case TMap map:
{
return $@"{{ {table.FullNameWithTopModule} __table = ({table.FullNameWithTopModule})_tables.get(""{tableName}""); this.{refVarName} = new {field.ElementRefType.Apply(JavaDefineTypeName.Ins)}(); for(Map.Entry<{map.KeyType.TypeName},{map.ValueType.TypeName}> __e : {name}.entrySet()) {{ {map.KeyType.TypeName} __eKey = entry.getKey(); {map.ValueType.TypeName} __eValue = entry.getValue(); this.{refVarName}.add(__eKey, __table.get(__eValue)); }} }}";
}
default: throw new NotSupportedException($"type:'{field.CType.TypeName}' not support ref");
}
}
}
public static string CppDeserialize(string bufName, string fieldName, TType type)
{