go_dreamfactory/modules/dragon/configure_comp.go
2023-08-30 19:40:27 +08:00

63 lines
1.4 KiB
Go

package dragon
import (
"go_dreamfactory/modules"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
)
const moduleName = "dragon"
const (
dragon_trainlv = "game_trainlv.json"
)
// /配置管理组件
type configureComp struct {
modules.MCompConfigure
module *Dragon
}
// 组件初始化接口
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
err = this.MCompConfigure.Init(service, module, comp, options)
this.module = module.(*Dragon)
err = this.LoadMultiConfigure(map[string]interface{}{
dragon_trainlv: cfg.NewGameTrainlv,
})
return
}
//加载多个配置文件
func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) {
for k, v := range confs {
err = configure.RegisterConfigure(k, v, nil)
if err != nil {
log.Errorf("配置文件:%s解析失败!", k)
break
}
}
return
}
//读取配置数据
func (this *configureComp) GetConfigure(name string) (v interface{}, err error) {
return configure.GetConfigure(name)
}
func (this *configureComp) GetTrainlvConfById(id int32) (conf *cfg.GameTrainlvData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(dragon_trainlv); err == nil {
if configure, ok := v.(*cfg.GameTrainlv); ok {
conf = configure.Get(id)
}
}
return
}