go_dreamfactory/modules/user/comp_configure.go
2022-11-07 21:55:08 +08:00

67 lines
1.6 KiB
Go

package user
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_signreset = "game_signreset.json"
game_sign = "game_sign.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)
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
}