go_dreamfactory/modules/atlas/comp_configure.go
2023-05-26 16:24:47 +08:00

105 lines
2.8 KiB
Go

package atlas
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 (
pandaJx = "game_pandamasjx.json" // 武馆教习
pandaAtlas = "game_pandamastj.json" // 武馆图鉴
pandaAtlasAward = "game_pandamastjjl.json" // 武馆图鉴奖励
)
// /配置管理基础组件
type configureComp struct {
modules.MCompConfigure
module *PandaAtlas
}
// 组件初始化接口
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.(*PandaAtlas)
err = this.LoadMultiConfigure(map[string]interface{}{
pandaJx: cfg.NewGamePandamasJx,
pandaAtlas: cfg.NewGamePandamasTj,
pandaAtlasAward: cfg.NewGamePandamasTjjl,
})
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) GetPandoJxConf(id string) (conf *cfg.GamePandamasJxData, err error) {
if v, err := this.GetConfigure(pandaJx); err == nil {
if configure, ok := v.(*cfg.GamePandamasJx); ok {
if conf = configure.Get(id); conf == nil {
err = comm.NewNotFoundConfErr("atlas", pandaJx, id)
this.module.Errorln(err)
}
}
}
err = comm.NewNotFoundConfErr("atlas", pandaJx, id)
return
}
// 获取武馆图鉴数据
func (this *configureComp) GetPandoAtlasConf(id string) (conf *cfg.GamePandamasTjData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(pandaAtlas); err == nil {
if configure, ok := v.(*cfg.GamePandamasTj); ok {
if conf = configure.Get(id); nil == conf {
err = comm.NewNotFoundConfErr("atlas", pandaAtlas, id)
this.module.Errorln(err)
}
return
}
}
err = comm.NewNotFoundConfErr("atlas", pandaAtlas, id)
return
}
// 获取图鉴奖励
func (this *configureComp) GetPandoAtlasAwardConf(lv int32) (conf *cfg.GamePandamasTjjlData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(pandaAtlasAward); err == nil {
if configure, ok := v.(*cfg.GamePandamasTjjl); ok {
if conf = configure.Get(lv); nil == conf {
err = comm.NewNotFoundConfErr("atlas", pandaAtlasAward, lv)
this.module.Errorln(err)
}
return
}
}
err = comm.NewNotFoundConfErr("atlas", pandaAtlasAward, lv)
return
}