Skip to content

Commit

Permalink
More origin stripping fixes for ModKey/FormKey VMs
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed May 8, 2021
1 parent c4a97e4 commit 2d9c937
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion Mutagen.Bethesda.Synthesis.WPF/VMs/Settings/FormKeySettingsVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Mutagen.Bethesda.Synthesis.WPF
public class FormKeySettingsVM : BasicSettingsVM<FormKey>
{
public FormKeySettingsVM(FieldMeta fieldMeta, object? defaultVal)
: base(fieldMeta, defaultVal is FormKey form ? StripOrigin(form) : null)
: base(fieldMeta, TryStripOrigin(defaultVal))
{
}

Expand Down Expand Up @@ -69,6 +69,16 @@ public static FormKey StripOrigin(FormKey formKey)
return FormKey.Factory(formKey.ToString());
}

public static FormKey? TryStripOrigin(object? o)
{
if (o == null) return null;
if (FormKey.TryFactory(o.ToString(), out var form))
{
return form;
}
return null;
}

public override void WrapUp()
{
Value = StripOrigin(Value);
Expand Down
12 changes: 11 additions & 1 deletion Mutagen.Bethesda.Synthesis.WPF/VMs/Settings/ModKeySettingsVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public ModKeySettingsVM(
IObservable<IChangeSet<ModKey>> detectedLoadOrder,
FieldMeta fieldMeta,
object? defaultVal)
: base(fieldMeta, defaultVal)
: base(fieldMeta, TryStripOrigin(defaultVal))
{
DetectedLoadOrder = detectedLoadOrder;
}
Expand Down Expand Up @@ -72,5 +72,15 @@ public static string Persist(ModKey modKey)
return modKey.ToString();
}
}

public static ModKey? TryStripOrigin(object? o)
{
if (o == null) return null;
if (ModKey.TryFromNameAndExtension(o.ToString(), out var modKey))
{
return modKey;
}
return null;
}
}
}

0 comments on commit 2d9c937

Please sign in to comment.