mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-14 17:58:01 +00:00
Merge branch 'master' into 'master'
Optimize some code paths in Forge (card type logic and property get with default). See merge request core-developers/forge!2334
This commit is contained in:
@@ -643,7 +643,7 @@ public class ComputerUtilCard {
|
||||
return getMostProminentType(list, CardType.getAllCreatureTypes());
|
||||
}
|
||||
|
||||
public static String getMostProminentType(final CardCollectionView list, final List<String> valid) {
|
||||
public static String getMostProminentType(final CardCollectionView list, final Collection<String> valid) {
|
||||
if (list.size() == 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -502,12 +502,11 @@ public class PlayerControllerAi extends PlayerController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String chooseSomeType(String kindOfType, SpellAbility sa, List<String> validTypes, List<String> invalidTypes, boolean isOptional) {
|
||||
public String chooseSomeType(String kindOfType, SpellAbility sa, Collection<String> validTypes, List<String> invalidTypes, boolean isOptional) {
|
||||
String chosen = ComputerUtil.chooseSomeType(player, kindOfType, sa.getParam("AILogic"), invalidTypes);
|
||||
if (StringUtils.isBlank(chosen) && !validTypes.isEmpty())
|
||||
{
|
||||
chosen = validTypes.get(0);
|
||||
System.err.println("AI has no idea how to choose " + kindOfType +", defaulting to 1st element: chosen");
|
||||
if (StringUtils.isBlank(chosen) && !validTypes.isEmpty()) {
|
||||
chosen = validTypes.iterator().next();
|
||||
System.err.println("AI has no idea how to choose " + kindOfType +", defaulting to arbitrary element: chosen");
|
||||
}
|
||||
game.getAction().nofityOfValue(sa, player, chosen, player);
|
||||
return chosen;
|
||||
|
||||
@@ -606,13 +606,13 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
|
||||
|
||||
public static class Constant {
|
||||
public static final Settable LOADED = new Settable();
|
||||
public static final List<String> BASIC_TYPES = Lists.newArrayList();
|
||||
public static final List<String> LAND_TYPES = Lists.newArrayList();
|
||||
public static final List<String> CREATURE_TYPES = Lists.newArrayList();
|
||||
public static final List<String> SPELL_TYPES = Lists.newArrayList();
|
||||
public static final List<String> ENCHANTMENT_TYPES = Lists.newArrayList();
|
||||
public static final List<String> ARTIFACT_TYPES = Lists.newArrayList();
|
||||
public static final List<String> WALKER_TYPES = Lists.newArrayList();
|
||||
public static final Set<String> BASIC_TYPES = Sets.newHashSet();
|
||||
public static final Set<String> LAND_TYPES = Sets.newHashSet();
|
||||
public static final Set<String> CREATURE_TYPES = Sets.newHashSet();
|
||||
public static final Set<String> SPELL_TYPES = Sets.newHashSet();
|
||||
public static final Set<String> ENCHANTMENT_TYPES = Sets.newHashSet();
|
||||
public static final Set<String> ARTIFACT_TYPES = Sets.newHashSet();
|
||||
public static final Set<String> WALKER_TYPES = Sets.newHashSet();
|
||||
|
||||
// singular -> plural
|
||||
public static final BiMap<String,String> pluralTypes = HashBiMap.create();
|
||||
@@ -699,12 +699,12 @@ public final class CardType implements Comparable<CardType>, CardTypeView {
|
||||
return sortedSubTypes;
|
||||
}
|
||||
|
||||
public static List<String> getBasicTypes() {
|
||||
return Collections.unmodifiableList(Constant.BASIC_TYPES);
|
||||
public static Collection<String> getBasicTypes() {
|
||||
return Collections.unmodifiableCollection(Constant.BASIC_TYPES);
|
||||
}
|
||||
|
||||
public static List<String> getAllCreatureTypes() {
|
||||
return Collections.unmodifiableList(Constant.CREATURE_TYPES);
|
||||
public static Collection<String> getAllCreatureTypes() {
|
||||
return Collections.unmodifiableCollection(Constant.CREATURE_TYPES);
|
||||
}
|
||||
public static List<String> getAllLandTypes() {
|
||||
return ImmutableList.<String>builder()
|
||||
|
||||
@@ -73,7 +73,7 @@ public abstract class CardTraitBase extends GameObject implements IHasCardView {
|
||||
}
|
||||
|
||||
public final String getParamOrDefault(String key, String defaultValue) {
|
||||
return hasParam(key) ? getParam(key) : defaultValue;
|
||||
return mapParams.getOrDefault(key, defaultValue);
|
||||
}
|
||||
|
||||
public String getParam(String key) {
|
||||
|
||||
@@ -161,8 +161,8 @@ public abstract class PlayerController {
|
||||
public abstract List<SpellAbility> chooseSaToActivateFromOpeningHand(List<SpellAbility> usableFromOpeningHand);
|
||||
public abstract Mana chooseManaFromPool(List<Mana> manaChoices);
|
||||
|
||||
public abstract String chooseSomeType(String kindOfType, SpellAbility sa, List<String> validTypes, List<String> invalidTypes, boolean isOptional);
|
||||
public final String chooseSomeType(String kindOfType, SpellAbility sa, List<String> validTypes, List<String> invalidTypes) {
|
||||
public abstract String chooseSomeType(String kindOfType, SpellAbility sa, Collection<String> validTypes, List<String> invalidTypes, boolean isOptional);
|
||||
public final String chooseSomeType(String kindOfType, SpellAbility sa, Collection<String> validTypes, List<String> invalidTypes) {
|
||||
return chooseSomeType(kindOfType, sa, validTypes, invalidTypes, false);
|
||||
}
|
||||
|
||||
|
||||
@@ -481,7 +481,7 @@ public class PlayerControllerForTests extends PlayerController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String chooseSomeType(String kindOfType, SpellAbility sa, List<String> validTypes, List<String> invalidTypes, boolean isOptional) {
|
||||
public String chooseSomeType(String kindOfType, SpellAbility sa, Collection<String> validTypes, List<String> invalidTypes, boolean isOptional) {
|
||||
return chooseItem(validTypes);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,7 @@ import forge.util.storage.StorageBase;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The default Model implementation for Forge.
|
||||
@@ -259,31 +260,31 @@ public final class FModel {
|
||||
if (!CardType.Constant.LOADED.isSet()) {
|
||||
final List<String> typeListFile = FileUtil.readFile(ForgeConstants.TYPE_LIST_FILE);
|
||||
|
||||
List<String> tList = null;
|
||||
Set<String> addTo = null;
|
||||
|
||||
for (final String s : typeListFile) {
|
||||
if (s.equals("[BasicTypes]")) {
|
||||
tList = CardType.Constant.BASIC_TYPES;
|
||||
addTo = CardType.Constant.BASIC_TYPES;
|
||||
} else if (s.equals("[LandTypes]")) {
|
||||
tList = CardType.Constant.LAND_TYPES;
|
||||
addTo = CardType.Constant.LAND_TYPES;
|
||||
} else if (s.equals("[CreatureTypes]")) {
|
||||
tList = CardType.Constant.CREATURE_TYPES;
|
||||
addTo = CardType.Constant.CREATURE_TYPES;
|
||||
} else if (s.equals("[SpellTypes]")) {
|
||||
tList = CardType.Constant.SPELL_TYPES;
|
||||
addTo = CardType.Constant.SPELL_TYPES;
|
||||
} else if (s.equals("[EnchantmentTypes]")) {
|
||||
tList = CardType.Constant.ENCHANTMENT_TYPES;
|
||||
addTo = CardType.Constant.ENCHANTMENT_TYPES;
|
||||
} else if (s.equals("[ArtifactTypes]")) {
|
||||
tList = CardType.Constant.ARTIFACT_TYPES;
|
||||
addTo = CardType.Constant.ARTIFACT_TYPES;
|
||||
} else if (s.equals("[WalkerTypes]")) {
|
||||
tList = CardType.Constant.WALKER_TYPES;
|
||||
addTo = CardType.Constant.WALKER_TYPES;
|
||||
} else if (s.length() > 1) {
|
||||
if (tList != null) {
|
||||
if (addTo != null) {
|
||||
if (s.contains(":")) {
|
||||
String[] k = s.split(":");
|
||||
tList.add(k[0]);
|
||||
addTo.add(k[0]);
|
||||
CardType.Constant.pluralTypes.put(k[0], k[1]);
|
||||
} else {
|
||||
tList.add(s);
|
||||
addTo.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1034,7 +1034,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
|
||||
* java.lang.String, java.util.List, java.util.List, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public String chooseSomeType(final String kindOfType, final SpellAbility sa, final List<String> validTypes,
|
||||
public String chooseSomeType(final String kindOfType, final SpellAbility sa, final Collection<String> validTypes,
|
||||
final List<String> invalidTypes, final boolean isOptional) {
|
||||
final List<String> types = Lists.newArrayList(validTypes);
|
||||
if (invalidTypes != null && !invalidTypes.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user