Skip to content

Commit

Permalink
feat: add RemoteConfig flag to disable tier7
Browse files Browse the repository at this point in the history
  • Loading branch information
azeier committed Aug 17, 2023
1 parent f38171b commit 65b6294
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Hearthstone_Deck_Tracker.HsReplay;
using Hearthstone_Deck_Tracker.Utility;
using Hearthstone_Deck_Tracker.Utility.MVVM;
using Hearthstone_Deck_Tracker.Utility.RemoteData;
using HSReplay.Requests;
using static System.Windows.Visibility;

Expand Down Expand Up @@ -99,6 +100,13 @@ public async void SetHeroes(int[] heroIds)
if(!HSReplayNetOAuth.IsFullyAuthenticated)
return;

if(Remote.Config.Data?.Tier7?.Disabled ?? false)
{
Message.Disabled();
Visibility = Visible;
return;
}

var userOwnsTier7 = HSReplayNetOAuth.AccountData?.IsTier7 ?? false;

if(!userOwnsTier7 && (Tier7Trial.RemainingTrials ?? 0) == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public async void Error()

public void Loading() => Text = LocUtil.Get("BattlegroundsOverlayMessage_Loading");

public void Disabled() => Text = LocUtil.Get("BattlegroundsOverlayMessage_Disabled");

private static readonly Dictionary<string, int> MmrPercentValues = new()
{
{ "TOP_1_PERCENT", 1 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@
<Button Style="{StaticResource Tier7ButtonStyle}" Content="{lex:Loc BattlegroundsPreLobby_Subscribed_MyStats}" Margin="0 8 0 0" Command="{Binding MyStatsCommand}"/>
</StackPanel>

<!-- Disabled -->
<DockPanel Width="182" Margin="16" Visibility="{Binding UserState, Converter={StaticResource EnumToVisibility}, ConverterParameter={x:Static local:UserState.Disabled}}">
<Rectangle Fill="{StaticResource Tier7Orange}" Width="17" Height="15" Margin="4 0 0 0" DockPanel.Dock="Right">
<Rectangle.OpacityMask>
<VisualBrush Visual="{DynamicResource appbar_warning}" />
</Rectangle.OpacityMask>
</Rectangle>
<TextBlock Text="{lex:Loc BattlegroundsPreLobby_Disabled}" TextWrapping="Wrap" />
</DockPanel>
</StackPanel>
</StackPanel>
</Border>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Hearthstone_Deck_Tracker.Utility;
using Hearthstone_Deck_Tracker.Utility.Extensions;
using Hearthstone_Deck_Tracker.Utility.MVVM;
using Hearthstone_Deck_Tracker.Utility.RemoteData;

namespace Hearthstone_Deck_Tracker.Controls.Overlay.Battlegrounds.Tier7
{
Expand All @@ -20,11 +21,22 @@ public Tier7PreLobbyViewModel()
{
HSReplayNetOAuth.AccountDataUpdated += () => Update(false).Forget();
HSReplayNetOAuth.LoggedOut += () => Update(false).Forget();
Remote.Config.Loaded += (_) =>
{
OnPropertyChanged(nameof(UserState));
OnPropertyChanged(nameof(PanelMinWidth));
};
}

public UserState UserState
{
get => GetProp(UserState.Loading);
get
{
if(Remote.Config.Data?.Tier7?.Disabled ?? false)
return UserState.Disabled;
return GetProp(UserState.Loading);
}

set
{
SetProp(value);
Expand Down Expand Up @@ -69,6 +81,9 @@ public string? TrialTimeRemaining
private bool _isUpdatingAccount;
public async Task Update(bool checkAccountStatus)
{
if(UserState == UserState.Disabled)
return;

if(_isUpdatingAccount)
{
// AccountDataUpdated event was likely triggered by the
Expand Down Expand Up @@ -197,7 +212,8 @@ public enum UserState
Loading,
Anonymous,
Authenticated,
Subscribed
Subscribed,
Disabled
}

public class UserStateToVisibilityConverter : IValueConverter
Expand Down
1 change: 1 addition & 0 deletions Hearthstone Deck Tracker/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ private static async void UpdateOverlayAsync()
}
//Watchers.ExperienceWatcher.Run();

Remote.Config.Load();
Remote.Mercenaries.Load();
}
Overlay.UpdatePosition();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ internal class Config
[JsonProperty("bobs_buddy")]
public BobsBuddyData? BobsBuddy { get; set; }

[JsonProperty("tier7")]
public Tier7Data? Tier7 { get; set; }

[JsonProperty("update_info")]
public UpdateData? UpdateInfo { get; set; }
}
Expand Down Expand Up @@ -139,6 +142,12 @@ internal class BobsBuddyData
public bool DataQualityWarning { get; set; }
}

internal class Tier7Data
{
[JsonProperty("disabled")]
public bool Disabled { get; set; }
}

internal class UpdateData
{
[JsonProperty("image_update_hearthstone_version")]
Expand Down

0 comments on commit 65b6294

Please sign in to comment.