mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +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");
|
||||
// mainboard
|
||||
JSONArray mainBoard = (JSONArray) rootObj.get("mainBoard");
|
||||
List<mage.cards.decks.DeckCardInfo> mainDeckList = deckList.getCards();
|
||||
addBoardToList(mainBoard, mainDeckList, set);
|
||||
// sideboard
|
||||
JSONArray sideBoard = (JSONArray) rootObj.get("sideBoard");
|
||||
List<mage.cards.decks.DeckCardInfo> sideDeckList = deckList.getSideboard();
|
||||
addBoardToList(sideBoard, sideDeckList, set);
|
||||
JSONObject data = (JSONObject) rootObj.get("data");
|
||||
if (data == null) {
|
||||
sbMessage.append("Could not find data in json").append("'\n");
|
||||
return;
|
||||
}
|
||||
|
||||
private void addBoardToList(JSONArray board, List<mage.cards.decks.DeckCardInfo> list, String set) {
|
||||
// info
|
||||
String deckSet = (String) data.get("code");
|
||||
String name = (String) data.get("name");
|
||||
if (name != null) {
|
||||
deckList.setName(name);
|
||||
}
|
||||
// mainboard
|
||||
JSONArray mainBoard = (JSONArray) data.get("mainBoard");
|
||||
List<mage.cards.decks.DeckCardInfo> mainDeckList = deckList.getCards();
|
||||
addBoardToList(mainBoard, mainDeckList, deckSet);
|
||||
// sideboard
|
||||
JSONArray sideBoard = (JSONArray) data.get("sideBoard");
|
||||
List<mage.cards.decks.DeckCardInfo> sideDeckList = deckList.getSideboard();
|
||||
addBoardToList(sideBoard, sideDeckList, deckSet);
|
||||
}
|
||||
|
||||
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,12 +1,12 @@
|
|||
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 {
|
||||
|
||||
|
@ -32,10 +32,10 @@ public class TestDeckChecker {
|
|||
}
|
||||
|
||||
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());
|
||||
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);
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue