Working on deck building.

This commit is contained in:
marcins78@gmail.com
2011-09-04 02:58:04 +00:00
parent c144a8d6f0
commit 4701f7830a
3 changed files with 36 additions and 4 deletions

View File

@@ -1,15 +1,15 @@
package com.gempukku.lotro.game;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
public class LotroCardBlueprintLibrary {
private String[] _packageNames =
new String[]{
"", ".dwarven", ".elven", ".isengard", ".moria", ".shire", ".site"
};
private Map<String, LotroCardBlueprint> _blueprintMap = new TreeMap<String, LotroCardBlueprint>();
private Map<String, LotroCardBlueprint> _blueprintMap = new HashMap<String, LotroCardBlueprint>();
public LotroCardBlueprint getLotroCardBlueprint(String blueprintId) {
if (_blueprintMap.containsKey(blueprintId))

View File

@@ -7,7 +7,7 @@ import java.util.*;
public class DefaultCardCollection implements CardCollection {
private Map<String, Integer> _cardsCount = new TreeMap<String, Integer>();
private Map<String, LotroCardBlueprint> _cards = new TreeMap<String, LotroCardBlueprint>();
private Map<String, LotroCardBlueprint> _cards = new TreeMap<String, LotroCardBlueprint>(new CardBlueprintIdComparator());
public void addCards(String blueprintId, LotroCardBlueprint blueprint, int count) {
_cardsCount.put(blueprintId, count);
@@ -65,4 +65,16 @@ public class DefaultCardCollection implements CardCollection {
}
return defaultResult;
}
private static class CardBlueprintIdComparator implements Comparator<String> {
@Override
public int compare(String o1, String o2) {
String[] o1Parts = o1.split("_");
String[] o2Parts = o2.split("_");
if (o1Parts[0].equals(o2Parts[0]))
return Integer.parseInt(o1Parts[1]) - Integer.parseInt(o2Parts[1]);
else
return Integer.parseInt(o1Parts[0]) - Integer.parseInt(o2Parts[0]);
}
}
}

View File

@@ -1,12 +1,17 @@
var GempLotrDeckBuildingUI = Class.extend({
deckDiv: null,
collectionDiv: null,
collectionGroup: null,
loadCollectionFunc: null,
init: function() {
this.deckDiv = $("<div></div>");
this.collectionDiv = $("<div></div>");
this.collectionGroup = new NormalCardGroup(null, function(card) {
return (card.zone == "collection");
});
$("#main").append(this.deckDiv);
$("#main").append(this.collectionDiv);
},
@@ -20,7 +25,21 @@ var GempLotrDeckBuildingUI = Class.extend({
},
displayCollection: function(xml) {
alert(xml.text);
var root = xml.documentElement;
if (root.tagName == "collection") {
var cards = root.getElementsByTagName("card");
for (var i = 0; i < cards.length; i++) {
var cardElem = cards[i];
var blueprintId = cardElem.getAttribute("blueprintId");
var count = cardElem.getAttribute("count");
var card = new Card(blueprintId, "collection", "collection" + i, "player");
var cardDiv = createCardDiv(card.imageUrl, null);
cardDiv.data("card", card);
this.collectionDiv.append(cardDiv);
}
this.collectionGroup.layoutCards();
}
},
layoutUI: function() {
@@ -31,6 +50,7 @@ var GempLotrDeckBuildingUI = Class.extend({
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"});
this.collectionGroup.setBounds(0, 0, width, height - deckHeight);
},
processError: function (xhr, ajaxOptions, thrownError) {