go_dreamfactory/modules/gourmet/comp_configure.go
2023-05-29 17:23:53 +08:00

91 lines
2.1 KiB
Go

package gourmet
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
)
const (
game_food = "game_breakingbad.json"
)
///配置管理基础组件
type configureComp struct {
modules.MCompConfigure
module *Gourmet
normal string // 普通菜
}
//组件初始化接口
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.(*Gourmet)
err = this.LoadMultiConfigure(map[string]interface{}{
game_food: cfg.NewGameBreakingbad,
})
configure.RegisterConfigure(game_food, cfg.NewGameBreakingbad, this.SetGrormetCookBookConf)
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) SetGrormetCookBookConf() {
if v, err := this.GetConfigure(game_food); err == nil {
if conf, ok := v.(*cfg.GameBreakingbad); ok {
for _, v1 := range conf.GetDataList() {
if v1.Type == -1 {
this.normal = v1.Delicacies
return
}
}
}
}
return
}
func (this *configureComp) GetGrormetCookBookConf(id string) (configure *cfg.GameBreakingbadData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_food); err == nil {
if conf, ok := v.(*cfg.GameBreakingbad); ok {
configure = conf.Get(id)
if configure == nil {
err = comm.NewNotFoundConfErr("gourmet", game_food, id)
}
return
}
}
err = comm.NewNotFoundConfErr("gourmet", game_food, id)
return
}
// 获取类型为1 的菜谱
func (this *configureComp) GetNormalGourmetFood() string {
return this.normal
}