OSDN Git Service

Merge pull request #2 from hizumiaoba/Library-patch
[delesterandomselector/DelesteRandomSelector.git] / src / com / ranfa / lib / Settings.java
1 package com.ranfa.lib;
2
3 import java.io.File;
4 import java.io.IOException;
5
6 import com.fasterxml.jackson.databind.JsonNode;
7 import com.fasterxml.jackson.databind.ObjectMapper;
8
9 /**
10  * 「settings.json」ファイルから各種設定を読み込みます
11  * 設定できる内容は
12  * ・起動時のバージョンチェック (checkVersion)
13  * ・起動時にライブラリの更新有無のチェック (checkLibraryUpdates)
14  * ・ウィンドウサイズ (windowWidth), (windowHeight)
15  * ・デフォルトの曲指定上限数 (songsLimit)
16  * ・スコアログの保存 (saveScoreLog)
17  * ・標準出力へデバッグ用簡易ログを流すかどうか (outputDebugSentences)
18  * の6つ(括弧内はフィールド名)
19  * 今後、設定可能事項は増える可能性あり
20  * @author hizum
21  * @since v1.0.0
22  *
23  */
24 public class Settings {
25
26         // 設定ファイルパス
27         private final static String FILEPATH = "settings.json";
28
29         public static boolean needToCheckVersion() {
30                 boolean res = true;
31                 ObjectMapper mapper = new ObjectMapper();
32                 try {
33                         JsonNode node = mapper.readTree(new File(FILEPATH));
34                         res = node.get("checkVersion").asBoolean();
35                 } catch (IOException e) {
36                         e.printStackTrace();
37                 }
38                 return res;
39         }
40
41         public static boolean needToCheckLibraryUpdates() {
42                 boolean res = true;
43                 ObjectMapper mapper = new ObjectMapper();
44                 try {
45                         JsonNode node = mapper.readTree(new File(FILEPATH));
46                         res = node.get("checkLibraryUpdates").asBoolean();
47                 } catch (IOException e) {
48                         e.printStackTrace();
49                 }
50                 return res;
51         }
52
53         public static int getWindowWidth() {
54                 int res = 640;
55                 ObjectMapper mapper = new ObjectMapper();
56                 try {
57                         JsonNode node = mapper.readTree(new File(FILEPATH));
58                         res = node.get("windowWidth").asInt();
59                 } catch (IOException e) {
60                         e.printStackTrace();
61                 }
62                 return res;
63         }
64
65         public static int getWindowHeight() {
66                 int res = 480;
67                 ObjectMapper mapper = new ObjectMapper();
68                 try {
69                         JsonNode node = mapper.readTree(new File(FILEPATH));
70                         res = node.get("windowHeight").asInt();
71                 } catch (IOException e) {
72                         e.printStackTrace();
73                 }
74                 return res;
75         }
76
77         public static int getSongsLimit() {
78                 int res = 3;
79                 ObjectMapper mapper = new ObjectMapper();
80                 try {
81                         JsonNode node = mapper.readTree(new File(FILEPATH));
82                         res = node.get("songsLimit").asInt();
83                 } catch (IOException e) {
84                         e.printStackTrace();
85                 }
86                 return res;
87         }
88
89         public static boolean saveScoreLog() {
90                 boolean res = false;
91                 ObjectMapper mapper = new ObjectMapper();
92                 try {
93                         JsonNode node = mapper.readTree(new File(FILEPATH));
94                         res = node.get("saveScoreLog").asBoolean();
95                 } catch (IOException e) {
96                         e.printStackTrace();
97                 }
98                 return res;
99         }
100
101         public static boolean outputDebugSentences() {
102                 boolean res = false;
103                 ObjectMapper mapper = new ObjectMapper();
104                 try {
105                         JsonNode node = mapper.readTree(new File(FILEPATH));
106                         res = node.get("outputDebugSentences").asBoolean();
107                 } catch (IOException e) {
108                         e.printStackTrace();
109                 }
110                 return res;
111         }
112 }