|
|
@ -25,20 +25,29 @@ import (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// /savedata/newclear - return whether a session is a new clear for its seed
|
|
|
|
// /savedata/newclear - return whether a session is a new clear for its seed
|
|
|
|
func NewClear(uuid []byte, slot int) (bool, error) {
|
|
|
|
func NewClear(uuid []byte, slot int, result bool) (bool, error) {
|
|
|
|
if slot < 0 || slot >= defs.SessionSlotCount {
|
|
|
|
if slot < 0 || slot >= defs.SessionSlotCount {
|
|
|
|
return false, fmt.Errorf("slot id %d out of range", slot)
|
|
|
|
return false, fmt.Errorf("slot id %d out of range", slot)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
session, err := db.ReadSessionSaveData(uuid, slot)
|
|
|
|
session, err := db.ReadSessionSaveData(uuid, slot)
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gameMode := getGameModeKey(session.GameMode)
|
|
|
|
|
|
|
|
waveIndex := fmt.Sprintf("%d", session.WaveIndex)
|
|
|
|
|
|
|
|
completed := true
|
|
|
|
|
|
|
|
if result {
|
|
|
|
|
|
|
|
runResultCounter.WithLabelValues("victory", waveIndex, gameMode).Inc()
|
|
|
|
completed, err := db.ReadSeedCompleted(uuid, session.Seed)
|
|
|
|
completed, err := db.ReadSeedCompleted(uuid, session.Seed)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return false, fmt.Errorf("failed to read seed completed: %s", err)
|
|
|
|
return false, fmt.Errorf("failed to read seed completed: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return !completed, err
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
runResultCounter.WithLabelValues("loss", waveIndex, gameMode).Inc()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return !completed, nil
|
|
|
|
return !completed, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|