124 lines
3.0 KiB
Go
124 lines
3.0 KiB
Go
package modules
|
|
|
|
import (
|
|
"fmt"
|
|
"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_global = "game_global.json" //全局配置表
|
|
game_initial = "game_initial.json" //初始化表
|
|
game_playerlv = "game_playerlv.json" //玩家等级
|
|
)
|
|
|
|
///配置管理基础组件
|
|
type MCompConfigure struct {
|
|
cbase.ModuleCompBase
|
|
}
|
|
|
|
//组件初始化接口
|
|
func (this *MCompConfigure) 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.LoadConfigure(game_global, cfg.NewGame_global)
|
|
err = this.LoadConfigure(game_initial, cfg.NewGame_initial)
|
|
err = this.LoadConfigure(game_playerlv, cfg.NewGame_playerlv)
|
|
return
|
|
}
|
|
|
|
//加载一个配置文件
|
|
func (this *MCompConfigure) LoadConfigure(name string, fn interface{}) (err error) {
|
|
return configure.RegisterConfigure(name, fn)
|
|
}
|
|
|
|
//加载多个配置文件
|
|
func (this *MCompConfigure) 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 *MCompConfigure) GetConfigure(name string) (v interface{}, err error) {
|
|
return configure.GetConfigure(name)
|
|
}
|
|
|
|
//全局配置
|
|
func (this *MCompConfigure) GetGlobalConf(key string) string {
|
|
if v, err := this.GetConfigure(game_initial); err != nil {
|
|
log.Errorf("get global conf err:%v", err)
|
|
return ""
|
|
} else {
|
|
var (
|
|
configure *cfg.Game_global
|
|
ok bool
|
|
)
|
|
if configure, ok = v.(*cfg.Game_global); !ok {
|
|
log.Errorf("%T no is *cfg.Game_global", v)
|
|
return ""
|
|
}
|
|
|
|
if v, ok := configure.GetDataMap()[key]; ok {
|
|
return v.Var
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func (this *MCompConfigure) GetGlobalInitConf() (configure *cfg.Game_initial, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_initial); err != nil {
|
|
return
|
|
} else {
|
|
if configure, ok = v.(*cfg.Game_initial); !ok {
|
|
err = fmt.Errorf("%T no is *cfg.Game_comInitial", v)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 主角等级经验配置列表
|
|
func (this *MCompConfigure) GetPlayerlvConfList() (list []*cfg.Game_playerlvData) {
|
|
if v, err := this.GetConfigure(game_playerlv); err != nil {
|
|
return
|
|
} else {
|
|
if configure, ok := v.(*cfg.Game_playerlv); !ok {
|
|
err = fmt.Errorf("%T no is *cfg.Game_playerlv", v)
|
|
return
|
|
} else {
|
|
if configure != nil {
|
|
list = configure.GetDataList()
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *MCompConfigure) GetPlayerlvConf(lv int32) (data *cfg.Game_playerlvData) {
|
|
if v, err := this.GetConfigure(game_playerlv); err != nil {
|
|
return
|
|
} else {
|
|
if configure, ok := v.(*cfg.Game_playerlv); !ok {
|
|
err = fmt.Errorf("%T no is *cfg.Game_playerlv", v)
|
|
return
|
|
} else {
|
|
if configure != nil {
|
|
data = configure.GetDataMap()[lv]
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|