From d1d76cab53499f015334dfa0d460c7e1c6fe2e7f Mon Sep 17 00:00:00 2001 From: seberoth Date: Sat, 5 Nov 2022 22:40:16 +0100 Subject: [PATCH] feat: Update localMaterialBuffer names while renaming CMeshMaterialEntry. Closes #988 --- .../ViewModels/Shell/ChunkViewModel.cs | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/WolvenKit.App/ViewModels/Shell/ChunkViewModel.cs b/WolvenKit.App/ViewModels/Shell/ChunkViewModel.cs index eca3172a5a..085429ce80 100644 --- a/WolvenKit.App/ViewModels/Shell/ChunkViewModel.cs +++ b/WolvenKit.App/ViewModels/Shell/ChunkViewModel.cs @@ -106,7 +106,6 @@ public ChunkViewModel(IRedType export, ChunkViewModel parent = null, string name if (Parent is not null) { - if (Parent.Data is IRedArray arr) { var index = int.Parse(Name); @@ -159,6 +158,15 @@ public ChunkViewModel(IRedType export, ChunkViewModel parent = null, string name } Parent.CalculateDescriptor(); + + if (Parent.Data is CMeshMaterialEntry meshMaterialEntry && meshMaterialEntry.IsLocalInstance) + { + var materials = GetRootModel().GetModelFromPath("localMaterialBuffer.materials"); + if (materials != null && materials.Properties.Count > meshMaterialEntry.Index) + { + materials.Properties[meshMaterialEntry.Index].CalculateDescriptor(); + } + } } }); @@ -2582,5 +2590,34 @@ public IList Inputs public ICommand OpenSelfCommand { get; private set; } private bool CanOpenSelf() => RelativePath != CName.Empty && _tab == null; private void ExecuteOpenSelf() => Locator.Current.GetService().OpenFileFromDepotPath(RelativePath); + + private ChunkViewModel GetRootModel() + { + var result = this; + while (result.Parent != null) + { + result = result.Parent; + } + return result; + } + + private ChunkViewModel GetModelFromPath(string path) + { + var parts = path.Split('.'); + + var result = this; + foreach (var part in parts) + { + var newResult = result.Properties.FirstOrDefault(x => x.Name == part); + if (newResult == null) + { + return null; + } + + result = newResult; + } + + return result; + } } }