Skip to content

Commit

Permalink
Merge branch 'release/1.98.0' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
kkuepper committed Mar 21, 2024
2 parents 8abf5e6 + 079a29f commit 98cc7cf
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions BMM.Core/Implementations/Storage/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,41 +214,41 @@ public static CurrentTrackPositionStorage CurrentTrackPosition

public static bool HighlightedTextPopupAlreadyShown
{
get => GetValueOrDefault(nameof(HighlightedTextPopupAlreadyShown), default(bool));
get => GetValueOrDefault(nameof(HighlightedTextPopupAlreadyShown), false);
set => AddOrUpdateValue(value, nameof(HighlightedTextPopupAlreadyShown));
}

public static bool DarkGreenRewardUnlocked
{
get => GetValueOrDefault(nameof(DarkGreenRewardUnlocked), default(bool));
get => GetValueOrDefault(nameof(DarkGreenRewardUnlocked), false);
set => AddOrUpdateValue(value, nameof(DarkGreenRewardUnlocked));
}

public static bool OrangeRewardUnlocked
{
get => GetValueOrDefault(nameof(OrangeRewardUnlocked), default(bool));
get => GetValueOrDefault(nameof(OrangeRewardUnlocked), false);
set => AddOrUpdateValue(value, nameof(OrangeRewardUnlocked));
}

public static bool VioletRewardUnlocked
{
get => GetValueOrDefault(nameof(VioletRewardUnlocked), default(bool));
get => GetValueOrDefault(nameof(VioletRewardUnlocked), false);
set => AddOrUpdateValue(value, nameof(VioletRewardUnlocked));
}

public static bool RedRewardUnlocked
{
get => GetValueOrDefault(nameof(RedRewardUnlocked), default(bool));
get => GetValueOrDefault(nameof(RedRewardUnlocked), false);
set => AddOrUpdateValue(value, nameof(RedRewardUnlocked));
}

public static bool GoldenRewardUnlocked
{
get => GetValueOrDefault(nameof(GoldenRewardUnlocked), default(bool));
get => GetValueOrDefault(nameof(GoldenRewardUnlocked), false);
set => AddOrUpdateValue(value, nameof(GoldenRewardUnlocked));
}

public static Guid DeviceId => GetValueOrDefault(nameof(DeviceId), Guid.NewGuid());
public static Guid DeviceId => GetValueOrCreateDefault(nameof(DeviceId), Guid.NewGuid());

public static void Clear() => Settings.Clear();

Expand Down Expand Up @@ -291,5 +291,31 @@ private static TValue GetValueOrDefault<TValue>(string settingsKey, TValue defau
}
}
}

private static TValue GetValueOrCreateDefault<TValue>(string settingsKey, TValue defaultValue)
{
string value = Settings.Get<string>(settingsKey, null);

switch (value)
{
case TValue stringValue:
return stringValue;
case null:
AddOrUpdateValue(defaultValue, settingsKey);
return defaultValue;
default:
{
try
{
return JsonConvert.DeserializeObject<TValue>(value);
}
catch
{
AddOrUpdateValue(defaultValue, settingsKey);
return defaultValue;
}
}
}
}
}
}

0 comments on commit 98cc7cf

Please sign in to comment.