1
This commit is contained in:
parent
8263b4ded9
commit
f753f0cf02
28
metatable.go
28
metatable.go
@ -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](
|
||||
|
Loading…
x
Reference in New Issue
Block a user