You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
775 B
Go

package manager
import (
"errors"
"git.noahlan.cn/northlan/ngs/session"
)
type DataManager struct {
}
func NewDataManager() *DataManager {
return &DataManager{}
}
func (m *DataManager) SessionGameStatus(session *session.Session, status GameStatus) GameStatus {
if data, err := m.SessionData(session); err != nil {
return GameEnded
} else {
return data.SetStatus(status)
}
}
func (m *DataManager) SessionData(session *session.Session) (*GameData, error) {
if !session.HasKey(DataKey) {
return nil, errors.New("session中无data数据")
}
return session.Value(DataKey).(*GameData), nil
}
func (m *DataManager) BattleIdBySession(session *session.Session) int64 {
data, err := m.SessionData(session)
if err != nil {
return 0
}
return data.BattleId()
}