Skip to content

Commit 9d1e0f8

Browse files
committed
Clean up and improve blueprint selector
1 parent b46f220 commit 9d1e0f8

3 files changed

Lines changed: 48 additions & 16 deletions

File tree

Packages/com.bocud.vrcapitools/Editor/VRChatApiToolsGUI.cs

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ public class BlueprintPicker : EditorWindow
222222
private Type targetType;
223223
private string targetName;
224224
private bool confirm;
225+
private string lastUserID;
225226

226227
public static void BlueprintSelector<T>(Action<T> onComplete, bool confirm = false, string initialSelection = null) where T : ApiModel
227228
{
@@ -242,9 +243,11 @@ public static void BlueprintSelector<T>(Action<T> onComplete, bool confirm = fal
242243
}
243244
else
244245
{
245-
throw new ArgumentException("The specified blueprint type is not supported");
246+
throw new ArgumentException("The specified ApiModel type is not supported");
246247
}
247248

249+
blueprintPicker.lastUserID = APIUser.CurrentUser?.id;
250+
248251
blueprintPicker.onComplete = m => onComplete((T)m);
249252
blueprintPicker.targetType = type;
250253
blueprintPicker.minSize = new Vector2(640, 400);
@@ -267,34 +270,61 @@ private void OnGUI()
267270
EditorGUILayout.BeginHorizontal();
268271
EditorGUILayout.LabelField($"{APIUser.CurrentUser.displayName}'s Uploaded {targetName}s", EditorStyles.boldLabel);
269272

270-
if (VRChatApiTools.uploadedAvatars == null)
273+
//invalidate cache if we switched users
274+
if (APIUser.CurrentUser?.id != lastUserID)
271275
{
272-
VRChatApiTools.uploadedAvatars = new List<ApiAvatar>();
273-
274-
EditorCoroutine.Start(VRChatApiToolsEditor.FetchUploadedData());
276+
if (APIUser.CurrentUser != null)
277+
{
278+
VRChatApiTools.ClearCaches();
279+
lastUserID = APIUser.CurrentUser.id;
280+
}
275281
}
276282

277-
if (VRChatApiToolsEditor.fetchingAvatars != null)
283+
if (targetName == "Avatar")
278284
{
279-
GUILayout.FlexibleSpace();
280-
EditorGUILayout.LabelField("Fetching data from VRChat Api");
285+
if (VRChatApiTools.uploadedAvatars == null)
286+
{
287+
VRChatApiTools.uploadedAvatars = new List<ApiAvatar>();
288+
EditorCoroutine.Start(VRChatApiToolsEditor.FetchUploadedData());
289+
}
290+
291+
if (VRChatApiToolsEditor.fetchingAvatars != null)
292+
{
293+
GUILayout.FlexibleSpace();
294+
EditorGUILayout.LabelField("Fetching data from VRChat Api");
295+
}
296+
}
297+
else if (targetName == "World")
298+
{
299+
if (VRChatApiTools.uploadedWorlds == null)
300+
{
301+
VRChatApiTools.uploadedWorlds = new List<ApiWorld>();
302+
EditorCoroutine.Start(VRChatApiToolsEditor.FetchUploadedData());
303+
}
304+
305+
if (VRChatApiToolsEditor.fetchingAvatars != null)
306+
{
307+
GUILayout.FlexibleSpace();
308+
EditorGUILayout.LabelField("Fetching data from VRChat Api");
309+
}
281310
}
282-
else
311+
312+
if (VRChatApiToolsEditor.fetchingWorlds == null || VRChatApiToolsEditor.fetchingAvatars == null)
283313
{
284314
GUILayout.FlexibleSpace();
285-
315+
286316
if (GUILayout.Button("Enter ID", GUILayout.Width(120)))
287317
{
288318
if (targetName == "Avatar")
289319
{
290320
ManualBlueprintSelector.BlueprintSelector<ApiAvatar>(OnSelected);
291-
}
321+
}
292322
else if (targetName == "World")
293323
{
294324
ManualBlueprintSelector.BlueprintSelector<ApiWorld>(OnSelected);
295325
}
296326
}
297-
327+
298328
if (GUILayout.Button("Refresh", GUILayout.Width(120)))
299329
{
300330
VRChatApiTools.ClearCaches();
@@ -391,12 +421,12 @@ private void UpdateListContent()
391421
if (targetType == typeof(ApiWorld) && VRChatApiTools.uploadedWorlds != null)
392422
{
393423
displayedBlueprints = VRChatApiTools.uploadedWorlds.OrderByDescending(x => x.updated_at)
394-
.Where(w => w.name.IndexOf(searchString, StringComparison.InvariantCultureIgnoreCase) >= 0).Cast<ApiModel>().ToList();
424+
.Where(w => w.name.IndexOf(searchString, StringComparison.InvariantCultureIgnoreCase) >= 0 || w.id.Contains(searchString)).Cast<ApiModel>().ToList();
395425
}
396426
else if (targetType == typeof(ApiAvatar) && VRChatApiTools.uploadedAvatars != null)
397427
{
398428
displayedBlueprints = VRChatApiTools.uploadedAvatars.OrderByDescending(x => x.updated_at)
399-
.Where(a => a.name.IndexOf(searchString, StringComparison.InvariantCultureIgnoreCase) >= 0).Cast<ApiModel>().ToList();
429+
.Where(a => a.name.IndexOf(searchString, StringComparison.InvariantCultureIgnoreCase) >= 0 || a.id.Contains(searchString)).Cast<ApiModel>().ToList();
400430
}
401431
else
402432
{
@@ -459,7 +489,7 @@ private void OnGUI()
459489
if (!VRChatApiToolsGUI.HandleLogin(this, false)) return;
460490

461491
EditorGUILayout.BeginHorizontal();
462-
EditorGUILayout.LabelField("Blueprint ID", GUILayout.Width(100));
492+
EditorGUILayout.LabelField("Enter Blueprint ID", GUILayout.Width(100));
463493
string oldID = blueprintID;
464494
blueprintID = EditorGUILayout.TextField(blueprintID);
465495
if (oldID != blueprintID) ranFetch = false;

Packages/com.bocud.vrcapitools/Runtime/VRChatApiTools.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ public static async Task<bool> TryAutoLoginAsync()
274274
autoLoginFailed = false;
275275
succes = true;
276276
wait = false;
277+
278+
ClearCaches();
277279
}
278280

279281
while (wait)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.0
1+
0.2.1

0 commit comments

Comments
 (0)