Merge pull request #2910 from ingmargoudt/master

changed cardtype from list to enumset
This commit is contained in:
ingmargoudt 2017-03-03 23:01:56 +01:00 committed by GitHub
commit a4f64c74c9
24 changed files with 172 additions and 81 deletions

View file

@ -177,7 +177,7 @@ public class TableModel extends AbstractTableModel implements ICardGrid {
String key1 = cv.getName() + cv.getExpansionSetCode() + cv.getCardNumber();
for (CardView cardView : cards.values()) {
String key2 = cardView.getName() + cardView.getExpansionSetCode() + cardView.getCardNumber();
if ((key1).equals(key2)) {
if (key1.equals(key2)) {
view.set(j, cardView);
break;
}

View file

@ -44,6 +44,7 @@ import javax.swing.ImageIcon;
import javax.swing.SwingUtilities;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
import mage.client.cards.BigCard;
import mage.client.util.GUISizeHelper;
import mage.client.util.ImageHelper;
@ -58,7 +59,6 @@ import org.apache.log4j.Logger;
import org.mage.plugins.card.utils.impl.ImageManagerImpl;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class CardInfoWindowDialog extends MageDialog {
@ -109,7 +109,7 @@ public class CardInfoWindowDialog extends MageDialog {
this.setFrameIcon(new ImageIcon(ImageManagerImpl.getInstance().getExileImage()));
break;
default:
// no icon yet
// no icon yet
}
this.setTitelBarToolTip(name);
setGUISize();
@ -202,17 +202,19 @@ public class CardInfoWindowDialog extends MageDialog {
});
}
private int qtyCardTypes(mage.view.CardsView cardsView){
Set<String> cardTypesPresent = new LinkedHashSet<String>() {};
for (CardView card : cardsView.values()){
List<CardType> cardTypes = card.getCardTypes();
for (CardType cardType : cardTypes){
private int qtyCardTypes(mage.view.CardsView cardsView) {
Set<String> cardTypesPresent = new LinkedHashSet<String>() {
};
for (CardView card : cardsView.values()) {
Set<CardType> cardTypes = card.getCardTypes();
for (CardType cardType : cardTypes) {
cardTypesPresent.add(cardType.toString());
}
}
if (cardTypesPresent.isEmpty()) return 0;
else return cardTypesPresent.size();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
@ -227,24 +229,24 @@ public class CardInfoWindowDialog extends MageDialog {
setIconifiable(true);
setResizable(true);
setPreferredSize(new Dimension((int) Math.round(GUISizeHelper.otherZonesCardDimension.width * 1.3),
(int) Math.round(GUISizeHelper.otherZonesCardDimension.height * 1.2)));
(int) Math.round(GUISizeHelper.otherZonesCardDimension.height * 1.2)));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(cards, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(0, 0, 0))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(cards, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(0, 0, 0))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(cards, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(0, 0, 0))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(cards, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(0, 0, 0))
);
pack();
pack();
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables

View file

@ -869,7 +869,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
Set<String> cardTypesPresent = new LinkedHashSet<String>() {
};
for (CardView card : cardsView.values()) {
List<CardType> cardTypes = card.getCardTypes();
Set<CardType> cardTypes = card.getCardTypes();
for (CardType cardType : cardTypes) {
cardTypesPresent.add(cardType.toString());
}

View file

@ -0,0 +1,27 @@
package mage.client.util;
import mage.client.deckeditor.table.CardHelper;
import mage.constants.CardType;
import mage.view.CardView;
import org.junit.Assert;
import org.junit.Test;
import static org.hamcrest.core.Is.is;
/**
* Created by IGOUDT on 3-3-2017.
*/
public class CardHelperTest {
@Test
public void testCardTypeOrder() {
CardView v = new CardView(true);
v.getCardTypes().add(CardType.CREATURE);
v.getCardTypes().add(CardType.ARTIFACT);
String cardtypeText = CardHelper.getType(v);
Assert.assertThat(cardtypeText, is("Artifact Creature"));
}
}

View file

@ -28,12 +28,14 @@
package mage.view;
import java.util.ArrayList;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.constants.CardType;
import java.util.ArrayList;
import java.util.EnumSet;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class AbilityView extends CardView {
@ -53,7 +55,7 @@ public class AbilityView extends CardView {
this.power = "";
this.toughness = "";
this.loyalty = "";
this.cardTypes = new ArrayList<>();
this.cardTypes = EnumSet.noneOf(CardType.class);
this.subTypes = new ArrayList<>();
this.superTypes = new ArrayList<>();
this.color = new ObjectColor();

View file

@ -27,9 +27,8 @@
*/
package mage.view;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.*;
import mage.MageObject;
import mage.ObjectColor;
import mage.abilities.Mode;
@ -71,7 +70,7 @@ public class CardView extends SimpleCardView {
protected String toughness;
protected String loyalty;
protected String startingLoyalty;
protected List<CardType> cardTypes;
protected EnumSet<CardType> cardTypes;
protected List<String> subTypes;
protected List<String> superTypes;
protected ObjectColor color;
@ -519,7 +518,7 @@ public class CardView extends SimpleCardView {
this.toughness = "";
this.loyalty = "";
this.startingLoyalty = "";
this.cardTypes = new ArrayList<>();
this.cardTypes = EnumSet.noneOf(CardType.class);
this.subTypes = new ArrayList<>();
this.superTypes = new ArrayList<>();
this.color = new ObjectColor();
@ -640,7 +639,7 @@ public class CardView extends SimpleCardView {
return startingLoyalty;
}
public List<CardType> getCardTypes() {
public Set<CardType> getCardTypes() {
return cardTypes;
}

View file

@ -170,7 +170,7 @@ public class UserManager {
calendar.add(Calendar.MINUTE, -3);
List<User> usersToCheck = new ArrayList<>(users.values());
for (User user : usersToCheck) {
if (!user.getUserState().equals(UserState.Expired) && user.isExpired(calendar.getTime())) {
if (user.getUserState() != UserState.Expired && user.isExpired(calendar.getTime())) {
removeUser(user.getId(), DisconnectReason.SessionExpired);
}
}

View file

@ -401,7 +401,7 @@ public class GameController implements GameCallback {
return false;
}
}
if (player.isHuman() && gameSessions.get(player.getId()) == null) {
if (player.isHuman() && !gameSessions.containsKey(player.getId())) {
return false;
}
}
@ -410,11 +410,11 @@ public class GameController implements GameCallback {
}
public void watch(UUID userId) {
if (userPlayerMap.get(userId) != null) {
if (userPlayerMap.containsKey(userId)) {
// You can't watch a game if you already a player in it
return;
}
if (watchers.get(userId) != null) {
if (watchers.containsKey(userId)) {
// You can't watch a game if you already watch it
return;
}

View file

@ -29,6 +29,7 @@
package mage.cards.c;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.OnEventTriggeredAbility;
@ -95,7 +96,7 @@ class CrawlingSensationTriggeredAbility extends TriggeredAbilityImpl {
for (Card card : zEvent.getCards()) {
if (card != null) {
UUID cardOwnerId = card.getOwnerId();
List<CardType> cardType = card.getCardType();
Set<CardType> cardType = card.getCardType();
if (cardOwnerId != null
&& card.getOwnerId().equals(getControllerId())

View file

@ -28,6 +28,7 @@
package mage.cards.m;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.MageObject;
import mage.ObjectColor;
@ -90,7 +91,7 @@ class PermanentsAreArtifactsEffect extends ContinuousEffectImpl {
@Override
public boolean apply(Game game, Ability source) {
for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
List<CardType> cardType = perm.getCardType();
Set<CardType> cardType = perm.getCardType();
if (!cardType.contains(CardType.ARTIFACT)) {
cardType.add(CardType.ARTIFACT);
}

View file

@ -27,7 +27,9 @@
*/
package mage.cards.p;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
@ -164,7 +166,7 @@ class PossibilityStormEffect extends OneShotEffect {
return false;
}
private boolean sharesType(Card card, List<CardType> cardTypes) {
private boolean sharesType(Card card, EnumSet<CardType> cardTypes) {
for (CardType type : card.getCardType()) {
if (cardTypes.contains(type)) {
return true;

View file

@ -28,6 +28,7 @@
package mage.cards.p;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.constants.CardType;
import mage.constants.Outcome;
@ -95,7 +96,7 @@ class PrimalSurgeEffect extends OneShotEffect {
Card card = player.getLibrary().removeFromTop(game);
if (card != null) {
card.moveToExile(null, "", source.getSourceId(), game);
List<CardType> cardType = card.getCardType();
Set<CardType> cardType = card.getCardType();
if ((cardType.contains(CardType.ARTIFACT) || cardType.contains(CardType.CREATURE)
|| cardType.contains(CardType.ENCHANTMENT) || cardType.contains(CardType.LAND)
|| cardType.contains(CardType.PLANESWALKER))

View file

@ -28,6 +28,7 @@
package mage.cards.s;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.TriggeredAbilityImpl;
@ -99,7 +100,7 @@ class SidisiBroodTyrantTriggeredAbility extends TriggeredAbilityImpl {
if (card != null) {
UUID cardOwnerId = card.getOwnerId();
List<CardType> cardType = card.getCardType();
Set<CardType> cardType = card.getCardType();
if (cardOwnerId != null
&& card.getOwnerId().equals(getControllerId())

View file

@ -28,6 +28,7 @@
package mage.cards.t;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.TriggeredAbilityImpl;
@ -110,7 +111,7 @@ class TheGitrogMonsterTriggeredAbility extends TriggeredAbilityImpl {
for (Card card : zEvent.getCards()) {
if (card != null) {
UUID cardOwnerId = card.getOwnerId();
List<CardType> cardType = card.getCardType();
Set<CardType> cardType = card.getCardType();
if (cardOwnerId != null
&& card.getOwnerId().equals(getControllerId())
&& cardType != null

View file

@ -0,0 +1,26 @@
package org.mage.test.cards.continuous;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
* Created by IGOUDT on 23-2-2017.
*/
public class AuratouchedMageTest extends CardTestPlayerBase {
@Test
public void testSearch() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 10);
addCard(Zone.HAND, playerA, "Auratouched Mage");
castSpell(0, PhaseStep.PRECOMBAT_MAIN, playerA, "Auratouched Mage");
addCard(Zone.LIBRARY, playerA, "White Ward", 1);
setChoice(playerA, "White ward");
setStopAt(0, PhaseStep.PRECOMBAT_MAIN);
execute();
}
}

View file

@ -1,7 +1,9 @@
package mage;
import java.io.Serializable;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Abilities;
import mage.abilities.Ability;
@ -24,7 +26,7 @@ public interface MageObject extends MageItem, Serializable {
void setName(String name);
List<CardType> getCardType();
EnumSet<CardType> getCardType();
List<String> getSubtype(Game game);

View file

@ -27,9 +27,8 @@
*/
package mage;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.*;
import mage.abilities.Abilities;
import mage.abilities.AbilitiesImpl;
import mage.abilities.Ability;
@ -55,7 +54,7 @@ public abstract class MageObjectImpl implements MageObject {
protected ObjectColor color;
protected ObjectColor frameColor;
protected FrameStyle frameStyle;
protected List<CardType> cardType = new ArrayList<>();
protected EnumSet<CardType> cardType = EnumSet.noneOf(CardType.class);
protected List<String> subtype = new ArrayList<>();
protected List<String> supertype = new ArrayList<>();
protected Abilities<Ability> abilities;
@ -127,7 +126,7 @@ public abstract class MageObjectImpl implements MageObject {
}
@Override
public List<CardType> getCardType() {
public EnumSet<CardType> getCardType() {
return cardType;
}

View file

@ -30,10 +30,9 @@ package mage.cards.repository;
import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.*;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
@ -253,8 +252,8 @@ public class CardInfo {
return Arrays.asList(list.split(SEPARATOR));
}
public final List<CardType> getTypes() {
ArrayList<CardType> list = new ArrayList<>();
public final EnumSet<CardType> getTypes() {
EnumSet<CardType> list = EnumSet.noneOf(CardType.class);
for (String type : this.types.split(SEPARATOR)) {
try {
list.add(CardType.valueOf(type));
@ -264,7 +263,7 @@ public class CardInfo {
return list;
}
public final void setTypes(List<CardType> types) {
public final void setTypes(Set<CardType> types) {
StringBuilder sb = new StringBuilder();
for (CardType item : types) {
sb.append(item.name()).append(SEPARATOR);

View file

@ -5,9 +5,8 @@
*/
package mage.designations;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.*;
import mage.MageInt;
import mage.MageObject;
import mage.ObjectColor;
@ -29,6 +28,7 @@ import mage.util.GameLog;
*/
public abstract class Designation implements MageObject {
private static EnumSet emptySet = EnumSet.noneOf(CardType.class);
private static List emptyList = new ArrayList();
private static ObjectColor emptyColor = new ObjectColor();
private static ManaCosts<ManaCost> emptyCost = new ManaCostsImpl();
@ -118,8 +118,8 @@ public abstract class Designation implements MageObject {
}
@Override
public List<CardType> getCardType() {
return emptyList;
public EnumSet<CardType> getCardType() {
return emptySet;
}
@Override

View file

@ -27,7 +27,9 @@
*/
package mage.game.command;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import mage.MageInt;
import mage.ObjectColor;
@ -110,7 +112,7 @@ public class Commander implements CommandObject {
}
@Override
public List<CardType> getCardType() {
public EnumSet<CardType> getCardType() {
return sourceObject.getCardType();
}

View file

@ -27,9 +27,8 @@
*/
package mage.game.command;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.*;
import mage.MageInt;
import mage.MageObject;
import mage.ObjectColor;
@ -51,7 +50,8 @@ import mage.util.GameLog;
*/
public class Emblem implements CommandObject {
private static List emptyList = new ArrayList();
private static EnumSet<CardType> emptySet = EnumSet.noneOf(CardType.class);
private static List emptyList = new ArrayList();
private static ObjectColor emptyColor = new ObjectColor();
private static ManaCosts emptyCost = new ManaCostsImpl();
@ -148,8 +148,8 @@ public class Emblem implements CommandObject {
}
@Override
public List<CardType> getCardType() {
return emptyList;
public EnumSet<CardType> getCardType() {
return emptySet;
}
@Override

View file

@ -27,9 +27,8 @@
*/
package mage.game.stack;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.*;
import mage.MageInt;
import mage.MageObject;
import mage.Mana;
@ -457,14 +456,14 @@ public class Spell extends StackObjImpl implements Card {
}
@Override
public List<CardType> getCardType() {
public EnumSet<CardType> getCardType() {
if (faceDown) {
List<CardType> cardTypes = new ArrayList<>();
EnumSet<CardType> cardTypes = EnumSet.noneOf(CardType.class);
cardTypes.add(CardType.CREATURE);
return cardTypes;
}
if (this.getSpellAbility() instanceof BestowAbility) {
List<CardType> cardTypes = new ArrayList<>();
EnumSet<CardType> cardTypes = EnumSet.noneOf(CardType.class);
cardTypes.addAll(card.getCardType());
cardTypes.remove(CardType.CREATURE);
return cardTypes;

View file

@ -27,9 +27,8 @@
*/
package mage.game.stack;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.*;
import mage.MageInt;
import mage.MageObject;
import mage.ObjectColor;
@ -72,7 +71,7 @@ import mage.watchers.Watcher;
*/
public class StackAbility extends StackObjImpl implements Ability {
private static List<CardType> emptyCardType = new ArrayList<>();
private static EnumSet<CardType> emptyCardType = EnumSet.noneOf(CardType.class);
private static List<String> emptyString = new ArrayList<>();
private static ObjectColor emptyColor = new ObjectColor();
private static ManaCosts<ManaCost> emptyCost = new ManaCostsImpl<>();
@ -160,7 +159,7 @@ public class StackAbility extends StackObjImpl implements Ability {
}
@Override
public List<CardType> getCardType() {
public EnumSet<CardType> getCardType() {
return emptyCardType;
}

View file

@ -0,0 +1,28 @@
package mage;
import mage.abilities.decorator.ConditionalContinuousEffect;
import mage.abilities.effects.common.continuous.BoostTargetEffect;
import mage.constants.DependencyType;
import mage.constants.Duration;
import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Set;
import java.util.UUID;
import static org.hamcrest.CoreMatchers.is;
/**
* Created by IGOUDT on 25-2-2017.
*/
public class ContinuousEffectImplTest {
@Test
public void isDependentTo(){
BoostTargetEffect ghe = new BoostTargetEffect(0,0, Duration.Custom);
ghe.setDependedToType(DependencyType.AuraAddingRemoving);
Set<UUID> x = ghe.isDependentTo(new ArrayList<>());
Assert.assertThat(x.size(), is(0));
}
}