go_dreamfactory/modules/sys/config.go
2023-09-07 18:57:53 +08:00

145 lines
3.5 KiB
Go

package sys
import (
"fmt"
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"sync"
)
const (
gameOpencond = "game_opencond.json"
)
type configureComp struct {
modules.MCompConfigure
module *ModuleSys
hlock sync.RWMutex
maplv map[int32][]string // 监听等级大于1 的配置
maptask map[int32][]string
mapmline map[int32][]string
mapfriend map[int32][]string // 好友数量
}
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.LoadConfigure(gameOpencond, cfg.NewGameOpencond)
configure.RegisterConfigure(gameOpencond, cfg.NewGameOpencond, this.LoadCondConfig)
this.module = module.(*ModuleSys)
return
}
func (this *configureComp) LoadCondConfig() {
if v, err := this.GetConfigure(gameOpencond); err == nil {
if data, ok := v.(*cfg.GameOpencond); ok {
this.hlock.Lock()
this.maplv = make(map[int32][]string, 0)
this.maptask = make(map[int32][]string, 0)
this.mapmline = make(map[int32][]string, 0)
this.mapfriend = make(map[int32][]string, 0)
defer this.hlock.Unlock()
for _, v := range data.GetDataList() {
for _, v1 := range v.Main {
if v.ActivateType == 2 {
if v1.Key == 1 && v1.Param > 1 {
this.maplv[v1.Param] = append(this.maplv[v1.Param], v.Id)
}
if v1.Key == 3 && v1.Param > 1 {
this.maptask[v1.Param] = append(this.maptask[v1.Param], v.Id)
}
if v1.Key == 2 && v1.Param > 1 {
this.mapmline[v1.Param] = append(this.mapmline[v1.Param], v.Id)
}
if v1.Key == 4 && v1.Param > 1 {
this.mapfriend[v1.Param] = append(this.mapfriend[v1.Param], v.Id)
}
}
}
}
}
}
}
func (this *configureComp) GetOpencondLv(lv int32) []string {
this.hlock.RLock()
defer this.hlock.RUnlock()
return this.maplv[lv]
}
func (this *configureComp) getOpencondMline(id int32) []string {
this.hlock.RLock()
defer this.hlock.RUnlock()
return this.mapmline[id]
}
func (this *configureComp) getOpencondTask(id int32) []string {
this.hlock.RLock()
defer this.hlock.RUnlock()
return this.maptask[id]
}
func (this *configureComp) getFriendTask(id int32) []string {
this.hlock.RLock()
defer this.hlock.RUnlock()
return this.mapfriend[id]
}
func (this *configureComp) getOpencondCfg() (data *cfg.GameOpencond, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(gameOpencond); err == nil {
if data, ok = v.(*cfg.GameOpencond); !ok {
err = fmt.Errorf("%T no is *cfg.GameOpencond", v)
return
}
}
return
}
func (this *configureComp) GetOpenCondCfgById(id string) (data *cfg.GameOpencondData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(gameOpencond); err == nil {
if c, ok := v.(*cfg.GameOpencond); ok {
if data = c.Get(id); data != nil {
return
}
}
}
err = comm.NewNotFoundConfErr("opencond", gameOpencond, id)
return
}
func (this *configureComp) getOpencondConf() (list []*cfg.GameOpencondData) {
if cfg, err := this.getOpencondCfg(); err == nil {
list = cfg.GetDataList()
}
return
}
// 通过cid 找数据
func (this *configureComp) getOpencondCfgByCid(id string) (conf *cfg.GameOpencondData) {
if v, err := this.GetConfigure(gameOpencond); err == nil {
if data, ok := v.(*cfg.GameOpencond); ok {
if conf, ok = data.GetDataMap()[id]; ok {
return
}
}
}
return nil
}