Working on deck building.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
<script type="text/javascript" src="js/jCardGroup.js"></script>
|
||||
<script type="text/javascript" src="js/jCards.js"></script>
|
||||
<script type="text/javascript" src="js/logging.js"></script>
|
||||
<script type="text/javascript" src="js/deckBuildingUi.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
var ui;
|
||||
@@ -98,29 +99,28 @@
|
||||
|
||||
$(document).ready(
|
||||
function () {
|
||||
ui = new GempLotrDeckBuildingUI();
|
||||
|
||||
communication = new GempLotrCommunication("/gemp-lotr/server",
|
||||
function(xml) {
|
||||
ui.processXml(xml);
|
||||
},
|
||||
function() {
|
||||
ui.processError();
|
||||
});
|
||||
ui.setUpdateState(function() {
|
||||
communication.updateGameState();
|
||||
});
|
||||
ui.setDecisionFunction(function(decisionId, result) {
|
||||
communication.gameDecisionMade(decisionId, result);
|
||||
});
|
||||
ui.setGetCardModifiers(function(cardId, func) {
|
||||
communication.getGameCardModifiers(cardId, func);
|
||||
});
|
||||
ui.layoutUI();
|
||||
|
||||
$(window).resize(function() {
|
||||
ui.layoutUI();
|
||||
});
|
||||
|
||||
communication.startGameSession();
|
||||
ui.setLoadCollectionFunc(function(collectionType, filter, start, count) {
|
||||
communication.getCollection(collectionType, filter, start, count, function(xml) {
|
||||
ui.displayCollection(xml);
|
||||
});
|
||||
});
|
||||
|
||||
ui.layoutUI();
|
||||
|
||||
communication.getDeck("default", function(xml) {
|
||||
ui.setupDeck(xml);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
|
||||
<script type="text/javascript" src="js/inheritance.js"></script>
|
||||
<script type="text/javascript" src="js/communication.js"></script>
|
||||
<script type="text/javascript" src="js/ui.js"></script>
|
||||
<script type="text/javascript" src="js/gameUi.js"></script>
|
||||
<script type="text/javascript" src="js/jCardGroup.js"></script>
|
||||
<script type="text/javascript" src="js/jCards.js"></script>
|
||||
<script type="text/javascript" src="js/logging.js"></script>
|
||||
@@ -100,7 +100,7 @@
|
||||
|
||||
$(document).ready(
|
||||
function () {
|
||||
ui = new GempLotrUI();
|
||||
ui = new GempLotrGameUI();
|
||||
|
||||
communication = new GempLotrCommunication("/gemp-lotr/server",
|
||||
function() {
|
||||
|
||||
@@ -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"
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
39
gemp-lotr/gemp-lotr-web/src/main/webapp/js/deckBuildingUi.js
Normal file
39
gemp-lotr/gemp-lotr-web/src/main/webapp/js/deckBuildingUi.js
Normal file
@@ -0,0 +1,39 @@
|
||||
var GempLotrDeckBuildingUI = Class.extend({
|
||||
deckDiv: null,
|
||||
collectionDiv: null,
|
||||
loadCollectionFunc: null,
|
||||
|
||||
init: function() {
|
||||
this.deckDiv = $("<div></div>");
|
||||
this.collectionDiv = $("<div></div>");
|
||||
|
||||
$("#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");
|
||||
}
|
||||
});
|
||||
@@ -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 = $("<div class='card'><img src='" + card.imageUrl + "' width='100%' height='100%'>" + ((text != null) ? text : "") + "</div>");
|
||||
var cardDiv = createCardDiv(card.imageUrl, text);
|
||||
cardDiv.data("card", card);
|
||||
var overlayDiv = $("<div class='tokenOverlay'></div>");
|
||||
cardDiv.append(overlayDiv);
|
||||
var borderDiv = $("<div class='borderOverlay'></div>");
|
||||
cardDiv.append(borderDiv);
|
||||
|
||||
var that = this;
|
||||
var swipeOptions = {
|
||||
@@ -75,5 +75,14 @@ var Card = Class.extend({
|
||||
else
|
||||
return Math.floor(height * cardScale);
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
function createCardDiv(image, text) {
|
||||
var cardDiv = $("<div class='card'><img src='" + image + "' width='100%' height='100%'>" + ((text != null) ? text : "") + "</div>");
|
||||
var overlayDiv = $("<div class='tokenOverlay'></div>");
|
||||
cardDiv.append(overlayDiv);
|
||||
var borderDiv = $("<div class='borderOverlay'></div>");
|
||||
cardDiv.append(borderDiv);
|
||||
|
||||
return cardDiv;
|
||||
}
|
||||
Reference in New Issue
Block a user