Skip to content

Commit 12414d8

Browse files
committed
feat: pretty-print JSON values
1 parent 766a6ef commit 12414d8

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

Editor/Aarthificial.Safekeeper.Editor.asmdef

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
"precompiledReferences": [],
1414
"autoReferenced": true,
1515
"defineConstraints": [],
16-
"versionDefines": [],
16+
"versionDefines": [
17+
{
18+
"name": "com.unity.nuget.newtonsoft-json",
19+
"expression": "3.0.0",
20+
"define": "UNITY_NEWTONSOFT_JSON"
21+
}
22+
],
1723
"noEngineReferences": false
18-
}
24+
}

Editor/SafekeeperEditor.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,17 @@ private void DataGUI(ISaveData data) {
159159
var chunk = data.GetChunk(_currentChunk);
160160
if (chunk.TryGetValue(_currentLocation, out var value)) {
161161
if (!_formattedData.TryGetValue(value, out var formatted)) {
162-
// formatted = JToken.Parse(value).ToString(Formatting.Indented);
163-
// _formattedData.Add(value, formatted);
162+
#if UNITY_NEWTONSOFT_JSON
163+
try {
164+
formatted = Newtonsoft.Json.Linq.JToken.Parse(value)
165+
.ToString(Newtonsoft.Json.Formatting.Indented);
166+
_formattedData.Add(value, formatted);
167+
} catch {
168+
formatted = value;
169+
}
170+
#else
164171
formatted = value;
172+
#endif
165173
}
166174
EditorGUILayout.TextArea(formatted, GUILayout.ExpandHeight(true));
167175
}

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
"licensesUrl": "https://github.com/aarthificial-gamedev/safekeeper/blob/main/LICENSE",
2222
"documentationUrl": "https://safekeeper.aarthificial.com",
2323
"changelogUrl": "https://github.com/aarthificial-gamedev/safekeeper/blob/main/CHANGELOG.md",
24+
"peerDependencies": {
25+
"com.unity.nuget.newtonsoft-json": "3.0.0"
26+
},
2427
"author": {
2528
"name": "aarthificial",
2629
"email": "[email protected]",

0 commit comments

Comments
 (0)