OSDN Git Service

feat:add settings file
authorhizumiaoba <56146205+hizumiaoba@users.noreply.github.com>
Sun, 27 Jun 2021 12:40:25 +0000 (21:40 +0900)
committerhizumiaoba <56146205+hizumiaoba@users.noreply.github.com>
Sun, 27 Jun 2021 12:40:25 +0000 (21:40 +0900)
src/com/ranfa/lib/LimitedLog.java [new file with mode: 0644]
src/com/ranfa/lib/Settings.java [new file with mode: 0644]

diff --git a/src/com/ranfa/lib/LimitedLog.java b/src/com/ranfa/lib/LimitedLog.java
new file mode 100644 (file)
index 0000000..da2d386
--- /dev/null
@@ -0,0 +1,22 @@
+package com.ranfa.lib;
+
+public class LimitedLog {
+
+       private final static boolean ISALLOWED = Settings.outputDebugSentences();
+
+       public static void print(String s) {
+               if(!ISALLOWED) {
+                       return;
+               } else {
+                       System.out.print(s);
+                       return;
+               }
+       }
+
+       public static void println(String s) {
+               if(!ISALLOWED) {
+                       return;
+               }
+               System.out.println(s);
+       }
+}
diff --git a/src/com/ranfa/lib/Settings.java b/src/com/ranfa/lib/Settings.java
new file mode 100644 (file)
index 0000000..7ee6d01
--- /dev/null
@@ -0,0 +1,112 @@
+package com.ranfa.lib;
+
+import java.io.File;
+import java.io.IOException;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * 「settings.json」ファイルから各種設定を読み込みます
+ * 設定できる内容は
+ * ・起動時のバージョンチェック (checkVersion)
+ * ・起動時にライブラリの更新有無のチェック (checkLibraryUpdates)
+ * ・ウィンドウサイズ (windowWidth), (windowHeight)
+ * ・デフォルトの曲指定上限数 (songsLimit)
+ * ・スコアログの保存 (saveScoreLog)
+ * ・標準出力へデバッグ用簡易ログを流すかどうか (outputDebugSentences)
+ * の6つ(括弧内はフィールド名)
+ * 今後、設定可能事項は増える可能性あり
+ * @author hizum
+ * @since v1.0.0
+ *
+ */
+public class Settings {
+
+       // 設定ファイルパス
+       private final static String FILEPATH = "settings.json";
+
+       public static boolean needToCheckVersion() {
+               boolean res = true;
+               ObjectMapper mapper = new ObjectMapper();
+               try {
+                       JsonNode node = mapper.readTree(new File(FILEPATH));
+                       res = node.get("checkVersion").asBoolean();
+               } catch (IOException e) {
+                       e.printStackTrace();
+               }
+               return res;
+       }
+
+       public static boolean needToCheckLibraryUpdates() {
+               boolean res = true;
+               ObjectMapper mapper = new ObjectMapper();
+               try {
+                       JsonNode node = mapper.readTree(new File(FILEPATH));
+                       res = node.get("checkLibraryUpdates").asBoolean();
+               } catch (IOException e) {
+                       e.printStackTrace();
+               }
+               return res;
+       }
+
+       public static int getWindowWidth() {
+               int res = 640;
+               ObjectMapper mapper = new ObjectMapper();
+               try {
+                       JsonNode node = mapper.readTree(new File(FILEPATH));
+                       res = node.get("windowWidth").asInt();
+               } catch (IOException e) {
+                       e.printStackTrace();
+               }
+               return res;
+       }
+
+       public static int getWindowHeight() {
+               int res = 480;
+               ObjectMapper mapper = new ObjectMapper();
+               try {
+                       JsonNode node = mapper.readTree(new File(FILEPATH));
+                       res = node.get("windowHeight").asInt();
+               } catch (IOException e) {
+                       e.printStackTrace();
+               }
+               return res;
+       }
+
+       public static int getSongsLimit() {
+               int res = 3;
+               ObjectMapper mapper = new ObjectMapper();
+               try {
+                       JsonNode node = mapper.readTree(new File(FILEPATH));
+                       res = node.get("songsLimit").asInt();
+               } catch (IOException e) {
+                       e.printStackTrace();
+               }
+               return res;
+       }
+
+       public static boolean saveScoreLog() {
+               boolean res = false;
+               ObjectMapper mapper = new ObjectMapper();
+               try {
+                       JsonNode node = mapper.readTree(new File(FILEPATH));
+                       res = node.get("saveScoreLog").asBoolean();
+               } catch (IOException e) {
+                       e.printStackTrace();
+               }
+               return res;
+       }
+
+       public static boolean outputDebugSentences() {
+               boolean res = false;
+               ObjectMapper mapper = new ObjectMapper();
+               try {
+                       JsonNode node = mapper.readTree(new File(FILEPATH));
+                       res = node.get("outputDebugSentences").asBoolean();
+               } catch (IOException e) {
+                       e.printStackTrace();
+               }
+               return res;
+       }
+}