go_dreamfactory/modules/user/comp_configure.go
2022-12-27 14:39:03 +08:00

88 lines
2.1 KiB
Go

package user
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_signreset = "game_signreset.json"
game_sign = "game_sign.json"
gameOpencond = "game_opencond.json"
)
///配置管理基础组件
type configureComp struct {
hlock sync.RWMutex
modules.MCompConfigure
_sign map[int32]*cfg.GameSignData
}
//组件初始化接口
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._sign = make(map[int32]*cfg.GameSignData, 0)
configure.RegisterConfigure(game_sign, cfg.NewGameSign, this.LoadSignData)
this.LoadConfigure(gameOpencond, cfg.NewGameOpencond)
return
}
// 获取签到信息
func (this *configureComp) GetSignConf(day, group int32) *cfg.GameSignData {
if v, ok := this._sign[day<<8+group]; ok {
return v
}
return nil
}
// 获取组id
func (this *configureComp) GetSignResetConf(id int32) int32 {
if v, err := this.GetConfigure(game_signreset); err == nil {
if configure, ok := v.(*cfg.GameSignReset); ok {
if configure != nil {
return configure.Get(id).Groups
}
}
}
return -1
}
func (this *configureComp) LoadSignData() {
if v, err := this.GetConfigure(game_sign); err == nil {
if configure, ok := v.(*cfg.GameSign); ok {
this.hlock.Lock()
defer this.hlock.Unlock()
for _, value := range configure.GetDataList() {
this._sign[value.Day<<8+value.Group] = value
}
return
}
} else {
log.Errorf("get game_sign conf err:%v", err)
}
return
}
func (this *configureComp) FindFunc(lv int32) (funcIds []string) {
if v, err := this.GetConfigure(gameOpencond); err != nil {
return nil
} else {
data, ok := v.(*cfg.GameOpencond)
if !ok {
err = fmt.Errorf("%T no is *cfg.GameOpencond", v)
return nil
}
for _, d := range data.GetDataList() {
if d.Main == lv {
funcIds = append(funcIds, d.Id)
}
}
}
return
}