package data import ( "f1-game/internal/types" cprofile "github.com/cherry-game/cherry/profile" ) var GameDebug = &gameDebugConfig{} func init() { _allList = append(_allList, GameDebug) } type ( GameDebugRow struct { Env string `json:"Env"` // 环境 Debug bool `json:"Debug"` // 是否开启调试 Values types.Map[string, int64] `json:"Values"` // 调试值 } gameDebugConfig struct { baseConfig list []*GameDebugRow // all list maps map[string]*GameDebugRow // key:env } ) func (p *gameDebugConfig) Name() string { return "game_debug" } func (p *gameDebugConfig) Init() { p.maps = map[string]*GameDebugRow{} } func (p *gameDebugConfig) OnLoad(maps interface{}, reload bool) (int, error) { if reload && p.denyLoad { return 0, nil } var list []*GameDebugRow if err := DecodeData(maps, &list); err != nil { return 0, err } p.list = list m := map[string]*GameDebugRow{} for _, row := range list { m[row.Env] = row } p.maps = m return len(list), nil } // func (p *chapterRewardConfig) OnAfterLoad(_ bool) { // } func (p *gameDebugConfig) List() []*GameDebugRow { return p.list } func (p *gameDebugConfig) GetByEnv(env string) (*GameDebugRow, bool) { mapItem, found := p.maps[env] if !found { return nil, false } return mapItem, found } func (p *gameDebugConfig) GetDebugValue(key string) (int64, bool) { row, ok := p.GetByEnv(cprofile.Env()) if !ok || !row.Debug { return 0, false } return row.Values.Get(key) }