Skip to content

Commit 3d14d82

Browse files
Merge pull request #16 from CarterGames/release/0.7.0
📦 Release/0.7.0
2 parents 04d118a + 644df61 commit 3d14d82

104 files changed

Lines changed: 1605 additions & 2504 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Carter Games/Notion Database To Unity/Code/Editor/CarterGames.NotionData.Editor.asmdef

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"rootNamespace": "CarterGames.NotionData.Editor",
44
"references": [
55
"GUID:aa312903d0d2e3541bf075ab426e5d8d",
6-
"GUID:f091c6eaefcd9154fbffa0b3a07f41fe",
76
"GUID:f0ee9ecf377e42043831037e8ccfaaf9",
87
"GUID:b7ef0f805fe70004c8b0b07af22ee394"
98
],

Carter Games/Notion Database To Unity/Code/Editor/Editors/Auto Download All/DownloadAllHandler.cs

Lines changed: 136 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
* THE SOFTWARE.
2222
*/
2323

24+
using System;
2425
using System.Collections.Generic;
2526
using System.Linq;
2627
using System.Reflection;
2728
using CarterGames.Shared.NotionData;
2829
using CarterGames.Shared.NotionData.Editor;
2930
using CarterGames.NotionData.Filters;
31+
using Newtonsoft.Json.Linq;
3032
using UnityEditor;
3133
using UnityEngine;
3234

@@ -41,12 +43,23 @@ public sealed class DownloadAllHandler : EditorWindow
4143
| Fields
4244
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */
4345

44-
private static bool haltOnDownload = true;
46+
private static bool haltOnError = true;
4547
private static List<NdAsset> toProcess;
4648
private static int TotalToProcessed = 0;
4749
private static int TotalProcessed = 0;
4850
private static bool hasErrorOnDownload;
4951
private static List<NotionRequestError> silencedErrors;
52+
53+
/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
54+
| Properties
55+
───────────────────────────────────────────────────────────────────────────────────────────────────────────── */
56+
57+
public static bool IsDownloadingAllAssets { get; private set; }
58+
59+
public static float AllDownloadProgress01 => TotalProcessed / TotalToProcessed;
60+
61+
private static NdAsset TargetAsset { get; set; }
62+
private static SerializedObject TargetAssetObject { get; set; }
5063

