Skip to content

Commit

Permalink
Patch Head Part's Valid Races to use merged keys.
Browse files Browse the repository at this point in the history
Works (almost) the same way as it does for Worn Armor addons. As NPCs are imported, their races are registered into the importer which adds them to the form list. Ensures that the form list contains all of the races that are actually used by merged NPCs, and no other races.

Fixes #119
  • Loading branch information
focustense committed Oct 3, 2021
1 parent a40c912 commit e92144f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Focus.Apps.EasyNpc/Build/Pipeline/NpcFacesTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ protected override Task<Result> Run(BuildSettings settings)
if (mergedHeadPart.HasValue)
record.HeadParts.Add(mergedHeadPart.Value);
}
foreach (var headPart in record.HeadParts)
patch.Importer.AddHeadPartRace(headPart, record.Race);
log.Debug("Importing hair color from {pluginName}", model.FaceOption.PluginName);
record.HairColor.SetTo(patch.Importer.Import(faceNpcRecord.HairColor, x => x.Colors));
log.Debug("Importing face texture from {pluginName}", model.FaceOption.PluginName);
Expand Down
28 changes: 28 additions & 0 deletions Focus.Apps.EasyNpc/Build/Pipeline/RecordImporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,28 @@ public void AddArmorRace(
addon.AdditionalRaces.Add(actualRace.FormKey);
}

public void AddFormListKey(IFormLinkGetter<IFormListGetter> formListLink, FormKey itemKey)
{
var formListKey = formListLink.FormKey;
if (formListKey.IsNull || formListKey.ModKey != mergedMod.ModKey)
return;
var formList = GetIfMerged<FormList>(formListKey);
if (formList is not null && !formList.Items.Contains(itemKey))
formList.Items.Add(itemKey);
}

public void AddHeadPartRace(IFormLinkGetter<IHeadPartGetter> headPartLink, IFormLinkGetter<IRaceGetter> raceLink)
{
if (raceLink.IsNull)
return;
var headPartKey = headPartLink.FormKey;
if (headPartKey.IsNull || headPartKey.ModKey != mergedMod.ModKey)
return;
var headPart = GetIfMerged<HeadPart>(headPartKey);
if (headPart is not null)
AddFormListKey(headPart.ValidRaces, raceLink.FormKey);
}

public void AddMaster(string pluginName)
{
masters.Add(ModKey.FromNameAndExtension(pluginName));
Expand Down Expand Up @@ -140,6 +162,11 @@ private void ImportArtObjectDependencies(ArtObject art)
log.Information("Finished processing cloned art object {FormKey} '{EditorId}'", art.EditorID, art.FormKey);
}

private void ImportEmptyFormList(FormList formList)
{
formList.Items.Clear();
}

private void ImportHeadPartDependencies(HeadPart headPart)
{
log.Debug(
Expand All @@ -148,6 +175,7 @@ private void ImportHeadPartDependencies(HeadPart headPart)
headPart.Flags &= ~HeadPart.Flag.Playable;
headPart.Color.SetTo(Import(headPart.Color, mergedMod.Colors));
headPart.TextureSet.SetTo(Import(headPart.TextureSet, mergedMod.TextureSets));
headPart.ValidRaces.SetTo(Import(headPart.ValidRaces, mergedMod.FormLists, ImportEmptyFormList));
ReplaceAlternateTextures(headPart.Model?.AlternateTextures);
ReplaceList(headPart.ExtraParts, mergedMod.HeadParts, ImportHeadPartDependencies);
log.Information(
Expand Down

0 comments on commit e92144f

Please sign in to comment.