Skip to content

Commit

Permalink
Fix a possible bug adding new NPCs to profile.
Browse files Browse the repository at this point in the history
When restoring autosaves, it was possible for new NPCs to never be added to the autosave afterward, due to the policy defaults not actually making any real changes (e.g. having only 2 options where both the pre-policy and post-policy defaults pointed to the 2nd one).

New NPCs will now always be logged to the autosave. The implementation should prevent redundant entries, as the "force write" only occurs when explicitly requested and when no implicit event was generated.
  • Loading branch information
focustense committed Aug 19, 2021
1 parent f290869 commit 8a20d36
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions Focus.Apps.EasyNpc/Profiles/Npc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,19 @@ public Npc(
FaceOption = DefaultOption = Options[Options.Count - 1];
}

public void ApplyPolicy(bool resetDefaultPlugin = false, bool resetFacePlugin = false)
public void ApplyPolicy(bool resetDefaultPlugin = false, bool resetFacePlugin = false, bool alwaysLog = false)
{
if (!resetDefaultPlugin && !resetFacePlugin)
return;
var previousDefaultPlugin = DefaultOption.PluginName;
var previousFacePlugin = FaceOption.PluginName;
var setupAttributes = policy.GetSetupRecommendation(this);
if (resetDefaultPlugin)
SetDefaultOption(setupAttributes.DefaultPluginName);
if (SetDefaultOption(setupAttributes.DefaultPluginName) == ChangeResult.Redundant && alwaysLog)
LogProfileEvent(NpcProfileField.DefaultPlugin, previousDefaultPlugin, DefaultOption.PluginName);
if (resetFacePlugin)
SetFaceOption(setupAttributes.FacePluginName);
if (SetFaceOption(setupAttributes.FacePluginName) == ChangeResult.Redundant && alwaysLog)
LogProfileEvent(NpcProfileField.FacePlugin, previousFacePlugin, FaceOption.PluginName);
}

public IEnumerable<string> GetFaceModNames()
Expand Down
2 changes: 1 addition & 1 deletion Focus.Apps.EasyNpc/Profiles/ProfileFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ faceMod is not null &&
profileEventLog.Resume();
}
foreach (var newNpc in newNpcsList)
newNpc.ApplyPolicy(true, true);
newNpc.ApplyPolicy(true, true, true);
failures = failuresList.AsReadOnly();
newNpcs = newNpcsList.AsReadOnly();
return profile;
Expand Down

0 comments on commit 8a20d36

Please sign in to comment.