【修复】修复当意外使用bean或容器等不能作为index类型的字段为table的index时,打印的错误日志没有报告正确的错误的信息的问题。在DefTable Compile时检查并且给出清晰的错误信息。

main
walon 2022-02-10 12:47:15 +08:00
parent 0b63b1fcb3
commit 45f4a13dd2
4 changed files with 23 additions and 48 deletions

View File

@ -80,7 +80,7 @@ luban统一了游戏配置开发工作流极大提升了策划和程序的工
<tr align="center"> <tr align="center">
<td>##type</td> <td>##type</td>
<td>int</id> <td>int</id>
<td>array,int</td> <td>(array#sep=;),int</td>
<td colspan="4">list,int</td> <td colspan="4">list,int</td>
<td>(list#sep=|),string</td> <td>(list#sep=|),string</td>
<td colspan="3">list,string</td> <td colspan="3">list,string</td>
@ -97,7 +97,7 @@ luban统一了游戏配置开发工作流极大提升了策划和程序的工
<tr align="center"> <tr align="center">
<td/> <td/>
<td>1</td> <td>1</td>
<td>1,2,3</td> <td>1;2;3</td>
<td>1</td><td>2</td><td></td><td></td> <td>1</td><td>2</td><td></td><td></td>
<td>xx|yy</td> <td>xx|yy</td>
<td>xxx</td><td>zzz</td><td></td> <td>xxx</td><td>zzz</td><td></td>
@ -115,7 +115,7 @@ luban统一了游戏配置开发工作流极大提升了策划和程序的工
<tr align="center"> <tr align="center">
<td/> <td/>
<td>3</td> <td>3</td>
<td>2|4|6</td> <td>2;4;6</td>
<td>3</td><td>4</td><td>5</td><td>6</td> <td>3</td><td>4</td><td>5</td><td>6</td>
<td>aaaa|bbbb|cccc</td> <td>aaaa|bbbb|cccc</td>
<td>aaa</td><td>bbb</td><td>ccc</td> <td>aaa</td><td>bbb</td><td>ccc</td>
@ -372,7 +372,7 @@ Reward为包含 "int item_id; int count; string desc; " 这三个字段的子结
<table border="1"> <table border="1">
<tr align="center"> <tr align="center">
<td>##var&column</td> <td>##var#column</td>
<td>##type</td> <td>##type</td>
<td>##</td> <td>##</td>
<td></td> <td></td>

View File

@ -1,5 +1,6 @@
using Bright.Collections; using Bright.Collections;
using Luban.Job.Cfg.RawDefs; using Luban.Job.Cfg.RawDefs;
using Luban.Job.Cfg.TypeVisitors;
using Luban.Job.Common.Types; using Luban.Job.Common.Types;
using Luban.Job.Common.Utils; using Luban.Job.Common.Utils;
using System; using System;
@ -130,6 +131,7 @@ namespace Luban.Job.Cfg.Defs
} }
KeyTType = IndexField.CType; KeyTType = IndexField.CType;
Type = TMap.Create(false, null, KeyTType, ValueTType, false); Type = TMap.Create(false, null, KeyTType, ValueTType, false);
this.IndexList.Add(new IndexInfo(KeyTType, IndexField, IndexFieldIdIndex));
break; break;
} }
case ETableMode.LIST: case ETableMode.LIST:
@ -154,6 +156,20 @@ namespace Luban.Job.Cfg.Defs
} }
default: throw new Exception($"unknown mode:'{Mode}'"); default: throw new Exception($"unknown mode:'{Mode}'");
} }
foreach(var index in IndexList)
{
TType indexType = index.Type;
string idxName = index.IndexField.Name;
if (indexType.IsNullable)
{
throw new Exception($"table:'{FullName}' index:'{idxName}' 不能为 nullable类型");
}
if (!indexType.Apply(IsValidTableKeyTypeVisitor.Ins))
{
throw new Exception($"table:'{FullName}' index:'{idxName}' 的类型:'{index.IndexField.Type}' 不能作为index");
}
}
} }
} }
} }

View File

@ -1,41 +0,0 @@
using Luban.Job.Common.Types;
using Luban.Job.Common.TypeVisitors;
namespace Luban.Job.Cfg.TypeVisitors
{
class IsMultiData : AllFalseVisitor
{
public static IsMultiData Ins { get; } = new IsMultiData();
public override bool Accept(TBytes type)
{
return true;
}
public override bool Accept(TBean type)
{
return true;
}
public override bool Accept(TArray type)
{
return true;
}
public override bool Accept(TList type)
{
return true;
}
public override bool Accept(TSet type)
{
return true;
}
public override bool Accept(TMap type)
{
return true;
}
}
}

View File

@ -3,11 +3,11 @@ using Luban.Job.Common.TypeVisitors;
namespace Luban.Job.Cfg.TypeVisitors namespace Luban.Job.Cfg.TypeVisitors
{ {
class IsNotSepTypeVisitor : AllTrueVisitor class IsValidTableKeyTypeVisitor : AllTrueVisitor
{ {
//public static IsNotSepTypeVisitor Ins { get; } = new IsNotSepTypeVisitor(); public static IsValidTableKeyTypeVisitor Ins { get; } = new();
public override bool Accept(TString type) public override bool Accept(TText type)
{ {
return false; return false;
} }