package caravan import ( "go_dreamfactory/lego/core" "go_dreamfactory/lego/sys/log" "go_dreamfactory/modules" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" ) const ( game_caravan = "game_itinerant_city.json" game_caravan_lv = "game_itinerant_lv.json" game_caravan_reward = "game_itinerant_reward.json" game_caravan_thing = "game_itinerant_thing.json" ) ///配置管理基础组件 type configureComp struct { modules.MCompConfigure } //组件初始化接口 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) return } //加载多个配置文件 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) GetCaravanCity(cityId int32) (data *cfg.Gameitinerant_cityData) { if v, err := this.GetConfigure(game_caravan); err == nil { if configure, ok := v.(*cfg.Gameitinerant_city); ok { data = configure.Get(cityId) return } } else { log.Errorf("get GetCaravanCity conf err:%v", err) } return } // 获取货物基本信息 func (this *configureComp) GetCaravanLv(lv int32) (data *cfg.Gameitinerant_lvData) { if v, err := this.GetConfigure(game_caravan_lv); err == nil { if configure, ok := v.(*cfg.Gameitinerant_lv); ok { data = configure.Get(lv) return } } else { log.Errorf("get GetCaravanGoods conf err:%v", err) } return } func (this *configureComp) GetCaravanGoods(itemId int32) (data *cfg.Gameitinerant_thingData) { if v, err := this.GetConfigure(game_caravan_thing); err == nil { if configure, ok := v.(*cfg.Gameitinerant_thing); ok { data = configure.Get(itemId) return } } else { log.Errorf("get GetCaravanGoods conf err:%v", err) } return } func (this *configureComp) GetAllCaravanCity() (data []*cfg.Gameitinerant_cityData) { if v, err := this.GetConfigure(game_caravan); err == nil { if configure, ok := v.(*cfg.Gameitinerant_city); ok { for _, v := range configure.GetDataList() { data = append(data, v) } return } } else { log.Errorf("get GetAllCaravanCity conf err:%v", err) } return } func (this *configureComp) GetAllCaravanItem() (data []*cfg.Gameitinerant_thingData) { if v, err := this.GetConfigure(game_caravan_thing); err == nil { if configure, ok := v.(*cfg.Gameitinerant_thing); ok { for _, v := range configure.GetDataList() { data = append(data, v) } return } } else { log.Errorf("get GetAllCaravanItem conf err:%v", err) } return }