Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 84 additions & 10 deletions Editor/DataVisualizer/Data/DataVisualizerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ public void MarkDirty()
#endif
}

public bool SetSelectActiveObject(bool value)
{
if (selectActiveObject == value)
{
return false;
}

selectActiveObject = value;
MarkDirty();
return true;
}

public void HydrateFrom(DataVisualizerUserState userState)
{
if (userState == null)
Expand Down Expand Up @@ -144,24 +156,54 @@ internal List<string> GetOrCreateObjectOrderList(string typeFullName)
return entry.ObjectGuids;
}

internal void SetLastObjectForType(string typeName, string guid)
internal bool SetLastObjectForType(string typeName, string guid)
{
if (string.IsNullOrWhiteSpace(typeName))
{
return;
return false;
}

lastObjectSelections ??= new List<LastObjectSelectionEntry>();
int existingIndex = lastObjectSelections.FindIndex(e =>
string.Equals(e.typeFullName, typeName, StringComparison.Ordinal)
);
if (string.IsNullOrWhiteSpace(guid))
{
return;
if (existingIndex < 0)
{
return false;
}

lastObjectSelections.RemoveAt(existingIndex);
MarkDirty();
return true;
}

lastObjectSelections.RemoveAll(e =>
string.Equals(e.typeFullName, typeName, StringComparison.Ordinal)
);
lastObjectSelections.Add(
new LastObjectSelectionEntry { typeFullName = typeName, objectGuid = guid }
);
if (
existingIndex >= 0
&& string.Equals(
lastObjectSelections[existingIndex].objectGuid,
guid,
StringComparison.Ordinal
)
)
{
return false;
}

if (existingIndex >= 0)
{
lastObjectSelections[existingIndex].objectGuid = guid;
}
else
{
lastObjectSelections.Add(
new LastObjectSelectionEntry { typeFullName = typeName, objectGuid = guid }
);
}

MarkDirty();
return true;
}

internal string GetLastObjectForType(string typeName)
Expand All @@ -172,7 +214,7 @@ internal string GetLastObjectForType(string typeName)
}

return lastObjectSelections
.Find(e => string.Equals(e.typeFullName, typeName, StringComparison.Ordinal))
?.Find(e => string.Equals(e.typeFullName, typeName, StringComparison.Ordinal))
?.objectGuid;
}

Expand All @@ -199,6 +241,38 @@ internal bool HasCollapseState(string namespaceKey)
return entry != null;
}

public bool SetNamespaceCollapsed(string namespaceKey, bool isCollapsed)
{
if (string.IsNullOrWhiteSpace(namespaceKey))
{
return false;
}

namespaceCollapseStates ??= new List<NamespaceCollapseState>();
bool changed = NamespaceCollapseState.SetCollapsed(
namespaceCollapseStates,
namespaceKey,
isCollapsed
);
if (changed)
{
MarkDirty();
}

return changed;
}

public bool RemoveNamespaceCollapseState(string namespaceKey)
{
bool changed = NamespaceCollapseState.Remove(namespaceCollapseStates, namespaceKey);
if (changed)
{
MarkDirty();
}

return changed;
}

internal NamespaceCollapseState GetOrCreateCollapseState(string namespaceKey)
{
NamespaceCollapseState entry = namespaceCollapseStates.Find(o =>
Expand Down
68 changes: 58 additions & 10 deletions Editor/DataVisualizer/Data/DataVisualizerUserState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,52 @@ public List<string> GetOrCreateObjectOrderList(string typeFullName)
return entry.ObjectGuids;
}

public void SetLastObjectForType(string typeName, string guid)
public bool SetLastObjectForType(string typeName, string guid)
{
if (string.IsNullOrWhiteSpace(typeName))
{
return;
return false;
}

lastObjectSelections ??= new List<LastObjectSelectionEntry>();
int existingIndex = lastObjectSelections.FindIndex(e =>
string.Equals(e.typeFullName, typeName, StringComparison.Ordinal)
);
if (string.IsNullOrWhiteSpace(guid))
{
return;
if (existingIndex < 0)
{
return false;
}

lastObjectSelections.RemoveAt(existingIndex);
return true;
}

lastObjectSelections.RemoveAll(e =>
string.Equals(e.typeFullName, typeName, StringComparison.Ordinal)
);
lastObjectSelections.Add(
new LastObjectSelectionEntry { typeFullName = typeName, objectGuid = guid }
);
if (
existingIndex >= 0
&& string.Equals(
lastObjectSelections[existingIndex].objectGuid,
guid,
StringComparison.Ordinal
)
)
{
return false;
}

if (existingIndex >= 0)
{
lastObjectSelections[existingIndex].objectGuid = guid;
}
else
{
lastObjectSelections.Add(
new LastObjectSelectionEntry { typeFullName = typeName, objectGuid = guid }
);
}

return true;
}

public string GetLastObjectForType(string typeName)
Expand All @@ -95,7 +123,7 @@ public string GetLastObjectForType(string typeName)
}

