go_dreamfactory/modules/mline/comp_configure.go
2023-01-06 19:51:00 +08:00

131 lines
3.3 KiB
Go

package mline
import (
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
"sync"
)
const (
game_mainchapter = "game_mainchapter.json"
game_mainstage = "game_mainstage.json"
game_mainstarreward = "game_mainstarreward.json"
)
///配置管理基础组件
type configureComp struct {
modules.MCompConfigure
module *Mline
hlock sync.RWMutex
}
//组件初始化接口
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.(*Mline)
err = this.LoadMultiConfigure(map[string]interface{}{
game_mainchapter: cfg.NewGameMainChapter,
game_mainstage: cfg.NewGameMainStage,
game_mainstarreward: cfg.NewGameMainStarreward,
})
return
}
//读取配置数据
func (this *configureComp) GetConfigure(name string) (v interface{}, err error) {
return configure.GetConfigure(name)
}
func (this *configureComp) GetMainChapterConf(id int32) (data *cfg.GameMainChapterData) {
if v, err := this.GetConfigure(game_mainchapter); err == nil {
if configure, ok := v.(*cfg.GameMainChapter); ok {
return configure.Get(id)
}
}
this.module.Errorf("GameMainChapterData conf not found key :%d", id)
return
}
func (this *configureComp) GetMainStarRewardConf(boxId int32) (data []*cfg.GameMainStarrewardData) {
if v, err := this.GetConfigure(game_mainstarreward); err == nil {
if configure, ok := v.(*cfg.GameMainStarreward); ok {
for _, v1 := range configure.GetDataList() {
if v1.Boxid == boxId {
data = append(data, v1)
}
}
}
}
return
}
func (this *configureComp) GetMainStageConf(id int32) (data *cfg.GameMainStageData) {
if v, err := this.GetConfigure(game_mainstage); err == nil {
if configure, ok := v.(*cfg.GameMainStage); ok {
return configure.Get(id)
}
}
this.module.Errorf("GameMainStageData conf not found key :%d", id)
return
}
// 获取上一章节信息
func (this *configureComp) GetPreMainChapter(id int32) (stageID int32) {
if v, err := this.GetConfigure(game_mainchapter); err == nil {
if configure, ok := v.(*cfg.GameMainChapter); ok {
for index, v1 := range configure.GetDataList() {
if v1.Id == id {
if index > 0 {
data := configure.GetDataList()[index-1]
if v1.ChapterType != data.ChapterType { // 章节类型必须一致
stageID = data.Id
}
} else { // 第一章节
stageID = 0
}
break
}
}
}
}
return
}
// 获取该章节最后一关ID
func (this *configureComp) GetLastStageIDByChapter(id int32) (stageID int32) {
var (
sz []int32
)
if v, err := this.GetConfigure(game_mainstage); err == nil {
if configure, ok := v.(*cfg.GameMainStage); ok {
for _, v := range configure.GetDataList() {
if v.Chapterid == id {
sz = append(sz, v.Id)
}
}
}
}
if len(sz) > 0 {
stageID = sz[len(sz)-1]
}
return stageID
}
func (this *configureComp) GetFirstStageIDByChapter(iType int32) *cfg.GameMainStageData {
if v, err := this.GetConfigure(game_mainstage); err == nil {
if configure, ok := v.(*cfg.GameMainStage); ok {
for _, v := range configure.GetDataList() {
if v.Episodetype == iType {
return v
}
}
}
}
return nil
}