go_dreamfactory/modules/linestory/config.go
2022-11-15 19:39:38 +08:00

112 lines
2.5 KiB
Go

package linestory
import (
"fmt"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/log"
"go_dreamfactory/modules"
cfg "go_dreamfactory/sys/configure/structs"
)
const (
gameLinestoryTimeline = "game_linestorytimeline.json"
gameLinestoryMainTask = "game_linestorymaintask.json"
)
type configureComp struct {
modules.MCompConfigure
}
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)
err = this.LoadMultiConfigure(map[string]interface{}{
gameLinestoryTimeline: cfg.NewGameLinestoryTimeLine,
gameLinestoryMainTask: cfg.NewGameLinestoryMainTask,
})
return
}
func (this *configureComp) getLinestoryTimelineCfg() (data *cfg.GameLinestoryTimeLine, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(gameLinestoryTimeline); err != nil {
return
} else {
if data, ok = v.(*cfg.GameLinestoryTimeLine); !ok {
err = fmt.Errorf("%T no is *cfg.GameLineStoryChapter", v)
return
}
}
return
}
func (this *configureComp) getLinestoryMainTaskCfg() (data *cfg.GameLinestoryMainTask, err error) {
var (
v interface{}
ok bool
)
if v, err = this.GetConfigure(gameLinestoryMainTask); err != nil {
return
} else {
if data, ok = v.(*cfg.GameLinestoryMainTask); !ok {
err = fmt.Errorf("%T no is *cfg.GameLineStoryTask", v)
return
}
}
return
}
func (this *configureComp) getChapterCfgById(id int32) (data *cfg.GameLinestoryTimeLineData) {
if cfg, err := this.getLinestoryTimelineCfg(); err != nil {
log.Errorf("%v", err)
return
} else {
if cfg != nil {
data = cfg.GetDataMap()[id]
}
}
return
}
func (this *configureComp) getMainTaskCfgById(id int32) (data *cfg.GameLinestoryMainTaskData) {
if cfg, err := this.getLinestoryMainTaskCfg(); err != nil {
log.Errorf("%v", err)
return
} else {
if cfg != nil {
data = cfg.GetDataMap()[id]
}
}
return
}
func (this *configureComp) getMainTaskCfgByGroup(groupId int32) (data []*cfg.GameLinestoryMainTaskData) {
if cfg, err := this.getLinestoryMainTaskCfg(); err != nil {
log.Errorf("%v", err)
return
} else {
if cfg != nil {
for _, v := range cfg.GetDataList() {
if v.Group == groupId {
data = append(data, v)
}
}
}
}
return
}
func (this *configureComp) converArr(groupId int32) (taskIds []int32) {
data := this.getMainTaskCfgByGroup(groupId)
if data != nil {
for _, v := range data {
if v.Group == groupId {
taskIds = append(taskIds, v.Id)
}
}
}
return
}