Refactoring method in FModel to return all block formats

This method is currently used in CardManager and DeckManager for Block Filter when Historic format are supported in forge. However, now the same method will also be used in Deck Import so this refactoring was very much necessary!

Signed-off-by: leriomaggio <valeriomaggio@gmail.com>
This commit is contained in:
leriomaggio
2021-09-16 20:34:55 +01:00
parent 4d90d4f7e4
commit 7674d5c1fa
3 changed files with 16 additions and 21 deletions

View File

@@ -233,15 +233,7 @@ public class CardManager extends ItemManager<PaperCard> {
if (FModel.getPreferences().getPrefBoolean(ForgePreferences.FPref.LOAD_HISTORIC_FORMATS)) {
JMenu blocks = GuiUtils.createMenu(localizer.getMessage("lblBlock"));
List<GameFormat> blockFormats = new ArrayList<>();
for (GameFormat format : FModel.getFormats().getHistoricList()){
if (format.getFormatSubType() != GameFormat.FormatSubType.BLOCK)
continue;
if (!format.getName().endsWith("Block"))
continue;
blockFormats.add(format);
}
Collections.sort(blockFormats); // GameFormat will be sorted by Index!
final List<GameFormat> blockFormats = FModel.getBlockFormats();
for (final GameFormat f : blockFormats) {
GuiUtils.addMenuItem(blocks, f.getName(), null, new Runnable() {
@Override

View File

@@ -281,15 +281,7 @@ public final class DeckManager extends ItemManager<DeckProxy> implements IHasGam
if (FModel.getPreferences().getPrefBoolean(ForgePreferences.FPref.LOAD_HISTORIC_FORMATS)) {
JMenu blocks = GuiUtils.createMenu(localizer.getMessage("lblBlock"));
List<GameFormat> blockFormats = new ArrayList<>();
for (GameFormat format : FModel.getFormats().getHistoricList()){
if (format.getFormatSubType() != GameFormat.FormatSubType.BLOCK)
continue;
if (!format.getName().endsWith("Block"))
continue;
blockFormats.add(format);
}
Collections.sort(blockFormats); // GameFormat will be sorted by Index!
final List<GameFormat> blockFormats = FModel.getBlockFormats();
for (final GameFormat f : blockFormats) {
GuiUtils.addMenuItem(blocks, f.getName(), null, new Runnable() {
@Override

View File

@@ -64,9 +64,7 @@ import forge.util.storage.IStorage;
import forge.util.storage.StorageBase;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
/**
* The default Model implementation for Forge.
@@ -465,6 +463,19 @@ public final class FModel {
return blocks;
}
public static List<GameFormat> getBlockFormats(){
List<GameFormat> blockFormats = new ArrayList<>();
for (GameFormat format : FModel.getFormats().getHistoricList()){
if (format.getFormatSubType() != GameFormat.FormatSubType.BLOCK)
continue;
if (!format.getName().endsWith("Block"))
continue;
blockFormats.add(format);
}
Collections.sort(blockFormats); // GameFormat will be sorted by Index!
return blockFormats;
}
public static QuestPreferences getQuestPreferences() {
return questPreferences;
}