Skip to content

Commit

Permalink
Fixed Metatype-Associated Special Attributes Sometimes Not Working
Browse files Browse the repository at this point in the history
  • Loading branch information
DelnarErsike committed Mar 13, 2024
1 parent 2f8afab commit ff204f6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
15 changes: 15 additions & 0 deletions Chummer/Backend/Attributes/AttributeSection.cs
Expand Up @@ -539,6 +539,21 @@ public AttributeSection(Character objCharacter)
AttributeList.BeforeClearCollectionChangedAsync += AttributeListOnBeforeClearCollectionChanged;
SpecialAttributeList.CollectionChangedAsync += SpecialAttributeListOnCollectionChanged;
SpecialAttributeList.BeforeClearCollectionChangedAsync += SpecialAttributeListOnBeforeClearCollectionChanged;
_objCharacter.MultiplePropertiesChangedAsync += CharacterOnMultiplePropertiesChangedAsync;
}

private Task CharacterOnMultiplePropertiesChangedAsync(object sender, MultiplePropertiesChangedEventArgs e, CancellationToken token)
{
if (token.IsCancellationRequested)
return Task.FromCanceled(token);
if (e.PropertyNames.Contains(nameof(Character.MAGEnabled)) ||
e.PropertyNames.Contains(nameof(Character.RESEnabled)) ||
e.PropertyNames.Contains(nameof(Character.DEPEnabled)))
{
return InitializeAttributesListAsync(token);
}

return Task.CompletedTask;
}

private async Task SpecialAttributeListOnBeforeClearCollectionChanged(object sender,
Expand Down
21 changes: 13 additions & 8 deletions Chummer/Forms/Character Forms/CharacterCreate.cs
Expand Up @@ -2388,17 +2388,22 @@ await CharacterObject.AttributeSection.Attributes

if (e.PropertyNames.Contains(nameof(Character.DEPEnabled)))
{
if (await CharacterObject.GetDEPEnabledAsync(token).ConfigureAwait(false) && !await CharacterObject
.AttributeSection.Attributes
.ContainsAsync(CharacterObject.DEP, token)
.ConfigureAwait(false))
if (await CharacterObject.GetDEPEnabledAsync(token).ConfigureAwait(false))
{
if (!await CharacterObject
.AttributeSection.Attributes
.ContainsAsync(CharacterObject.DEP, token)
.ConfigureAwait(false))
{
await CharacterObject.AttributeSection.Attributes
.AddAsync(CharacterObject.DEP, token).ConfigureAwait(false);
}
}
else
{
await CharacterObject.AttributeSection.Attributes
.AddAsync(CharacterObject.DEP, token).ConfigureAwait(false);
.RemoveAsync(CharacterObject.DEP, token).ConfigureAwait(false);
}

await CharacterObject.AttributeSection.Attributes
.RemoveAsync(CharacterObject.DEP, token).ConfigureAwait(false);
}

if (e.PropertyNames.Contains(nameof(Character.Ambidextrous)))
Expand Down

0 comments on commit ff204f6

Please sign in to comment.