go_dreamfactory/modules/gourmet/comp_configure.go
2023-03-24 18:28:17 +08:00

123 lines
3.1 KiB
Go

package gourmet
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"sync"
)
const (
game_gourmet = "game_gourmet.json"
game_food = "game_breakingbad.json"
)
///配置管理基础组件
type configureComp struct {
hlock sync.RWMutex
modules.MCompConfigure
_gourmetMap map[int64]*cfg.GameGourmetData
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,
})
this._gourmetMap = make(map[int64]*cfg.GameGourmetData, 0)
configure.RegisterConfigure(game_gourmet, cfg.NewGameGourmet, func() {
if v, err := this.GetConfigure(game_gourmet); err == nil {
if configure, ok := v.(*cfg.GameGourmet); ok {
this.hlock.Lock()
defer this.hlock.Unlock()
for _, value := range configure.GetDataList() {
this._gourmetMap[int64(value.Type<<16)+int64(value.Level)] = value
}
return
}
}
log.Errorf("get game_pagoda conf err:%v", err)
return
})
this.SetGrormetCookBookConf()
return
}
// 获取美食馆配置数据
func (this *configureComp) GetGourmetConfigData(gourmetType int32, level int32) (data *cfg.GameGourmetData) {
return this._gourmetMap[int64(gourmetType<<16)+int64(level)]
}
//加载多个配置文件
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) GetGourmetSkillConfigBySkillType(skillType int32) (data []int32) {
data = make([]int32, 0)
if v, err := this.GetConfigure(game_gourmet); err == nil {
if configure, ok := v.(*cfg.GameGourmet); ok {
this.hlock.Lock()
defer this.hlock.Unlock()
for _, value := range configure.GetDataList() {
if value.SkillType == skillType && value.Initial == 1 {
data = append(data, value.Type)
}
}
return
}
}
return
}
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) {
if v, err := this.GetConfigure(game_food); err == nil {
if conf, ok := v.(*cfg.GameBreakingbad); ok {
return conf.Get(id)
}
}
this.module.Errorf("can't found GameBreakingbadData:%d", id)
return
}
// 获取类型为1 的菜谱
func (this *configureComp) GetNormalGourmetFood() string {
return this.normal
}