go_dreamfactory/modules/activity/comp_configure.go

78 lines
1.9 KiB
Go

package activity
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 (
hdcelebration = "game_celebration.json" //开服庆典
)
// /配置管理基础组件
type configureComp struct {
modules.MCompConfigure
module *Activity
hlock sync.RWMutex
pool1 map[int32]*cfg.GameVenturegiftsDrawData
pool2 map[int32]*cfg.GameVenturegiftsDrawData
}
// 组件初始化接口
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.(*Activity)
err = this.LoadMultiConfigure(map[string]interface{}{
hdcelebration: cfg.NewGameCelebration,
})
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)
}
// id
func (this *configureComp) GetHDCelebration(id int32) (conf *cfg.GameCelebrationData, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(hdcelebration); err == nil {
if conf, ok = v.(*cfg.GameCelebration).GetDataMap()[id]; !ok {
err = fmt.Errorf("%T no is *cfg.GameCelebrationData", v)
return
}
}
return
}
func (this *configureComp) GetHDCelebrationData() (days []int32) {
if v, err := this.GetConfigure(hdcelebration); err == nil {
for _, v := range v.(*cfg.GameCelebration).GetDataList() {
days = append(days, v.Days)
}
}
return
}