加载global配置

This commit is contained in:
zhaocy 2022-06-30 15:23:48 +08:00
parent 65560dfa5c
commit 93570f645f
4 changed files with 56 additions and 18 deletions

View File

@ -28,5 +28,15 @@
"index": "task_reset",
"var": "8",
"intr": "日/周常任务刷新时间8点"
},
{
"index": "init_gold",
"var": "100000",
"intr": "初始金币"
},
{
"index": "init_hero",
"var": "15001, 25001",
"intr": "初始英雄"
}
]

View File

@ -6,6 +6,11 @@ import (
"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"
)
///配置管理基础组件
@ -20,6 +25,7 @@ func (this *MCompConfigure) Init(service core.IService, module core.IModule, com
this.ModuleCompBase.Init(service, module, comp, options)
this.S = service.(base.IRPCXService)
this.M = module.(IModule)
err = this.LoadConfigure(game_global, cfg.NewGame_global)
return
}
@ -44,3 +50,25 @@ func (this *MCompConfigure) LoadMultiConfigure(confs map[string]interface{}) (er
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_global); 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 ""
}

16
modules/user/configure.go Normal file
View File

@ -0,0 +1,16 @@
package user
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
)
type configureComp struct {
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)
return
}

View File

@ -3,7 +3,6 @@ package configure
import (
"fmt"
"go_dreamfactory/lego/sys/log"
cfg "go_dreamfactory/sys/configure/structs"
"io/fs"
"io/ioutil"
"os"
@ -31,7 +30,6 @@ func newSys(options Options) (sys *Configure, err error) {
configure: make(map[string]interface{}),
fileinfos: make(map[string]*FileInfo),
}
err = sys.init()
return
}
@ -45,20 +43,6 @@ type Configure struct {
fileinfos map[string]*FileInfo
}
const (
game_com = "game_com.json"
)
func (this *Configure) init() (err error) {
this.RegisterConfigure(game_com, cfg.NewGame_com)
// _data := this.configure[game_com]
// if _da, ok := _data.(*cfg.Game_com).GetDataMap()["max_char"]; ok {
// log.Debugf("%b==%v", ok, _da.Var)
// }
return
}
func (this *Configure) Start() (err error) {
tc := time.NewTicker(time.Second * time.Duration(this.options.CheckInterval))
go func() {
@ -166,12 +150,12 @@ func (this *Configure) loaderConfigure(name string, handle *configurehandle) (er
fliepath = path.Join(this.options.ConfigurePath, name)
if fileInfo, err = os.Stat(fliepath); err != nil {
err = fmt.Errorf("no fond file:%s", fliepath)
err = fmt.Errorf("no found file:%s", fliepath)
return
}
if file, err = os.Open(fliepath); err != nil {
err = fmt.Errorf("no fond file:%s", fliepath)
err = fmt.Errorf("no found file:%s", fliepath)
return
}
defer file.Close()