Skip to content

Commit

Permalink
VoteTracker 1.36.0 fix (buildable, seems working)
Browse files Browse the repository at this point in the history
  • Loading branch information
qe201020335 committed Apr 24, 2024
1 parent 8ab3e85 commit 41e8cfc
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
6 changes: 3 additions & 3 deletions SongPlayHistory/Patches/DiTailsVotePatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ private static bool Prepare()
}

[HarmonyPrefix]
public static void Prefix(bool upvote, IDifficultyBeatmap? ____activeBeatmap)
public static void Prefix(bool upvote, BeatmapLevel? ____activeBeatmap) //TODO: update when DiTails Update
{
if (____activeBeatmap == null) return;
var vote = upvote ? VoteType.Upvote : VoteType.Downvote;
Plugin.Log.Debug($"DiTails voted {vote} to {____activeBeatmap.level.levelID}");
InMenuVoteTrackingHelper.Instance?.Vote(____activeBeatmap.level, vote);
Plugin.Log.Debug($"DiTails voted {vote} to {____activeBeatmap.levelID}");
InMenuVoteTrackingHelper.Instance?.Vote(____activeBeatmap, vote);
}
}
}
2 changes: 1 addition & 1 deletion SongPlayHistory/Patches/HarmonyPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static bool Prepare()
}

[HarmonyAfter("com.kyle1413.BeatSaber.SongCore")]
public static void Postfix(LevelListTableCell __instance, IPreviewBeatmapLevel? level, bool isFavorite,
public static void Postfix(LevelListTableCell __instance, BeatmapLevel? level, bool isFavorite,
Image ____favoritesBadgeImage, TextMeshProUGUI? ____songBpmText)
{
if (!PluginConfig.Instance.ShowVotes) return;
Expand Down
7 changes: 4 additions & 3 deletions SongPlayHistory/Utils/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
Expand Down Expand Up @@ -32,9 +33,9 @@ internal static bool IsInReplay()
}
#endregion

internal static string GetCustomLevelHash(CustomPreviewBeatmapLevel level)
internal static string? GetCustomLevelHash(BeatmapLevel level)
{
return Hashing.GetCustomLevelHash(level).ToLower();
return level.levelID.StartsWith("custom_level_") ? Hashing.GetCustomLevelHash(level) : null;
}

internal static IList<ISongPlayRecord> Copy(this IEnumerable<Record> records)
Expand Down
20 changes: 14 additions & 6 deletions SongPlayHistory/VoteTracker/BeatSaverVotingTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ internal class BeatSaverVotingTracker: IVoteTracker
}
}

public void Vote(IPreviewBeatmapLevel level, VoteType voteType)
public void Vote(BeatmapLevel level, VoteType voteType)
{
if (!(level is CustomPreviewBeatmapLevel customLevel)) return;
try
{
var hash = Utils.Utils.GetCustomLevelHash(customLevel);
var hash = Utils.Utils.GetCustomLevelHash(level);
if (hash == null)
{
return;
}

var bsvType = voteType == VoteType.Upvote ? BSVType.Upvote : BSVType.Downvote;
if (_votes == null)
{
Expand All @@ -55,13 +59,17 @@ public void Vote(IPreviewBeatmapLevel level, VoteType voteType)
}
}

public bool TryGetVote(IPreviewBeatmapLevel level, out VoteType voteType)
public bool TryGetVote(BeatmapLevel level, out VoteType voteType)
{
voteType = VoteType.Downvote;
if (!(level is CustomPreviewBeatmapLevel customLevel)) return false;
try
{
var hash = Utils.Utils.GetCustomLevelHash(customLevel);
var hash = Utils.Utils.GetCustomLevelHash(level);
if (hash == null)
{
return false;
}

var voteStatus = BeatSaverVoting.Plugin.CurrentVoteStatus(hash);
if (voteStatus == null)
{
Expand Down
4 changes: 2 additions & 2 deletions SongPlayHistory/VoteTracker/IVoteTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace SongPlayHistory.VoteTracker
{
public interface IVoteTracker
{
public bool TryGetVote(IPreviewBeatmapLevel level, out VoteType voteType);
public bool TryGetVote(BeatmapLevel level, out VoteType voteType);

public void Vote(IPreviewBeatmapLevel level, VoteType voteType);
public void Vote(BeatmapLevel level, VoteType voteType);

}
}
4 changes: 2 additions & 2 deletions SongPlayHistory/VoteTracker/InMenuVoteTrackingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ private void OnPlayResultDismiss(ResultsViewController _)
_tableView.RefreshCellsContent();
}

internal void Vote(IPreviewBeatmapLevel level, VoteType voteType)
internal void Vote(BeatmapLevel level, VoteType voteType)
{
_voteTracker.Vote(level, voteType);
_tableView.RefreshCellsContent();
}

internal bool TryGetVote(IPreviewBeatmapLevel level, out VoteType voteType)
internal bool TryGetVote(BeatmapLevel level, out VoteType voteType)
{
return _voteTracker.TryGetVote(level, out voteType);
}
Expand Down
15 changes: 6 additions & 9 deletions SongPlayHistory/VoteTracker/InternalVoteTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,13 @@ public void Dispose()
}
}

public bool TryGetVote(IPreviewBeatmapLevel level, out VoteType voteType)
public bool TryGetVote(BeatmapLevel level, out VoteType voteType)
{
voteType = VoteType.Downvote;
try
{
if (!(level is CustomPreviewBeatmapLevel customLevel)) return false;
var hash = Utils.Utils.GetCustomLevelHash(customLevel);
if (Votes?.TryGetValue(hash.ToLower(), out var vote) == true)
var hash = Utils.Utils.GetCustomLevelHash(level);
if (hash != null && Votes?.TryGetValue(hash.ToLower(), out var vote) == true)
{
voteType = vote.VoteType;
return true;
Expand All @@ -122,16 +121,14 @@ public bool TryGetVote(IPreviewBeatmapLevel level, out VoteType voteType)
return false;
}

public void Vote(IPreviewBeatmapLevel level, VoteType voteType)
public void Vote(BeatmapLevel level, VoteType voteType)
{
Task.Run(() =>
{
if (!(level is CustomPreviewBeatmapLevel customLevel)) return;

lock (_voteWriteLock)
{
var hash = Utils.Utils.GetCustomLevelHash(customLevel);
if (Votes != null)
var hash = Utils.Utils.GetCustomLevelHash(level);
if (hash != null && Votes != null)
{
hash = hash.ToLower();
if (!Votes.ContainsKey(hash) || Votes[hash].VoteType != voteType)
Expand Down

0 comments on commit 41e8cfc

Please sign in to comment.