配置表重定义key 并支持热更
This commit is contained in:
parent
a515c59e21
commit
6ee83fa224
File diff suppressed because it is too large
Load Diff
@ -33,13 +33,13 @@ func (this *MCompConfigure) Init(service core.IService, module core.IModule, com
|
|||||||
|
|
||||||
//加载一个配置文件
|
//加载一个配置文件
|
||||||
func (this *MCompConfigure) LoadConfigure(name string, fn interface{}) (err error) {
|
func (this *MCompConfigure) LoadConfigure(name string, fn interface{}) (err error) {
|
||||||
return configure.RegisterConfigure(name, fn)
|
return configure.RegisterConfigure(name, fn, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
//加载多个配置文件
|
//加载多个配置文件
|
||||||
func (this *MCompConfigure) LoadMultiConfigure(confs map[string]interface{}) (err error) {
|
func (this *MCompConfigure) LoadMultiConfigure(confs map[string]interface{}) (err error) {
|
||||||
for k, v := range confs {
|
for k, v := range confs {
|
||||||
err = configure.RegisterConfigure(k, v)
|
err = configure.RegisterConfigure(k, v, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("配置文件:%s解析失败!", k)
|
log.Errorf("配置文件:%s解析失败!", k)
|
||||||
break
|
break
|
||||||
|
@ -2,7 +2,7 @@ package mainline
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"go_dreamfactory/lego/core"
|
"go_dreamfactory/lego/core"
|
||||||
"go_dreamfactory/lego/core/cbase"
|
"go_dreamfactory/modules"
|
||||||
"go_dreamfactory/sys/configure"
|
"go_dreamfactory/sys/configure"
|
||||||
cfg "go_dreamfactory/sys/configure/structs"
|
cfg "go_dreamfactory/sys/configure/structs"
|
||||||
)
|
)
|
||||||
@ -16,32 +16,21 @@ const (
|
|||||||
|
|
||||||
///配置管理基础组件
|
///配置管理基础组件
|
||||||
type configureComp struct {
|
type configureComp struct {
|
||||||
cbase.ModuleCompBase
|
modules.MCompConfigure
|
||||||
module *Mainline
|
module *Mainline
|
||||||
}
|
}
|
||||||
|
|
||||||
//组件初始化接口
|
//组件初始化接口
|
||||||
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
func (this *configureComp) 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.ModuleCompBase.Init(service, module, comp, options)
|
||||||
|
this.module = module.(*Mainline)
|
||||||
err = this.LoadMultiConfigure(map[string]interface{}{
|
err = this.LoadMultiConfigure(map[string]interface{}{
|
||||||
game_mainlinechapter: cfg.NewGame_mainlineChapter,
|
game_mainlinechapter: cfg.NewGame_mainlineChapter,
|
||||||
game_mainlineeasy: cfg.NewGame_mainlineEasy,
|
game_mainlineeasy: cfg.NewGame_mainlineEasy,
|
||||||
game_mainlinehard: cfg.NewGame_mainlineHard,
|
game_mainlinehard: cfg.NewGame_mainlineHard,
|
||||||
game_mainlinepurgatory: cfg.NewGame_mainlinePurgatory,
|
game_mainlinepurgatory: cfg.NewGame_mainlinePurgatory,
|
||||||
})
|
})
|
||||||
this.module = module.(*Mainline)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//加载多个配置文件
|
|
||||||
func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) {
|
|
||||||
for k, v := range confs {
|
|
||||||
err = configure.RegisterConfigure(k, v)
|
|
||||||
if err != nil {
|
|
||||||
this.module.Errorf("配置文件:%s解析失败!", k)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"go_dreamfactory/lego/sys/log"
|
"go_dreamfactory/lego/sys/log"
|
||||||
"go_dreamfactory/sys/configure"
|
"go_dreamfactory/sys/configure"
|
||||||
cfg "go_dreamfactory/sys/configure/structs"
|
cfg "go_dreamfactory/sys/configure/structs"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -17,23 +18,47 @@ const (
|
|||||||
///配置管理基础组件
|
///配置管理基础组件
|
||||||
type configureComp struct {
|
type configureComp struct {
|
||||||
cbase.ModuleCompBase
|
cbase.ModuleCompBase
|
||||||
|
hlock sync.RWMutex
|
||||||
|
_pagodaMap map[int64]*cfg.Game_pagodaData
|
||||||
}
|
}
|
||||||
|
|
||||||
//组件初始化接口
|
//组件初始化接口
|
||||||
func (this *configureComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
func (this *configureComp) 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.ModuleCompBase.Init(service, module, comp, options)
|
||||||
err = this.LoadMultiConfigure(map[string]interface{}{
|
err = this.LoadMultiConfigure(map[string]interface{}{
|
||||||
game_pagoda: cfg.NewGame_pagoda,
|
//game_pagoda: cfg.NewGame_pagoda,
|
||||||
game_pagodaseasonreward: cfg.NewGame_pagodaSeasonReward,
|
game_pagodaseasonreward: cfg.NewGame_pagodaSeasonReward,
|
||||||
game_pagodataskreward: cfg.NewGame_pagodaTaskReward,
|
game_pagodataskreward: cfg.NewGame_pagodaTaskReward,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this._pagodaMap = make(map[int64]*cfg.Game_pagodaData, 0)
|
||||||
|
configure.RegisterConfigure(game_pagoda, cfg.NewGame_pagoda, func() {
|
||||||
|
if v, err := this.GetConfigure(game_pagoda); err == nil {
|
||||||
|
if configure, ok := v.(*cfg.Game_pagoda); ok {
|
||||||
|
this.hlock.Lock()
|
||||||
|
defer this.hlock.Unlock()
|
||||||
|
for _, value := range configure.GetDataList() {
|
||||||
|
this._pagodaMap[int64(value.PagodaType<<16)+int64(value.LayerNum)] = value
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Errorf("get game_pagoda conf err:%v", err)
|
||||||
|
return
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取爬塔信息 参数1 塔类型 参数2 层数
|
||||||
|
func (this *configureComp) GetPagodaConfigData(PagodaType int32, floorId int32) (data *cfg.Game_pagodaData) {
|
||||||
|
|
||||||
|
return this._pagodaMap[int64(PagodaType<<16)+int64(floorId)]
|
||||||
|
}
|
||||||
|
|
||||||
//加载多个配置文件
|
//加载多个配置文件
|
||||||
func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) {
|
func (this *configureComp) LoadMultiConfigure(confs map[string]interface{}) (err error) {
|
||||||
for k, v := range confs {
|
for k, v := range confs {
|
||||||
err = configure.RegisterConfigure(k, v)
|
err = configure.RegisterConfigure(k, v, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("配置文件:%s解析失败!", k)
|
log.Errorf("配置文件:%s解析失败!", k)
|
||||||
break
|
break
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
"go_dreamfactory/modules/mail"
|
"go_dreamfactory/modules/mail"
|
||||||
"go_dreamfactory/modules/mainline"
|
"go_dreamfactory/modules/mainline"
|
||||||
"go_dreamfactory/modules/notify"
|
"go_dreamfactory/modules/notify"
|
||||||
|
"go_dreamfactory/modules/pagoda"
|
||||||
"go_dreamfactory/modules/shop"
|
"go_dreamfactory/modules/shop"
|
||||||
"go_dreamfactory/modules/task"
|
"go_dreamfactory/modules/task"
|
||||||
"go_dreamfactory/modules/user"
|
"go_dreamfactory/modules/user"
|
||||||
@ -57,6 +58,7 @@ func main() {
|
|||||||
chat.NewModule(),
|
chat.NewModule(),
|
||||||
gm.NewModule(),
|
gm.NewModule(),
|
||||||
forum.NewModule(),
|
forum.NewModule(),
|
||||||
|
pagoda.NewModule(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ var typeOfError = reflect.TypeOf((*error)(nil)).Elem()
|
|||||||
type configurehandle struct {
|
type configurehandle struct {
|
||||||
configureType reflect.Type
|
configureType reflect.Type
|
||||||
fn reflect.Value
|
fn reflect.Value
|
||||||
|
events []func()
|
||||||
}
|
}
|
||||||
|
|
||||||
func newSys(options Options) (sys *Configure, err error) {
|
func newSys(options Options) (sys *Configure, err error) {
|
||||||
@ -66,12 +67,16 @@ func (this *Configure) Stop() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//加载配置文件
|
//加载配置文件
|
||||||
func (this *Configure) RegisterConfigure(name string, fn interface{}) (err error) {
|
func (this *Configure) RegisterConfigure(name string, fn interface{}, callback func()) (err error) {
|
||||||
this.hlock.RLock()
|
this.hlock.RLock()
|
||||||
_, ok := this.configurehandles[name]
|
handle, ok := this.configurehandles[name]
|
||||||
this.hlock.RUnlock()
|
this.hlock.RUnlock()
|
||||||
if ok {
|
if ok {
|
||||||
// err = fmt.Errorf("重复 注册配置【%s】", name)
|
// err = fmt.Errorf("重复 注册配置【%s】", name)
|
||||||
|
if callback != nil {
|
||||||
|
handle.events = append(handle.events, callback)
|
||||||
|
callback()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fnvalue := reflect.ValueOf(fn)
|
fnvalue := reflect.ValueOf(fn)
|
||||||
@ -97,9 +102,10 @@ func (this *Configure) RegisterConfigure(name string, fn interface{}) (err error
|
|||||||
err = fmt.Errorf("LoadConfigure fn 类型错误! 只接受fn( _buf []map[string]interface{})(v,error) 函数参数")
|
err = fmt.Errorf("LoadConfigure fn 类型错误! 只接受fn( _buf []map[string]interface{})(v,error) 函数参数")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
handle := &configurehandle{
|
handle = &configurehandle{
|
||||||
configureType: dataType,
|
configureType: dataType,
|
||||||
fn: fnvalue,
|
fn: fnvalue,
|
||||||
|
events: []func(){callback},
|
||||||
}
|
}
|
||||||
if err = this.loaderConfigure(name, handle); err != nil {
|
if err = this.loaderConfigure(name, handle); err != nil {
|
||||||
return
|
return
|
||||||
@ -107,23 +113,10 @@ func (this *Configure) RegisterConfigure(name string, fn interface{}) (err error
|
|||||||
this.hlock.Lock()
|
this.hlock.Lock()
|
||||||
this.configurehandles[name] = handle
|
this.configurehandles[name] = handle
|
||||||
this.hlock.Unlock()
|
this.hlock.Unlock()
|
||||||
return
|
if callback != nil {
|
||||||
}
|
callback()
|
||||||
|
|
||||||
//更新配置信息
|
|
||||||
func (this *Configure) UpdateConfigure(names ...string) (err error) {
|
|
||||||
for _, v := range names {
|
|
||||||
this.hlock.RLock()
|
|
||||||
handle, ok := this.configurehandles[v]
|
|
||||||
this.hlock.RUnlock()
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err = this.loaderConfigure(v, handle); err != nil {
|
|
||||||
err = fmt.Errorf("loaderConfigure:%s err:%v", v, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,6 +191,9 @@ func (this *Configure) checkConfigure() {
|
|||||||
if err = this.loaderConfigure(v.Name, handle); err != nil {
|
if err = this.loaderConfigure(v.Name, handle); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
for _, v := range handle.events {
|
||||||
|
v()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,8 @@ type (
|
|||||||
ISys interface {
|
ISys interface {
|
||||||
Start() (err error)
|
Start() (err error)
|
||||||
Stop() (err error)
|
Stop() (err error)
|
||||||
RegisterConfigure(name string, fn interface{}) (err error) //注册配置
|
RegisterConfigure(name string, fn interface{}, callback func()) (err error) //注册配置
|
||||||
UpdateConfigure(names ...string) (err error) //更新配置
|
GetConfigure(name string) (v interface{}, err error) //获取配置
|
||||||
GetConfigure(name string) (v interface{}, err error) //获取配置
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -48,12 +47,8 @@ func Start() (err error) {
|
|||||||
func Stop() (err error) {
|
func Stop() (err error) {
|
||||||
return defsys.Stop()
|
return defsys.Stop()
|
||||||
}
|
}
|
||||||
func RegisterConfigure(name string, fn interface{}) (err error) {
|
func RegisterConfigure(name string, fn interface{}, callback func()) (err error) {
|
||||||
return defsys.RegisterConfigure(name, fn)
|
return defsys.RegisterConfigure(name, fn, callback)
|
||||||
}
|
|
||||||
|
|
||||||
func UpdateConfigure(names ...string) (err error) {
|
|
||||||
return defsys.UpdateConfigure(names...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetConfigure(name string) (v interface{}, err error) {
|
func GetConfigure(name string) (v interface{}, err error) {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// <auto-generated>
|
// <auto-generated>
|
||||||
// This code was generated by a tool.
|
// This code was generated by a tool.
|
||||||
@ -8,9 +9,8 @@
|
|||||||
package cfg
|
package cfg
|
||||||
|
|
||||||
type Game_pagoda struct {
|
type Game_pagoda struct {
|
||||||
_dataMap map[int32]*Game_pagodaData
|
_dataMap map[int32]*Game_pagodaData
|
||||||
_dataList []*Game_pagodaData
|
_dataList []*Game_pagodaData
|
||||||
_dataList1 map[int32]*Game_pagodaData
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGame_pagoda(_buf []map[string]interface{}) (*Game_pagoda, error) {
|
func NewGame_pagoda(_buf []map[string]interface{}) (*Game_pagoda, error) {
|
||||||
@ -24,17 +24,19 @@ func NewGame_pagoda(_buf []map[string]interface{}) (*Game_pagoda, error) {
|
|||||||
dataMap[_v.Key] = _v
|
dataMap[_v.Key] = _v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &Game_pagoda{_dataList: _dataList, _dataMap: dataMap}, nil
|
return &Game_pagoda{_dataList:_dataList, _dataMap:dataMap}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (table *Game_pagoda) GetDataMap() map[int32]*Game_pagodaData {
|
func (table *Game_pagoda) GetDataMap() map[int32]*Game_pagodaData {
|
||||||
return table._dataMap
|
return table._dataMap
|
||||||
}
|
}
|
||||||
|
|
||||||
func (table *Game_pagoda) GetDataList() []*Game_pagodaData {
|
func (table *Game_pagoda) GetDataList() []*Game_pagodaData {
|
||||||
return table._dataList
|
return table._dataList
|
||||||
}
|
}
|
||||||
|
|
||||||
func (table *Game_pagoda) Get(key int32) *Game_pagodaData {
|
func (table *Game_pagoda) Get(key int32) *Game_pagodaData {
|
||||||
return table._dataMap[key]
|
return table._dataMap[key]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ type Game_pagodaData struct {
|
|||||||
MonsterLv []int32
|
MonsterLv []int32
|
||||||
MonsterHp []float32
|
MonsterHp []float32
|
||||||
MonsterAtk []float32
|
MonsterAtk []float32
|
||||||
MonsterDef float32
|
MonsterDef []float32
|
||||||
Batch1 []int32
|
Batch1 []int32
|
||||||
Batch2 []int32
|
Batch2 []int32
|
||||||
Batch3 []int32
|
Batch3 []int32
|
||||||
@ -85,7 +85,20 @@ func NewGame_pagodaData(_buf map[string]interface{}) (_v *Game_pagodaData, err e
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["monster_def"].(float64); !_ok_ { err = errors.New("monster_def error"); return }; _v.MonsterDef = float32(_tempNum_) }
|
{
|
||||||
|
var _arr_ []interface{}
|
||||||
|
var _ok_ bool
|
||||||
|
if _arr_, _ok_ = _buf["monster_def"].([]interface{}); !_ok_ { err = errors.New("monster_def error"); return }
|
||||||
|
|
||||||
|
_v.MonsterDef = make([]float32, 0, len(_arr_))
|
||||||
|
|
||||||
|
for _, _e_ := range _arr_ {
|
||||||
|
var _list_v_ float32
|
||||||
|
{ var _ok_ bool; var _x_ float64; if _x_, _ok_ = _e_.(float64); !_ok_ { err = errors.New("_list_v_ error"); return }; _list_v_ = float32(_x_) }
|
||||||
|
_v.MonsterDef = append(_v.MonsterDef, _list_v_)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
var _arr_ []interface{}
|
var _arr_ []interface{}
|
||||||
var _ok_ bool
|
var _ok_ bool
|
||||||
|
@ -13,7 +13,7 @@ import "errors"
|
|||||||
type Game_pagodaTaskRewardData struct {
|
type Game_pagodaTaskRewardData struct {
|
||||||
Key int32
|
Key int32
|
||||||
PagodaType int32
|
PagodaType int32
|
||||||
LayerNum []int32
|
LayerNum int32
|
||||||
Reward []*Game_atn
|
Reward []*Game_atn
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,20 +25,7 @@ func NewGame_pagodaTaskRewardData(_buf map[string]interface{}) (_v *Game_pagodaT
|
|||||||
_v = &Game_pagodaTaskRewardData{}
|
_v = &Game_pagodaTaskRewardData{}
|
||||||
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["key"].(float64); !_ok_ { err = errors.New("key error"); return }; _v.Key = int32(_tempNum_) }
|
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["key"].(float64); !_ok_ { err = errors.New("key error"); return }; _v.Key = int32(_tempNum_) }
|
||||||
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["pagoda_type"].(float64); !_ok_ { err = errors.New("pagoda_type error"); return }; _v.PagodaType = int32(_tempNum_) }
|
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["pagoda_type"].(float64); !_ok_ { err = errors.New("pagoda_type error"); return }; _v.PagodaType = int32(_tempNum_) }
|
||||||
{
|
{ var _ok_ bool; var _tempNum_ float64; if _tempNum_, _ok_ = _buf["layer_num"].(float64); !_ok_ { err = errors.New("layer_num error"); return }; _v.LayerNum = int32(_tempNum_) }
|
||||||
var _arr_ []interface{}
|
|
||||||
var _ok_ bool
|
|
||||||
if _arr_, _ok_ = _buf["layer_num"].([]interface{}); !_ok_ { err = errors.New("layer_num error"); return }
|
|
||||||
|
|
||||||
_v.LayerNum = make([]int32, 0, len(_arr_))
|
|
||||||
|
|
||||||
for _, _e_ := range _arr_ {
|
|
||||||
var _list_v_ int32
|
|
||||||
{ var _ok_ bool; var _x_ float64; if _x_, _ok_ = _e_.(float64); !_ok_ { err = errors.New("_list_v_ error"); return }; _list_v_ = int32(_x_) }
|
|
||||||
_v.LayerNum = append(_v.LayerNum, _list_v_)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
var _arr_ []interface{}
|
var _arr_ []interface{}
|
||||||
var _ok_ bool
|
var _ok_ bool
|
||||||
|
Loading…
Reference in New Issue
Block a user