go_dreamfactory/modules/user/comp_configure.go

149 lines
3.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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"
game_SignExtra = "game_signextra.json"
game_initial = "game_initial.json" //初始化表
)
///配置管理基础组件
type configureComp struct {
hlock sync.RWMutex
modules.MCompConfigure
_sign map[int32]*cfg.GameSignData
_signExtra map[int32]*cfg.GameSignExtraData
}
//组件初始化接口
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.LoadConfigure(game_initial, cfg.NewGameInitial)
this._sign = make(map[int32]*cfg.GameSignData, 0)
configure.RegisterConfigure(game_sign, cfg.NewGameSign, this.LoadSignData)
this.LoadConfigure(gameOpencond, cfg.NewGameOpencond)
this._signExtra = make(map[int32]*cfg.GameSignExtraData, 0)
configure.RegisterConfigure(game_SignExtra, cfg.NewGameSignExtra, this.LoadSignExtraData)
return
}
// 获取签到信息
func (this *configureComp) GetSignConf(day, group int32) *cfg.GameSignData {
if v, ok := this._sign[group<<8+day]; ok {
return v
}
log.Errorf("get GetSignConf conf err day:%d,group%d", day, group)
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 {
if _, ok := configure.GetDataMap()[id]; !ok {
return configure.Get(1).Groups
}
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.Group<<8+value.Day] = value
}
return
}
} else {
log.Errorf("get game_sign conf err:%v", err)
}
return
}
func (this *configureComp) GetOpenCondConf() []*cfg.GameOpencondData {
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
}
return data.GetDataList()
}
}
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() {
for _, v := range d.Main {
if v.Key == 1 && v.Param == lv {
funcIds = append(funcIds, d.Id)
continue
}
}
}
}
return
}
func (this *configureComp) LoadSignExtraData() {
if v, err := this.GetConfigure(game_SignExtra); err == nil {
if configure, ok := v.(*cfg.GameSignExtra); ok {
this.hlock.Lock()
defer this.hlock.Unlock()
for _, value := range configure.GetDataList() {
this._signExtra[value.Groups<<8+value.Day] = value
}
return
}
} else {
log.Errorf("get SignExtra conf err:%v", err)
}
return
}
func (this *configureComp) GetSignExtarConf(day, group int32) *cfg.GameSignExtraData {
if v, ok := this._signExtra[group<<8+day]; ok {
return v
}
return nil
}
func (this *configureComp) GetGlobalInitConf() (configure *cfg.GameInitial, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(game_initial); err == nil {
if configure, ok = v.(*cfg.GameInitial); !ok {
err = fmt.Errorf("%T no is *cfg.Game_comInitial", v)
return
}
}
return
}