Files
cheesy-arena-lite/model/event_settings.go

79 lines
2.6 KiB
Go
Raw Normal View History

2014-05-24 17:58:57 -07:00
// Copyright 2014 Team 254. All Rights Reserved.
// Author: pat@patfairbank.com (Patrick Fairbank)
//
// Model and datastore read/write methods for event-level configuration.
package model
2014-05-24 17:58:57 -07:00
2021-05-16 11:00:29 -07:00
import "github.com/Team254/cheesy-arena-lite/game"
2014-05-24 17:58:57 -07:00
type EventSettings struct {
Id int64 `db:"id"`
2020-03-15 22:24:23 -07:00
Name string
NumElimAlliances int
SelectionRound2Order string
SelectionRound3Order string
TBADownloadEnabled bool
TbaPublishingEnabled bool
TbaEventCode string
TbaSecretId string
TbaSecret string
NetworkSecurityEnabled bool
ApAddress string
ApUsername string
ApPassword string
ApTeamChannel int
ApAdminChannel int
ApAdminWpaKey string
Ap2Address string
Ap2Username string
Ap2Password string
Ap2TeamChannel int
SwitchAddress string
SwitchPassword string
PlcAddress string
AdminPassword string
WarmupDurationSec int
AutoDurationSec int
PauseDurationSec int
TeleopDurationSec int
WarningRemainingDurationSec int
2014-05-24 17:58:57 -07:00
}
func (database *Database) GetEventSettings() (*EventSettings, error) {
var allEventSettings []EventSettings
if err := database.eventSettingsTable.getAll(&allEventSettings); err != nil {
return nil, err
}
if len(allEventSettings) == 1 {
return &allEventSettings[0], nil
}
// Database record doesn't exist yet; create it now.
eventSettings := EventSettings{
Name: "Untitled Event",
NumElimAlliances: 8,
SelectionRound2Order: "L",
SelectionRound3Order: "",
TBADownloadEnabled: true,
ApTeamChannel: 157,
ApAdminChannel: 0,
ApAdminWpaKey: "1234Five",
Ap2TeamChannel: 0,
WarmupDurationSec: game.MatchTiming.WarmupDurationSec,
AutoDurationSec: game.MatchTiming.AutoDurationSec,
PauseDurationSec: game.MatchTiming.PauseDurationSec,
TeleopDurationSec: game.MatchTiming.TeleopDurationSec,
WarningRemainingDurationSec: game.MatchTiming.WarningRemainingDurationSec,
}
2016-07-29 23:17:39 -07:00
if err := database.eventSettingsTable.create(&eventSettings); err != nil {
return nil, err
2014-05-24 17:58:57 -07:00
}
return &eventSettings, nil
2014-05-24 17:58:57 -07:00
}
func (database *Database) UpdateEventSettings(eventSettings *EventSettings) error {
return database.eventSettingsTable.update(eventSettings)
2014-05-24 17:58:57 -07:00
}