From e67b55d3cf44d0537b9ade570e9becf66ce7857b Mon Sep 17 00:00:00 2001 From: Tim Scott Date: Sun, 3 Mar 2019 10:00:10 -0600 Subject: [PATCH] Add ability to audit cards and card image data. README version info fixup. --- README.md | 2 +- .../home/settings/CSubmenuDownloaders.java | 6 + .../home/settings/VSubmenuDownloaders.java | 147 ++++++++++++++++++ forge-gui/res/languages/en-US.properties | 3 + 4 files changed, 157 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d00a3fc29b..c6617fcc120 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ SNAPSHOT builds can be built via the Maven integration in Eclipse. 2) Run forge Maven build. If everything built, you should see "BUILD SUCCESS" in the Console View. -The resulting snapshot will be found at: forge-gui-desktop/target/forge-gui-desktop-1.6.22-SNAPSHOT +The resulting snapshot will be found at: forge-gui-desktop/target/forge-gui-desktop-[version]-SNAPSHOT # IntelliJ diff --git a/forge-gui-desktop/src/main/java/forge/screens/home/settings/CSubmenuDownloaders.java b/forge-gui-desktop/src/main/java/forge/screens/home/settings/CSubmenuDownloaders.java index 57b2486f3d3..79a7f188bb8 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/home/settings/CSubmenuDownloaders.java +++ b/forge-gui-desktop/src/main/java/forge/screens/home/settings/CSubmenuDownloaders.java @@ -53,6 +53,11 @@ public enum CSubmenuDownloaders implements ICDoc { VSubmenuDownloaders.SINGLETON_INSTANCE.showHowToPlay(); } }; + private final UiCommand cmdListImageData = new UiCommand() { + @Override public void run() { + VSubmenuDownloaders.SINGLETON_INSTANCE.showCardandImageAuditData(); + } + }; private final UiCommand cmdImportPictures = new UiCommand() { @Override public void run() { new ImportDialog(null, null).show(); @@ -78,6 +83,7 @@ public enum CSubmenuDownloaders implements ICDoc { view.setDownloadSetPicsCommand(cmdSetDownload); view.setDownloadQuestImagesCommand(cmdQuestImages); view.setDownloadAchievementImagesCommand(cmdAchievementImages); + view.setListImageDataCommand(cmdListImageData); view.setReportBugCommand(cmdReportBug); view.setImportPicturesCommand(cmdImportPictures); view.setHowToPlayCommand(cmdHowToPlay); diff --git a/forge-gui-desktop/src/main/java/forge/screens/home/settings/VSubmenuDownloaders.java b/forge-gui-desktop/src/main/java/forge/screens/home/settings/VSubmenuDownloaders.java index ed7ebed404c..36376fb343c 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/home/settings/VSubmenuDownloaders.java +++ b/forge-gui-desktop/src/main/java/forge/screens/home/settings/VSubmenuDownloaders.java @@ -1,25 +1,36 @@ package forge.screens.home.settings; +import forge.ImageKeys; +import forge.StaticData; import forge.UiCommand; import forge.assets.FSkinProp; +import forge.card.CardDb; +import forge.card.CardEdition; +import forge.card.CardEdition.CardInSet; import forge.gui.SOverlayUtils; import forge.gui.framework.DragCell; import forge.gui.framework.DragTab; import forge.gui.framework.EDocID; +import forge.item.PaperCard; import forge.properties.ForgeConstants; import forge.screens.home.EMenuGroup; import forge.screens.home.IVSubmenu; import forge.screens.home.VHomeUI; import forge.toolbox.*; import forge.util.FileUtil; +import forge.util.ImageUtil; import forge.util.Localizer; import forge.util.RuntimeVersion; import net.miginfocom.swing.MigLayout; import javax.swing.*; import java.awt.*; +import java.awt.datatransfer.StringSelection; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; /** * Assembles Swing components of utilities submenu singleton. @@ -46,6 +57,7 @@ public enum VSubmenuDownloaders implements IVSubmenu { private final FLabel btnDownloadQuestImages = _makeButton(localizer.getMessage("btnDownloadQuestImages")); private final FLabel btnDownloadAchievementImages = _makeButton(localizer.getMessage("btnDownloadAchievementImages")); private final FLabel btnReportBug = _makeButton(localizer.getMessage("btnReportBug")); + private final FLabel btnListImageData = _makeButton(localizer.getMessage("btnListImageData")); private final FLabel btnImportPictures = _makeButton(localizer.getMessage("btnImportPictures")); private final FLabel btnHowToPlay = _makeButton(localizer.getMessage("btnHowToPlay")); private final FLabel btnDownloadPrices = _makeButton(localizer.getMessage("btnDownloadPrices")); @@ -94,6 +106,9 @@ public enum VSubmenuDownloaders implements IVSubmenu { pnlContent.add(label, "w 90%!, h 25px!, center, gap 0 0 0 36px"); } + + pnlContent.add(btnListImageData, constraintsBTN); + pnlContent.add(_makeLabel(localizer.getMessage("lblListImageData")), constraintsLBL); pnlContent.add(btnImportPictures, constraintsBTN); pnlContent.add(_makeLabel(localizer.getMessage("lblImportPictures")), constraintsLBL); @@ -144,6 +159,7 @@ public enum VSubmenuDownloaders implements IVSubmenu { public void setDownloadQuestImagesCommand(UiCommand command) { btnDownloadQuestImages.setCommand(command); } public void setDownloadAchievementImagesCommand(UiCommand command) { btnDownloadAchievementImages.setCommand(command); } public void setReportBugCommand(UiCommand command) { btnReportBug.setCommand(command); } + public void setListImageDataCommand(UiCommand command) { btnListImageData.setCommand(command); } public void setImportPicturesCommand(UiCommand command) { btnImportPictures.setCommand(command); } public void setHowToPlayCommand(UiCommand command) { btnHowToPlay.setCommand(command); } public void setDownloadPricesCommand(UiCommand command) { btnDownloadPrices.setCommand(command); } @@ -180,6 +196,137 @@ public enum VSubmenuDownloaders implements IVSubmenu { } }); } + + /** + * Loops through the editions and card databases, looking for missing images and unimplemented cards. + * + * @param tar - Text area to report info + * @param scr + */ + public void auditUpdate(FTextArea tar, FScrollPane scr) { + // Get top-level Forge objects + CardDb cardDb = StaticData.instance().getCommonCards(); + CardEdition.Collection editions = StaticData.instance().getEditions(); + + int missingCount = 0; + int notImplementedCount = 0; + int internalErrorCount = 0; + + final StringBuffer sb = new StringBuffer(); + + for (CardEdition e : editions) { + sb.append("Edition: " + e.getName() + "\n"); + + String lastName = null; + int artIndex = 1; + ArrayList cis = new ArrayList(); + for (CardInSet c : e.getCards()) { + cis.add(c.name); + } + Collections.sort(cis.subList(1, cis.size())); + for (String c : cis) { + if ((lastName != null) && (c.contentEquals(lastName))) { + artIndex++; + } else { + artIndex = 1; + } + + PaperCard cp = cardDb.getCard(c, e.getCode(), artIndex); + if (cp != null) { + String imagePath; + + // + // check the front image + // + imagePath = ImageUtil.getImageRelativePath(cp, false, true, false); + if (imagePath != null) { + File file = ImageKeys.getImageFile(imagePath); + if (file == null) { + sb.append(" NIF: " + imagePath + "\n"); + missingCount++; + } + } else { + sb.append(" ERR: " + c + "\n"); + internalErrorCount++; + } + + // + // check the back face + // + if (ImageUtil.hasBackFacePicture(cp)) { + imagePath = ImageUtil.getImageRelativePath(cp, true, true, false); + if (imagePath != null) { + File file = ImageKeys.getImageFile(imagePath); + if (file == null) { + sb.append(" NIF: " + imagePath + "\n"); + missingCount++; + } + } else { + sb.append(" ERR: " + c + "\n"); + internalErrorCount++; + } + } + } else { + sb.append(" CNI: " + c + "\n"); + notImplementedCount++; + } + lastName = c; + } + } + + // TODO: Audit token images here... + + String totalStats = "NIF count: " + missingCount + "\nCNI count: " + notImplementedCount + "\nERR count: " + + internalErrorCount + "\n"; + + sb.append("\n-----------\n"); + sb.append(totalStats); + sb.append("-----------\n\n"); + sb.append( + "NIF = 'no image graphic found'\nCNI = 'card not implemented in Forge'\nERR = 'internal error detected'\n"); + + tar.setText(sb.toString()); + tar.setCaretPosition(0); // this will move scroll view to the top... + + final FButton btnClipboardCopy = new FButton(localizer.getMessage("btnCopyToClipboard")); + btnClipboardCopy.addActionListener(new ActionListener() { + @Override + public void actionPerformed(final ActionEvent arg0) { + Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(sb.toString()), null); + SOverlayUtils.hideOverlay(); + } + }); + scr.getParent().add(btnClipboardCopy, "w 200!, h pref+12!, center, gaptop 10"); + + FOverlay.SINGLETON_INSTANCE.getPanel().validate(); + FOverlay.SINGLETON_INSTANCE.getPanel().repaint(); + + } + + public void showCardandImageAuditData() { + final FTextArea tar = new FTextArea("Auditing card and image data. Please wait..."); + tar.setOpaque(true); + tar.setLineWrap(true); + tar.setWrapStyleWord(true); + tar.setEditable(false); + tar.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); + + tar.setFont(FSkin.getRelativeFixedFont(16)); + tar.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT)); + tar.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2)); + + final FScrollPane scr = new FScrollPane(tar, true, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, + ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); + + _showDialog(scr, new Runnable() { + @Override + public void run() { + auditUpdate(tar, scr); + scr.getViewport().setViewPosition(new Point(0, 0)); + } + }); + } + public void showLicensing() { String license = "Forge License Information

