98 lines
2.9 KiB
Go
98 lines
2.9 KiB
Go
package mainline
|
|
|
|
import (
|
|
"go_dreamfactory/lego/core"
|
|
"go_dreamfactory/lego/sys/log"
|
|
"go_dreamfactory/modules"
|
|
"go_dreamfactory/sys/configure"
|
|
cfg "go_dreamfactory/sys/configure/structs"
|
|
"sync"
|
|
)
|
|
|
|
const (
|
|
game_mainlinechapter = "game_mainlinechapter.json"
|
|
game_mainline = "game_mainline.json"
|
|
)
|
|
|
|
///配置管理基础组件
|
|
type configureComp struct {
|
|
modules.MCompConfigure
|
|
module *Mainline
|
|
hlock sync.RWMutex
|
|
_mapMainline map[int64]*cfg.GameMainlineData
|
|
_mapMainlineNextC map[int64]*cfg.GameMainlineData // 获取下一章节的对象
|
|
}
|
|
|
|
//组件初始化接口
|
|
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_mainlinechapter: cfg.NewGameMainlineChapter,
|
|
})
|
|
this._mapMainline = make(map[int64]*cfg.GameMainlineData, 0)
|
|
this._mapMainlineNextC = make(map[int64]*cfg.GameMainlineData, 0)
|
|
configure.RegisterConfigure(game_mainline, cfg.NewGameMainline, this.GetMainline)
|
|
|
|
this.module.modelMainline.checkNewCapter(1, 1, 110)
|
|
return
|
|
}
|
|
|
|
func (this *configureComp) GetMainline() {
|
|
if v, err := this.GetConfigure(game_mainline); err == nil {
|
|
if configure, ok := v.(*cfg.GameMainline); ok {
|
|
this.hlock.Lock()
|
|
defer this.hlock.Unlock()
|
|
for _, value := range configure.GetDataList() {
|
|
this._mapMainline[int64(value.Id<<16)+int64(value.Intensity)] = value
|
|
}
|
|
for _, value := range configure.GetDataList() {
|
|
if _, ok := this._mapMainlineNextC[int64(value.Intensity<<16)+int64(value.Chapter)]; !ok {
|
|
this._mapMainlineNextC[int64(value.Intensity<<16)+int64(value.Chapter)] = value
|
|
}
|
|
}
|
|
return
|
|
}
|
|
} else {
|
|
log.Errorf("get game_pagoda conf err:%v", err)
|
|
}
|
|
return
|
|
}
|
|
|
|
// id + intensity
|
|
func (this *configureComp) GetMainlineConfigData(id, intensity int32) *cfg.GameMainlineData {
|
|
return this._mapMainline[int64(id<<16)+int64(intensity)]
|
|
}
|
|
|
|
// intensity + chapter
|
|
func (this *configureComp) GetMainlineChapterConfigData(intensity, chapter int32) *cfg.GameMainlineData {
|
|
return this._mapMainlineNextC[int64(intensity<<16)+int64(chapter)]
|
|
}
|
|
|
|
//读取配置数据
|
|
func (this *configureComp) GetConfigure(name string) (v interface{}, err error) {
|
|
return configure.GetConfigure(name)
|
|
|
|
}
|
|
|
|
func (this *configureComp) GetMainlineChapter(id int32) (data *cfg.GameMainlineChapterData) {
|
|
if v, err := this.GetConfigure(game_mainlinechapter); err != nil {
|
|
this.module.Errorf("get global conf err:%v", err)
|
|
return
|
|
} else {
|
|
var (
|
|
configure *cfg.GameMainlineChapter
|
|
ok bool
|
|
)
|
|
if configure, ok = v.(*cfg.GameMainlineChapter); !ok {
|
|
this.module.Errorf("%T no is *cfg.Game_MainlineChapterData", v)
|
|
return
|
|
}
|
|
|
|
if data, ok = configure.GetDataMap()[id]; ok {
|
|
return
|
|
}
|
|
}
|
|
return
|
|
}
|