Skip to content

Commit

Permalink
feat: Update localMaterialBuffer names while renaming CMeshMaterialEn…
Browse files Browse the repository at this point in the history
…try. Closes WolvenKit#988
  • Loading branch information
seberoth committed Nov 5, 2022
1 parent dd26777 commit d1d76ca
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion WolvenKit.App/ViewModels/Shell/ChunkViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
}
}
});

Expand Down Expand Up @@ -2582,5 +2590,34 @@ public IList<ReferenceSocket> Inputs
public ICommand OpenSelfCommand { get; private set; }
private bool CanOpenSelf() => RelativePath != CName.Empty && _tab == null;
private void ExecuteOpenSelf() => Locator.Current.GetService<AppViewModel>().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;
}
}
}

0 comments on commit d1d76ca

Please sign in to comment.