Replacing some strings to make the messages sent between server and client shorter.
Chat in game will be less responsive (updates every 3 seconds).
This commit is contained in:
@@ -10,7 +10,7 @@ import java.util.Map;
|
||||
|
||||
public class EventSerializer {
|
||||
public Node serializeEvent(Document doc, GameEvent gameEvent) {
|
||||
Element eventElem = doc.createElement("gameEvent");
|
||||
Element eventElem = doc.createElement("ge");
|
||||
eventElem.setAttribute("type", gameEvent.getType().name());
|
||||
if (gameEvent.getBlueprintId() != null)
|
||||
eventElem.setAttribute("blueprintId", gameEvent.getBlueprintId());
|
||||
|
||||
@@ -11,14 +11,14 @@ import java.util.List;
|
||||
|
||||
public class GameEvent {
|
||||
public enum Type {
|
||||
PARTICIPANT, GAME_PHASE_CHANGE, TURN_CHANGE, PLAYER_POSITION, TWILIGHT_POOL,
|
||||
PUT_CARD_IN_PLAY, MOVE_CARD_IN_PLAY, REMOVE_CARD_FROM_PLAY,
|
||||
ADD_ASSIGNMENT, REMOVE_ASSIGNMENT,
|
||||
START_SKIRMISH, REMOVE_FROM_SKIRMISH, END_SKIRMISH,
|
||||
ADD_TOKENS, REMOVE_TOKENS,
|
||||
MESSAGE, WARNING,
|
||||
GAME_STATS,
|
||||
CARD_AFFECTS_CARD, EVENT_PLAYED
|
||||
P, GPC, TC, PP, TP,
|
||||
PCIP, MCIP, RCFP,
|
||||
AA, RA,
|
||||
SS, RFS, ES,
|
||||
AT, RT,
|
||||
M, W,
|
||||
GS,
|
||||
CAC, EP
|
||||
}
|
||||
|
||||
private String _message;
|
||||
|
||||
@@ -27,7 +27,7 @@ public class GatheringParticipantCommunicationChannel implements GameStateListen
|
||||
List<String> participantIds = new LinkedList<String>();
|
||||
for (String participant : participants)
|
||||
participantIds.add(participant);
|
||||
_events.add(new GameEvent(PARTICIPANT).participantId(_self).allParticipantIds(participantIds));
|
||||
_events.add(new GameEvent(P).participantId(_self).allParticipantIds(participantIds));
|
||||
}
|
||||
|
||||
private int[] getCardIds(Collection<PhysicalCard> cards) {
|
||||
@@ -42,17 +42,17 @@ public class GatheringParticipantCommunicationChannel implements GameStateListen
|
||||
|
||||
@Override
|
||||
public void addAssignment(PhysicalCard freePeople, List<PhysicalCard> minions) {
|
||||
_events.add(new GameEvent(ADD_ASSIGNMENT).cardId(freePeople.getCardId()).otherCardIds(getCardIds(minions)));
|
||||
_events.add(new GameEvent(AA).cardId(freePeople.getCardId()).otherCardIds(getCardIds(minions)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAssignment(PhysicalCard freePeople) {
|
||||
_events.add(new GameEvent(REMOVE_ASSIGNMENT).cardId(freePeople.getCardId()));
|
||||
_events.add(new GameEvent(RA).cardId(freePeople.getCardId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startSkirmish(PhysicalCard freePeople, List<PhysicalCard> minions) {
|
||||
GameEvent gameEvent = new GameEvent(START_SKIRMISH).otherCardIds(getCardIds(minions));
|
||||
GameEvent gameEvent = new GameEvent(SS).otherCardIds(getCardIds(minions));
|
||||
if (freePeople != null)
|
||||
gameEvent.cardId(freePeople.getCardId());
|
||||
_events.add(gameEvent);
|
||||
@@ -60,82 +60,82 @@ public class GatheringParticipantCommunicationChannel implements GameStateListen
|
||||
|
||||
@Override
|
||||
public void removeFromSkirmish(PhysicalCard card) {
|
||||
_events.add(new GameEvent(REMOVE_FROM_SKIRMISH).card(card));
|
||||
_events.add(new GameEvent(RFS).card(card));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishSkirmish() {
|
||||
_events.add(new GameEvent(END_SKIRMISH));
|
||||
_events.add(new GameEvent(ES));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentPhase(Phase phase) {
|
||||
_events.add(new GameEvent(GAME_PHASE_CHANGE).phase(phase));
|
||||
_events.add(new GameEvent(GPC).phase(phase));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cardCreated(PhysicalCard card) {
|
||||
_events.add(new GameEvent(PUT_CARD_IN_PLAY).card(card));
|
||||
_events.add(new GameEvent(PCIP).card(card));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cardMoved(PhysicalCard card) {
|
||||
_events.add(new GameEvent(MOVE_CARD_IN_PLAY).card(card));
|
||||
_events.add(new GameEvent(MCIP).card(card));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cardsRemoved(Collection<PhysicalCard> cards) {
|
||||
_events.add(new GameEvent(REMOVE_CARD_FROM_PLAY).otherCardIds(getCardIds(cards)));
|
||||
_events.add(new GameEvent(RCFP).otherCardIds(getCardIds(cards)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayerPosition(String participant, int position) {
|
||||
_events.add(new GameEvent(PLAYER_POSITION).participantId(participant).index(position));
|
||||
_events.add(new GameEvent(PP).participantId(participant).index(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTwilight(int twilightPool) {
|
||||
_events.add(new GameEvent(TWILIGHT_POOL).count(twilightPool));
|
||||
_events.add(new GameEvent(TP).count(twilightPool));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCurrentPlayerId(String currentPlayerId) {
|
||||
_events.add(new GameEvent(TURN_CHANGE).participantId(currentPlayerId));
|
||||
_events.add(new GameEvent(TC).participantId(currentPlayerId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTokens(PhysicalCard card, Token token, int count) {
|
||||
_events.add(new GameEvent(ADD_TOKENS).card(card).token(token).count(count));
|
||||
_events.add(new GameEvent(AT).card(card).token(token).count(count));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeTokens(PhysicalCard card, Token token, int count) {
|
||||
_events.add(new GameEvent(REMOVE_TOKENS).card(card).token(token).count(count));
|
||||
_events.add(new GameEvent(RT).card(card).token(token).count(count));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
_events.add(new GameEvent(MESSAGE).message(message));
|
||||
_events.add(new GameEvent(M).message(message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSite(PhysicalCard card) {
|
||||
_events.add(new GameEvent(PUT_CARD_IN_PLAY).card(card).index(card.getBlueprint().getSiteNumber()));
|
||||
_events.add(new GameEvent(PCIP).card(card).index(card.getBlueprint().getSiteNumber()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cardAffectedByCard(String playerPerforming, PhysicalCard card, Collection<PhysicalCard> affectedCards) {
|
||||
_events.add(new GameEvent(CARD_AFFECTS_CARD).participantId(playerPerforming).card(card).otherCardIds(getCardIds(affectedCards)));
|
||||
_events.add(new GameEvent(CAC).participantId(playerPerforming).card(card).otherCardIds(getCardIds(affectedCards)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void eventPlayed(PhysicalCard card) {
|
||||
_events.add(new GameEvent(EVENT_PLAYED).card(card));
|
||||
_events.add(new GameEvent(EP).card(card));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendGameStats(GameStats gameStats) {
|
||||
_events.add(new GameEvent(GAME_STATS).gameStats(gameStats.makeACopy()));
|
||||
_events.add(new GameEvent(GS).gameStats(gameStats.makeACopy()));
|
||||
}
|
||||
|
||||
public List<GameEvent> consumeGameEvents() {
|
||||
|
||||
@@ -222,7 +222,7 @@ public class LotroGameMediator {
|
||||
|
||||
String warning = _userFeedback.consumeWarning(participantId);
|
||||
if (warning != null)
|
||||
visitor.visitGameEvent(new GameEvent(GameEvent.Type.WARNING).message(warning));
|
||||
visitor.visitGameEvent(new GameEvent(GameEvent.Type.W).message(warning));
|
||||
|
||||
AwaitingDecision awaitingDecision = _userFeedback.getAwaitingDecision(participantId);
|
||||
if (awaitingDecision != null)
|
||||
@@ -235,7 +235,7 @@ public class LotroGameMediator {
|
||||
}
|
||||
visitor.visitClock(secondsLeft);
|
||||
} else {
|
||||
visitor.visitGameEvent(new GameEvent(GameEvent.Type.WARNING).message("Your browser was inactive for too long, please refresh your browser window to continue playing"));
|
||||
visitor.visitGameEvent(new GameEvent(GameEvent.Type.W).message("Your browser was inactive for too long, please refresh your browser window to continue playing"));
|
||||
}
|
||||
} finally {
|
||||
_readLock.unlock();
|
||||
|
||||
@@ -7,6 +7,7 @@ var ChatBoxUI = Class.extend({
|
||||
chatListDiv: null,
|
||||
showTimestamps: false,
|
||||
talkBoxHeight: 25,
|
||||
chatUpdateInterval: 1000,
|
||||
|
||||
init: function(name, div, url, showList) {
|
||||
var that = this;
|
||||
@@ -118,7 +119,7 @@ var ChatBoxUI = Class.extend({
|
||||
if (processAgain)
|
||||
setTimeout(function() {
|
||||
that.updateChatMessages();
|
||||
}, 1000);
|
||||
}, that.chatUpdateInterval);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
@@ -225,6 +225,7 @@ var GempLotrGameUI = Class.extend({
|
||||
});
|
||||
|
||||
this.chatBox = new ChatBoxUI("Game" + getUrlParam("gameId"), $("#chatBox"), this.communication.url);
|
||||
this.chatBox.chatUpdateInterval = 3000;
|
||||
|
||||
$("#gameOptionsBox").append("<button id='concedeGame'>Concede game</button>");
|
||||
$("#concedeGame").button().click(
|
||||
@@ -483,51 +484,51 @@ var GempLotrGameUI = Class.extend({
|
||||
},
|
||||
|
||||
processGameEventsXml: function(element, animate) {
|
||||
var gameEvents = element.getElementsByTagName("gameEvent");
|
||||
var gameEvents = element.getElementsByTagName("ge");
|
||||
|
||||
// Go through all the events
|
||||
for (var i = 0; i < gameEvents.length; i++) {
|
||||
var gameEvent = gameEvents[i];
|
||||
var eventType = gameEvent.getAttribute("type");
|
||||
if (eventType == "PUT_CARD_IN_PLAY") {
|
||||
if (eventType == "PCIP") {
|
||||
this.animations.putCardInPlay(gameEvent, animate);
|
||||
} else if (eventType == "MOVE_CARD_IN_PLAY") {
|
||||
} else if (eventType == "MCIP") {
|
||||
this.animations.moveCardInPlay(gameEvent, animate);
|
||||
} else if (eventType == "PARTICIPANT") {
|
||||
} else if (eventType == "P") {
|
||||
this.participant(gameEvent);
|
||||
} else if (eventType == "REMOVE_CARD_FROM_PLAY") {
|
||||
} else if (eventType == "RCFP") {
|
||||
this.animations.removeCardFromPlay(gameEvent, animate);
|
||||
} else if (eventType == "GAME_PHASE_CHANGE") {
|
||||
} else if (eventType == "GPC") {
|
||||
this.animations.gamePhaseChange(gameEvent, animate);
|
||||
} else if (eventType == "TWILIGHT_POOL") {
|
||||
} else if (eventType == "TP") {
|
||||
this.animations.twilightPool(gameEvent, animate);
|
||||
} else if (eventType == "TURN_CHANGE") {
|
||||
} else if (eventType == "TC") {
|
||||
this.animations.turnChange(gameEvent, animate);
|
||||
} else if (eventType == "ADD_ASSIGNMENT") {
|
||||
} else if (eventType == "AA") {
|
||||
this.animations.addAssignment(gameEvent, animate);
|
||||
} else if (eventType == "REMOVE_ASSIGNMENT") {
|
||||
} else if (eventType == "RA") {
|
||||
this.animations.removeAssignment(gameEvent, animate);
|
||||
} else if (eventType == "START_SKIRMISH") {
|
||||
} else if (eventType == "SS") {
|
||||
this.animations.startSkirmish(gameEvent, animate);
|
||||
} else if (eventType == "REMOVE_FROM_SKIRMISH") {
|
||||
} else if (eventType == "RFS") {
|
||||
this.animations.removeFromSkirmish(gameEvent, animate);
|
||||
} else if (eventType == "END_SKIRMISH") {
|
||||
} else if (eventType == "ES") {
|
||||
this.animations.endSkirmish(animate);
|
||||
} else if (eventType == "ADD_TOKENS") {
|
||||
} else if (eventType == "AT") {
|
||||
this.animations.addTokens(gameEvent, animate);
|
||||
} else if (eventType == "REMOVE_TOKENS") {
|
||||
} else if (eventType == "RT") {
|
||||
this.animations.removeTokens(gameEvent, animate);
|
||||
} else if (eventType == "PLAYER_POSITION") {
|
||||
} else if (eventType == "PP") {
|
||||
this.animations.playerPosition(gameEvent, animate);
|
||||
} else if (eventType == "GAME_STATS") {
|
||||
} else if (eventType == "GS") {
|
||||
this.animations.gameStats(gameEvent, animate);
|
||||
} else if (eventType == "MESSAGE") {
|
||||
} else if (eventType == "M") {
|
||||
this.animations.message(gameEvent, animate);
|
||||
} else if (eventType == "WARNING") {
|
||||
} else if (eventType == "W") {
|
||||
this.animations.warning(gameEvent, animate);
|
||||
} else if (eventType == "CARD_AFFECTS_CARD") {
|
||||
} else if (eventType == "CAC") {
|
||||
this.animations.cardAffectsCard(gameEvent, animate);
|
||||
} else if (eventType == "EVENT_PLAYED") {
|
||||
} else if (eventType == "EP") {
|
||||
this.animations.eventPlayed(gameEvent, animate);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user