Skip to content

Commit

Permalink
feat: add RemoveComponent, support IntX and UintX
Browse files Browse the repository at this point in the history
  • Loading branch information
czastack committed Dec 11, 2023
1 parent 2ce76aa commit 139e325
Show file tree
Hide file tree
Showing 14 changed files with 696 additions and 285 deletions.
66 changes: 66 additions & 0 deletions RszTool.App/Common/ObjectModelUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;

namespace RszTool.App.Common
{
public static class ObjectModelUtils
{
public static void SyncObservableCollection<T>(
ObservableCollection<T> list,
Func<object, T> converter,
NotifyCollectionChangedEventArgs e)
{
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
for (int i = 0; i < e.NewItems!.Count; i++)
{
list.Insert(e.NewStartingIndex + i, converter(e.NewItems[i]!));
}
break;

case NotifyCollectionChangedAction.Move:
if (e.OldItems!.Count == 1)
{
list.Move(e.OldStartingIndex, e.NewStartingIndex);
}
else
{
T[] items = list.Skip(e.OldStartingIndex).Take(e.OldItems.Count).ToArray();
for (int i = 0; i < e.OldItems.Count; i++)
{
list.RemoveAt(e.OldStartingIndex);
}

for (int i = 0; i < items.Length; i++)
{
list.Insert(e.NewStartingIndex + i, items[i]);
}
}
break;

case NotifyCollectionChangedAction.Remove:
for (int i = 0; i < e.OldItems!.Count; i++)
list.RemoveAt(e.OldStartingIndex);
break;

case NotifyCollectionChangedAction.Replace:
// remove
for (int i = 0; i < e.OldItems!.Count; i++)
{
list.RemoveAt(e.OldStartingIndex);
}
// add
goto case NotifyCollectionChangedAction.Add;

case NotifyCollectionChangedAction.Reset:
list.Clear();
for (int i = 0; i < e.NewItems!.Count; i++)
list.Add(converter(e.NewItems[i]!));
break;
default:
break;
}
}
}
}
14 changes: 5 additions & 9 deletions RszTool.App/Converters/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public static IEnumerable<object> Convert(ScnFile.GameObjectData gameObject)
{
yield return new ClassViewModel(gameObject.Prefab, ["Path"]);
}
yield return new TreeItemViewModel("Components", gameObject.Components);
yield return new TreeItemViewModel("Components",
GameObejctComponentViewModel.MakeList(gameObject));
yield return new TreeItemViewModel("Children", gameObject.Children);
}

Expand Down Expand Up @@ -120,14 +121,9 @@ public static IEnumerable<object> Convert(PfbFile.GameObjectData gameObject)
{
yield return gameObject.Instance;
}
if (gameObject.Components.Count > 0)
{
yield return new TreeItemViewModel("Components", gameObject.Components);
}
if (gameObject.Children.Count > 0)
{
yield return new TreeItemViewModel("Children", gameObject.Children);
}
yield return new TreeItemViewModel("Components",
GameObejctComponentViewModel.MakeList(gameObject));
yield return new TreeItemViewModel("Children", gameObject.Children);
}

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
Expand Down
4 changes: 2 additions & 2 deletions RszTool.App/RszTool.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<UseWPF>true</UseWPF>
<NoWarn>$(NoWarn);CS0067</NoWarn>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AssemblyVersion>0.1.9.0</AssemblyVersion>
<FileVersion>0.1.9.0</FileVersion>
<AssemblyVersion>0.2.0.0</AssemblyVersion>
<FileVersion>0.2.0.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 139e325

Please sign in to comment.