diff --git a/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/ServerResource.java b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/ServerResource.java index 355066a06..92a522800 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/ServerResource.java +++ b/gemp-lotr/gemp-lotr-web/src/main/java/com/gempukku/lotro/server/ServerResource.java @@ -59,8 +59,10 @@ public class ServerResource { @Path("/login") @POST - public void login(@FormParam("login") String login, @FormParam("password") String password, - @Context HttpServletRequest request) { + public void login( + @FormParam("login") String login, + @FormParam("password") String password, + @Context HttpServletRequest request) { _logger.debug("/server/login " + login + ", " + password); if (login == null) sendError(Response.Status.NOT_FOUND); @@ -71,9 +73,10 @@ public class ServerResource { @Path("/game/{gameId}") @GET @Produces(MediaType.APPLICATION_XML) - public Document getGameState(@PathParam("gameId") String gameId, - @QueryParam("participantId") String participantId, - @Context HttpServletRequest request) throws ParserConfigurationException { + public Document getGameState( + @PathParam("gameId") String gameId, + @QueryParam("participantId") String participantId, + @Context HttpServletRequest request) throws ParserConfigurationException { // String participantId = getLoggedUser(request); LotroGameMediator gameMediator = _lotroServer.getGameById(gameId); @@ -101,10 +104,11 @@ public class ServerResource { @Path("/game/{gameId}/cardInfo") @GET @Produces("text/html") - public String getCardInfo(@PathParam("gameId") String gameId, - @QueryParam("cardId") int cardId, - @QueryParam("participantId") String participantId, - @Context HttpServletRequest request) throws ParserConfigurationException { + public String getCardInfo( + @PathParam("gameId") String gameId, + @QueryParam("cardId") int cardId, + @QueryParam("participantId") String participantId, + @Context HttpServletRequest request) throws ParserConfigurationException { // String participantId = getLoggedUser(request); LotroGameMediator gameMediator = _lotroServer.getGameById(gameId); @@ -161,8 +165,8 @@ public class ServerResource { @GET @Produces(MediaType.APPLICATION_XML) public Document getDeck( - @QueryParam("participantId") String participantId, @PathParam("deckType") String deckType, + @QueryParam("participantId") String participantId, @Context HttpServletRequest request) throws ParserConfigurationException { PlayerDAO playerDao = _lotroServer.getPlayerDao(); DeckDAO deckDao = _lotroServer.getDeckDao(); @@ -171,13 +175,17 @@ public class ServerResource { if (player == null) sendError(Response.Status.UNAUTHORIZED); - Deck deck = deckDao.getDeckForPlayer(player, deckType); - if (deck == null) - sendError(Response.Status.NOT_FOUND); - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); + Deck deck = deckDao.getDeckForPlayer(player, deckType); + if (deck == null) { + Document doc = documentBuilder.newDocument(); + Element deckElem = doc.createElement("deck"); + doc.appendChild(deckElem); + return doc; + } + Document doc = documentBuilder.newDocument(); Element deckElem = doc.createElement("deck"); doc.appendChild(deckElem); @@ -208,8 +216,8 @@ public class ServerResource { @POST @Produces(MediaType.APPLICATION_XML) public void createDeck( - @FormParam("participantId") String participantId, @PathParam("deckType") String deckType, + @FormParam("participantId") String participantId, @FormParam("deckContents") String contents) { PlayerDAO playerDao = _lotroServer.getPlayerDao(); @@ -230,8 +238,8 @@ public class ServerResource { @GET @Produces(MediaType.APPLICATION_XML) public Document getCollection( - @QueryParam("participantId") String participantId, @PathParam("collectionType") String collectionType, + @QueryParam("participantId") String participantId, @QueryParam("filter") String filter, @QueryParam("start") int start, @QueryParam("count") int count, diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/deckBuild.html b/gemp-lotr/gemp-lotr-web/src/main/webapp/deckBuild.html index 2bd64933a..2af845f7d 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/deckBuild.html +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/deckBuild.html @@ -68,6 +68,7 @@ + diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/game.html b/gemp-lotr/gemp-lotr-web/src/main/webapp/game.html index 43407dc0d..74707c88f 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/game.html +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/game.html @@ -66,7 +66,7 @@ - + @@ -100,7 +100,7 @@ $(document).ready( function () { - ui = new GempLotrUI(); + ui = new GempLotrGameUI(); communication = new GempLotrCommunication("/gemp-lotr/server", function() { diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/communication.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/communication.js index a76794c4c..b69458a97 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/communication.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/communication.js @@ -55,10 +55,31 @@ var GempLotrCommunication = Class.extend({ dataType: "xml" }); }, - getDeck: function(callback) { + getDeck: function(deckType, callback) { $.ajax({ type: "GET", - url: this + url: this.url + "/deck/" + deckType, + cache: false, + data: { + participantId: getUrlParam("participantId")}, + success: callback, + error: this.failure, + dataType: "xml" + }); + }, + getCollection: function(collectionType, filter, start, count, callback) { + $.ajax({ + type: "GET", + url: this.url + "/collection/" + collectionType, + cache: false, + data: { + participantId: getUrlParam("participantId"), + filter: filter, + start: start, + count: count}, + success: callback, + error: this.failure, + dataType: "xml" }); } }); diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/deckBuildingUi.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/deckBuildingUi.js new file mode 100644 index 000000000..b730ebf0f --- /dev/null +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/deckBuildingUi.js @@ -0,0 +1,39 @@ +var GempLotrDeckBuildingUI = Class.extend({ + deckDiv: null, + collectionDiv: null, + loadCollectionFunc: null, + + init: function() { + this.deckDiv = $("
"); + this.collectionDiv = $("
"); + + $("#main").append(this.deckDiv); + $("#main").append(this.collectionDiv); + }, + + setLoadCollectionFunc: function(func) { + this.loadCollectionFunc = func; + }, + + setupDeck: function(xml) { + this.loadCollectionFunc("default", "cardType:-SITE,THE_ONE_RING", 0, 18); + }, + + displayCollection: function(xml) { + alert(xml.text); + }, + + layoutUI: function() { + var width = $(window).width(); + var height = $(window).height(); + + var deckHeight = Math.floor(height * 0.3); + + this.deckDiv.css({left:0 + "px", top:0 + "px", width: width, height: deckHeight, position: "absolute"}); + this.collectionDiv.css({left:0 + "px", top:deckHeight + "px", width: width, height: height - deckHeight, position: "absolute"}); + }, + + processError: function (xhr, ajaxOptions, thrownError) { + alert("There was a problem during communication with server"); + } +}); \ No newline at end of file diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/ui.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gameUi.js similarity index 96% rename from gemp-lotr/gemp-lotr-web/src/main/webapp/js/ui.js rename to gemp-lotr/gemp-lotr-web/src/main/webapp/js/gameUi.js index 238d38fa0..40549820d 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/ui.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/gameUi.js @@ -1,4 +1,4 @@ -var GempLotrUI = Class.extend({ +var GempLotrGameUI = Class.extend({ padding: 5, updateGameState: null, @@ -592,12 +592,8 @@ var GempLotrUI = Class.extend({ }, createCardDiv: function(card, text) { - var cardDiv = $("
" + ((text != null) ? text : "") + "
"); + var cardDiv = createCardDiv(card.imageUrl, text); cardDiv.data("card", card); - var overlayDiv = $("
"); - cardDiv.append(overlayDiv); - var borderDiv = $("
"); - cardDiv.append(borderDiv); var that = this; var swipeOptions = { diff --git a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/jCards.js b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/jCards.js index 3aab27672..0e1d1845c 100644 --- a/gemp-lotr/gemp-lotr-web/src/main/webapp/js/jCards.js +++ b/gemp-lotr/gemp-lotr-web/src/main/webapp/js/jCards.js @@ -75,5 +75,14 @@ var Card = Class.extend({ else return Math.floor(height * cardScale); } +}); -}); \ No newline at end of file +function createCardDiv(image, text) { + var cardDiv = $("
" + ((text != null) ? text : "") + "
"); + var overlayDiv = $("
"); + cardDiv.append(overlayDiv); + var borderDiv = $("
"); + cardDiv.append(borderDiv); + + return cardDiv; +} \ No newline at end of file