From 93570f645faa0dc7e94eaf6b9bea6f95b0edeb9a Mon Sep 17 00:00:00 2001 From: zhaocy Date: Thu, 30 Jun 2022 15:23:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E8=BD=BDglobal=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/json/game_global.json | 10 ++++++++++ modules/compconfigure.go | 28 ++++++++++++++++++++++++++++ modules/user/configure.go | 16 ++++++++++++++++ sys/configure/configure.go | 20 ++------------------ 4 files changed, 56 insertions(+), 18 deletions(-) create mode 100644 modules/user/configure.go diff --git a/bin/json/game_global.json b/bin/json/game_global.json index 75bc5b99e..ee90363d6 100644 --- a/bin/json/game_global.json +++ b/bin/json/game_global.json @@ -28,5 +28,15 @@ "index": "task_reset", "var": "8", "intr": "日/周常任务刷新时间,8点" + }, + { + "index": "init_gold", + "var": "100000", + "intr": "初始金币" + }, + { + "index": "init_hero", + "var": "15001, 25001", + "intr": "初始英雄" } ] \ No newline at end of file diff --git a/modules/compconfigure.go b/modules/compconfigure.go index eac1f6aa3..262bd8ffc 100644 --- a/modules/compconfigure.go +++ b/modules/compconfigure.go @@ -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 "" +} diff --git a/modules/user/configure.go b/modules/user/configure.go new file mode 100644 index 000000000..d895376ef --- /dev/null +++ b/modules/user/configure.go @@ -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 +} diff --git a/sys/configure/configure.go b/sys/configure/configure.go index 2690f0ba5..f97e9d94f 100644 --- a/sys/configure/configure.go +++ b/sys/configure/configure.go @@ -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()