Added display of running tournaments to Hall UI.

This commit is contained in:
marcins78
2013-01-02 16:32:54 +00:00
parent 0fc67d0a0e
commit db53135844
10 changed files with 207 additions and 21 deletions

View File

@@ -14,6 +14,10 @@ public interface HallChannelVisitor {
public void updateTournamentQueue(String queueId, Map<String, String> props);
public void removeTournamentQueue(String queueId);
public void addTournament(String tournamentId, Map<String, String> props);
public void updateTournament(String tournamentId, Map<String, String> props);
public void removeTournament(String tournamentId);
public void addTable(String tableId, Map<String, String> props);
public void updateTable(String tableId, Map<String, String> props);
public void removeTable(String tableId);

View File

@@ -14,6 +14,7 @@ public class HallCommunicationChannel {
private long _lastConsumed;
private String _lastMotd;
private Map<String, Map<String, String>> _tournamentQueuePropsOnClient = new LinkedHashMap<String, Map<String, String>>();
private Map<String, Map<String, String>> _tournamentPropsOnClient = new LinkedHashMap<String, Map<String, String>>();
private Map<String, Map<String, String>> _tablePropsOnClient = new LinkedHashMap<String, Map<String, String>>();
public HallCommunicationChannel(int channelNumber) {
@@ -32,8 +33,9 @@ public class HallCommunicationChannel {
hallChannelVisitor.channelNumber(_channelNumber);
final MutableObject newMotd = new MutableObject();
final Map<String, Map<String, String>> tournamentsOnServer = new LinkedHashMap<String, Map<String, String>>();
final Map<String, Map<String, String>> tournamentQueuesOnServer = new LinkedHashMap<String, Map<String, String>>();
final Map<String, Map<String, String>> tablesOnServer = new LinkedHashMap<String, Map<String, String>>();
final Map<String, Map<String, String>> tournamentsOnServer = new LinkedHashMap<String, Map<String, String>>();
hallServer.processHall(player,
new HallInfoVisitor() {
@@ -82,7 +84,23 @@ public class HallCommunicationChannel {
props.put("start", startCondition);
props.put("signedUp", String.valueOf(playerSignedUp));
tournamentsOnServer.put(tournamentQueueKey, props);
tournamentQueuesOnServer.put(tournamentQueueKey, props);
}
@Override
public void visitTournament(String tournamentKey, String collectionName, String formatName, String tournamentName, String pairingDescription,
String tournamentStage, int round, int playerCount, boolean playerInCompetition) {
Map<String, String> props = new HashMap<String, String>();
props.put("collection", collectionName);
props.put("format", formatName);
props.put("name", tournamentName);
props.put("system", pairingDescription);
props.put("stage", tournamentStage);
props.put("round", String.valueOf(round));
props.put("playerCount", String.valueOf(playerCount));
props.put("signedUp", String.valueOf(playerInCompetition));
tournamentsOnServer.put(tournamentKey, props);
}
@Override
@@ -91,24 +109,22 @@ public class HallCommunicationChannel {
}
});
for (Map.Entry<String, Map<String, String>> tournamentQueueOnClient : _tournamentQueuePropsOnClient.entrySet()) {
String tournamentQueueId = tournamentQueueOnClient.getKey();
Map<String, String> tournamentProps = tournamentQueueOnClient.getValue();
Map<String, String> tournamentLatestProps = tournamentsOnServer.get(tournamentQueueId);
if (tournamentLatestProps != null) {
if (!tournamentProps.equals(tournamentLatestProps))
hallChannelVisitor.updateTournamentQueue(tournamentQueueId, tournamentLatestProps);
} else {
hallChannelVisitor.removeTournamentQueue(tournamentQueueId);
}
}
notifyAboutTournamentQueues(hallChannelVisitor, tournamentQueuesOnServer);
_tournamentQueuePropsOnClient = tournamentQueuesOnServer;
for (Map.Entry<String, Map<String, String>> tournamentQueueOnServer : tournamentsOnServer.entrySet())
if (!_tournamentQueuePropsOnClient.containsKey(tournamentQueueOnServer.getKey()))
hallChannelVisitor.addTournamentQueue(tournamentQueueOnServer.getKey(), tournamentQueueOnServer.getValue());
notifyAboutTournaments(hallChannelVisitor, tournamentsOnServer);
_tournamentPropsOnClient = tournamentsOnServer;
_tournamentQueuePropsOnClient = tournamentsOnServer;
notifyAboutTables(hallChannelVisitor, tablesOnServer);
_tablePropsOnClient = tablesOnServer;
if (newMotd.getValue() != null && !newMotd.equals(_lastMotd))
hallChannelVisitor.motdChanged((String) newMotd.getValue());
_lastConsumed = System.currentTimeMillis();
}
private void notifyAboutTables(HallChannelVisitor hallChannelVisitor, Map<String, Map<String, String>> tablesOnServer) {
for (Map.Entry<String, Map<String, String>> tableOnClient : _tablePropsOnClient.entrySet()) {
String tableId = tableOnClient.getKey();
Map<String, String> tableProps = tableOnClient.getValue();
@@ -124,12 +140,41 @@ public class HallCommunicationChannel {
for (Map.Entry<String, Map<String, String>> tableOnServer : tablesOnServer.entrySet())
if (!_tablePropsOnClient.containsKey(tableOnServer.getKey()))
hallChannelVisitor.addTable(tableOnServer.getKey(), tableOnServer.getValue());
}
if (newMotd.getValue() != null && !newMotd.equals(_lastMotd))
hallChannelVisitor.motdChanged((String) newMotd.getValue());
private void notifyAboutTournamentQueues(HallChannelVisitor hallChannelVisitor, Map<String, Map<String, String>> tournamentQueuesOnServer) {
for (Map.Entry<String, Map<String, String>> tournamentQueueOnClient : _tournamentQueuePropsOnClient.entrySet()) {
String tournamentQueueId = tournamentQueueOnClient.getKey();
Map<String, String> tournamentProps = tournamentQueueOnClient.getValue();
Map<String, String> tournamentLatestProps = tournamentQueuesOnServer.get(tournamentQueueId);
if (tournamentLatestProps != null) {
if (!tournamentProps.equals(tournamentLatestProps))
hallChannelVisitor.updateTournamentQueue(tournamentQueueId, tournamentLatestProps);
} else {
hallChannelVisitor.removeTournamentQueue(tournamentQueueId);
}
}
_tablePropsOnClient = tablesOnServer;
for (Map.Entry<String, Map<String, String>> tournamentQueueOnServer : tournamentQueuesOnServer.entrySet())
if (!_tournamentQueuePropsOnClient.containsKey(tournamentQueueOnServer.getKey()))
hallChannelVisitor.addTournamentQueue(tournamentQueueOnServer.getKey(), tournamentQueueOnServer.getValue());
}
_lastConsumed = System.currentTimeMillis();
private void notifyAboutTournaments(HallChannelVisitor hallChannelVisitor, Map<String, Map<String, String>> tournamentsOnServer) {
for (Map.Entry<String, Map<String, String>> tournamentOnClient : _tournamentPropsOnClient.entrySet()) {
String tournamentId = tournamentOnClient.getKey();
Map<String, String> tournamentProps = tournamentOnClient.getValue();
Map<String, String> tournamentLatestProps = tournamentsOnServer.get(tournamentId);
if (tournamentLatestProps != null) {
if (!tournamentProps.equals(tournamentLatestProps))
hallChannelVisitor.updateTournament(tournamentId, tournamentLatestProps);
} else {
hallChannelVisitor.removeTournament(tournamentId);
}
}
for (Map.Entry<String, Map<String, String>> tournamentQueueOnServer : tournamentsOnServer.entrySet())
if (!_tournamentPropsOnClient.containsKey(tournamentQueueOnServer.getKey()))
hallChannelVisitor.addTournament(tournamentQueueOnServer.getKey(), tournamentQueueOnServer.getValue());
}
}

View File

@@ -18,5 +18,7 @@ public interface HallInfoVisitor {
public void visitTournamentQueue(String tournamentQueueKey, int cost, String collectionName, String formatName, String tournamentQueueName, String tournamentPrizes,
String pairingDescription, String startCondition, int playerCount, boolean playerSignedUp);
public void visitTournament(String tournamentKey, String collectionName, String formatName, String tournamentName, String pairingDescription, String tournamentStage, int round, int playerCount, boolean playerInCompetition);
public void runningPlayerGame(String gameId);
}

View File

@@ -346,6 +346,15 @@ public class HallServer extends AbstractServer {
tournamentQueue.getPlayerCount(), tournamentQueue.isPlayerSignedUp(player.getName()));
}
for (Map.Entry<String, Tournament> tournamentEntry: _runningTournaments.entrySet()){
String tournamentKey = tournamentEntry.getKey();
Tournament tournament = tournamentEntry.getValue();
visitor.visitTournament(tournamentKey, tournament.getCollectionType().getFullName(),
_formatLibrary.getFormat(tournament.getFormat()).getName(), tournament.getTournamentName(), tournament.getPlayOffSystem(),
tournament.getTournamentStage().getHumanReadable(),
tournament.getCurrentRound(), tournament.getPlayersInCompetitionCount(), tournament.isPlayerInCompetition(player.getName()));
}
String gameId = getPlayingPlayerGameId(player.getName());
if (gameId != null)
visitor.runningPlayerGame(gameId);

View File

@@ -98,6 +98,16 @@ public class DefaultTournament implements Tournament {
_waitForPairingsTime = waitForPairingsTime;
}
@Override
public String getPlayOffSystem() {
return _pairingMechanism.getPlayOffSystem();
}
@Override
public int getPlayersInCompetitionCount() {
return _players.size() - _droppedPlayers.size();
}
@Override
public String getTournamentId() {
return _tournamentId;

View File

@@ -12,4 +12,6 @@ public interface PairingMechanism {
public boolean isFinished(int round, Set<String> players, Set<String> droppedPlayers);
public boolean pairPlayers(int round, Set<String> players, Set<String> droppedPlayers, Map<String, Integer> playerByes, List<PlayerStanding> currentStandings, Map<String, String> pairingResults, Set<String> byeResults);
public String getPlayOffSystem();
}

View File

@@ -10,6 +10,11 @@ public class SingleEliminationPairing implements PairingMechanism {
return players.size() - droppedPlayers.size() < 2;
}
@Override
public String getPlayOffSystem() {
return "Single elimination";
}
@Override
public boolean pairPlayers(int round, Set<String> players, Set<String> droppedPlayers, Map<String, Integer> playerByes, List<PlayerStanding> currentStandings, Map<String, String> pairingResults, Set<String> byeResults) {
if (isFinished(round, players, droppedPlayers))

View File

@@ -28,9 +28,11 @@ public interface Tournament {
public String getFormat();
public CollectionType getCollectionType();
public String getTournamentName();
public String getPlayOffSystem();
public Stage getTournamentStage();
public int getCurrentRound();
public int getPlayersInCompetitionCount();
public void advanceTournament(TournamentCallback tournamentCallback, CollectionsManager collectionsManager);

View File

@@ -324,6 +324,34 @@ public class HallResource extends AbstractResource {
_hall.appendChild(queue);
}
@Override
public void addTournament(String tournamentId, Map<String, String> props) {
Element tournament = _doc.createElement("tournament");
tournament.setAttribute("action", "add");
tournament.setAttribute("id", tournamentId);
for (Map.Entry<String, String> attribute : props.entrySet())
tournament.setAttribute(attribute.getKey(), attribute.getValue());
_hall.appendChild(tournament);
}
@Override
public void updateTournament(String tournamentId, Map<String, String> props) {
Element tournament = _doc.createElement("tournament");
tournament.setAttribute("action", "update");
tournament.setAttribute("id", tournamentId);
for (Map.Entry<String, String> attribute : props.entrySet())
tournament.setAttribute(attribute.getKey(), attribute.getValue());
_hall.appendChild(tournament);
}
@Override
public void removeTournament(String tournamentId) {
Element tournament = _doc.createElement("tournament");
tournament.setAttribute("action", "remove");
tournament.setAttribute("id", tournamentId);
_hall.appendChild(tournament);
}
@Override
public void addTable(String tableId, Map<String, String> props) {
Element table = _doc.createElement("table");

View File

@@ -41,6 +41,7 @@ var GempLotrHallUI = Class.extend({
this.tablesDiv.css({overflow:"auto", left:"0px", top:"0px", width:width + "px", height:(height - 30) + "px"});
this.addQueuesTable();
this.addTournamentsTable();
this.addWaitingTablesTable();
this.addPlayingTablesTable();
this.addFinishedTablesTable();
@@ -135,6 +136,38 @@ var GempLotrHallUI = Class.extend({
this.tablesDiv.append(content);
},
addTournamentsTable: function() {
var header = $("<div class='eventHeader tournaments'></div>");
var content = $("<div></div>");
var toggleContent = $("<div>Toggle tournaments</div>").button({
icons: {
primary: "ui-icon-circlesmall-minus"
},
text: false
});
toggleContent.css({width: "13px", height: "15px"});
toggleContent.click(
function() {
if (toggleContent.button("option", "icons")["primary"] == "ui-icon-circlesmall-minus")
toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-plus"});
else
toggleContent.button("option", "icons", {primary: "ui-icon-circlesmall-minus"});
content.toggle("blind", {}, 200);
});
header.append(toggleContent);
header.append(" Tournaments");
header.append(" <span class='count'>(0)</span>");
var table = $("<table class='tables tournaments'></table>");
table.append("<tr><th width='10%'>Format</th><th width='10%'>Collection</th><th width='25%'>Tournament name</th><th width='15%'>System</th><th width='10%'>Stage</th><th width='10%'>Round</th><th width='10%'>Players</th><th width='10%'>Actions</th></tr>");
content.append(table);
this.tablesDiv.append(header);
this.tablesDiv.append(content);
},
addWaitingTablesTable: function() {
var header = $("<div class='eventHeader waitingTables'></div>");
@@ -372,6 +405,51 @@ var GempLotrHallUI = Class.extend({
}
}
var tournaments = root.getElementsByTagName("tournament");
for (var i = 0; i < tournaments.length; i++) {
var tournament = tournaments[i];
var id = tournament.getAttribute("id");
var action = tournament.getAttribute("action");
if (action == "add" || action == "update") {
var actionsField = $("<td></td>");
var joined = tournament.getAttribute("signedUp");
if (joined == "true") {
var but = $("<button>Drop from tournament</button>");
$(but).button().click((
function(tournamentId) {
return function () {
that.comm.dropFromTournament(tournamentId, function (xml) {
that.processResponse(xml);
});
};
}
)(id));
actionsField.append(but);
}
var row = $("<tr class='tournament" + id + "'><td>" + tournament.getAttribute("format") + "</td>" +
"<td>" + tournament.getAttribute("collection") + "</td>" +
"<td>" + tournament.getAttribute("name") + "</td>" +
"<td>" + tournament.getAttribute("system") + "</td>" +
"<td>" + tournament.getAttribute("stage") + "</td>" +
"<td>" + tournament.getAttribute("round") + "</td>" +
"<td>" + tournament.getAttribute("playerCount") + "</td>" +
"</tr>");
row.append(actionsField);
if (action == "add") {
$("table.tournaments", this.tablesDiv)
.append(row);
} else if (action == "update") {
$(".tournament" + id, this.tablesDiv).replaceWith(row);
}
} else if (action == "remove") {
$(".tournament" + id, this.tablesDiv).remove();
}
}
var tables = root.getElementsByTagName("table");
for (var i = 0; i < tables.length; i++) {
var table = tables[i];
@@ -482,6 +560,7 @@ var GempLotrHallUI = Class.extend({
}
$(".count", $(".eventHeader.queues")).html("("+($("tr", $("table.queues")).length-1)+")");
$(".count", $(".eventHeader.tournaments")).html("("+($("tr", $("table.tournaments")).length-1)+")");
$(".count", $(".eventHeader.waitingTables")).html("("+($("tr", $("table.waitingTables")).length-1)+")");
$(".count", $(".eventHeader.playingTables")).html("("+($("tr", $("table.playingTables")).length-1)+")");
$(".count", $(".eventHeader.finishedTables")).html("("+($("tr", $("table.finishedTables")).length-1)+")");