forked from External/mage
* 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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue