mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
* GUI: fixed broken mtgjson decks import (#7065);
Fixed typos in comments;
This commit is contained in:
parent
87caf1ddd1
commit
1db8d07cbd
7 changed files with 4410 additions and 4570 deletions
|
@ -236,7 +236,7 @@ public class Modes extends LinkedHashMap<UUID, Mode> {
|
|||
if (card != null) {
|
||||
for (Ability modeModifyingAbility : card.getAbilities(game)) {
|
||||
if (modeModifyingAbility instanceof OptionalAdditionalModeSourceCosts) {
|
||||
// cost must check activation conditional in changeModes
|
||||
// cost must check activation condition in changeModes
|
||||
((OptionalAdditionalModeSourceCosts) modeModifyingAbility).changeModes(source, game);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import mage.abilities.Ability;
|
|||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* Cost that can change ability's modes (example: Kicker or Entwine can make all modes selectabled).
|
||||
* Cost that can change ability's modes (example: Kicker or Entwine can make all modes selectable).
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
|
|
@ -35,7 +35,6 @@ public abstract class JsonDeckImporter extends DeckImporter {
|
|||
try { // Json parsing
|
||||
JSONParser parser = new JSONParser();
|
||||
JSONObject rootObj = (JSONObject) parser.parse(reader);
|
||||
deckList.setName((String) rootObj.get("name"));
|
||||
readJson(rootObj, deckList);
|
||||
|
||||
if (sbMessage.length() > 0) {
|
||||
|
|
|
@ -1,42 +1,55 @@
|
|||
package mage.cards.decks.importer;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.List;
|
||||
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import mage.cards.decks.DeckCardInfo;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author github: timhae
|
||||
*/
|
||||
public class MtgjsonDeckImporter extends JsonDeckImporter {
|
||||
|
||||
@Override
|
||||
protected void readJson(JSONObject rootObj, DeckCardLists deckList) {
|
||||
// set
|
||||
String set = (String) rootObj.get("code");
|
||||
JSONObject data = (JSONObject) rootObj.get("data");
|
||||
if (data == null) {
|
||||
sbMessage.append("Could not find data in json").append("'\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// info
|
||||
String deckSet = (String) data.get("code");
|
||||
String name = (String) data.get("name");
|
||||
if (name != null) {
|
||||
deckList.setName(name);
|
||||
}
|
||||
// mainboard
|
||||
JSONArray mainBoard = (JSONArray) rootObj.get("mainBoard");
|
||||
JSONArray mainBoard = (JSONArray) data.get("mainBoard");
|
||||
List<mage.cards.decks.DeckCardInfo> mainDeckList = deckList.getCards();
|
||||
addBoardToList(mainBoard, mainDeckList, set);
|
||||
addBoardToList(mainBoard, mainDeckList, deckSet);
|
||||
// sideboard
|
||||
JSONArray sideBoard = (JSONArray) rootObj.get("sideBoard");
|
||||
JSONArray sideBoard = (JSONArray) data.get("sideBoard");
|
||||
List<mage.cards.decks.DeckCardInfo> sideDeckList = deckList.getSideboard();
|
||||
addBoardToList(sideBoard, sideDeckList, set);
|
||||
addBoardToList(sideBoard, sideDeckList, deckSet);
|
||||
}
|
||||
|
||||
private void addBoardToList(JSONArray board, List<mage.cards.decks.DeckCardInfo> list, String set) {
|
||||
private void addBoardToList(JSONArray board, List<mage.cards.decks.DeckCardInfo> list, String deckSet) {
|
||||
board.forEach(arrayCard -> {
|
||||
JSONObject card = (JSONObject) arrayCard;
|
||||
String name = (String) card.get("name");
|
||||
String setCode = (String) card.get("setCode");
|
||||
if (setCode == null || setCode.isEmpty()) {
|
||||
setCode = deckSet;
|
||||
}
|
||||
|
||||
int num = ((Number) card.get("count")).intValue();
|
||||
Optional<CardInfo> cardLookup = getCardLookup().lookupCardInfo(name, set);
|
||||
Optional<CardInfo> cardLookup = getCardLookup().lookupCardInfo(name, setCode);
|
||||
if (!cardLookup.isPresent()) {
|
||||
sbMessage.append("Could not find card: '").append(name).append("'\n");
|
||||
} else {
|
||||
|
|
|
@ -18,10 +18,11 @@ public class MtgjsonDeckImportTest {
|
|||
return LOOKUP;
|
||||
}
|
||||
};
|
||||
|
||||
// offline deck from https://mtgjson.com/api/v5/decks/ArcaneTempo_GRN.json
|
||||
DeckCardLists deck = importer.importDeck(
|
||||
"src/test/java/mage/cards/decks/importer/samples/testdeck.json", errors, false);
|
||||
assertEquals("Arcane Tempo", deck.getName());
|
||||
|
||||
TestDeckChecker.checker()
|
||||
.addMain("Goblin Electromancer", 4)
|
||||
.addMain("Crackling Drake", 4)
|
||||
|
@ -41,6 +42,7 @@ public class MtgjsonDeckImportTest {
|
|||
.addMain("Izzet Guildgate", 4)
|
||||
.addMain("Island", 8)
|
||||
.addMain("Mountain", 7)
|
||||
//
|
||||
.addSide("The Mirari Conjecture", 1)
|
||||
.addSide("Beacon Bolt", 1)
|
||||
.addSide("Negate", 3)
|
||||
|
@ -48,6 +50,7 @@ public class MtgjsonDeckImportTest {
|
|||
.addSide("Fiery Cannonade", 3)
|
||||
.addSide("Shivan Fire", 2)
|
||||
.addSide("Disdainful Stroke", 2)
|
||||
//
|
||||
.verify(deck, 60, 15);
|
||||
|
||||
assertEquals("", errors.toString());
|
||||
|
|
|
@ -1,52 +1,52 @@
|
|||
package mage.cards.decks.importer;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class TestDeckChecker {
|
||||
|
||||
private final List<String> main = new ArrayList<>();
|
||||
private final List<String> side = new ArrayList<>();
|
||||
private final List<String> main = new ArrayList<>();
|
||||
private final List<String> side = new ArrayList<>();
|
||||
|
||||
public TestDeckChecker addMain(String name) {
|
||||
return addMain(name, 1);
|
||||
}
|
||||
|
||||
public TestDeckChecker addMain(String name, int quantity) {
|
||||
main.addAll(Collections.nCopies(quantity, name));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestDeckChecker addSide(String name) {
|
||||
return addSide(name, 1);
|
||||
}
|
||||
|
||||
public TestDeckChecker addSide(String name, int quantity) {
|
||||
side.addAll(Collections.nCopies(quantity, name));
|
||||
return this;
|
||||
}
|
||||
|
||||
public void verify(DeckCardLists deck, int nMain, int nSide) {
|
||||
assertEquals(nMain, main.size());
|
||||
assertEquals(nSide, side.size());
|
||||
assertEquals(nMain, deck.getCards().size());
|
||||
assertEquals(nSide, deck.getSideboard().size());
|
||||
|
||||
for (int i = 0; i < main.size(); i++) {
|
||||
String expected = main.get(i);
|
||||
String actual = deck.getCards().get(i).getCardName();
|
||||
assertEquals(String.format("Expected: '%s' Actual: '%s' at index: %s",
|
||||
expected, actual, i), expected, actual);
|
||||
public TestDeckChecker addMain(String name) {
|
||||
return addMain(name, 1);
|
||||
}
|
||||
}
|
||||
|
||||
public static TestDeckChecker checker() {
|
||||
return new TestDeckChecker();
|
||||
}
|
||||
public TestDeckChecker addMain(String name, int quantity) {
|
||||
main.addAll(Collections.nCopies(quantity, name));
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestDeckChecker addSide(String name) {
|
||||
return addSide(name, 1);
|
||||
}
|
||||
|
||||
public TestDeckChecker addSide(String name, int quantity) {
|
||||
side.addAll(Collections.nCopies(quantity, name));
|
||||
return this;
|
||||
}
|
||||
|
||||
public void verify(DeckCardLists deck, int nMain, int nSide) {
|
||||
assertEquals("main deck size", nMain, main.size());
|
||||
assertEquals("main deck loaded size", nMain, deck.getCards().size());
|
||||
assertEquals("sideboard size", nSide, side.size());
|
||||
assertEquals("sideboard loaded size", nSide, deck.getSideboard().size());
|
||||
|
||||
for (int i = 0; i < main.size(); i++) {
|
||||
String expected = main.get(i);
|
||||
String actual = deck.getCards().get(i).getCardName();
|
||||
assertEquals(String.format("Expected: '%s' Actual: '%s' at index: %s",
|
||||
expected, actual, i), expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
public static TestDeckChecker checker() {
|
||||
return new TestDeckChecker();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue