Skip to content

Commit

Permalink
Don't download accsaber data unless it's enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
PulseLane committed May 21, 2023
1 parent 3938026 commit e6a9f6a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
33 changes: 28 additions & 5 deletions PPCounter/Data/AccSaberData.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using PPCounter.Utilities;
using PPCounter.Settings;
using PPCounter.Utilities;
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine.Profiling.Memory.Experimental;
using Zenject;
using static PPCounter.Utilities.Structs;

namespace PPCounter.Data
{
internal class AccSaberData : IInitializable
internal class AccSaberData : IInitializable, IDisposable
{
private bool _dataInitStart = false;
public bool DataInit { get; private set; } = false;
[Inject] private PPDownloader _ppDownloader;
private Dictionary<Structs.SongID, float> _rankedMaps = new Dictionary<Structs.SongID, float>();
Expand All @@ -17,10 +20,25 @@ internal class AccSaberData : IInitializable

public void Initialize()
{
//LoadAccSaberFile();
_ppDownloader.OnAccSaberDataDownloaded += OnDataDownloaded;
PluginSettings.OnAccSaberEnabled += GetData;
if (PluginSettings.Instance.accSaberEnabled)
{
GetData();
}
}

private void GetData()
{
if (!_dataInitStart)
{
PluginSettings.OnAccSaberEnabled -= GetData;
_dataInitStart = true;

_ppDownloader.StartDownloadingAccSaber();
//LoadAccSaberFile();
_ppDownloader.OnAccSaberDataDownloaded += OnDataDownloaded;

_ppDownloader.StartDownloadingAccSaber();
}
}

public void OnDataDownloaded(List<AccSaberRankedMap> rankedMaps)
Expand Down Expand Up @@ -95,5 +113,10 @@ private void CreateRankedMapsDict(List<AccSaberRankedMap> rankedMaps)
_rankedMaps[songID] = rankedMap.complexity;
}
}

public void Dispose()
{
PluginSettings.OnAccSaberEnabled -= GetData;
}
}
}
16 changes: 15 additions & 1 deletion PPCounter/Settings/PluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,25 @@ namespace PPCounter.Settings
{
internal class PluginSettings
{
public static Action OnAccSaberEnabled;

public static PluginSettings Instance { get; set; }
public virtual bool showIcons { get; set; } = false;
public virtual bool scoreSaberEnabled { get; set; } = true;
public virtual bool beatLeaderEnabled { get; set; } = false;
public virtual bool accSaberEnabled { get; set; } = false;
private bool _accSaberEnabled = false;
public virtual bool accSaberEnabled
{
get => _accSaberEnabled;
set
{
_accSaberEnabled = value;
if (value)
{
OnAccSaberEnabled?.Invoke();
}
}
}

// Default Enum ordering
public virtual long preferredOrder { get; set; } = 123;
Expand Down

0 comments on commit e6a9f6a

Please sign in to comment.