go_dreamfactory/modules/buried/configure.go
2023-05-29 17:50:51 +08:00

106 lines
2.8 KiB
Go

package buried
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"sync"
)
const (
game_buriedtype = "game_buriedtype.json"
game_buriedcondi = "game_buriedcondi.json"
)
//配置管理组件
type configureComp struct {
modules.MCompConfigure
module *Buried
lock sync.RWMutex
group map[comm.TaskType][]*cfg.GameBuriedCondiData //安排点类型 分组
}
//组件初始化接口
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MCompConfigure.Init(service, module, comp, options)
this.module = module.(*Buried)
this.LoadConfigure(game_buriedcondi, cfg.NewGameBuriedCondi)
configure.RegisterConfigure(game_buriedcondi, cfg.NewGameBuriedCondi, this.updateconfigure)
return
}
//读取埋点配置数据
func (this *configureComp) getburiedtypedata(tt comm.TaskType) (result *cfg.GameBuriedTypeData, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(game_buriedtype); err != nil {
this.module.Errorf("err:%v", err)
return
} else {
if result, ok = v.(*cfg.GameBuriedType).GetDataMap()[int32(tt)]; !ok {
err = comm.NewNotFoundConfErr(moduleName, game_buriedtype, tt)
this.module.Errorf("err:%v", err)
return
}
}
return
}
//读取条件任务id配置
func (this *configureComp) getburiedcondidata(cid int32) (result *cfg.GameBuriedCondiData, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(game_buriedcondi); err != nil {
this.module.Errorf("err:%v", err)
return
} else {
if result, ok = v.(*cfg.GameBuriedCondi).GetDataMap()[cid]; !ok {
err = comm.NewNotFoundConfErr(moduleName, game_buriedtype, cid)
this.module.Errorf("err:%v", err)
return
}
}
return
}
//动态更新配置
func (this *configureComp) updateconfigure() {
if v, err := this.GetConfigure(game_buriedcondi); err != nil {
return
} else {
if data, ok := v.(*cfg.GameBuriedCondi); !ok {
err = fmt.Errorf("%T is *cfg.GameBuriedCondi", v)
return
} else {
group := map[comm.TaskType][]*cfg.GameBuriedCondiData{}
for _, v := range data.GetDataList() {
if _, ok = group[comm.TaskType(v.Type)]; !ok {
group[comm.TaskType(v.Type)] = make([]*cfg.GameBuriedCondiData, 0)
}
group[comm.TaskType(v.Type)] = append(group[comm.TaskType(v.Type)], v)
}
this.lock.Lock()
this.group = group
this.lock.Unlock()
}
}
}
//读取埋点条件配置
func (this *configureComp) getCondiDatas(tt comm.TaskType) (result []*cfg.GameBuriedCondiData) {
result = make([]*cfg.GameBuriedCondiData, 0)
this.lock.RLock()
if _, ok := this.group[tt]; ok {
result = this.group[tt]
}
this.lock.RUnlock()
return
}