return lastObjectSelections
.Find(e => string.Equals(e.typeFullName, typeName, StringComparison.Ordinal))
?.Find(e => string.Equals(e.typeFullName, typeName, StringComparison.Ordinal))
?.objectGuid;
}

Expand All @@ -122,6 +150,26 @@ public bool HasCollapseState(string namespaceKey)
return entry != null;
}

public bool SetNamespaceCollapsed(string namespaceKey, bool isCollapsed)
{
if (string.IsNullOrWhiteSpace(namespaceKey))
{
return false;
}

namespaceCollapseStates ??= new List<NamespaceCollapseState>();
return NamespaceCollapseState.SetCollapsed(
namespaceCollapseStates,
namespaceKey,
isCollapsed
);
}

public bool RemoveNamespaceCollapseState(string namespaceKey)
{
return NamespaceCollapseState.Remove(namespaceCollapseStates, namespaceKey);
}

public NamespaceCollapseState GetOrCreateCollapseState(string namespaceKey)
{
NamespaceCollapseState entry = namespaceCollapseStates.Find(o =>
Expand Down
48 changes: 48 additions & 0 deletions Editor/DataVisualizer/Data/NamespaceCollapseState.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,61 @@
namespace WallstopStudios.DataVisualizer.Editor.Data
{
using System;
using System.Collections.Generic;

[Serializable]
public sealed class NamespaceCollapseState
{
public string namespaceKey = string.Empty;
public bool isCollapsed;

public static bool SetCollapsed(
List<NamespaceCollapseState> states,
string namespaceKey,
bool isCollapsed
)
{
if (states == null || string.IsNullOrWhiteSpace(namespaceKey))
{
return false;
}

NamespaceCollapseState entry = states.Find(state =>
string.Equals(state?.namespaceKey, namespaceKey, StringComparison.Ordinal)
);
if (entry == null)
{
states.Add(
new NamespaceCollapseState
{
namespaceKey = namespaceKey,
isCollapsed = isCollapsed,
}
);
return true;
}

if (entry.isCollapsed == isCollapsed)
{
return false;
}

entry.isCollapsed = isCollapsed;
return true;
}

public static bool Remove(List<NamespaceCollapseState> states, string namespaceKey)
{
if (states == null || string.IsNullOrWhiteSpace(namespaceKey))
{
return false;
}

return states.RemoveAll(state =>
string.Equals(state?.namespaceKey, namespaceKey, StringComparison.Ordinal)
) > 0;
}

public NamespaceCollapseState Clone()
{
return new NamespaceCollapseState
Expand Down
84 changes: 84 additions & 0 deletions Editor/DataVisualizer/Data/NamespaceTypeOrder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,72 @@ public sealed class NamespaceTypeOrder
public string namespaceKey = string.Empty;
public List<string> typeNames = new();

public static int CompareTypesByFullNameOrder(
Type lhs,
Type rhs,
IReadOnlyList<string> typeFullNameOrder
)
{
return CompareTypeFullNames(
lhs?.FullName ?? string.Empty,
rhs?.FullName ?? string.Empty,
typeFullNameOrder
);
}

public static int CompareTypesByFullName(Type lhs, Type rhs)
{
return string.Compare(
lhs?.FullName ?? string.Empty,
rhs?.FullName ?? string.Empty,
StringComparison.Ordinal
);
}

public static int CompareTypesByNameThenFullName(Type lhs, Type rhs)
{
int nameComparison = string.Compare(
lhs?.Name ?? string.Empty,
rhs?.Name ?? string.Empty,
StringComparison.Ordinal
);
return nameComparison != 0 ? nameComparison : CompareTypesByFullName(lhs, rhs);
}

public static int CompareTypeFullNames(
string lhsFullName,
string rhsFullName,
IReadOnlyList<string> typeFullNameOrder
)
{
int indexA = IndexOf(typeFullNameOrder, lhsFullName);
int indexB = IndexOf(typeFullNameOrder, rhsFullName);

switch (indexA)
{
case >= 0 when indexB >= 0:
return indexA.CompareTo(indexB);
case >= 0:
return -1;
}

return 0 <= indexB
? 1
: string.Compare(lhsFullName, rhsFullName, StringComparison.Ordinal);
}

public static Type FindTypeByFullName(IEnumerable<Type> types, string typeFullName)
{
if (types == null || string.IsNullOrWhiteSpace(typeFullName))
{
return null;
}

return types.FirstOrDefault(type =>
string.Equals(type?.FullName, typeFullName, StringComparison.Ordinal)
);
}

public NamespaceTypeOrder Clone()
{
return new NamespaceTypeOrder
Expand All @@ -18,5 +84,23 @@ public NamespaceTypeOrder Clone()
typeNames = typeNames?.ToList() ?? new List<string>(),
};
}

private static int IndexOf(IReadOnlyList<string> values, string value)
{
if (values == null || string.IsNullOrWhiteSpace(value))
{
return -1;
}

for (int i = 0; i < values.Count; ++i)
{
if (string.Equals(values[i], value, StringComparison.Ordinal))
{
return i;
}
}

return -1;
}
}
}
Loading