This commit is contained in:
aozhiwei 2023-08-12 16:13:47 +08:00
parent 8263b4ded9
commit f753f0cf02

View File

@ -53,7 +53,10 @@ func (this *RawMetaTable[T]) IsNoLoad() bool {
func (this *RawMetaTable[T]) PreInit1() {
}
func (this *RawMetaTable[T]) ElementInit(round int) {
func (this *RawMetaTable[T]) PostInit1() {
}
func (this *RawMetaTable[T]) ElementsInit(round int) {
type RoundInit1 interface {
Init1()
}
@ -122,6 +125,7 @@ func (this *RawMetaTable[T]) Load() {
func (this *IdMetaTable[T]) Load() {
this.RawMetaTable.Load()
this.idHash = make(map[int64]*T)
i := int64(0)
getFuncName := "Get" + q5.ConvertUpperCamelCase(this.PrimKey)
this.Traverse(func (obj *T) bool {
@ -130,7 +134,12 @@ func (this *IdMetaTable[T]) Load() {
} else {
ele := reflect.ValueOf(obj).Elem()
in := []reflect.Value{}
ele.FieldByName(getFuncName).Call(in)
out := ele.FieldByName(getFuncName).Call(in)
if key, err := q5.ToInt64Ex(out[0].Interface()); err == nil {
this.idHash[key] = obj
} else {
panic("IdMetaTable load PrimKey error")
}
}
i++
return true
@ -147,6 +156,21 @@ func (this *NameMetaTable[T]) GetByName(name string) *T {
func (this *NameMetaTable[T]) Load() {
this.RawMetaTable.Load()
this.nameHash = make(map[string]*T)
i := int64(0)
getFuncName := "Get" + q5.ConvertUpperCamelCase(this.PrimKey)
this.Traverse(func (obj *T) bool {
ele := reflect.ValueOf(obj).Elem()
in := []reflect.Value{}
out := ele.FieldByName(getFuncName).Call(in)
if key, err := q5.ToStringEx(out[0].Interface()); err == nil {
this.nameHash[key] = obj
} else {
panic("NameMetaTable load PrimKey error")
}
i++
return true
})
}
func ReadMetaTableField[T string | int | int32 | int64 | float32 | float64](