- reload hand after reloading page

- use transform animation in all browsers to reduce complexity :(
This commit is contained in:
Andy Janata 2012-01-23 23:02:59 -08:00
parent 2f2d683384
commit 5915a3558d
8 changed files with 122 additions and 70 deletions

View File

@ -151,12 +151,13 @@
#chat {
border: 1px solid black;
left: -4px;
right: 46px;
left: -2px;
/*right: 46px;*/
bottom: -1px;
height: 17px;
position: absolute;
bottom: -1px;
padding: 0px;
width: 90%;
}
#chat_submit {
@ -182,10 +183,6 @@ span.debug {
height: 200px;
border: 1px solid gray;
padding: 15px;
/*
position: absolute;
bottom: 0px;
*/
font-family: Arial, Verdana, san-serif;
font-size: 18pt;
float: left;
@ -208,9 +205,9 @@ span.debug {
color: black;
}
.cah {
.game_hand_cards .cah {
position: absolute;
bottom: 0px;
bottom: -150px;
left: 0px;
margin: 15px;
}
@ -237,7 +234,7 @@ span.debug {
bottom: 0px;
left: 0px;
right: 0px;
height: 33%;
height: 30%;
border-top: 1px solid black;
}
@ -246,11 +243,6 @@ span.debug {
bottom: 0px;
height: 100%;
width: 100%;
/* * /
zoom: .35;
-moz-transform: scale(.35);
-moz-transform-origin: 0 0;
/ * */
cursor: pointer;
}
@ -262,11 +254,6 @@ span.debug {
.card_holder {
float: left;
position: relative;
/*
zoom: .35;
-moz-transform: scale(.35);
-moz-transform-origin: 0 0;
*/
}
.scoreboard {

View File

@ -99,10 +99,20 @@ cah.ajax.SuccessHandlers[cah.$.AjaxOperation.LEAVE_GAME] = function(data) {
game.dispose();
delete cah.currentGames[data[cah.$.AjaxResponse.GAME_ID]];
}
// This will get updated when the server fires a refresh event
cah.GameList.instance.update();
cah.GameList.instance.show();
};
cah.ajax.SuccessHandlers[cah.$.AjaxOperation.START_GAME] = function(data) {
// pass
};
cah.ajax.SuccessHandlers[cah.$.AjaxOperation.GET_HAND] = function(data) {
var gameId = data[cah.$.AjaxResponse.GAME_ID];
var game = cah.currentGames[gameId];
if (game) {
game.dealtCards(data[cah.$.AjaxResponse.HAND]);
} else {
cah.log.error("Received hand for unknown game id " + gameId);
}
};

View File

@ -11,6 +11,7 @@ cah.$.AjaxOperation.FIRST_LOAD = "firstload";
cah.$.AjaxOperation.LOG_OUT = "logout";
cah.$.AjaxOperation.GAME_LIST = "games";
cah.$.AjaxOperation.JOIN_GAME = "join_game";
cah.$.AjaxOperation.GET_HAND = "get_hand";
cah.$.AjaxOperation.GET_GAME_INFO = "get_game_info";
cah.$.AjaxOperation.REGISTER = "register";
cah.$.AjaxOperation.CREATE_GAME = "create_game";
@ -32,17 +33,18 @@ cah.$.AjaxResponse = function() {
// pass
};
cah.$.AjaxResponse.prototype.dummy = undefined;
cah.$.AjaxResponse.NEXT = "next";
cah.$.AjaxResponse.GAME_ID = "game_id";
cah.$.AjaxResponse.GAME_INFO = "game_info";
cah.$.AjaxResponse.ERROR = "error";
cah.$.AjaxResponse.HAND = "hand";
cah.$.AjaxResponse.PLAYER_INFO = "player_info";
cah.$.AjaxResponse.ERROR_CODE = "error_code";
cah.$.AjaxResponse.SERIAL = "serial";
cah.$.AjaxResponse.MAX_GAMES = "max_games";
cah.$.AjaxResponse.IN_PROGRESS = "in_progress";
cah.$.AjaxResponse.GAMES = "games";
cah.$.AjaxResponse.NICKNAME = "nickname";
cah.$.AjaxResponse.NEXT = "next";
cah.$.AjaxResponse.GAME_INFO = "game_info";
cah.$.AjaxResponse.ERROR = "error";
cah.$.AjaxResponse.ERROR_CODE = "error_code";
cah.$.AjaxResponse.SERIAL = "serial";
cah.$.AjaxResponse.MAX_GAMES = "max_games";
cah.$.AjaxResponse.NAMES = "names";
cah.$.DisconnectReason = function() {

View File

@ -77,6 +77,7 @@ cah.Game = function(id) {
*/
cah.Game.joinGame = function(gameId) {
cah.Ajax.build(cah.$.AjaxOperation.GET_GAME_INFO).withGameId(gameId).run();
cah.Ajax.build(cah.$.AjaxOperation.GET_HAND).withGameId(gameId).run();
cah.GameList.instance.hide();
var game = new cah.Game(gameId);
cah.currentGames[gameId] = game;
@ -118,48 +119,34 @@ cah.Game.prototype.dealtCard = function(card) {
var element = card.getElement();
jQuery(".game_hand_cards", this.element_).append(element);
$(element).css("zoom", ".35");
var data = {
card : element,
};
// animate it so we don't have to hard-code per browser
$(element).animate({
scale : .35,
}, {
duration : 1,
});
$(element).css("transform", "scale(0.35, 0.35)").css("transform-origin", "0 0");
// TODO scale on available width and number of cards
var origSize = parseInt($(element).css("width"));
$(element).css("width", origSize * .35).css("height", origSize * .35);
var options = {
duration : 200,
queue : false,
};
if ($.browser.mozilla || $.browser.opera) {
var origSize = parseInt($(element).css("width"));
if ($.browser.mozilla) {
$(element).css("-moz-transform", "scale(0.35, 0.35)").css("-moz-transform-origin", "0 0");
} else {
$(element).css("-o-transform", "scale(0.35, 0.35)").css("-o-transform-origin", "0 0");
}
$(element).css("width", origSize * .35).css("height", origSize * .35).css("z-index",
this.badBrowserZOrderHack_--);
$(".cah", element).css("bottom", "-150px");
$(element).mouseenter(data, function(e) {
$(e.data.card).animate({
scale : .7,
}, options);
}).mouseleave(data, function(e) {
$(e.data.card).animate({
scale : .35,
}, options);
});
} else {
$(element).mouseenter(data, function(e) {
$(e.data.card).animate({
zoom : .7
}, options);
}).mouseleave(data, function(e) {
$(e.data.card).animate({
zoom : .35
}, options);
});
}
$(element).mouseenter(function(e) {
$(this).animate({
scale : .6,
"z-index" : 2,
}, options);
}).mouseleave(function(e) {
$(this).animate({
scale : .35,
"z-index" : 1,
}, options);
});
};
cah.Game.prototype.insertIntoDocument = function() {

View File

@ -57,6 +57,7 @@ public class Constants {
FIRST_LOAD("firstload"),
GAME_LIST("games"),
GET_GAME_INFO("get_game_info"),
GET_HAND("get_hand"),
JOIN_GAME("join_game"),
LEAVE_GAME("leave_game"),
LOG_OUT("logout"),
@ -101,6 +102,7 @@ public class Constants {
GAME_ID("game_id"),
GAME_INFO("game_info"),
GAMES("games"),
HAND("hand"),
IN_PROGRESS("in_progress"),
MAX_GAMES("max_games"),
NAMES("names"),

View File

@ -232,15 +232,22 @@ public class Game {
hand.add(card);
newCards.add(card);
}
sendDealtCardsToPlayer(player, newCards);
sendCardsToPlayer(player, newCards);
}
}
}
private void sendDealtCardsToPlayer(final Player player, final List<WhiteCard> cards) {
private void sendCardsToPlayer(final Player player, final List<WhiteCard> cards) {
final Map<ReturnableData, Object> data = new HashMap<ReturnableData, Object>();
data.put(LongPollResponse.EVENT, LongPollEvent.HAND_DEAL.toString());
data.put(LongPollResponse.GAME_ID, id);
final List<Map<WhiteCardData, Object>> cardData = handSubsetToClient(cards);
data.put(LongPollResponse.HAND, cardData);
final QueuedMessage qm = new QueuedMessage(MessageType.GAME_EVENT, data);
player.getUser().enqueueMessage(qm);
}
private List<Map<WhiteCardData, Object>> handSubsetToClient(final List<WhiteCard> cards) {
final List<Map<WhiteCardData, Object>> cardData =
new ArrayList<Map<WhiteCardData, Object>>(cards.size());
for (final WhiteCard card : cards) {
@ -249,9 +256,18 @@ public class Game {
thisCard.put(WhiteCardData.TEXT, card.getText());
cardData.add(thisCard);
}
data.put(LongPollResponse.HAND, cardData);
final QueuedMessage qm = new QueuedMessage(MessageType.GAME_EVENT, data);
player.getUser().enqueueMessage(qm);
return cardData;
}
public List<Map<WhiteCardData, Object>> getHand(final User user) {
synchronized (players) {
for (final Player player : players) {
if (player.getUser() == user) {
return handSubsetToClient(player.getHand());
}
}
}
return null;
}
private List<User> playersToUsers() {

View File

@ -0,0 +1,47 @@
package net.socialgamer.cah.handlers;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import net.socialgamer.cah.Constants.AjaxOperation;
import net.socialgamer.cah.Constants.AjaxResponse;
import net.socialgamer.cah.Constants.ReturnableData;
import net.socialgamer.cah.Constants.WhiteCardData;
import net.socialgamer.cah.RequestWrapper;
import net.socialgamer.cah.data.Game;
import net.socialgamer.cah.data.GameManager;
import net.socialgamer.cah.data.User;
import com.google.inject.Inject;
public class GetHandHandler extends GameHandler {
@Inject
public GetHandHandler(final GameManager gameManager) {
super(gameManager);
}
public static final String OP = AjaxOperation.GET_HAND.toString();
@SuppressWarnings("unchecked")
@Override
public Map<ReturnableData, Object> handle(final RequestWrapper request,
final HttpSession session, final User user, final Game game) {
final Map<ReturnableData, Object> data = new HashMap<ReturnableData, Object>();
final List<Map<WhiteCardData, Object>> hand = user.getGame().getHand(user);
if (hand != null) {
data.put(AjaxResponse.HAND, hand);
} else {
data.put(AjaxResponse.HAND, Arrays.asList(new HashMap<WhiteCardData, Object>()));
}
data.put(AjaxResponse.GAME_ID, game.getId());
return data;
}
}

View File

@ -15,6 +15,7 @@ public class Handlers {
LIST.put(FirstLoadHandler.OP, FirstLoadHandler.class);
LIST.put(GameListHandler.OP, GameListHandler.class);
LIST.put(GetGameInfoHandler.OP, GetGameInfoHandler.class);
LIST.put(GetHandHandler.OP, GetHandHandler.class);
LIST.put(JoinGameHandler.OP, JoinGameHandler.class);
LIST.put(LeaveGameHandler.OP, LeaveGameHandler.class);
LIST.put(LogoutHandler.OP, LogoutHandler.class);