139 lines
3.6 KiB
Go
139 lines
3.6 KiB
Go
package mainline
|
|
|
|
import (
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/core/cbase"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
)
|
|
|
|
const (
|
|
game_mainlinechapter = "game_mainlinechapter.json"
|
|
game_mainlineeasy = "game_mainlineeasy.json"
|
|
game_mainlinehard = "game_mainlinehard.json"
|
|
game_mainlinepurgatory = "game_mainlinepurgatory.json"
|
|
)
|
|
|
|
///配置管理基础组件
|
|
type configureComp struct {
|
|
cbase.ModuleCompBase
|
|
module *Mainline
|
|
}
|
|
|
|
//组件初始化接口
|
|
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_mainlinechapter: cfg.NewGame_mainlineChapter,
|
|
game_mainlineeasy: cfg.NewGame_mainlineEasy,
|
|
game_mainlinehard: cfg.NewGame_mainlineHard,
|
|
game_mainlinepurgatory: cfg.NewGame_mainlinePurgatory,
|
|
})
|
|
this.module = module.(*Mainline)
|
|
return
|
|
}
|
|
|
|
//加载多个配置文件
|
|
func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) {
|
|
for k, v := range confs {
|
|
err = configure.RegisterConfigure(k, v)
|
|
if err != nil {
|
|
this.module.Errorf("配置文件:%s解析失败!", k)
|
|
break
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
//读取配置数据
|
|
func (this *configureComp) GetConfigure(name string) (v interface{}, err error) {
|
|
return configure.GetConfigure(name)
|
|
}
|
|
|
|
func (this *configureComp) GetMainlineChapter(id int32) (data *cfg.Game_mainlineChapterData) {
|
|
if v, err := this.GetConfigure(game_mainlinechapter); err != nil {
|
|
this.module.Errorf("get global conf err:%v", err)
|
|
return
|
|
} else {
|
|
var (
|
|
configure *cfg.Game_mainlineChapter
|
|
ok bool
|
|
)
|
|
if configure, ok = v.(*cfg.Game_mainlineChapter); !ok {
|
|
this.module.Errorf("%T no is *cfg.Game_mainlineChapterData", v)
|
|
return
|
|
}
|
|
|
|
if data, ok = configure.GetDataMap()[id]; ok {
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取简单的关卡配置信息
|
|
func (this *configureComp) GetMainlineEasyChapter(id int32) (data *cfg.Game_mainlineEasyData) {
|
|
if v, err := this.GetConfigure(game_mainlineeasy); err != nil {
|
|
this.module.Errorf("get global conf err:%v", err)
|
|
return
|
|
} else {
|
|
var (
|
|
configure *cfg.Game_mainlineEasy
|
|
ok bool
|
|
)
|
|
if configure, ok = v.(*cfg.Game_mainlineEasy); !ok {
|
|
this.module.Errorf("%T no is *cfg.Game_mainlineEasyData", v)
|
|
return
|
|
}
|
|
|
|
if data, ok = configure.GetDataMap()[id]; ok {
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取炼狱级别难度的关卡配置
|
|
func (this *configureComp) GetMainlinePurgatoryChapter(id int32) (data *cfg.Game_mainlinePurgatoryData) {
|
|
if v, err := this.GetConfigure(game_mainlinepurgatory); err != nil {
|
|
this.module.Errorf("get global conf err:%v", err)
|
|
return
|
|
} else {
|
|
var (
|
|
configure *cfg.Game_mainlinePurgatory
|
|
ok bool
|
|
)
|
|
if configure, ok = v.(*cfg.Game_mainlinePurgatory); !ok {
|
|
this.module.Errorf("%T no is *cfg.Game_mainlinePurgatoryData", v)
|
|
return
|
|
}
|
|
|
|
if data, ok = configure.GetDataMap()[id]; ok {
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 获取困难的关卡配置
|
|
func (this *configureComp) GetMainlineHardChapter(id int32) (data *cfg.Game_mainlineHardData) {
|
|
if v, err := this.GetConfigure(game_mainlinehard); err != nil {
|
|
this.module.Errorf("get global conf err:%v", err)
|
|
return
|
|
} else {
|
|
var (
|
|
configure *cfg.Game_mainlineHard
|
|
ok bool
|
|
)
|
|
if configure, ok = v.(*cfg.Game_mainlineHard); !ok {
|
|
this.module.Errorf("%T no is *cfg.Game_mainlineHardData", v)
|
|
return
|
|
}
|
|
|
|
if data, ok = configure.GetDataMap()[id]; ok {
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|