Allow setting a custom name for a test match.

This commit is contained in:
Patrick Fairbank
2022-07-24 16:50:41 -07:00
parent c78c5323bb
commit 3236456089
5 changed files with 44 additions and 14 deletions

View File

@@ -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.

View File

@@ -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.

View File

@@ -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.

View File

@@ -283,6 +283,11 @@
<button type="button" id="startTimeout" class="btn btn-info btn-xs" onclick="startTimeout();">
Start
</button>
{{if eq .Match.Type "test" }}
<br /><br />
<p>Match Name</p>
<input type="text" id="testMatchName" value="{{.Match.DisplayName}}" onblur="setTestMatchName();" />
{{end}}
</div>
</div>
<div class="row">

View File

@@ -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))