75 lines
1.7 KiB
Go
75 lines
1.7 KiB
Go
package entertainment
|
|
|
|
import (
|
|
"fmt"
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"sync"
|
|
|
|
"go_dreamfactory/lego/core"
|
|
)
|
|
|
|
const (
|
|
game_block = "game_block.json"
|
|
)
|
|
|
|
// /配置管理组件
|
|
type configureComp struct {
|
|
modules.MCompConfigure
|
|
module *Entertainment
|
|
lock sync.RWMutex
|
|
block map[int32]*cfg.GameBlockData
|
|
}
|
|
|
|
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.(*Entertainment)
|
|
err = this.LoadMultiConfigure(map[string]interface{}{
|
|
game_block: cfg.NewGameBlock,
|
|
})
|
|
|
|
configure.RegisterConfigure(game_block, cfg.NewGameBlock, this.LoadGameBlock)
|
|
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) LoadGameBlock() {
|
|
var (
|
|
v interface{}
|
|
configure *cfg.GameBlock
|
|
err error
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_block); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
block := make(map[int32]*cfg.GameBlockData)
|
|
if configure, ok = v.(*cfg.GameBlock); ok {
|
|
for _, v := range configure.GetDataList() {
|
|
key := v.Color<<8 + v.Type
|
|
block[key] = v
|
|
}
|
|
}
|
|
this.lock.Lock()
|
|
this.block = block
|
|
this.lock.Unlock()
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetGameBlock(color int32, iType int32) (conf *cfg.GameBlockData, err error) {
|
|
var (
|
|
ok bool
|
|
key int32
|
|
)
|
|
key = color<<8 + iType
|
|
this.lock.RLock()
|
|
defer this.lock.RUnlock()
|
|
if conf, ok = this.block[key]; !ok {
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_block, fmt.Sprintf("color:%d,itype:%d", color, key))
|
|
}
|
|
return
|
|
}
|