138 lines
3.5 KiB
Go
138 lines
3.5 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" //玩家等级
|
|
game_facemod = "game_facemod.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.NewGameglobal)
|
|
err = this.LoadConfigure(game_initial, cfg.NewGameinitial)
|
|
err = this.LoadConfigure(game_playerlv, cfg.NewGameplayerlv)
|
|
err = this.LoadConfigure(game_facemod, cfg.NewGamefacemod)
|
|
return
|
|
}
|
|
|
|
//加载一个配置文件
|
|
func (this *MCompConfigure) LoadConfigure(name string, fn interface{}) (err error) {
|
|
return configure.RegisterConfigure(name, fn, nil)
|
|
}
|
|
|
|
//加载多个配置文件
|
|
func (this *MCompConfigure) 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 *MCompConfigure) GetConfigure(name string) (v interface{}, err error) {
|
|
return configure.GetConfigure(name)
|
|
}
|
|
|
|
//全局配置
|
|
func (this *MCompConfigure) GetGlobalConf() *cfg.GameglobalData {
|
|
var (
|
|
configure *cfg.Gameglobal
|
|
ok bool
|
|
)
|
|
if v, err := this.GetConfigure(game_global); err != nil {
|
|
log.Errorf("get global conf err:%v", err)
|
|
} else {
|
|
if configure, ok = v.(*cfg.Gameglobal); !ok {
|
|
log.Errorf("%T no is *cfg.Game_global", v)
|
|
}
|
|
}
|
|
return configure.GetDataList()[0] // 返回对象信息
|
|
}
|
|
|
|
func (this *MCompConfigure) GetGlobalInitConf() (configure *cfg.Gameinitial, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_initial); err != nil {
|
|
return
|
|
} else {
|
|
if configure, ok = v.(*cfg.Gameinitial); !ok {
|
|
err = fmt.Errorf("%T no is *cfg.Game_comInitial", v)
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 主角等级经验配置列表
|
|
func (this *MCompConfigure) GetPlayerlvConfList() (list []*cfg.GameplayerlvData) {
|
|
if v, err := this.GetConfigure(game_playerlv); err != nil {
|
|
return
|
|
} else {
|
|
if configure, ok := v.(*cfg.Gameplayerlv); !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.GameplayerlvData) {
|
|
if v, err := this.GetConfigure(game_playerlv); err != nil {
|
|
return
|
|
} else {
|
|
if configure, ok := v.(*cfg.Gameplayerlv); !ok {
|
|
err = fmt.Errorf("%T no is *cfg.Game_playerlv", v)
|
|
return
|
|
} else {
|
|
if configure != nil {
|
|
data = configure.GetDataMap()[lv]
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
// 玩家形象预设配置
|
|
func (this *MCompConfigure) GetPlayerFigureConf() (list []*cfg.GamefacemodData) {
|
|
if v, err := this.GetConfigure(game_facemod); err != nil {
|
|
return
|
|
} else {
|
|
if configure, ok := v.(*cfg.Gamefacemod); !ok {
|
|
err = fmt.Errorf("%T no is *cfg.Game_playerlv", v)
|
|
return
|
|
} else {
|
|
if configure != nil {
|
|
list = configure.GetDataList()
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|