4 import java.io.IOException;
5 import java.nio.file.Files;
6 import java.nio.file.Path;
7 import java.nio.file.Paths;
9 import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
10 import com.fasterxml.jackson.databind.JsonNode;
11 import com.fasterxml.jackson.databind.ObjectMapper;
12 import com.fasterxml.jackson.databind.ObjectWriter;
15 * 「settings.json」ファイルから各種設定を読み込みます
17 * ・起動時のバージョンチェック (checkVersion)
18 * ・起動時にライブラリの更新有無のチェック (checkLibraryUpdates)
19 * ・ウィンドウサイズ (windowWidth), (windowHeight)
20 * ・デフォルトの曲指定上限数 (songsLimit)
21 * ・スコアログの保存 (saveScoreLog)
22 * ・標準出力へデバッグ用簡易ログを流すかどうか (outputDebugSentences)
29 public class Settings {
32 private final static String FILEPATH = "settings.json";
34 public static boolean fileExists() {
35 Path path = Paths.get(FILEPATH);
36 return Files.exists(path);
39 public static boolean needToCheckVersion() {
41 ObjectMapper mapper = new ObjectMapper();
43 JsonNode node = mapper.readTree(new File(FILEPATH));
44 res = node.get("checkVersion").asBoolean();
45 } catch (IOException e) {
51 public static boolean needToCheckLibraryUpdates() {
53 ObjectMapper mapper = new ObjectMapper();
55 JsonNode node = mapper.readTree(new File(FILEPATH));
56 res = node.get("checkLibraryUpdates").asBoolean();
57 } catch (IOException e) {
63 public static int getWindowWidth() {
65 ObjectMapper mapper = new ObjectMapper();
67 JsonNode node = mapper.readTree(new File(FILEPATH));
68 res = node.get("windowWidth").asInt();
69 } catch (IOException e) {
75 public static int getWindowHeight() {
77 ObjectMapper mapper = new ObjectMapper();
79 JsonNode node = mapper.readTree(new File(FILEPATH));
80 res = node.get("windowHeight").asInt();
81 } catch (IOException e) {
87 public static int getSongsLimit() {
89 ObjectMapper mapper = new ObjectMapper();
91 JsonNode node = mapper.readTree(new File(FILEPATH));
92 res = node.get("songLimit").asInt();
93 } catch (IOException e) {
99 public static boolean saveScoreLog() {
101 ObjectMapper mapper = new ObjectMapper();
103 JsonNode node = mapper.readTree(new File(FILEPATH));
104 res = node.get("saveScoreLog").asBoolean();
105 } catch (IOException e) {
111 public static boolean outputDebugSentences() {
113 ObjectMapper mapper = new ObjectMapper();
115 JsonNode node = mapper.readTree(new File(FILEPATH));
116 res = node.get("outputDebugSentences").asBoolean();
117 } catch (IOException e) {
123 public static boolean writeDownJSON() {
125 SettingJSONProperty property = new SettingJSONProperty();
126 property.setCheckVersion(true);
127 property.setCheckLibraryUpdates(true);
128 property.setWindowWidth(640);
129 property.setWindowHeight(480);
130 property.setSongLimit(3);
131 property.setSaveScoreLog(false);
132 property.setOutputDebugSentences(false);
133 ObjectWriter writer = new ObjectMapper().writer(new DefaultPrettyPrinter());
135 writer.writeValue(Paths.get(FILEPATH).toFile(), property);
136 } catch (IOException e) {