OSDN Git Service

chore: increment version to v2.0.3
[delesterandomselector/DelesteRandomSelector.git] / src / com / ranfa / main / DelesteRandomSelector.java
index cdda4af..69c9b18 100644 (file)
@@ -5,6 +5,8 @@ import java.awt.EventQueue;
 import java.awt.Font;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Random;
 import java.util.concurrent.CompletableFuture;
@@ -25,12 +27,15 @@ import javax.swing.JSpinner;
 import javax.swing.JTextArea;
 import javax.swing.border.EmptyBorder;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import com.jgoodies.forms.layout.ColumnSpec;
 import com.jgoodies.forms.layout.FormLayout;
 import com.jgoodies.forms.layout.FormSpecs;
 import com.jgoodies.forms.layout.RowSpec;
 import com.ranfa.lib.CheckVersion;
-import com.ranfa.lib.LimitedLog;
+import com.ranfa.lib.EstimateAlbumTypeCycle;
 import com.ranfa.lib.Scraping;
 import com.ranfa.lib.SettingJSONProperty;
 import com.ranfa.lib.Settings;
@@ -38,7 +43,7 @@ import com.ranfa.lib.Song;
 import com.ranfa.lib.TwitterIntegration;
 import com.ranfa.lib.Version;
 
-@Version(major = 1, minor = 3, patch = 3)
+@Version(major = 2, minor = 0, patch = 3)
 public class DelesteRandomSelector extends JFrame {
 
        private static ArrayList<Song> selectedSongsList = new ArrayList<Song>();
@@ -67,12 +72,17 @@ public class DelesteRandomSelector extends JFrame {
        private boolean integratorBool = false;
        private JTextArea textArea;
        private JScrollPane scrollPane;
+       private CompletableFuture<Void> softwareUpdateFuture = null;
+       private CompletableFuture<Void> albumTypeEstimateFuture = null;
+       private String albumType = "計算中";
+       private Logger logger = LoggerFactory.getLogger(DelesteRandomSelector.class);
 
        /**
         * Launch the application.
         */
        public static void main(String[] args) {
                EventQueue.invokeLater(new Runnable() {
+                       @Override
                        public void run() {
                                try {
                                        DelesteRandomSelector frame = new DelesteRandomSelector();
@@ -97,7 +107,7 @@ public class DelesteRandomSelector extends JFrame {
                if(isFirst) {
                        JOptionPane.showMessageDialog(this, "楽曲データベースが見つかりませんでした。自動的に作成されます…\n注意:初回起動ではなく、かつ、Jarファイルと同じ階層に\"database.json\"というファイルが存在するにも関わらず\nこのポップアップが出た場合、開発者までご一報ください。\nGithub URL: https://github.com/hizumiaoba/DelesteRandomSelector/issues");
                        if(!Scraping.writeToJson(Scraping.getWholeData())) {
-                               JOptionPane.showMessageDialog(this, "Exception:NullPointerException\\nCannot Keep up! Please re-download this Application!");
+                               JOptionPane.showMessageDialog(this, "Exception:NullPointerException\nCannot Keep up! Please re-download this Application!");
                                throw new NullPointerException("FATAL: cannot continue!");
                        }
                }
@@ -108,35 +118,37 @@ public class DelesteRandomSelector extends JFrame {
                        JOptionPane.showMessageDialog(this, "Exception:NullPointerException\nCannot Keep up! Please re-download this Application!");
                        throw new NullPointerException("FATAL: cannot continue!");
                }
-               LimitedLog.println(this.getClass() + ":[DEBUG]: " + "Loading Settings...");
+               logger.debug("Loading settings...");
                property.setCheckLibraryUpdates(Settings.needToCheckLibraryUpdates());
                property.setCheckVersion(Settings.needToCheckVersion());
                property.setWindowWidth(Settings.getWindowWidth());
                property.setWindowHeight(Settings.getWindowHeight());
                property.setSongLimit(Settings.getSongsLimit());
                property.setSaveScoreLog(Settings.saveScoreLog());
-               property.setOutputDebugSentences(Settings.outputDebugSentences());
-               LimitedLog.println(this.getClass() + ":[DEBUG]: " + "Loading Settings done."
-                               + "\nVersion Check: " + property.isCheckVersion()
-                               + "\nLibrary Update Check: " + property.isCheckLibraryUpdates()
-                               + "\nWindow Width: " + property.getWindowWidth()
-                               + "\nWindow Height: " + property.getWindowHeight()
-                               + "\nSong Limit: " + property.getSongLimit()
-                               + "\nSaveScoreLog: " + property.isSaveScoreLog()
-                               + "\nOutputDebugSentences: " + property.isOutputDebugSentences());
+               logger.debug("Load settings done.");
+               logger.debug("Version check: " + property.isCheckVersion());
+               logger.debug("Library update check: " + property.isCheckLibraryUpdates());
+               logger.debug("Window Width: " + property.getWindowWidth());
+               logger.debug("Window Height: " + property.getWindowHeight());
+               logger.debug("Song Limit: " + property.getSongLimit());
+               logger.debug("SaveScoreLog: " + property.isSaveScoreLog());
+               EstimateAlbumTypeCycle.Initialization();
+               if(Files.exists(Paths.get("generated/albumCycle.json"))) {
+                       albumType = EstimateAlbumTypeCycle.getCurrentCycle();
+               }
                if(property.isCheckVersion()) {
-                       CompletableFuture<Void> softwareUpdateFuture = CompletableFuture.runAsync(() -> CheckVersion.needToBeUpdated(), es);
+                       softwareUpdateFuture = CompletableFuture.runAsync(() -> CheckVersion.needToBeUpdated(), es);
                }
                BiConsumer<ArrayList<Song>, ArrayList<Song>> updateConsumer = (list1, list2) -> {
-                       LimitedLog.println(this.getClass() + ":[INFO]: " + "Checking database updates...");
+                       logger.info("Checking database updates...");
                        if(list1.size() > list2.size()) {
                                long time = System.currentTimeMillis();
-                               LimitedLog.println(this.getClass() + ":[INFO]: " + (list1.size() - list2.size()) + " Update detected.");
+                               logger.info((list1.size() - list2.size()) + " Update detected.");
                                Scraping.writeToJson(list1);
-                               LimitedLog.println(this.getClass() + ":[INFO]: " + "Update completed in " + (System.currentTimeMillis() - time) + "ms");
-                               LimitedLog.println(this.getClass() + ":[INFO]: " + "Updated database size: " + list1.size());
+                               logger.info("Update completed in " + (System.currentTimeMillis() - time) + "ms");
+                               logger.info("Updated database size: " + list1.size());
                        } else {
-                               LimitedLog.println(this.getClass() + ":[INFO]: " + "database is up-to-date.");
+                               logger.info("database is up-to-date.");
                        }
                };
                Runnable setEnabled = () -> {
@@ -149,15 +161,16 @@ public class DelesteRandomSelector extends JFrame {
                        btnImport.setEnabled(true);
                        btnImport.setText("<html><body>楽曲<br>絞り込み</body></html>");
                };
-               getWholeDataFuture.thenAcceptAsync(list -> LimitedLog.println(this.getClass() + ":[INFO]: Scraping data size:" + list.size()), es);
-               getFromJsonFuture.thenAcceptAsync(list -> LimitedLog.println(this.getClass() + ":[INFO]: Currently database size:" + list.size()), es);
+               getWholeDataFuture.thenAcceptAsync(list -> logger.info("Scraping data size:" + list.size()), es);
+               getFromJsonFuture.thenAcceptAsync(list -> logger.info("Currently database size:" + list.size()), es);
                if(property.isCheckLibraryUpdates()) {
                        CompletableFuture<Void> updatedFuture = getWholeDataFuture.thenAcceptBothAsync(getFromJsonFuture, updateConsumer, es);
                        updatedFuture.thenRunAsync(setEnabled, es);
                }
-               LimitedLog.println(this.getClass() + ":[DEBUG]: " + "Version:" + CheckVersion.getVersion());
+               logger.debug("Version:" + CheckVersion.getVersion());
                setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                setBounds(100, 100, property.getWindowWidth(), property.getWindowHeight());
+               // setBounds(100, 100, 640, 360);
                contentPane = new JPanel();
                contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
                setContentPane(contentPane);
@@ -262,15 +275,17 @@ public class DelesteRandomSelector extends JFrame {
                btnImport = new JButton("<html><body>データベース<br>更新中…</body></html>");
                btnImport.setEnabled(false);
                btnImport.addActionListener(new ActionListener() {
+                       @Override
                        public void actionPerformed(ActionEvent e) {
                                ArrayList<Song> fromJson = Scraping.getFromJson();
                                        ArrayList<Song> specificlevelList = Scraping.getSpecificLevelSongs(fromJson, (Integer)spinnerLevel.getValue(), checkLessLv.isSelected(), checkMoreLv.isSelected());
                                        ArrayList<Song> specificDifficultyList = Scraping.getSpecificDifficultySongs(specificlevelList, comboDifficultySelect.getSelectedItem().toString());
                                        ArrayList<Song> specificAttributeList = Scraping.getSpecificAttributeSongs(specificDifficultyList, comboAttribute.getSelectedItem().toString());
+                                       ArrayList<Song> specificTypeList = Scraping.getSpecificAlbumTypeSongs(specificAttributeList, EstimateAlbumTypeCycle.getCurrentCycle());
                                        if(!selectedSongsList.isEmpty())
                                        selectedSongsList.clear();
-                               selectedSongsList.addAll(specificAttributeList);
-                               LimitedLog.println(this.getClass() + ":[INFO]: " +"Songs are selected.We are Ready to go.");
+                               selectedSongsList.addAll((comboDifficultySelect.getSelectedItem().equals(Scraping.MASTERPLUS) || comboDifficultySelect.getSelectedItem().equals(Scraping.LEGACYMASTERPLUS)) ? specificTypeList : specificAttributeList);
+                               logger.info("Songs are selected.We are Ready to go.");
                                JOptionPane.showMessageDialog(null, "絞り込み完了!「開始」をクリックすることで選曲できます!");
                        }
                });
@@ -279,23 +294,21 @@ public class DelesteRandomSelector extends JFrame {
 
                btnStart = new JButton("開始!");
                btnStart.addActionListener(new ActionListener() {
+                       @Override
                        public void actionPerformed(ActionEvent e) {
                                Random random = new Random(System.currentTimeMillis());
-                               String[] tmp = new String[property.getSongLimit()];
+                               String paneString = "";
                                integratorArray = new String[property.getSongLimit()];
                                for(int i = 0; i < property.getSongLimit(); i++) {
                                        int randomInt = random.nextInt(selectedSongsList.size());
-                                       tmp[i] = (i + 1) + "曲目: " + selectedSongsList.get(randomInt).getAttribute() + " [" + selectedSongsList.get(randomInt).getDifficulty() + "]「" + selectedSongsList.get(randomInt).getName() + "」!(Lv:" + selectedSongsList.get(randomInt).getLevel() + ")\n\n";
+                                       String typeString = comboDifficultySelect.getSelectedItem().equals(Scraping.MASTERPLUS) || comboDifficultySelect.getSelectedItem().equals(Scraping.LEGACYMASTERPLUS) ? EstimateAlbumTypeCycle.getCurrentCycle() : "";
+                                       paneString = paneString + (i + 1) + "曲目: " + selectedSongsList.get(randomInt).getAttribute() + " [" + selectedSongsList.get(randomInt).getDifficulty() + "]「" + selectedSongsList.get(randomInt).getName() + "」!(Lv:" + selectedSongsList.get(randomInt).getLevel() + " " + typeString + ")\n\n";
                                        integratorArray[i] = selectedSongsList.get(randomInt).getName() + "(Lv" + selectedSongsList.get(randomInt).getLevel() + ")\n";
                                }
-                               String paneString = "";
-                               for (int i = 0; i < tmp.length; i++) {
-                                       paneString = paneString + tmp[i];
-                               }
-                               paneString = paneString + "この" + tmp.length + "曲をプレイしましょう!!!";
+                               paneString = paneString + "この" + property.getSongLimit() + "曲をプレイしましょう!!!";
                                textArea.setText(paneString);
                                integratorBool = true;
-                               LimitedLog.println(this.getClass() + ":[INFO]: " + "show up completed.");
+                               logger.info("show up completed.");
                        }
                });
                btnStart.setFont(new Font("UD デジタル 教科書体 NP-B", Font.BOLD, 13));
@@ -304,17 +317,14 @@ public class DelesteRandomSelector extends JFrame {
                                btnTwitterIntegration = new JButton("Twitter連携");
                                btnTwitterIntegration.setFont(new Font("UD デジタル 教科書体 NP-B", Font.BOLD, 11));
                                btnTwitterIntegration.addActionListener(new ActionListener() {
+                                       @Override
                                        public void actionPerformed(ActionEvent e) {
-                                               LimitedLog.println(this.getClass() + ":[INFO]: " + "Twitter Integration requested.Verify permission status.");
                                                boolean authorizationStatus = TwitterIntegration.authorization();
-                                               LimitedLog.println(this.getClass() + ":[INFO]: " + "Permission Verifying completed.\nStatus: " + authorizationStatus);
-                                               LimitedLog.print(this.getClass() + ":[INFO]: " + "Construction status message...");
                                                String updatedStatus = "デレステ課題曲セレクターで\n";
                                                int lengthLimit = updatedStatus.length();
                                                boolean isBroken = false;
                                                if(!integratorBool) {
                                                        JOptionPane.showMessageDialog(null, "ちひろ「まだプレイを始めていないみたいですね」");
-                                                       LimitedLog.println();
                                                        return;
                                                }
                                                for(int i = 0; i < integratorArray.length; i++) {
@@ -330,28 +340,28 @@ public class DelesteRandomSelector extends JFrame {
                                                } else {
                                                        updatedStatus = updatedStatus + "をプレイしました!\n#DelesteRandomSelector #デレステ ";
                                                }
-                                               LimitedLog.println("completed.\n" + updatedStatus);
+                                               logger.info("status message constructed.");
                                                lengthLimit = updatedStatus.length();
                                                if(authorizationStatus) {
                                                        int option = JOptionPane.showConfirmDialog(null, "Twitterへ以下の内容を投稿します。よろしいですか?\n\n" + updatedStatus + "\n\n文字数:" + lengthLimit);
-                                                       LimitedLog.println(this.getClass() + ":[INFO]: " + "User selected " + option);
+                                                       logger.info("user seletced: " + option);
                                                        switch(option) {
                                                                case JOptionPane.OK_OPTION:
                                                                        TwitterIntegration.PostTwitter(updatedStatus);
-                                                                       LimitedLog.println(this.getClass() + ":[INFO]: " + "Success to update the status.");
+                                                                       logger.info("Success to update the status.");
                                                                        JOptionPane.showMessageDialog(null, "投稿が完了しました。");
                                                                        break;
                                                                case JOptionPane.NO_OPTION:
-                                                                       LimitedLog.println(this.getClass() + ":[INFO]: " + "There is no will to post.");
+                                                                       logger.info("There is no will to post.");
                                                                        break;
                                                                case JOptionPane.CANCEL_OPTION:
-                                                                       LimitedLog.println(this.getClass() + ":[INFO]: " + "The Operation was canceled by user.");
+                                                                       logger.info("The Operation was canceled by user.");
                                                                        break;
                                                                default:
                                                                        break;
                                                        }
                                                } else {
-                                                       LimitedLog.println(this.getClass() + ":[WARN]: " + "seems to reject the permission.it should need try again.");
+                                                       logger.info("seems to reject the permission.it should need try again.");
                                                }
                                        }
                                });
@@ -359,9 +369,14 @@ public class DelesteRandomSelector extends JFrame {
 
                                                                btnExit = new JButton("終了");
                                                                btnExit.addActionListener(new ActionListener() {
+                                                                       @Override
                                                                        public void actionPerformed(ActionEvent e) {
-                                                                               LimitedLog.println(this.getClass() + ":[INFO]: " +"Requested Exit by Button");
-                                                                               System.exit(0);
+                                                                               if(softwareUpdateFuture.isDone() || albumTypeEstimateFuture.isDone()) {
+                                                                                       logger.info("Requested Exit by Button");
+                                                                                       System.exit(0);
+                                                                               } else {
+                                                                                       JOptionPane.showMessageDialog(null, "内部更新処理が完了していません。少し待ってからやり直してください。");
+                                                                               }
                                                                        }
                                                                });
                                                                btnExit.setFont(new Font("UD デジタル 教科書体 NP-B", Font.BOLD, 13));
@@ -372,13 +387,14 @@ public class DelesteRandomSelector extends JFrame {
                panelCentre.setLayout(new BorderLayout(0, 0));
 
                textArea = new JTextArea();
-               textArea.setText("楽曲選択の手順\r\n1.難易度、属性、レベルを選択する\r\n2.「楽曲取り込み」ボタンを押す!\r\n3.「開始」ボタンを押す!\r\n4.選択された楽曲がここに表示されます!\r\n現在設定されている楽曲選択の最大数:" + property.getSongLimit());
+               textArea.setText("楽曲選択の手順\r\n1.難易度、属性、レベルを選択する\r\n2.「楽曲取り込み」ボタンを押す!\r\n3.「開始」ボタンを押す!\r\n4.選択された楽曲がここに表示されます!\r\n現在設定されている楽曲選択の最大数:" + property.getSongLimit() + "\n現在のMASTER+アルバム周期(推定):" + albumType);
                textArea.setEditable(false);
 
                scrollPane = new JScrollPane(textArea);
                panelCentre.add(scrollPane, BorderLayout.CENTER);
-               if(isFirst || !property.isCheckLibraryUpdates())
+               if(isFirst || !property.isCheckLibraryUpdates()) {
                        setEnabled.run();
+               }
        }
 
 }