From 32364560897f9f0f9651c5ff83801e0e4b07ddd7 Mon Sep 17 00:00:00 2001 From: Patrick Fairbank Date: Sun, 24 Jul 2022 16:50:41 -0700 Subject: [PATCH] Allow setting a custom name for a test match. --- field/arena.go | 2 +- static/js/audience_display.js | 33 ++++++++++++++++++++------------- static/js/match_play.js | 5 +++++ templates/match_play.html | 5 +++++ web/match_play.go | 13 +++++++++++++ 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/field/arena.go b/field/arena.go index 30f2d18..ac0b778 100755 --- a/field/arena.go +++ b/field/arena.go @@ -219,7 +219,7 @@ func (arena *Arena) LoadMatch(match *model.Match) error { // Sets a new test match containing no teams as the current match. func (arena *Arena) LoadTestMatch() error { - return arena.LoadMatch(&model.Match{Type: "test"}) + return arena.LoadMatch(&model.Match{Type: "test", DisplayName: "Test Match"}) } // Loads the first unplayed match of the current match type. diff --git a/static/js/audience_display.js b/static/js/audience_display.js index 889ae5f..aa1cee4 100644 --- a/static/js/audience_display.js +++ b/static/js/audience_display.js @@ -9,6 +9,7 @@ var transitionMap; var currentScreen = "blank"; var redSide; var blueSide; +var currentMatch; var overlayCenteringHideParams; var overlayCenteringShowParams; var allianceSelectionTemplate = Handlebars.compile($("#allianceSelectionTemplate").html()); @@ -54,19 +55,25 @@ var handleAudienceDisplayMode = function(targetScreen) { // Handles a websocket message to update the teams for the current match. var handleMatchLoad = function(data) { - $("#" + redSide + "Team1").text(data.Match.Red1); - $("#" + redSide + "Team2").text(data.Match.Red2); - $("#" + redSide + "Team3").text(data.Match.Red3); - $("#" + redSide + "Team1Avatar").attr("src", getAvatarUrl(data.Match.Red1)); - $("#" + redSide + "Team2Avatar").attr("src", getAvatarUrl(data.Match.Red2)); - $("#" + redSide + "Team3Avatar").attr("src", getAvatarUrl(data.Match.Red3)); - $("#" + blueSide + "Team1").text(data.Match.Blue1); - $("#" + blueSide + "Team2").text(data.Match.Blue2); - $("#" + blueSide + "Team3").text(data.Match.Blue3); - $("#" + blueSide + "Team1Avatar").attr("src", getAvatarUrl(data.Match.Blue1)); - $("#" + blueSide + "Team2Avatar").attr("src", getAvatarUrl(data.Match.Blue2)); - $("#" + blueSide + "Team3Avatar").attr("src", getAvatarUrl(data.Match.Blue3)); - $("#matchName").text(data.MatchType + " " + data.Match.DisplayName); + currentMatch = data.Match; + $("#" + redSide + "Team1").text(currentMatch.Red1); + $("#" + redSide + "Team2").text(currentMatch.Red2); + $("#" + redSide + "Team3").text(currentMatch.Red3); + $("#" + redSide + "Team1Avatar").attr("src", getAvatarUrl(currentMatch.Red1)); + $("#" + redSide + "Team2Avatar").attr("src", getAvatarUrl(currentMatch.Red2)); + $("#" + redSide + "Team3Avatar").attr("src", getAvatarUrl(currentMatch.Red3)); + $("#" + blueSide + "Team1").text(currentMatch.Blue1); + $("#" + blueSide + "Team2").text(currentMatch.Blue2); + $("#" + blueSide + "Team3").text(currentMatch.Blue3); + $("#" + blueSide + "Team1Avatar").attr("src", getAvatarUrl(currentMatch.Blue1)); + $("#" + blueSide + "Team2Avatar").attr("src", getAvatarUrl(currentMatch.Blue2)); + $("#" + blueSide + "Team3Avatar").attr("src", getAvatarUrl(currentMatch.Blue3)); + + if (data.Match.Type === "test") { + $("#matchName").text(currentMatch.DisplayName); + } else { + $("#matchName").text(data.MatchType + " " + currentMatch.DisplayName); + } }; // Handles a websocket message to update the match time countdown. diff --git a/static/js/match_play.js b/static/js/match_play.js index 3f019b5..5978f2d 100755 --- a/static/js/match_play.js +++ b/static/js/match_play.js @@ -97,6 +97,11 @@ var confirmCommit = function(isReplay) { } }; +// Sends a websocket message to specify a custom name for the current test match. +var setTestMatchName = function() { + websocket.send("setTestMatchName", $("#testMatchName").val()); +}; + // Handles a websocket message to update the team connection status. var handleArenaStatus = function(data) { // If getting data for the wrong match (e.g. after a server restart), reload the page. diff --git a/templates/match_play.html b/templates/match_play.html index fc2dded..bbdbd31 100755 --- a/templates/match_play.html +++ b/templates/match_play.html @@ -283,6 +283,11 @@ + {{if eq .Match.Type "test" }} +

+

Match Name

+ + {{end}}
diff --git a/web/match_play.go b/web/match_play.go index c7aa356..c7b98fc 100755 --- a/web/match_play.go +++ b/web/match_play.go @@ -326,6 +326,19 @@ func (web *Web) matchPlayWebsocketHandler(w http.ResponseWriter, r *http.Request ws.WriteError(err.Error()) continue } + case "setTestMatchName": + if web.arena.CurrentMatch.Type != "test" { + // Don't allow changing the name of a non-test match. + continue + } + name, ok := data.(string) + if !ok { + ws.WriteError(fmt.Sprintf("Failed to parse '%s' message.", messageType)) + continue + } + web.arena.CurrentMatch.DisplayName = name + web.arena.MatchLoadNotifier.Notify() + continue case "updateRealtimeScore": args := data.(map[string]interface{}) web.arena.BlueScore.AutoPoints = int(args["blueAuto"].(float64))