-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch_style_settings.cpp
120 lines (111 loc) · 6.66 KB
/
patch_style_settings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include "patch_style_settings.h"
#include <fstream>
#include "utilities.h"
using json = nlohmann::json;
namespace fs = std::filesystem;
PatchStyleSettings::PatchStyleSettings() { }
PatchStyleSettings::PatchStyleSettings(std::filesystem::path settingsPath) {
if (fs::exists(settingsPath)) {
loadSettings(fetchJson(settingsPath));
} else {
std::stringstream settingsText;
writeSettings(settingsText);
writeStringStreamToPath(settingsText, settingsPath);
}
}
void PatchStyleSettings::writeSettings(std::stringstream & settingsText) {
std::stringstream settingsJson;
settingsJson << '{'
<< "\n \"indentationSpacesPerModifier\" : " << indentationSpacesPerModifier
<< "\n //Outer wrapper brackets"
<< "\n \"newLineAfterOuterOpenerBracket\" : " << newLineAfterOuterOpenerBracket
<< "\n \"newLineAfterOuterCloserBracket\" : " << newLineAfterOuterCloserBracket
<< "\n \"indentationInOuterBrackets\" : " << indentationInOuterBrackets
<< "\n //Operation set wrapper brackets (Starbound)"
<< "\n \"newLineAfterOperationSetOpenerBracket\" : " << newLineAfterOperationSetOpenerBracket
<< "\n \"newLineAfterOperationSetCloserBracket\" : " << newLineAfterOperationSetCloserBracket
<< "\n \"newLineAfterOperationSetCloserBracketComma\" : " << newLineAfterOperationSetCloserBracketComma
<< "\n \"indentationInOperationSetBrackets\" : " << indentationInOperationSetBrackets
<< "\n //Operation wrapper brackets"
<< "\n \"newLineAfterOperationOpenerBracket\" : " << newLineAfterOperationOpenerBracket
<< "\n \"newLineAfterOperationCloserBracket\" : " << newLineAfterOperationCloserBracket
<< "\n \"newLineAfterOperationCloserBracketComma\" : " << newLineAfterOperationCloserBracketComma
<< "\n \"indentationInOperationBrackets\" : " << indentationInOperationBrackets
<< "\n //Operation contents"
<< "\n \"newLineAfterOperationSegment\" : " << newLineAfterOperationSegment
<< "\n \"spaceBeforeOperationColon\" : " << spaceBeforeOperationColon
<< "\n \"spaceAfterOperationColon\" : " << spaceAfterOperationColon
<< "\n}\n";
}
void PatchStyleSettings::loadSettings(json settingsJson) {
//TODO: Handle invalid types
if (settingsJson.contains("indentationSpacesPerModifier")) {
indentationSpacesPerModifier = settingsJson["indentationSpacesPerModifier"];
}
//Outer wrapper brackets
if (settingsJson.contains("newLineAfterOuterOpenerBracket")) {
newLineAfterOuterOpenerBracket = settingsJson["newLineAfterOuterOpenerBracket"];
}
if (settingsJson.contains("newLineAfterOuterCloserBracket")) {
newLineAfterOuterCloserBracket = settingsJson["newLineAfterOuterCloserBracket"];
}
if (settingsJson.contains("indentationInOuterBrackets")) {
indentationInOuterBrackets = settingsJson["indentationInOuterBrackets"];
}
//Operation set wrapper brackets (Starbound specific)
if (settingsJson.contains("newLineAfterOperationSetOpenerBracket")) {
newLineAfterOperationSetOpenerBracket = settingsJson["newLineAfterOperationSetOpenerBracket"];
}
if (settingsJson.contains("newLineAfterOperationSetCloserBracket")) {
newLineAfterOperationSetCloserBracket = settingsJson["newLineAfterOperationSetCloserBracket"];
}
if (settingsJson.contains("newLineAfterOperationSetCloserBracketComma")) {
newLineAfterOperationSetCloserBracketComma = settingsJson["newLineAfterOperationSetCloserBracketComma"];
}
if (settingsJson.contains("indentationInOperationSetBrackets")) {
indentationInOperationSetBrackets = settingsJson["indentationInOperationSetBrackets"];
}
//Operation wrapper brackets
if (settingsJson.contains("newLineAfterOperationOpenerBracket")) {
newLineAfterOperationOpenerBracket = settingsJson["newLineAfterOperationOpenerBracket"];
}
if (settingsJson.contains("newLineAfterOperationCloserBracket")) {
newLineAfterOperationCloserBracket = settingsJson["newLineAfterOperationCloserBracket"];
}
if (settingsJson.contains("newLineAfterOperationCloserBracketComma")) {
newLineAfterOperationCloserBracketComma = settingsJson["newLineAfterOperationCloserBracketComma"];
}
if (settingsJson.contains("indentationInOperationBrackets")) {
indentationInOperationBrackets = settingsJson["indentationInOperationBrackets"];
}
//Operation contents
if (settingsJson.contains("newLineAfterOperationSegment")) {
newLineAfterOperationSegment = settingsJson["newLineAfterOperationSegment"];
}
if (settingsJson.contains("spaceBeforeOperationColon")) {
spaceBeforeOperationColon = settingsJson["spaceBeforeOperationColon"];
}
if (settingsJson.contains("spaceAfterOperationColon")) {
spaceAfterOperationColon = settingsJson["spaceAfterOperationColon"];
}
}
//Getters
const int PatchStyleSettings::getIndentationSpacesPerModifier() { return indentationSpacesPerModifier; }
//Outer wrapper brackets
const bool PatchStyleSettings::getNewLineAfterOuterOpenerBracket() { return newLineAfterOuterOpenerBracket; }
const bool PatchStyleSettings::getNewLineAfterOuterCloserBracket() { return newLineAfterOuterCloserBracket; }
const bool PatchStyleSettings::getIndentationInOuterBrackets() { return indentationInOuterBrackets; }
//Operation set wrapper brackets (Starbound specific)
const bool PatchStyleSettings::getNewLineAfterOperationSetOpenerBracket() { return newLineAfterOperationSetOpenerBracket; }
const bool PatchStyleSettings::getNewLineAfterOperationSetCloserBracket() { return newLineAfterOperationSetCloserBracket; }
const bool PatchStyleSettings::getNewLineAfterOperationSetCloserBracketComma() { return newLineAfterOperationSetCloserBracketComma; }
const bool PatchStyleSettings::getIndentationInOperationSetBrackets() { return indentationInOperationSetBrackets; }
//Operation wrapper brackets
const bool PatchStyleSettings::getNewLineAfterOperationOpenerBracket() { return newLineAfterOperationOpenerBracket; }
const bool PatchStyleSettings::getNewLineAfterOperationCloserBracket() { return newLineAfterOperationCloserBracket; }
const bool PatchStyleSettings::getNewLineAfterOperationCloserBracketComma() { return newLineAfterOperationCloserBracketComma; }
const bool PatchStyleSettings::getIndentationInOperationBrackets() { return indentationInOperationBrackets; }
//Operation contents
const bool PatchStyleSettings::getNewLineAfterOperationSegment() { return newLineAfterOperationSegment; }
const bool PatchStyleSettings::getSpaceBeforeOperationColon() { return spaceBeforeOperationColon; }
const bool PatchStyleSettings::getSpaceAfterOperationColon() { return spaceAfterOperationColon; }