package jielong import ( "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/core" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" "sync" ) const ( game_fast = "game_gamefast.json" ) type configureComp struct { modules.MCompConfigure module *Jielong hlock sync.RWMutex tyep1 map[int32]*cfg.GameGameFastData tyep2 map[int32]*cfg.GameGameFastData } 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.(*Jielong) // err = this.LoadMultiConfigure(map[string]interface{}{ // game_fast: cfg.NewGameGameFast, // }) configure.RegisterConfigure(game_fast, cfg.NewGameGameFast, func() { if v, err := this.GetConfigure(game_fast); err == nil { this.hlock.Lock() defer this.hlock.Unlock() this.tyep1 = make(map[int32]*cfg.GameGameFastData) this.tyep2 = make(map[int32]*cfg.GameGameFastData) if _configure, ok := v.(*cfg.GameGameFast); ok { for _, v := range _configure.GetDataList() { if v.Type == 1 { this.tyep1[v.Condition] = v } else if v.Type == 2 { this.tyep2[v.Condition] = v } } return } } else { err = fmt.Errorf("%T no is *cfg.GameGameFastData", v) } }) return } func (this *configureComp) getGameFastDataByType(itype int32) (conf map[int32]*cfg.GameGameFastData, err error) { this.hlock.RLock() defer this.hlock.RUnlock() if itype == 1 { conf = this.tyep1 } else if itype == 2 { conf = this.tyep2 } if conf == nil { err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_fast, itype) return } return } //读取配置数据 func (this *configureComp) GetConfigure(name string) (v interface{}, err error) { return configure.GetConfigure(name) } func (this *configureComp) getGameFastData(id int32) (conf *cfg.GameGameFastData, err error) { var ( v interface{} ok bool ) if v, err = this.GetConfigure(game_fast); err != nil { return } if conf, ok = v.(*cfg.GameGameFast).GetDataMap()[id]; !ok { err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_fast, id) this.module.Errorln(err) return } return }