go_dreamfactory/modules/uigame/comp_configure.go

147 lines
3.7 KiB
Go

package uigame
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
)
var moduleName = "uigame"
const (
game_puzzle = "game_uigamepuzzle.json"
game_lattice = "game_uigamelattice.json"
game_miner = "game_uigameminer.json"
game_consum = "game_uigameconsum.json"
)
///配置管理基础组件
type configureComp struct {
module *UiGame
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)
this.module = module.(*UiGame)
err = this.LoadMultiConfigure(map[string]interface{}{
game_puzzle: cfg.NewGameUiGamePuzzle,
game_lattice: cfg.NewGameUiGameLattice,
game_miner: cfg.NewGameUiGameMiner,
game_consum: cfg.NewGameUiGameConsum,
})
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) GetPuzzleConf(id int32) (conf *cfg.GameUiGamePuzzleData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_puzzle); err == nil {
if configure, ok := v.(*cfg.GameUiGamePuzzle); ok {
if conf = configure.Get(id); conf != nil {
return
}
}
}
this.module.Errorf("GetPuzzleConf conf not found key :%d", id)
return
}
// 获取拼图体力消耗
func (this *configureComp) GetPuzzleConsumConf() (conf *cfg.GameUiGameConsumData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_consum); err == nil {
if configure, ok := v.(*cfg.GameUiGameConsum); ok {
if conf = configure.Get(1); conf != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_consum, "1")
return
}
func (this *configureComp) GetLatticeConsumConf() (conf *cfg.GameUiGameConsumData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_consum); err == nil {
if configure, ok := v.(*cfg.GameUiGameConsum); ok {
if conf = configure.Get(2); conf != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_consum, "2")
return
}
func (this *configureComp) GetLatticeConf(id int32) (conf *cfg.GameUiGameLatticeData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_lattice); err == nil {
if configure, ok := v.(*cfg.GameUiGameLattice); ok {
if conf = configure.Get(id); conf != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_lattice, id)
return
}
// 获取矿工体力消耗
func (this *configureComp) GetMinerConsumConf() (conf *cfg.GameUiGameConsumData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_consum); err == nil {
if configure, ok := v.(*cfg.GameUiGameConsum); ok {
if conf = configure.Get(3); conf != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_consum, "3")
return
}
func (this *configureComp) GetMinerConf(id int32) (conf *cfg.GameUiGameMinerData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_miner); err == nil {
if configure, ok := v.(*cfg.GameUiGameMiner); ok {
if conf = configure.Get(id); conf != nil {
return
}
}
}
err = comm.NewNotFoundConfErr(moduleName, game_miner, id)
return
}