5164
/* ─────────────────────────────────────────────────────────────────────────────────────────────────────────────
5265
| Menu Item
@@ -55,7 +68,7 @@ public sealed class DownloadAllHandler : EditorWindow
5568
[MenuItem("Tools/Carter Games/Notion Data/Update All Notion Data", priority = 21)]
5669
private static void DownloadAll()
5770
{
58-
haltOnDownload = true;
71+
haltOnError = true;
5972
TotalToProcessed = 0;
6073
TotalProcessed = 0;
6174
hasErrorOnDownload = false;
@@ -69,7 +82,7 @@ private static void DownloadAll()
6982
}
7083
else
7184
{
72-
var window = GetWindow<DownloadAllHandler>(true, "Download Notion Data");
85+
var window = GetWindow<DownloadAllHandler>(true, "Download All Notion Data");
7386
window.minSize = new Vector2(400, 150);
7487
window.maxSize = new Vector2(400, 150);
7588
}
@@ -92,7 +105,7 @@ private void OnGUI()
92105
EditorGUILayout.LabelField("Settings", EditorStyles.boldLabel);
93106
GeneralUtilEditor.DrawHorizontalGUILine();
94107

95-
haltOnDownload = EditorGUILayout.Toggle(new GUIContent("Halt download on error:"), haltOnDownload);
108+
haltOnError = EditorGUILayout.Toggle(new GUIContent("Halt download on error:"), haltOnError);
96109

97110
GUILayout.Space(1.5f);
98111
EditorGUILayout.EndVertical();
@@ -106,17 +119,24 @@ private void OnGUI()
106119
{
107120
if (Application.internetReachability == NetworkReachability.NotReachable)
108121
{
109-
EditorUtility.DisplayDialog("Standalone Notion Data", "You cannot download data while offline.",
122+
EditorUtility.DisplayDialog("Download All Notion Data", "You cannot download data while offline.",
110123
"Continue");
111124
return;
112125
}
113126

114-
toProcess = NotionDataAccessor.GetAllAssets();
127+
NdAssetIndexHandler.UpdateIndex();
128+
129+
toProcess = NotionDataAccessor.GetAllAssets().Where(t => t.GetType() != typeof(EditorOnlyNdAsset))
130+
.ToList();
131+
115132
TotalToProcessed = toProcess.Count;
116133
TotalProcessed = 0;
117134
hasErrorOnDownload = false;
118135
silencedErrors ??= new List<NotionRequestError>();
119136
silencedErrors.Clear();
137+
TargetAsset = null;
138+
139+
IsDownloadingAllAssets = true;
120140

121141
ProcessNextAsset();
122142
}
@@ -130,74 +150,146 @@ private void OnGUI()
130150

131151
private static void ProcessNextAsset()
132152
{
133-
if (toProcess.Count <= 0)
153+
if (TotalProcessed == TotalToProcessed)
134154
{
135155
OnAllDownloadCompleted();
136156
return;
137157
}
138158

139-
var asset = toProcess.First();
140-
toProcess.RemoveAt(0);
141-
142-
var assetObject = new SerializedObject(asset);
143-
144-
if (assetObject.Fp("databaseApiKey") == null)
159+
try
145160
{
146-
ProcessNextAsset();
147-
return;
148-
}
149-
150-
TotalProcessed++;
161+
TargetAsset = toProcess[TotalProcessed];
162+
TargetAssetObject = new SerializedObject(TargetAsset);
163+
164+
if (TargetAssetObject.Fp("databaseApiKey") == null)
165+
{
166+
TotalProcessed++;
167+
ProcessNextAsset();
168+
Debug.LogWarning($"No api key assigned to asset {TargetAssetObject.targetObject.name}, skipping it.");
169+
return;
170+
}
151171

152-
var databaseId = assetObject.Fp("linkToDatabase").stringValue.Split('/').Last().Split('?').First();
172+
var databaseId = TargetAssetObject.Fp("linkToDatabase").stringValue.Split('/').Last().Split('?').First();
153173

154-
NotionApiRequestHandler.DataReceived.Remove(OnAssetDownloadComplete);
155-
NotionApiRequestHandler.DataReceived.Add(OnAssetDownloadComplete);
174+
EditorUtility.DisplayProgressBar("Download All Notion Data", $"Downloading {TargetAsset.name}", AllDownloadProgress01);
156175

157-
NotionApiRequestHandler.RequestError.Remove(OnAssetDownloadComplete);
158-
NotionApiRequestHandler.RequestError.Add(OnAssetDownloadComplete);
159-
160-
EditorUtility.DisplayProgressBar("Standalone Notion Data", $"Downloading {asset.name}", (float) TotalProcessed / TotalToProcessed);
161-
162-
NotionApiRequestHandler.ResetRequestData();
163-
164-
var filters = (NotionFilterContainer) assetObject.GetType().BaseType!
165-
.GetField("filters", BindingFlags.NonPublic | BindingFlags.Instance)
166-
!.GetValue(assetObject.targetObject);
167-
168-
var requestData = new NotionRequestData(asset, databaseId, assetObject.Fp("databaseApiKey").stringValue, assetObject.Fp("sortProperties").ToSortPropertyArray(), filters, true);
169-
NotionApiRequestHandler.WebRequestPostWithAuth(requestData);
176+
NotionFilterContainer filters = null;
177+
178+
if (TargetAssetObject.GetType().BaseType!
179+
.GetField("filters", BindingFlags.NonPublic | BindingFlags.Instance) != null)
180+
{
181+
filters = (NotionFilterContainer) TargetAssetObject.GetType().BaseType!
182+
.GetField("filters", BindingFlags.NonPublic | BindingFlags.Instance)
183+
!.GetValue(TargetAssetObject.targetObject);
184+
}
185+
186+
187+
var requestData = new NotionRequestData(TargetAsset, databaseId, TargetAssetObject.Fp("databaseApiKey").stringValue, TargetAssetObject.Fp("sortProperties").ToSortPropertyArray(), filters, true);
188+
189+
NotionApiRequestManager.RunRequest(requestData, OnAssetDownloadComplete, OnAssetDownloadComplete);
190+
}
191+
catch (Exception e)
192+
{
193+
Debug.LogError(e);
194+
EditorUtility.ClearProgressBar();
195+
IsDownloadingAllAssets = false;
196+
throw;
197+
}
170198
}
171199

172200

173201
private static void OnAssetDownloadComplete(NotionRequestResult result)
174202
{
203+
NotionDatabaseQueryResult queryResult;
204+
205+
try
206+
{
207+
queryResult = NotionDownloadParser.Parse(result.Data);
208+
}
209+
catch (Exception e)
210+
{
211+
Debug.LogError("Parsing of downloaded data failed. See message below for more information:");
212+
Debug.LogError(e);
213+
EditorUtility.ClearProgressBar();
214+
throw;
215+
}
216+
217+
try
218+
{
219+
TargetAsset.GetType().BaseType.GetMethod("Apply", BindingFlags.NonPublic | BindingFlags.Instance)
220+
?.Invoke(TargetAssetObject.targetObject, new object[] { queryResult });
221+
222+
EditorUtility.ClearProgressBar();
223+
224+
if (!result.SilentResponse)
225+
{
226+
EditorUtility.DisplayDialog("Notion Data Download", "Download completed & parsed successfully", "Continue");
227+
}
228+
}
229+
catch (Exception e)
230+
{
231+
if (!haltOnError)
232+
{
233+
hasErrorOnDownload = true;
234+
silencedErrors.Add(new NotionRequestError(TargetAsset, new JObject()
235+
{
236+
["message"] = $"Applying values from parsed data failed. See message below for more information: {e}"
237+
}));
238+
}
239+
else
240+
{
241+
Debug.LogError("Applying values from parsed data failed. See message below for more information:");
242+
Debug.LogError(e);
243+
244+
EditorUtility.ClearProgressBar();
245+
246+
if (!result.SilentResponse)
247+
{
248+
EditorUtility.DisplayDialog("Notion Data Download", "Download completed, but failed to parse all properties. See console for more information.", "Continue");
249+
}
250+
}
251+
}
252+
253+
TargetAssetObject.ApplyModifiedProperties();
254+
TargetAssetObject.Update();
255+
256+
TotalProcessed++;
175257
ProcessNextAsset();
176258
}
177259

178260

179261
private static void OnAssetDownloadComplete(NotionRequestError error)
180262
{
181-
if (!haltOnDownload)
263+
TotalProcessed++;
264+
265+
if (!haltOnError)
182266
{
183267
hasErrorOnDownload = true;
184268
silencedErrors.Add(error);
269+
270+
TargetAssetObject.ApplyModifiedProperties();
271+
TargetAssetObject.Update();
272+
185273
ProcessNextAsset();
186274
return;
187275
}
188276

189277
EditorUtility.ClearProgressBar();
190-
EditorUtility.DisplayDialog("Standalone Notion Data", $"Download failed due to an error:\n{error.Asset.name}\n{error.Error}\n{error.Message}", "Continue");
278+
EditorUtility.DisplayDialog("Download All Notion Data", $"Download failed due to an error:\n{error.Asset.name}\n{error.Error}\n{error.Message}", "Continue");
279+
280+
TargetAssetObject.ApplyModifiedProperties();
281+
TargetAssetObject.Update();
191282
}
192283

193284

194285
private static void OnAllDownloadCompleted()
195286
{
196287
EditorUtility.ClearProgressBar();
288+
IsDownloadingAllAssets = false;
197289

198290
if (hasErrorOnDownload)
199291
{
200-
if (EditorUtility.DisplayDialog("Standalone Notion Data",
292+
if (EditorUtility.DisplayDialog("Download All Notion Data",
201293
"Download completed with errors.\nSee console for errors.", "Continue"))
202294
{
203295
foreach (var error in silencedErrors)
@@ -208,8 +300,14 @@ private static void OnAllDownloadCompleted()
208300
}
209301
else
210302
{
211-
EditorUtility.DisplayDialog("Standalone Notion Data", "Download completed.", "Continue");
303+
EditorUtility.DisplayDialog("Download All Notion Data", "Download completed.", "Continue");
212304
}
213305
}
306+
307+
308+
public static void SetProgressMessage(string message)
309+
{
310+
EditorUtility.DisplayProgressBar("Download All Notion Data", message, AllDownloadProgress01);
311+
}
214312
}
215313
}

Carter Games/Notion Database To Unity/Code/Editor/Editors/Creator Tool/NotionDataAssetTemplate.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
using CarterGames.Standalone.NotionData;
1+
using CarterGames.NotionData;
22
using UnityEngine;
33

4-
54
namespace Data
65
{
76
[CreateAssetMenu(fileName = "%DataAssetName%")]

Carter Games/Notion Database To Unity/Code/Editor/Editors/Creator Tool/NotionDataTemplate.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using System;
22

3-
43
namespace Data
54
{
65
[Serializable]

Carter Games/Notion Database To Unity/Code/Editor/Editors/Drawer/NotionWrapperEditor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
3333
{
3434
EditorGUI.BeginProperty(position, label, property);
3535

36-
var spriteRef = property.Fpr("value");
36+
var valueRef = property.Fpr("value");
3737

3838
EditorGUI.BeginChangeCheck();
3939

40-
EditorGUI.PropertyField(position, spriteRef, label);
40+
EditorGUI.PropertyField(position, valueRef, label);
4141

4242
if (EditorGUI.EndChangeCheck())
4343
{

0 commit comments

Comments
 (0)