package buried import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "sync" ) const ( gameTaskCond = "game_rdtaskcondi.json" ) //配置管理组件 type configureComp struct { modules.MCompConfigure module *Buried lock sync.RWMutex group map[comm.TaskType][]*cfg.GameRdtaskCondiData //安排点类型 分组 } //组件初始化接口 func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { this.MCompConfigure.Init(service, module, comp, options) this.module = module.(*Buried) this.LoadConfigure(gameTaskCond, cfg.NewGameRdtaskCondi) configure.RegisterConfigure(gameTaskCond, cfg.NewGameRdtaskCondi, this.updateconfigure) return } //动态更新配置 func (this *configureComp) updateconfigure() { if v, err := this.GetConfigure(gameTaskCond); err != nil { return } else { if data, ok := v.(*cfg.GameRdtaskCondi); !ok { err = fmt.Errorf("%T is *cfg.GameRdtaskCondi", v) return } else { group := map[comm.TaskType][]*cfg.GameRdtaskCondiData{} for _, v := range data.GetDataList() { if _, ok = group[comm.TaskType(v.Type)]; !ok { group[comm.TaskType(v.Type)] = make([]*cfg.GameRdtaskCondiData, 0) } group[comm.TaskType(v.Type)] = append(group[comm.TaskType(v.Type)], v) } this.lock.Lock() this.group = group this.lock.Unlock() } } } //读取埋点条件配置 func (this *configureComp) getCondiDatas(tt comm.TaskType) (result []*cfg.GameRdtaskCondiData) { result = make([]*cfg.GameRdtaskCondiData, 0) this.lock.RLock() if _, ok := this.group[tt]; ok { result = this.group[tt] } this.lock.RUnlock() return }