go_dreamfactory/modules/mline/comp_configure.go
2023-05-29 19:39:31 +08:00

145 lines
3.8 KiB
Go

package mline
import (
"go_dreamfactory/comm"
"go_dreamfactory/lego/core"
"go_dreamfactory/modules"
"go_dreamfactory/sys/configure"
cfg "go_dreamfactory/sys/configure/structs"
)
const (
game_mainchapter = "game_mainchapter.json"
game_mainstage = "game_mainstage.json"
game_mainstarreward = "game_mainstarreward.json"
)
///配置管理基础组件
type configureComp struct {
modules.MCompConfigure
module *Mline
}
//组件初始化接口
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(stageId int32) (preStageID int32) {
if v, err := this.GetConfigure(game_mainstage); err == nil {
if configure, ok := v.(*cfg.GameMainStage); ok {
for _, v1 := range configure.GetDataList() {
if v1.Previoustage == stageId {
preStageID = v1.Id
break
}
}
}
}
return
}
func (this *configureComp) GetFirstChapterIDByType(iType int32) (conf *cfg.GameMainChapterData, err error) {
var (
v interface{}
)
if v, err = this.GetConfigure(game_mainchapter); err == nil {
if configure, ok := v.(*cfg.GameMainChapter); ok {
for _, conf = range configure.GetDataList() {
if conf.ChapterType == iType {
return
}
}
}
}
err = comm.NewNotFoundConfErr("mline", game_mainchapter, iType)
return
}
func (this *configureComp) GetFirstStageIDByChapter(chapterID 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.Chapterid == chapterID {
return v
}
}
}
}
return nil
}
// 红点用 获取所有章节数据
func (this *configureComp) GetAllChapterID() (chapter []int32) {
if v, err := this.GetConfigure(game_mainchapter); err == nil {
if configure, ok := v.(*cfg.GameMainChapter); ok {
for _, v1 := range configure.GetDataList() {
chapter = append(chapter, v1.Id)
}
}
}
return
}
// 红点用 获取所有类型为1 的小关ID
func (this *configureComp) GetAllStageByChapterID(chapterID int32) (stage []int32) {
if v, err := this.GetConfigure(game_mainstage); err == nil {
if configure, ok := v.(*cfg.GameMainStage); ok {
for _, v1 := range configure.GetDataList() {
if v1.Episodetype == 1 {
stage = append(stage, v1.Id)
}
}
}
}
return
}