mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 05:36:45 -04:00
Add setting to choose between single- and double-elimination.
This commit is contained in:
@@ -181,7 +181,14 @@ func (arena *Arena) CreatePlayoffBracket() error {
|
||||
return err
|
||||
}
|
||||
if len(alliances) > 0 {
|
||||
arena.PlayoffBracket, err = bracket.NewSingleEliminationBracket(len(alliances))
|
||||
switch arena.EventSettings.ElimType {
|
||||
case "single":
|
||||
arena.PlayoffBracket, err = bracket.NewSingleEliminationBracket(len(alliances))
|
||||
case "double":
|
||||
arena.PlayoffBracket, err = bracket.NewDoubleEliminationBracket(len(alliances))
|
||||
default:
|
||||
err = fmt.Errorf("Invalid playoff type: %v", arena.EventSettings.ElimType)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import "github.com/Team254/cheesy-arena-lite/game"
|
||||
type EventSettings struct {
|
||||
Id int `db:"id"`
|
||||
Name string
|
||||
ElimType string
|
||||
NumElimAlliances int
|
||||
SelectionRound2Order string
|
||||
SelectionRound3Order string
|
||||
@@ -52,6 +53,7 @@ func (database *Database) GetEventSettings() (*EventSettings, error) {
|
||||
// Database record doesn't exist yet; create it now.
|
||||
eventSettings := EventSettings{
|
||||
Name: "Untitled Event",
|
||||
ElimType: "single",
|
||||
NumElimAlliances: 8,
|
||||
SelectionRound2Order: "L",
|
||||
SelectionRound3Order: "",
|
||||
|
||||
@@ -14,10 +14,27 @@ func TestEventSettingsReadWrite(t *testing.T) {
|
||||
|
||||
eventSettings, err := db.GetEventSettings()
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, EventSettings{Id: 1, Name: "Untitled Event", NumElimAlliances: 8, SelectionRound2Order: "L",
|
||||
SelectionRound3Order: "", TBADownloadEnabled: true, ApTeamChannel: 157, ApAdminChannel: 0,
|
||||
ApAdminWpaKey: "1234Five", WarmupDurationSec: 0, AutoDurationSec: 15, PauseDurationSec: 2,
|
||||
TeleopDurationSec: 135, WarningRemainingDurationSec: 30}, *eventSettings)
|
||||
assert.Equal(
|
||||
t,
|
||||
EventSettings{
|
||||
Id: 1,
|
||||
Name: "Untitled Event",
|
||||
ElimType: "single",
|
||||
NumElimAlliances: 8,
|
||||
SelectionRound2Order: "L",
|
||||
SelectionRound3Order: "",
|
||||
TBADownloadEnabled: true,
|
||||
ApTeamChannel: 157,
|
||||
ApAdminChannel: 0,
|
||||
ApAdminWpaKey: "1234Five",
|
||||
WarmupDurationSec: 0,
|
||||
AutoDurationSec: 15,
|
||||
PauseDurationSec: 2,
|
||||
TeleopDurationSec: 135,
|
||||
WarningRemainingDurationSec: 30,
|
||||
},
|
||||
*eventSettings,
|
||||
)
|
||||
|
||||
eventSettings.Name = "Chezy Champs"
|
||||
eventSettings.NumElimAlliances = 6
|
||||
|
||||
@@ -24,10 +24,30 @@
|
||||
<input type="text" class="form-control" name="name" placeholder="{{.Name}}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-lg-5 control-label">Playoff Type</label>
|
||||
<div class="col-lg-7">
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input type="radio" name="elimType" value="single" onclick="updateNumElimAlliances(false);"
|
||||
{{if eq .ElimType "single"}}checked{{end}}>
|
||||
Single Elimination (2-16 alliances)
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input type="radio" name="elimType" value="double" onclick="updateNumElimAlliances(true);"
|
||||
{{if eq .ElimType "double"}}checked{{end}}>
|
||||
Double Elimination (8 alliances)
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-lg-5 control-label">Number of Alliances</label>
|
||||
<div class="col-lg-7">
|
||||
<input type="text" class="form-control" name="numElimAlliances" value="{{.NumElimAlliances}}">
|
||||
<input type="text" class="form-control" name="numElimAlliances" value="{{.NumElimAlliances}}"
|
||||
{{if eq .ElimType "double"}}disabled{{end}}>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
@@ -337,4 +357,13 @@
|
||||
</div>
|
||||
{{end}}
|
||||
{{define "script"}}
|
||||
<script>
|
||||
updateNumElimAlliances = function(isDoubleElimination) {
|
||||
const numElimAlliances = $("input[name=numElimAlliances]");
|
||||
numElimAlliances.prop("disabled", isDoubleElimination);
|
||||
if (isDoubleElimination) {
|
||||
numElimAlliances.val(8);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
{{end}}
|
||||
|
||||
@@ -41,10 +41,16 @@ func (web *Web) settingsPostHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
previousAdminPassword := eventSettings.AdminPassword
|
||||
|
||||
numAlliances, _ := strconv.Atoi(r.PostFormValue("numElimAlliances"))
|
||||
if numAlliances < 2 || numAlliances > 16 {
|
||||
web.renderSettings(w, r, "Number of alliances must be between 2 and 16.")
|
||||
return
|
||||
eventSettings.ElimType = r.PostFormValue("elimType")
|
||||
numAlliances := 0
|
||||
if eventSettings.ElimType == "double" {
|
||||
numAlliances = 8
|
||||
} else {
|
||||
numAlliances, _ = strconv.Atoi(r.PostFormValue("numElimAlliances"))
|
||||
if numAlliances < 2 || numAlliances > 16 {
|
||||
web.renderSettings(w, r, "Number of alliances must be between 2 and 16.")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
eventSettings.NumElimAlliances = numAlliances
|
||||
|
||||
@@ -39,6 +39,15 @@ func TestSetupSettings(t *testing.T) {
|
||||
assert.Contains(t, recorder.Body.String(), "tbasec")
|
||||
}
|
||||
|
||||
func TestSetupSettingsDoubleElimination(t *testing.T) {
|
||||
web := setupTestWeb(t)
|
||||
|
||||
recorder := web.postHttpResponse("/setup/settings", "elimType=double&numElimAlliances=3")
|
||||
assert.Equal(t, 303, recorder.Code)
|
||||
assert.Equal(t, "double", web.arena.EventSettings.ElimType)
|
||||
assert.Equal(t, 8, web.arena.EventSettings.NumElimAlliances)
|
||||
}
|
||||
|
||||
func TestSetupSettingsInvalidValues(t *testing.T) {
|
||||
web := setupTestWeb(t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user