package story import ( "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" "go_dreamfactory/lego/sys/log" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" ) const ( game_storychapter = "game_storychapter.json" game_storyeasy = "game_storyeasy.json" game_storyhard = "game_storyhard.json" game_storypurgatory = "game_storypurgatory.json" ) ///配置管理基础组件 type configureComp struct { cbase.ModuleCompBase } //组件初始化接口 func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) { err = this.ModuleCompBase.Init(service, module, comp, options) err = this.LoadMultiConfigure(map[string]interface{}{ game_storychapter: cfg.NewGame_storyChapter, game_storyeasy: cfg.NewGame_storyEasy, game_storyhard: cfg.NewGame_storyHard, game_storypurgatory: cfg.NewGame_storyPurgatory, }) return } //加载多个配置文件 func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) { for k, v := range confs { err = configure.RegisterConfigure(k, v) 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) GetStoryChapter(id int32) (data *cfg.Game_storyChapterData) { if v, err := this.GetConfigure(game_storychapter); err != nil { log.Errorf("get global conf err:%v", err) return } else { var ( configure *cfg.Game_storyChapter ok bool ) if configure, ok = v.(*cfg.Game_storyChapter); !ok { log.Errorf("%T no is *cfg.Game_storyChapterData", v) return } if data, ok = configure.GetDataMap()[id]; ok { return } } return } // 获取简单的关卡配置信息 func (this *configureComp) GetStoryEasyChapter(id int32) (data *cfg.Game_storyEasyData) { if v, err := this.GetConfigure(game_storyeasy); err != nil { log.Errorf("get global conf err:%v", err) return } else { var ( configure *cfg.Game_storyEasy ok bool ) if configure, ok = v.(*cfg.Game_storyEasy); !ok { log.Errorf("%T no is *cfg.Game_storyEasyData", v) return } if data, ok = configure.GetDataMap()[id]; ok { return } } return } // 获取炼狱级别难度的关卡配置 func (this *configureComp) GetStoryPurgatoryChapter(id int32) (data *cfg.Game_storyPurgatoryData) { if v, err := this.GetConfigure(game_storypurgatory); err != nil { log.Errorf("get global conf err:%v", err) return } else { var ( configure *cfg.Game_storyPurgatory ok bool ) if configure, ok = v.(*cfg.Game_storyPurgatory); !ok { log.Errorf("%T no is *cfg.Game_storyPurgatoryData", v) return } if data, ok = configure.GetDataMap()[id]; ok { return } } return } // 获取困难的关卡配置 func (this *configureComp) GetStoryHardChapter(id int32) (data *cfg.Game_storyHardData) { if v, err := this.GetConfigure(game_storyhard); err != nil { log.Errorf("get global conf err:%v", err) return } else { var ( configure *cfg.Game_storyHard ok bool ) if configure, ok = v.(*cfg.Game_storyHard); !ok { log.Errorf("%T no is *cfg.Game_storyHardData", v) return } if data, ok = configure.GetDataMap()[id]; ok { return } } return }