go_dreamfactory/modules/integral/comp_configure.go

100 lines
2.7 KiB
Go

package integral
import (
"fmt"
"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_integralboss = "game_integralboss.json"
game_integralcondition = "game_integralcondition.json"
game_integralreward = "game_integralreward.json"
game_integraltime = "game_integraltime.json"
)
///配置管理基础组件
type configureComp struct {
hlock sync.RWMutex
modules.MCompConfigure
boss map[int32]*cfg.GameIntegralBossData
}
//组件初始化接口
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)
err = this.LoadMultiConfigure(map[string]interface{}{
game_integraltime: cfg.NewGameIntegralTime,
})
configure.RegisterConfigure(game_integralboss, cfg.NewGameIntegralBoss, this.LoadStageBoss)
return
}
func (this *configureComp) LoadStageBoss() {
if v, err := this.GetConfigure(game_integralboss); err == nil {
if configure, ok := v.(*cfg.GameIntegralBoss); ok {
this.hlock.Lock()
defer this.hlock.Unlock()
this.boss = make(map[int32]*cfg.GameIntegralBossData, 0)
for _, value := range configure.GetDataList() {
this.boss[value.Hdid<<8+value.Difficulty] = value
}
return
}
} else {
log.Errorf("get game_integralboss conf err:%v", err)
}
return
}
// 通过活动id 和难度获取
func (this *configureComp) GetStageBoss(hdid int32, nandu int32) (conf *cfg.GameIntegralBossData, err error) {
this.hlock.RLock()
conf = this.boss[hdid<<8+nandu]
this.hlock.RUnlock()
if conf == nil {
err = fmt.Errorf("not found game_integralboss:hid:%d,难度:%d", hdid, nandu)
}
return
}
// 参数: boss类型 难度
func (this *configureComp) GetEnchantBossConfigData(bossId int32) (data []*cfg.GameEnchantBossData, err error) {
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) GetIntegralITime() (sz []*cfg.GameIntegralTimeData) {
if v, err := this.GetConfigure(game_integraltime); err == nil {
if configure, ok := v.(*cfg.GameIntegralTime); ok {
return configure.GetDataList()
}
} else {
log.Errorf("get game_integraltime conf err:%v", err)
}
return
}