package moonlv import ( "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "sync" ) const ( monnlv = "game_moonlv.json" monntask = "game_moontask.json" ) // /配置管理基础组件 type configureComp struct { modules.MCompConfigure module *Moonlv hlock sync.RWMutex taskgroup map[int32][]*cfg.GameMoonTaskData } // 组件初始化接口 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.(*Moonlv) err = this.LoadMultiConfigure(map[string]interface{}{ monnlv: cfg.NewGameMoonLv, monntask: cfg.NewGameMoonTask, }) configure.RegisterConfigure(monntask, cfg.NewGameMoonTask, this.LoadGameMoonTaskData) return } func (this *configureComp) LoadGameMoonTaskData() { if v, err := this.GetConfigure(monntask); err == nil { if configure, ok := v.(*cfg.GameMoonTask); ok { this.hlock.Lock() this.taskgroup = make(map[int32][]*cfg.GameMoonTaskData, 0) defer this.hlock.Unlock() for _, value := range configure.GetDataList() { this.taskgroup[value.TaskGroup] = append(this.taskgroup[value.TaskGroup], value) } return } } else { log.Errorf("get LoadGameMoonTaskData conf err:%v", err) } } // 加载多个配置文件 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) } func (this *configureComp) GetMoonLvConf(lv int32) (conf *cfg.GameMoonLvData, err error) { var ( v interface{} ) if v, err = this.GetConfigure(monnlv); err == nil { if configure, ok := v.(*cfg.GameMoonLv); ok { if conf = configure.Get(lv); conf != nil { return } } } err = comm.NewNotFoundConfErr("moonlv", monnlv, lv) return }