mirror of
https://github.com/Team254/cheesy-arena-lite.git
synced 2026-03-09 13:46:44 -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
|
return err
|
||||||
}
|
}
|
||||||
if len(alliances) > 0 {
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import "github.com/Team254/cheesy-arena-lite/game"
|
|||||||
type EventSettings struct {
|
type EventSettings struct {
|
||||||
Id int `db:"id"`
|
Id int `db:"id"`
|
||||||
Name string
|
Name string
|
||||||
|
ElimType string
|
||||||
NumElimAlliances int
|
NumElimAlliances int
|
||||||
SelectionRound2Order string
|
SelectionRound2Order string
|
||||||
SelectionRound3Order string
|
SelectionRound3Order string
|
||||||
@@ -52,6 +53,7 @@ func (database *Database) GetEventSettings() (*EventSettings, error) {
|
|||||||
// Database record doesn't exist yet; create it now.
|
// Database record doesn't exist yet; create it now.
|
||||||
eventSettings := EventSettings{
|
eventSettings := EventSettings{
|
||||||
Name: "Untitled Event",
|
Name: "Untitled Event",
|
||||||
|
ElimType: "single",
|
||||||
NumElimAlliances: 8,
|
NumElimAlliances: 8,
|
||||||
SelectionRound2Order: "L",
|
SelectionRound2Order: "L",
|
||||||
SelectionRound3Order: "",
|
SelectionRound3Order: "",
|
||||||
|
|||||||
@@ -14,10 +14,27 @@ func TestEventSettingsReadWrite(t *testing.T) {
|
|||||||
|
|
||||||
eventSettings, err := db.GetEventSettings()
|
eventSettings, err := db.GetEventSettings()
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, EventSettings{Id: 1, Name: "Untitled Event", NumElimAlliances: 8, SelectionRound2Order: "L",
|
assert.Equal(
|
||||||
SelectionRound3Order: "", TBADownloadEnabled: true, ApTeamChannel: 157, ApAdminChannel: 0,
|
t,
|
||||||
ApAdminWpaKey: "1234Five", WarmupDurationSec: 0, AutoDurationSec: 15, PauseDurationSec: 2,
|
EventSettings{
|
||||||
TeleopDurationSec: 135, WarningRemainingDurationSec: 30}, *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.Name = "Chezy Champs"
|
||||||
eventSettings.NumElimAlliances = 6
|
eventSettings.NumElimAlliances = 6
|
||||||
|
|||||||
@@ -24,10 +24,30 @@
|
|||||||
<input type="text" class="form-control" name="name" placeholder="{{.Name}}">
|
<input type="text" class="form-control" name="name" placeholder="{{.Name}}">
|
||||||
</div>
|
</div>
|
||||||
</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">
|
<div class="form-group">
|
||||||
<label class="col-lg-5 control-label">Number of Alliances</label>
|
<label class="col-lg-5 control-label">Number of Alliances</label>
|
||||||
<div class="col-lg-7">
|
<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>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
@@ -337,4 +357,13 @@
|
|||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{define "script"}}
|
{{define "script"}}
|
||||||
|
<script>
|
||||||
|
updateNumElimAlliances = function(isDoubleElimination) {
|
||||||
|
const numElimAlliances = $("input[name=numElimAlliances]");
|
||||||
|
numElimAlliances.prop("disabled", isDoubleElimination);
|
||||||
|
if (isDoubleElimination) {
|
||||||
|
numElimAlliances.val(8);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
@@ -41,10 +41,16 @@ func (web *Web) settingsPostHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
previousAdminPassword := eventSettings.AdminPassword
|
previousAdminPassword := eventSettings.AdminPassword
|
||||||
|
|
||||||
numAlliances, _ := strconv.Atoi(r.PostFormValue("numElimAlliances"))
|
eventSettings.ElimType = r.PostFormValue("elimType")
|
||||||
if numAlliances < 2 || numAlliances > 16 {
|
numAlliances := 0
|
||||||
web.renderSettings(w, r, "Number of alliances must be between 2 and 16.")
|
if eventSettings.ElimType == "double" {
|
||||||
return
|
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
|
eventSettings.NumElimAlliances = numAlliances
|
||||||
|
|||||||
@@ -39,6 +39,15 @@ func TestSetupSettings(t *testing.T) {
|
|||||||
assert.Contains(t, recorder.Body.String(), "tbasec")
|
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) {
|
func TestSetupSettingsInvalidValues(t *testing.T) {
|
||||||
web := setupTestWeb(t)
|
web := setupTestWeb(t)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user