" diff --git a/forge-gui/res/languages/en-US.properties b/forge-gui/res/languages/en-US.properties index 7c57b271f98..5e6a9c1f1d5 100644 --- a/forge-gui/res/languages/en-US.properties +++ b/forge-gui/res/languages/en-US.properties @@ -12,6 +12,7 @@ btnDeleteWorkshopUI = Reset Workshop Layout btnUserProfileUI = Open User Directory btnContentDirectoryUI = Open Content Directory btnResetJavaFutureCompatibilityWarnings = Reset Java Compatibility Warnings +btnCopyToClipboard= Copy to Clipboard cbRemoveSmall = Remove Small Creatures cbCardBased = Include Card-based Deck Generation cbSingletons = Singleton Mode @@ -138,6 +139,7 @@ btnDownloadPics = Download LQ Card Pictures btnDownloadQuestImages = Download Quest Images btnDownloadAchievementImages = Download Achievement Images btnReportBug =Report a Bug +btnListImageData =Audit Card and Image Data btnImportPictures = Import Data btnHowToPlay = How To Play btnDownloadPrices = Download Card Prices @@ -153,6 +155,7 @@ lblYoureRunning = You're running lblYouNeedAtLeastJavaVersion = You need at least version 1.8.0_101. lblImportPictures = Import data from a local directory. lblReportBug = Something broken? +lblListImageData = Audit cards not implemented by Forge and missing card images lblHowToPlay = Rules of the Game. lblLicensing = Forge legal. ContentDownloaders = Content Downloaders