Revert Android 8 codes to support older Android phones.

Hope I didn't miss any. :)
(tested with Android Marshmallow phone with 2gb RAM and mediatek cpu)
This commit is contained in:
Anthony Calosa
2019-09-07 22:54:53 +08:00
parent c1d5cfa27e
commit a0b71d60a1
30 changed files with 81 additions and 59 deletions

View File

@@ -547,7 +547,7 @@ public abstract class CardTraitBase extends GameObject implements IHasCardView {
Map<String, String> result = Maps.newHashMap(output);
for (Map.Entry<String, String> e : input.entrySet()) {
String value = e.getValue();
result.put(e.getKey(), output.getOrDefault(value, value));
result.put(e.getKey(), output.containsKey(value) ? output.get(value) : value);
}
return result;
}

View File

@@ -202,7 +202,7 @@ public class Game {
if (c == null) {
return null;
}
return changeZoneLKIInfo.getOrDefault(c.getId(), c);
return changeZoneLKIInfo.containsKey(c.getId()) ? changeZoneLKIInfo.get(c.getId()) : c;
}
public final void clearChangeZoneLKIInfo() {
changeZoneLKIInfo.clear();

View File

@@ -824,7 +824,7 @@ public class GameAction {
.result();
}
};
staticAbilities.sort(comp);
Collections.sort(staticAbilities, comp);
final Map<StaticAbility, CardCollectionView> affectedPerAbility = Maps.newHashMap();
for (final StaticAbilityLayer layer : StaticAbilityLayer.CONTINUOUS_LAYERS) {

View File

@@ -403,7 +403,8 @@ public class GameFormat implements Comparable<GameFormat> {
naturallyOrdered = reader.naturallyOrdered;
reverseDateOrdered = new ArrayList<>(naturallyOrdered);
Collections.sort(naturallyOrdered);
reverseDateOrdered.sort(new InverseDateComparator());
//Why this refactor doesnt work on some android phones? -> reverseDateOrdered.sort(new InverseDateComparator());
Collections.sort(reverseDateOrdered, new InverseDateComparator());
}
public Iterable<GameFormat> getOrderedList() {

View File

@@ -136,13 +136,13 @@ public class GameLogFormatter extends IGameEventVisitor.Base<GameLogEntry> {
for (final GameOutcome game : gamesPlayed) {
RegisteredPlayer player = game.getWinningPlayer();
int amount = winCount.getOrDefault(player, 0);
int amount = winCount.containsKey(player) ? winCount.get(player) : 0;
winCount.put(player, amount + 1);
}
final StringBuilder sb = new StringBuilder();
for (Entry<RegisteredPlayer, String> entry : players.entrySet()) {
int amount = winCount.getOrDefault(entry.getKey(), 0);
int amount = winCount.containsKey(entry.getKey()) ? winCount.get(entry.getKey()) : 0;
sb.append(entry.getValue()).append(": ").append(amount).append(" ");
}

View File

@@ -311,8 +311,8 @@ public final class AbilityFactory {
}
private static final TargetRestrictions readTarget(Map<String, String> mapParams) {
final String min = mapParams.getOrDefault("TargetMin", "1");
final String max = mapParams.getOrDefault("TargetMax", "1");
final String min = mapParams.containsKey("TargetMin") ? mapParams.get("TargetMin") : "1";
final String max = mapParams.containsKey("TargetMax") ? mapParams.get("TargetMax") : "1";
// TgtPrompt now optional

View File

@@ -11,6 +11,7 @@ import forge.game.spellability.SpellAbility;
import forge.util.Lang;
import forge.util.collect.FCollection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -190,7 +191,7 @@ public class CharmEffect extends SpellAbilityEffect {
}
// Sort Chosen by SA order
chosen.sort(new Comparator<AbilitySub>() {
Collections.sort(chosen, new Comparator<AbilitySub>() {
@Override
public int compare(AbilitySub o1, AbilitySub o2) {
return Integer.compare(o1.getSVarInt("CharmOrder"), o2.getSVarInt("CharmOrder"));

View File

@@ -1330,7 +1330,7 @@ public class Card extends GameEntity implements Comparable<Card> {
int counterAmount = 0;
if (countersAddedBy.containsKey(source)) {
final Map<CounterType, Integer> counterMap = countersAddedBy.get(source);
counterAmount = counterMap.getOrDefault(counterType, 0);
counterAmount = counterMap.containsKey(counterType) ? counterMap.get(counterType) : 0;
countersAddedBy.remove(source);
}
return counterAmount;
@@ -6188,7 +6188,7 @@ public class Card extends GameEntity implements Comparable<Card> {
}
return 0;
}
return numberTurnActivations.getOrDefault(original, 0);
return numberTurnActivations.containsKey(original) ? numberTurnActivations.get(original) : 0;
}
public int getAbilityActivatedThisGame(SpellAbility ability) {
@@ -6203,7 +6203,7 @@ public class Card extends GameEntity implements Comparable<Card> {
}
return 0;
}
return numberGameActivations.getOrDefault(original, 0);
return numberGameActivations.containsKey(original) ? numberGameActivations.get(original) : 0;
}
public void resetTurnActivations() {

View File

@@ -119,7 +119,7 @@ public class CardLists {
* @param list
*/
public static void sortByCmcDesc(final List<Card> list) {
list.sort(CmcComparatorInv);
Collections.sort(list, CmcComparatorInv);
} // sortByCmcDesc
/**
@@ -130,7 +130,7 @@ public class CardLists {
* @param list
*/
public static void sortByToughnessAsc(final List<Card> list) {
list.sort(ToughnessComparator);
Collections.sort(list, ToughnessComparator);
} // sortByToughnessAsc()
/**
@@ -141,7 +141,7 @@ public class CardLists {
* @param list
*/
public static void sortByToughnessDesc(final List<Card> list) {
list.sort(ToughnessComparatorInv);
Collections.sort(list, ToughnessComparatorInv);
} // sortByToughnessDesc()
/**
@@ -152,7 +152,7 @@ public class CardLists {
* @param list
*/
public static void sortByPowerAsc(final List<Card> list) {
list.sort(PowerComparator);
Collections.sort(list, PowerComparator);
} // sortAttackLowFirst()
// the higher the attack the better
@@ -164,7 +164,7 @@ public class CardLists {
* @param list
*/
public static void sortByPowerDesc(final List<Card> list) {
list.sort(Collections.reverseOrder(PowerComparator));
Collections.sort(list, Collections.reverseOrder(PowerComparator));
} // sortAttack()

View File

@@ -449,7 +449,11 @@ public class CardState extends GameObject {
return sVars;
}
public final String getSVar(final String var) {
return sVars.getOrDefault(var, "");
if (sVars.containsKey(var)) {
return sVars.get(var);
} else {
return "";
}
}
public final boolean hasSVar(final String var) {
if (var == null) {

View File

@@ -18,6 +18,7 @@
package forge.game.cost;
import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
@@ -125,7 +126,7 @@ public class Cost implements Serializable {
// Things that are pretty much happen at the end (Untap) 16+
// Things that NEED to happen last 100+
this.costParts.sort(new Comparator<CostPart>() {
Collections.sort(this.costParts, new Comparator<CostPart>() {
@Override
public int compare(CostPart o1, CostPart o2) {
return o1.paymentOrder() - o2.paymentOrder();

View File

@@ -96,7 +96,7 @@ public class CostAdjustment {
return;
}
final String scost = params.getOrDefault("Cost", "1");
final String scost = params.containsKey("Cost") ? params.get("Cost") : "1";
Cost part = new Cost(scost, sa.isAbility());
int count = 0;

View File

@@ -598,12 +598,12 @@ public class Player extends GameEntity implements Comparable<Player> {
view.updateCommanderDamage(this);
}
int old = assignedDamage.getOrDefault(source, 0);
int old = assignedDamage.containsKey(source) ? assignedDamage.get(source) : 0;
assignedDamage.put(source, old + amount);
source.getDamageHistory().registerDamage(this);
if (isCombat) {
old = assignedCombatDamage.getOrDefault(source, 0);
old = assignedCombatDamage.containsKey(source) ? assignedCombatDamage.get(source) : 0;
assignedCombatDamage.put(source, old + amount);
for (final String type : source.getType().getCreatureTypes()) {
source.getController().addProwlType(type);

View File

@@ -89,8 +89,8 @@ public class AbilityManaPart implements java.io.Serializable {
public AbilityManaPart(final Card sourceCard, final Map<String, String> params) {
this.sourceCard = sourceCard;
origProduced = params.getOrDefault("Produced", "1");
this.manaRestrictions = params.getOrDefault("RestrictValid", "");
origProduced = params.containsKey("Produced") ? params.get("Produced") : "1";
this.manaRestrictions = params.containsKey("RestrictValid") ? params.get("RestrictValid") : "";
this.cannotCounterSpell = params.get("AddsNoCounter");
this.addsKeywords = params.get("AddsKeywords");
this.addsKeywordsType = params.get("AddsKeywordsType");
@@ -98,7 +98,7 @@ public class AbilityManaPart implements java.io.Serializable {
this.addsCounters = params.get("AddsCounters");
this.triggersWhenSpent = params.get("TriggersWhenSpent");
this.persistentMana = (null != params.get("PersistentMana")) && "True".equalsIgnoreCase(params.get("PersistentMana"));
this.manaReplaceType = params.getOrDefault("ManaReplaceType", "");
this.manaReplaceType = params.containsKey("ManaReplaceType") ? params.get("ManaReplaceType") : "";
}
/**

View File

@@ -81,7 +81,7 @@ public class StaticAbilityCantBeCast {
if (params.containsKey("NumLimitEachTurn") && activator != null) {
int limit = Integer.parseInt(params.get("NumLimitEachTurn"));
String valid = params.getOrDefault("ValidCard", "Card");
String valid = params.containsKey("ValidCard") ? params.get("ValidCard") : "Card";
List<Card> thisTurnCast = CardUtil.getThisTurnCast(valid, card);
if (CardLists.filterControlledBy(thisTurnCast, activator).size() < limit) {
return false;

View File

@@ -83,7 +83,7 @@ public class StaticAbilityPreventDamage {
if (params.containsKey("Optional")) { //Assume if param is present it should be optional
if (!isTest) {
final String logic = params.getOrDefault("AILogic", "");
final String logic = params.containsKey("AILogic") ? params.get("AILogic") : "";
final String message = "Apply the effect of " + hostCard + "? (Affected: " + target + ")";
boolean confirmed = hostCard.getController().getController().confirmStaticApplication(hostCard, target, logic, message);