加载global配置
This commit is contained in:
parent
65560dfa5c
commit
93570f645f
@ -28,5 +28,15 @@
|
|||||||
"index": "task_reset",
|
"index": "task_reset",
|
||||||
"var": "8",
|
"var": "8",
|
||||||
"intr": "日/周常任务刷新时间,8点"
|
"intr": "日/周常任务刷新时间,8点"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": "init_gold",
|
||||||
|
"var": "100000",
|
||||||
|
"intr": "初始金币"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": "init_hero",
|
||||||
|
"var": "15001, 25001",
|
||||||
|
"intr": "初始英雄"
|
||||||
}
|
}
|
||||||
]
|
]
|
@ -6,6 +6,11 @@ import (
|
|||||||
"go_dreamfactory/lego/core/cbase"
|
"go_dreamfactory/lego/core/cbase"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
"go_dreamfactory/sys/configure"
|
"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.ModuleCompBase.Init(service, module, comp, options)
|
||||||
this.S = service.(base.IRPCXService)
|
this.S = service.(base.IRPCXService)
|
||||||
this.M = module.(IModule)
|
this.M = module.(IModule)
|
||||||
|
err = this.LoadConfigure(game_global, cfg.NewGame_global)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,3 +50,25 @@ func (this *MCompConfigure) LoadMultiConfigure(confs map[string]interface{}) (er
|
|||||||
func (this *MCompConfigure) GetConfigure(name string) (v interface{}, err error) {
|
func (this *MCompConfigure) GetConfigure(name string) (v interface{}, err error) {
|
||||||
return configure.GetConfigure(name)
|
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
16
modules/user/configure.go
Normal 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
|
||||||
|
}
|
@ -3,7 +3,6 @@ package configure
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
cfg "go_dreamfactory/sys/configure/structs"
|
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@ -31,7 +30,6 @@ func newSys(options Options) (sys *Configure, err error) {
|
|||||||
configure: make(map[string]interface{}),
|
configure: make(map[string]interface{}),
|
||||||
fileinfos: make(map[string]*FileInfo),
|
fileinfos: make(map[string]*FileInfo),
|
||||||
}
|
}
|
||||||
err = sys.init()
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,20 +43,6 @@ type Configure struct {
|
|||||||
fileinfos map[string]*FileInfo
|
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) {
|
func (this *Configure) Start() (err error) {
|
||||||
tc := time.NewTicker(time.Second * time.Duration(this.options.CheckInterval))
|
tc := time.NewTicker(time.Second * time.Duration(this.options.CheckInterval))
|
||||||
go func() {
|
go func() {
|
||||||
@ -166,12 +150,12 @@ func (this *Configure) loaderConfigure(name string, handle *configurehandle) (er
|
|||||||
|
|
||||||
fliepath = path.Join(this.options.ConfigurePath, name)
|
fliepath = path.Join(this.options.ConfigurePath, name)
|
||||||
if fileInfo, err = os.Stat(fliepath); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if file, err = os.Open(fliepath); err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
Loading…
Reference in New Issue
Block a user