Adding missing check for ring in the deck when opening.

This commit is contained in:
marcins78@gmail.com
2012-07-04 19:31:33 +00:00
parent c0cdfe15aa
commit c8202dfd13

View File

@@ -51,24 +51,24 @@ var GempLotrDeckBuildingUI = Class.extend({
this.comm = new GempLotrCommunication("/gemp-lotr-server", that.processError); this.comm = new GempLotrCommunication("/gemp-lotr-server", that.processError);
this.cardFilter = new CardFilter($("#collectionDiv"), this.cardFilter = new CardFilter($("#collectionDiv"),
function (filter, start, count, callback) { function (filter, start, count, callback) {
that.comm.getCollection(that.collectionType, filter, start, count, function (xml) { that.comm.getCollection(that.collectionType, filter, start, count, function (xml) {
callback(xml); callback(xml);
}, { }, {
"404":function () { "404":function () {
alert("You don't have collection of that type."); alert("You don't have collection of that type.");
} }
});
},
function () {
that.clearCollection();
},
function (elem, type, blueprintId, count) {
that.addCardToCollection(type, blueprintId, count, elem.getAttribute("side"), elem.getAttribute("contents"));
},
function () {
that.finishCollection();
}); });
},
function () {
that.clearCollection();
},
function (elem, type, blueprintId, count) {
that.addCardToCollection(type, blueprintId, count, elem.getAttribute("side"), elem.getAttribute("contents"));
},
function () {
that.finishCollection();
});
this.collectionType = "default"; this.collectionType = "default";
this.deckDiv = $("#deckDiv"); this.deckDiv = $("#deckDiv");
@@ -101,75 +101,75 @@ var GempLotrDeckBuildingUI = Class.extend({
this.deckDiv.append(this.manageDecksDiv); this.deckDiv.append(this.manageDecksDiv);
newDeckBut.click( newDeckBut.click(
function () { function () {
that.deckName = null; that.deckName = null;
$("#editingDeck").text("New deck"); $("#editingDeck").text("New deck");
that.clearDeck(); that.clearDeck();
}); });
saveDeckBut.click( saveDeckBut.click(
function () { function () {
if (that.deckName == null) { if (that.deckName == null) {
var newDeckName = prompt("Enter the name of the deck", ""); var newDeckName = prompt("Enter the name of the deck", "");
if (newDeckName == null)
return;
if (newDeckName.length < 3 || newDeckName.length > 40)
alert("Deck name has to have at least 3 characters and at most 40 characters.");
else {
that.deckName = newDeckName;
$("#editingDeck").text(newDeckName);
that.saveDeck(true);
}
} else {
that.saveDeck(false);
}
});
renameDeckBut.click(
function () {
if (that.deckName == null) {
alert("You can't rename this deck, since it's not named (saved) yet.");
return;
}
var newDeckName = prompt("Enter new name for the deck", "");
if (newDeckName == null) if (newDeckName == null)
return; return;
if (newDeckName.length < 3 || newDeckName.length > 40) if (newDeckName.length < 3 || newDeckName.length > 40)
alert("Deck name has to have at least 3 characters and at most 40 characters."); alert("Deck name has to have at least 3 characters and at most 40 characters.");
else { else {
var oldDeckName = that.deckName;
that.deckName = newDeckName; that.deckName = newDeckName;
$("#editingDeck").text(newDeckName); $("#editingDeck").text(newDeckName);
that.saveDeck(true); that.comm.renameDeck(oldDeckName, newDeckName,
} function () {
} else { if (confirm("Do you wish to save this deck?"))
that.saveDeck(false); that.saveDeck(false);
} }, {
});
renameDeckBut.click(
function () {
if (that.deckName == null) {
alert("You can't rename this deck, since it's not named (saved) yet.");
return;
}
var newDeckName = prompt("Enter new name for the deck", "");
if (newDeckName == null)
return;
if (newDeckName.length < 3 || newDeckName.length > 40)
alert("Deck name has to have at least 3 characters and at most 40 characters.");
else {
var oldDeckName = that.deckName;
that.deckName = newDeckName;
$("#editingDeck").text(newDeckName);
that.comm.renameDeck(oldDeckName, newDeckName,
function () {
if (confirm("Do you wish to save this deck?"))
that.saveDeck(false);
}, {
"404":function () { "404":function () {
alert("Couldn't find the deck to rename on the server."); alert("Couldn't find the deck to rename on the server.");
} }
}); });
} }
}); });
copyDeckBut.click( copyDeckBut.click(
function () { function () {
that.deckName = null; that.deckName = null;
$("#editingDeck").text("New deck"); $("#editingDeck").text("New deck");
}); });
deckListBut.click( deckListBut.click(
function () { function () {
that.loadDeckList(); that.loadDeckList();
}); });
this.collectionDiv = $("#collectionDiv"); this.collectionDiv = $("#collectionDiv");
$("#collectionSelect").change( $("#collectionSelect").change(
function () { function () {
that.collectionType = that.getCollectionType(); that.collectionType = that.getCollectionType();
that.cardFilter.getCollection(); that.cardFilter.getCollection();
}); });
this.normalCollectionDiv = $("<div></div>"); this.normalCollectionDiv = $("<div></div>");
this.normalCollectionGroup = new NormalCardGroup(this.normalCollectionDiv, function (card) { this.normalCollectionGroup = new NormalCardGroup(this.normalCollectionDiv, function (card) {
@@ -180,11 +180,11 @@ var GempLotrDeckBuildingUI = Class.extend({
this.ringBearerDiv = $("<div>Ring Bearer</div>"); this.ringBearerDiv = $("<div>Ring Bearer</div>");
this.ringBearerDiv.click( this.ringBearerDiv.click(
function () { function () {
if ($(".card", that.ringBearerDiv).length == 0) { if ($(".card", that.ringBearerDiv).length == 0) {
that.showPredefinedFilter("keyword:CAN_START_WITH_RING type:card", that.ringBearerDiv); that.showPredefinedFilter("keyword:CAN_START_WITH_RING type:card", that.ringBearerDiv);
} }
}); });
this.ringBearerGroup = new NormalCardGroup(this.ringBearerDiv, function (card) { this.ringBearerGroup = new NormalCardGroup(this.ringBearerDiv, function (card) {
return true; return true;
}); });
@@ -192,10 +192,10 @@ var GempLotrDeckBuildingUI = Class.extend({
this.ringDiv = $("<div>Ring</div>"); this.ringDiv = $("<div>Ring</div>");
this.ringDiv.click( this.ringDiv.click(
function () { function () {
if ($(".card", that.ringDiv).length == 0) if ($(".card", that.ringDiv).length == 0)
that.showPredefinedFilter("cardType:THE_ONE_RING type:card", that.ringDiv); that.showPredefinedFilter("cardType:THE_ONE_RING type:card", that.ringDiv);
}); });
this.ringGroup = new NormalCardGroup(this.ringDiv, function (card) { this.ringGroup = new NormalCardGroup(this.ringDiv, function (card) {
return true; return true;
}); });
@@ -227,28 +227,28 @@ var GempLotrDeckBuildingUI = Class.extend({
this.selectionFunc = this.addCardToDeckAndLayout; this.selectionFunc = this.addCardToDeckAndLayout;
$("body").click( $("body").click(
function (event) { function (event) {
return that.clickCardFunction(event); return that.clickCardFunction(event);
}); });
$("body").mousedown( $("body").mousedown(
function (event) { function (event) {
return that.dragStartCardFunction(event); return that.dragStartCardFunction(event);
}); });
$("body").mouseup( $("body").mouseup(
function (event) { function (event) {
return that.dragStopCardFunction(event); return that.dragStopCardFunction(event);
}); });
var width = $(window).width(); var width = $(window).width();
var height = $(window).height(); var height = $(window).height();
this.infoDialog = $("<div></div>") this.infoDialog = $("<div></div>")
.dialog({ .dialog({
autoOpen:false, autoOpen:false,
closeOnEscape:true, closeOnEscape:true,
resizable:false, resizable:false,
title:"Card information" title:"Card information"
}); });
var swipeOptions = { var swipeOptions = {
threshold:20, threshold:20,
@@ -278,16 +278,16 @@ var GempLotrDeckBuildingUI = Class.extend({
getCollectionTypes:function () { getCollectionTypes:function () {
var that = this; var that = this;
this.comm.getCollectionTypes( this.comm.getCollectionTypes(
function (xml) { function (xml) {
var root = xml.documentElement; var root = xml.documentElement;
if (root.tagName == "collections") { if (root.tagName == "collections") {
var collections = root.getElementsByTagName("collection"); var collections = root.getElementsByTagName("collection");
for (var i = 0; i < collections.length; i++) { for (var i = 0; i < collections.length; i++) {
var collection = collections[i]; var collection = collections[i];
$("#collectionSelect").append("<option value='" + collection.getAttribute("type") + "'>" + collection.getAttribute("name") + "</option>"); $("#collectionSelect").append("<option value='" + collection.getAttribute("type") + "'>" + collection.getAttribute("name") + "</option>");
}
} }
} });
});
}, },
loadDeckList:function () { loadDeckList:function () {
@@ -295,15 +295,15 @@ var GempLotrDeckBuildingUI = Class.extend({
this.comm.getDecks(function (xml) { this.comm.getDecks(function (xml) {
if (that.deckListDialog == null) { if (that.deckListDialog == null) {
that.deckListDialog = $("<div></div>") that.deckListDialog = $("<div></div>")
.dialog({ .dialog({
title:"Your stored decks", title:"Your stored decks",
autoOpen:false, autoOpen:false,
closeOnEscape:true, closeOnEscape:true,
resizable:true, resizable:true,
width:400, width:400,
height:400, height:400,
modal:true modal:true
}); });
} }
that.deckListDialog.html(""); that.deckListDialog.html("");
@@ -326,39 +326,39 @@ var GempLotrDeckBuildingUI = Class.extend({
that.deckListDialog.append(deckElem); that.deckListDialog.append(deckElem);
openDeckBut.click( openDeckBut.click(
(function (deckName) { (function (deckName) {
return function () { return function () {
that.comm.getDeck(deckName, that.comm.getDeck(deckName,
function (xml) { function (xml) {
that.setupDeck(xml, deckName); that.setupDeck(xml, deckName);
}); });
}; };
})(deckName)); })(deckName));
deckListBut.click( deckListBut.click(
(function (deckName) { (function (deckName) {
return function () { return function () {
window.open('/gemp-lotr-server/deck/html?deckName=' + encodeURIComponent(deckName), "_blank"); window.open('/gemp-lotr-server/deck/html?deckName=' + encodeURIComponent(deckName), "_blank");
}; };
})(deckName)); })(deckName));
deleteDeckBut.click( deleteDeckBut.click(
(function (deckName) { (function (deckName) {
return function () { return function () {
if (confirm("Are you sure you want to delete this deck?")) { if (confirm("Are you sure you want to delete this deck?")) {
that.comm.deleteDeck(deckName, that.comm.deleteDeck(deckName,
function () { function () {
if (that.deckName == deckName) { if (that.deckName == deckName) {
that.deckName = null; that.deckName = null;
$("#editingDeck").text("New deck"); $("#editingDeck").text("New deck");
that.clearDeck(); that.clearDeck();
} }
that.loadDeckList(); that.loadDeckList();
}); });
} }
}; };
})(deckName)); })(deckName));
} }
} }
@@ -420,15 +420,15 @@ var GempLotrDeckBuildingUI = Class.extend({
if (this.selectionDialog == null) { if (this.selectionDialog == null) {
this.selectionDialog = $("<div></div>") this.selectionDialog = $("<div></div>")
.dialog({ .dialog({
title:"Choose one", title:"Choose one",
autoOpen:false, autoOpen:false,
closeOnEscape:true, closeOnEscape:true,
resizable:true, resizable:true,
width:400, width:400,
height:200, height:200,
modal:true modal:true
}); });
this.selectionGroup = new NormalCardGroup(this.selectionDialog, function (card) { this.selectionGroup = new NormalCardGroup(this.selectionDialog, function (card) {
return true; return true;
@@ -535,17 +535,17 @@ var GempLotrDeckBuildingUI = Class.extend({
var sites = new Array(); var sites = new Array();
$(".card", this.siteDiv).each( $(".card", this.siteDiv).each(
function () { function () {
sites.push($(this).data("card").blueprintId); sites.push($(this).data("card").blueprintId);
}); });
result += sites; result += sites;
result += "|"; result += "|";
var cards = new Array(); var cards = new Array();
$(".card", this.drawDeckDiv).each( $(".card", this.drawDeckDiv).each(
function () { function () {
cards.push($(this).data("card").blueprintId); cards.push($(this).data("card").blueprintId);
}); });
result += cards; result += cards;
return result; return result;
@@ -626,14 +626,14 @@ var GempLotrDeckBuildingUI = Class.extend({
var that = this; var that = this;
var added = false; var added = false;
$(".card.cardInDeck", this.drawDeckDiv).each( $(".card.cardInDeck", this.drawDeckDiv).each(
function () { function () {
var cardData = $(this).data("card"); var cardData = $(this).data("card");
if (cardData.blueprintId == blueprintId) { if (cardData.blueprintId == blueprintId) {
var attDiv = that.addCardToContainer(blueprintId, "attached", that.drawDeckDiv, false); var attDiv = that.addCardToContainer(blueprintId, "attached", that.drawDeckDiv, false);
cardData.attachedCards.push(attDiv); cardData.attachedCards.push(attDiv);
added = true; added = true;
} }
}); });
if (!added) { if (!added) {
var div = this.addCardToContainer(blueprintId, side, this.drawDeckDiv, false) var div = this.addCardToContainer(blueprintId, side, this.drawDeckDiv, false)
div.addClass("cardInDeck"); div.addClass("cardInDeck");
@@ -649,9 +649,9 @@ var GempLotrDeckBuildingUI = Class.extend({
} else { } else {
var that = this; var that = this;
setTimeout( setTimeout(
function () { function () {
that.checkDeckStatsDirty(); that.checkDeckStatsDirty();
}, that.checkDirtyInterval); }, that.checkDirtyInterval);
} }
}, },
@@ -660,23 +660,23 @@ var GempLotrDeckBuildingUI = Class.extend({
var deckContents = this.getDeckContents(); var deckContents = this.getDeckContents();
if (deckContents != null) { if (deckContents != null) {
this.comm.getDeckStats(deckContents, this.comm.getDeckStats(deckContents,
function (html) { function (html) {
$("#deckStats").html(html); $("#deckStats").html(html);
setTimeout( setTimeout(
function () { function () {
that.checkDeckStatsDirty(); that.checkDeckStatsDirty();
}, that.checkDirtyInterval); }, that.checkDirtyInterval);
}, { }, {
"400":function () { "400":function () {
alert("Invalid deck for getting stats."); alert("Invalid deck for getting stats.");
} }
}); });
} else { } else {
$("#deckStats").html("Deck has no Ring, Ring-bearer or all 9 sites"); $("#deckStats").html("Deck has no Ring, Ring-bearer or all 9 sites");
setTimeout( setTimeout(
function () { function () {
that.checkDeckStatsDirty(); that.checkDeckStatsDirty();
}, that.checkDirtyInterval); }, that.checkDirtyInterval);
} }
}, },
@@ -690,11 +690,11 @@ var GempLotrDeckBuildingUI = Class.extend({
} }
var cardInCollectionElem = null; var cardInCollectionElem = null;
$(".card", this.normalCollectionDiv).each( $(".card", this.normalCollectionDiv).each(
function () { function () {
var tempCardData = $(this).data("card"); var tempCardData = $(this).data("card");
if (tempCardData.blueprintId == cardData.blueprintId) if (tempCardData.blueprintId == cardData.blueprintId)
cardInCollectionElem = $(this); cardInCollectionElem = $(this);
}); });
if (cardInCollectionElem != null) { if (cardInCollectionElem != null) {
var cardInCollectionData = cardInCollectionElem.data("card"); var cardInCollectionData = cardInCollectionElem.data("card");
cardInCollectionData.tokens = {count:(parseInt(cardInCollectionData.tokens["count"]) + 1)}; cardInCollectionData.tokens = {count:(parseInt(cardInCollectionData.tokens["count"]) + 1)};
@@ -708,11 +708,11 @@ var GempLotrDeckBuildingUI = Class.extend({
clearDeck:function () { clearDeck:function () {
$(".cardInDeck").each( $(".cardInDeck").each(
function () { function () {
var cardData = $(this).data("card"); var cardData = $(this).data("card");
for (var i = 0; i < cardData.attachedCards.length; i++) for (var i = 0; i < cardData.attachedCards.length; i++)
cardData.attachedCards[i].remove(); cardData.attachedCards[i].remove();
}); });
$(".cardInDeck").remove(); $(".cardInDeck").remove();
this.layoutUI(false); this.layoutUI(false);
@@ -732,7 +732,8 @@ var GempLotrDeckBuildingUI = Class.extend({
this.addCardToContainer(ringBearer[0].getAttribute("blueprintId"), "deck", this.ringBearerDiv, false).addClass("cardInDeck"); this.addCardToContainer(ringBearer[0].getAttribute("blueprintId"), "deck", this.ringBearerDiv, false).addClass("cardInDeck");
var ring = root.getElementsByTagName("ring"); var ring = root.getElementsByTagName("ring");
this.addCardToContainer(ring[0].getAttribute("blueprintId"), "deck", this.ringDiv, false).addClass("cardInDeck"); if (ring.length > 0)
this.addCardToContainer(ring[0].getAttribute("blueprintId"), "deck", this.ringDiv, false).addClass("cardInDeck");
var sites = root.getElementsByTagName("site"); var sites = root.getElementsByTagName("site");
for (var i = 0; i < sites.length; i++) for (var i = 0; i < sites.length; i++)
@@ -774,11 +775,11 @@ var GempLotrDeckBuildingUI = Class.extend({
var card = new Card(blueprintId, side, "collection", "player"); var card = new Card(blueprintId, side, "collection", "player");
var countInDeck = 0; var countInDeck = 0;
$(".card", this.deckDiv).each( $(".card", this.deckDiv).each(
function () { function () {
var tempCardData = $(this).data("card"); var tempCardData = $(this).data("card");
if (blueprintId == tempCardData.blueprintId) if (blueprintId == tempCardData.blueprintId)
countInDeck++; countInDeck++;
}); });
card.tokens = {"count":count - countInDeck}; card.tokens = {"count":count - countInDeck};
var cardDiv = createCardDiv(card.imageUrl, null, card.isFoil(), true, false, card.hasErrata()); var cardDiv = createCardDiv(card.imageUrl, null, card.isFoil(), true, false, card.hasErrata());
cardDiv.data("card", card); cardDiv.data("card", card);