151 lines
4.0 KiB
Go
151 lines
4.0 KiB
Go
package mainline
|
|
|
|
import (
|
|
"go_dreamfactory/comm"
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"sync"
|
|
)
|
|
|
|
const moduleName = "mline"
|
|
const (
|
|
game_mainchapter = "game_mainchapter.json"
|
|
game_mainstage = "game_mainstage.json"
|
|
game_mainstarreward = "game_mainstarreward.json"
|
|
)
|
|
|
|
// /配置管理基础组件
|
|
type configureComp struct {
|
|
modules.MCompConfigure
|
|
module *Mainline
|
|
lock sync.RWMutex
|
|
chapterMap map[int32][]*cfg.GameMainStageData
|
|
rewardMap map[int32][]*cfg.GameMainStarrewardData
|
|
}
|
|
|
|
// 组件初始化接口
|
|
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.(*Mainline)
|
|
err = this.LoadMultiConfigure(map[string]interface{}{
|
|
game_mainchapter: cfg.NewGameMainChapter,
|
|
})
|
|
this.chapterMap = make(map[int32][]*cfg.GameMainStageData)
|
|
configure.RegisterConfigure(game_mainstage, cfg.NewGameMainStage, this.updateMlineStage)
|
|
configure.RegisterConfigure(game_mainstarreward, cfg.NewGameMainStarreward, this.updateMlineReward)
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) getchapterMap() map[int32][]*cfg.GameMainStageData {
|
|
this.lock.Lock()
|
|
chapterMap := this.chapterMap
|
|
this.lock.RUnlock()
|
|
return chapterMap
|
|
}
|
|
|
|
func (this *configureComp) getrewardMap() map[int32][]*cfg.GameMainStarrewardData {
|
|
this.lock.Lock()
|
|
rewardMap := this.rewardMap
|
|
this.lock.Unlock()
|
|
return rewardMap
|
|
}
|
|
|
|
func (this *configureComp) updateMlineStage() {
|
|
var (
|
|
v interface{}
|
|
configure *cfg.GameMainStage
|
|
chapterMap map[int32][]*cfg.GameMainStageData
|
|
err error
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_mainstage); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if configure, ok = v.(*cfg.GameMainStage); ok {
|
|
chapterMap = make(map[int32][]*cfg.GameMainStageData)
|
|
for _, v := range configure.GetDataList() {
|
|
if _, ok = chapterMap[v.Chapterid]; !ok {
|
|
chapterMap[v.Chapterid] = make([]*cfg.GameMainStageData, 0)
|
|
}
|
|
chapterMap[v.Chapterid] = append(chapterMap[v.Chapterid], v)
|
|
}
|
|
}
|
|
this.lock.Lock()
|
|
this.chapterMap = chapterMap
|
|
this.lock.Unlock()
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) updateMlineReward() {
|
|
var (
|
|
v interface{}
|
|
configure *cfg.GameMainStarreward
|
|
rewardMap map[int32][]*cfg.GameMainStarrewardData
|
|
err error
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_mainstarreward); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if configure, ok = v.(*cfg.GameMainStarreward); ok {
|
|
rewardMap = make(map[int32][]*cfg.GameMainStarrewardData)
|
|
for _, v := range configure.GetDataList() {
|
|
if _, ok = rewardMap[v.Boxid]; !ok {
|
|
rewardMap[v.Boxid] = make([]*cfg.GameMainStarrewardData, 0)
|
|
}
|
|
rewardMap[v.Boxid] = append(rewardMap[v.Boxid], v)
|
|
}
|
|
}
|
|
this.lock.Lock()
|
|
this.rewardMap = rewardMap
|
|
this.lock.Unlock()
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetMainChapterConf(id int32) (conf *cfg.GameMainChapterData, err error) {
|
|
var (
|
|
v interface{}
|
|
ok bool
|
|
)
|
|
if v, err = this.GetConfigure(game_mainchapter); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
if conf, ok = v.(*cfg.GameMainChapter).GetDataMap()[id]; !ok {
|
|
err = comm.NewNotFoundConfErr(string(this.module.GetType()), game_mainchapter, id)
|
|
}
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetMainStageConfs() (data []*cfg.GameMainStageData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(game_mainstage); err != nil {
|
|
this.module.Errorln(err)
|
|
return
|
|
}
|
|
data = v.(*cfg.GameMainStage).GetDataList()
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetMainStageConf(id int32) (data *cfg.GameMainStageData, err error) {
|
|
var (
|
|
v interface{}
|
|
)
|
|
if v, err = this.GetConfigure(game_mainstage); err == nil {
|
|
if configure, ok := v.(*cfg.GameMainStage); ok {
|
|
data = configure.Get(id)
|
|
if data != nil {
|
|
return
|
|
}
|
|
}
|
|
}
|
|
err = comm.NewNotFoundConfErr(moduleName, game_mainstage, id)
|
|
return
|
|
}
|