Skip to content

Commit 7cc86f2

Browse files
authored
Clean up (Card-Forge#11215)
1 parent 1922ce4 commit 7cc86f2

10 files changed

Lines changed: 21 additions & 66 deletions

File tree

forge-ai/src/main/java/forge/ai/AiController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,6 +1135,7 @@ public CardCollection getCardsToDiscard(int min, final int max, final CardCollec
11351135
}
11361136
if (prefCard == null) {
11371137
prefCard = ComputerUtil.getCardPreference(player, sourceCard, "DiscardCost", validCards);
1138+
// TODO use DiscardMe:0 instead so each card without is just treated as 1
11381139
if (prefCard != null && prefCard.hasSVar("DoNotDiscardIfAble")) {
11391140
prefCard = null;
11401141
}
Lines changed: 15 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
package forge.deck;
22

3+
import forge.card.CardRulesPredicates;
34
import forge.card.CardType;
45
import forge.item.PaperCard;
6+
import forge.item.PaperCardPredicates;
57
import forge.util.Localizer;
68

7-
import java.util.function.Function;
9+
import java.util.function.Predicate;
810

911
public enum DeckSection {
1012
Main("lblMainDeck", Validators.DECK_AND_SIDE_VALIDATOR),
1113
Sideboard("lblSideboard", Validators.DECK_AND_SIDE_VALIDATOR),
1214
Commander("lblCommander", Validators.COMMANDER_VALIDATOR),
13-
Avatar("lblAvatar", Validators.AVATAR_VALIDATOR),
14-
Planes("lblPlanarDeck", Validators.PLANES_VALIDATOR),
15-
Schemes("lblSchemeDeck", Validators.SCHEME_VALIDATOR),
16-
Conspiracy("lblConspiracies", Validators.CONSPIRACY_VALIDATOR),
17-
Dungeon("lblDungeons", Validators.DUNGEON_VALIDATOR),
18-
Attractions("lblAttractions", Validators.ATTRACTION_VALIDATOR),
19-
Contraptions("lblContraptions", Validators.CONTRAPTION_VALIDATOR);
15+
Avatar("lblAvatar", PaperCardPredicates.fromRules(CardRulesPredicates.IS_VANGUARD)),
16+
Planes("lblPlanarDeck", PaperCardPredicates.fromRules(CardRulesPredicates.IS_PLANE_OR_PHENOMENON)),
17+
Schemes("lblSchemeDeck", PaperCardPredicates.fromRules(CardRulesPredicates.IS_SCHEME)),
18+
Conspiracy("lblConspiracies", PaperCardPredicates.fromRules(CardRulesPredicates.IS_CONSPIRACY)),
19+
Dungeon("lblDungeons", PaperCardPredicates.fromRules(CardRulesPredicates.IS_DUNGEON)),
20+
Attractions("lblAttractions", PaperCardPredicates.fromRules(CardRulesPredicates.IS_ATTRACTION)),
21+
Contraptions("lblContraptions", PaperCardPredicates.fromRules(CardRulesPredicates.IS_CONTRAPTION));
2022

2123
/**
2224
* Array of DeckSections that contain nontraditional cards.
2325
*/
2426
public static final DeckSection[] NONTRADITIONAL_SECTIONS = new DeckSection[]{Avatar, Planes, Schemes, Conspiracy, Dungeon, Attractions, Contraptions};
2527

2628
private final String nameLbl;
27-
private final Function<PaperCard, Boolean> fnValidator;
29+
private final Predicate<PaperCard> fnValidator;
2830

29-
DeckSection(String nameLbl, Function<PaperCard, Boolean> validator) {
31+
DeckSection(String nameLbl, Predicate<PaperCard> validator) {
3032
this.nameLbl = nameLbl;
3133
fnValidator = validator;
3234
}
@@ -49,7 +51,7 @@ public String getLocalizedShortName() {
4951

5052
public boolean validate(PaperCard card){
5153
if (fnValidator == null) return true;
52-
return fnValidator.apply(card);
54+
return fnValidator.test(card);
5355
}
5456

5557
// Returns the matching section for "special"/supplementary core types.
@@ -84,53 +86,18 @@ public static DeckSection smartValueOf(String value) {
8486
}
8587

8688
private static class Validators {
87-
static final Function<PaperCard, Boolean> DECK_AND_SIDE_VALIDATOR = card -> {
89+
static final Predicate<PaperCard> DECK_AND_SIDE_VALIDATOR = card -> {
8890
CardType t = card.getRules().getType();
8991
// NOTE: Same rules applies to both Deck and Side, despite "Conspiracy cards" are allowed
9092
// in the SideBoard (see Rule 313.2)
9193
// Those will be matched later, in case (see `Deck::normalizeDeferredSections`)
9294
return !t.isConspiracy() && !t.isDungeon() && !t.isPhenomenon() && !t.isPlane() && !t.isScheme() && !t.isVanguard();
9395
};
9496

95-
static final Function<PaperCard, Boolean> COMMANDER_VALIDATOR = card -> {
97+
static final Predicate<PaperCard> COMMANDER_VALIDATOR = card -> {
9698
CardType t = card.getRules().getType();
9799
return card.getRules().canBeCommander() || t.isPlaneswalker() || card.getRules().canBeOathbreaker() || card.getRules().canBeSignatureSpell();
98100
};
99101

100-
static final Function<PaperCard, Boolean> PLANES_VALIDATOR = card -> {
101-
CardType t = card.getRules().getType();
102-
return t.isPlane() || t.isPhenomenon();
103-
};
104-
105-
static final Function<PaperCard, Boolean> DUNGEON_VALIDATOR = card -> {
106-
CardType t = card.getRules().getType();
107-
return t.isDungeon();
108-
};
109-
110-
static final Function<PaperCard, Boolean> SCHEME_VALIDATOR = card -> {
111-
CardType t = card.getRules().getType();
112-
return t.isScheme();
113-
};
114-
115-
static final Function<PaperCard, Boolean> CONSPIRACY_VALIDATOR = card -> {
116-
CardType t = card.getRules().getType();
117-
return t.isConspiracy();
118-
};
119-
120-
static final Function<PaperCard, Boolean> AVATAR_VALIDATOR = card -> {
121-
CardType t = card.getRules().getType();
122-
return t.isVanguard();
123-
};
124-
125-
static final Function<PaperCard, Boolean> ATTRACTION_VALIDATOR = card -> {
126-
CardType t = card.getRules().getType();
127-
return t.isAttraction();
128-
};
129-
130-
static final Function<PaperCard, Boolean> CONTRAPTION_VALIDATOR = card -> {
131-
CardType t = card.getRules().getType();
132-
return t.isContraption();
133-
};
134-
135102
}
136103
}

forge-gui-ios/minlog-1.2.jar

-4.76 KB
Binary file not shown.

forge-gui-mobile/src/forge/adventure/stage/MapStage.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,6 @@ else if (prop.containsKey("portalState")) {
656656
//Flow continues into "shop" case with above data overriding base logic.
657657

658658
case "shop":
659-
660659
int restockPrice = 0;
661660
String shopList = "";
662661

forge-gui-mobile/src/forge/adventure/util/Config.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,11 @@ static public Config instance() {
6060

6161
private Config() {
6262
String path = resPath();
63-
FilenameFilter planesFilter = (file, s) -> (!s.contains(".") && !s.equals(commonDirectoryName));
63+
FilenameFilter planesFilter = (file, s) -> !s.contains(".") && !s.equals(commonDirectoryName);
6464

6565
adventures = new File(GuiBase.isAndroid() ? ForgeConstants.ADVENTURE_DIR : path + "/res/adventure").list(planesFilter);
6666
try {
6767
settingsData = new Json().fromJson(SettingData.class, new FileHandle(ForgeConstants.USER_ADVENTURE_DIR + "settings.json"));
68-
6968
} catch (Exception e) {
7069
settingsData = new SettingData();
7170
}
@@ -102,7 +101,6 @@ private Config() {
102101
if (settingsData.cardTooltipAdjLandscape == null || settingsData.cardTooltipAdjLandscape == 0f)
103102
settingsData.cardTooltipAdjLandscape = 1f;
104103

105-
106104
//prefix = "forge-gui/res/adventure/Shandalar/";
107105
prefix = getPlanePath(settingsData.plane);
108106
commonPrefix = resPath() + "/res/adventure/" + commonDirectoryName + "/";
@@ -120,11 +118,9 @@ private Config() {
120118
e.printStackTrace();
121119
configData = new ConfigData();
122120
}
123-
124121
}
125122

126123
private String resPath() {
127-
128124
return GuiBase.isAndroid() ? ForgeConstants.ASSETS_DIR : Files.exists(Paths.get("./res")) ? "./" : Files.exists(Paths.get("./forge-gui/")) ? "./forge-gui/" : "../forge-gui";
129125
}
130126

@@ -215,7 +211,6 @@ public FileHandle getFile(String path) {
215211
String langFile = fileName + "-" + Lang + ext;
216212

217213
for (int iter = 1; iter <= 2; iter++) {
218-
219214
if (Files.exists(Paths.get(langFile))) {
220215
System.out.println("Found!");
221216
Cache.put(path, new FileHandle(langFile));
@@ -238,17 +233,14 @@ public String getPlane() {
238233
}
239234

240235
public String[] colorIdNames() {
241-
242236
return configData.colorIdNames;
243237
}
244238

245239
public String[] colorIds() {
246-
247240
return configData.colorIds;
248241
}
249242

250243
public String[] starterEditionNames() {
251-
252244
return configData.starterEditionNames;
253245
}
254246

@@ -403,11 +395,9 @@ public Array<String> getAllAdventures() {
403395
}
404396

405397
public void saveSettings() {
406-
407398
Json json = new Json(JsonWriter.OutputType.json);
408399
FileHandle handle = new FileHandle(ForgeProfileProperties.getUserDir() + "/adventure/settings.json");
409400
handle.writeString(json.prettyPrint(json.toJson(settingsData, SettingData.class)), false);
410-
411401
}
412402

413403
// --- Folder-backed starter deck support ---

forge-gui/src/main/java/forge/deck/DeckProxy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ public static Iterable<DeckProxy> getAllCommanderPreconDecks() {
474474
return getAllCommanderPreconDecks(null);
475475
}
476476
public static Iterable<DeckProxy> getAllCommanderPreconDecks(final Predicate<Deck> filter) {
477-
final List<DeckProxy> result = new ArrayList<DeckProxy>();
477+
final List<DeckProxy> result = new ArrayList<>();
478478
addDecksRecursivelly("Commander Precon", GameType.Commander, result, "", FModel.getDecks().getCommanderPrecons(), filter);
479479
return result;
480480
}

forge-gui/src/main/java/forge/gamemodes/quest/QuestController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public static IStorage<PreconDeck> getPrecons() {
220220
// read with a special class, that will fill sell rules as it processes each PreconDeck
221221
preconManager = new StorageBase<>("Quest shop decks", new PreconDeck.Reader(new File(ForgeConstants.QUEST_PRECON_DIR)) {
222222
@Override
223-
protected PreconDeck getPreconDeckFromSections(java.util.Map<String, java.util.List<String>> sections) {
223+
protected PreconDeck getPreconDeckFromSections(Map<String, List<String>> sections) {
224224
PreconDeck result = super.getPreconDeckFromSections(sections);
225225
preconDeals.put(result.getName(), new SellRules(sections.get("shop")));
226226
return result;

forge-gui/src/main/java/forge/localinstance/properties/ForgePreferences.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public enum FPref implements PreferencesStore.IPref {
151151
UI_ALLOW_ORDER_GRAVEYARD_WHEN_NEEDED ("Never"),
152152
UI_DEFAULT_FONT_SIZE("12"),
153153
UI_CARD_ART_FORMAT("Full"),
154-
UI_SELECT_FROM_CARD_DISPLAYS("true"),
154+
UI_SELECT_FROM_CARD_DISPLAYS("true"),
155155
UI_SWITCH_STATES_DECKVIEW("Switch back on hover"),
156156
UI_ORDER_HAND("false"),
157157
UI_HAND_MAX_CARDS_PER_ROW("0"),

forge-gui/src/main/java/forge/localinstance/properties/ForgeProfileProperties.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ public static void load(boolean isUsingAppDirectory) {
7575
decksDir = getDir(props, DECKS_DIR_KEY, userDir + "decks" + File.separator);
7676
decksConstructedDir = getDir(props, DECKS_CONSTRUCTED_DIR_KEY, decksDir + "constructed" + File.separator);
7777

78-
79-
//ensure directories exist
8078
FileUtil.ensureDirectoryExists(userDir);
8179
FileUtil.ensureDirectoryExists(cacheDir);
8280
FileUtil.ensureDirectoryExists(cardPicsDir);

forge-gui/src/main/java/forge/model/CardCollections.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public IStorage<Deck> getOathbreaker() {
128128

129129
public IStorage<Deck> getCommanderPrecons() {
130130
if (commanderPrecons == null) {
131-
commanderPrecons = new StorageImmediatelySerialized<Deck>("Commander Precon decks",
131+
commanderPrecons = new StorageImmediatelySerialized<>("Commander Precon decks",
132132
new DeckStorage(new File(ForgeConstants.COMMANDER_PRECON_DIR), ForgeConstants.QUEST_PRECON_DIR));
133133
}
134134
return commanderPrecons;

0 commit comments

Comments
 (0)