Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swapped SongLoader plugin for SongCore plugin; unsure about CustomBea… #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VideoPlayer/VideoData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class VideoData
public string videoPath;

[System.NonSerialized]
public IBeatmapLevel level;
public IPreviewBeatmapLevel level;
[System.NonSerialized]
public float downloadProgress = 0f;
[System.NonSerialized]
Expand Down
38 changes: 19 additions & 19 deletions VideoPlayer/VideoLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SongLoaderPlugin;
using UnityEngine;
using System.IO;
using SongLoaderPlugin.OverrideClasses;
using System.Diagnostics;
using SongCore;
using MusicVideoPlayer.YT;

namespace MusicVideoPlayer.Util
Expand All @@ -20,7 +19,7 @@ public class VideoLoader : MonoBehaviour

public bool autoDownload = false;

private Dictionary<IBeatmapLevel, VideoData> videos;
private Dictionary<IPreviewBeatmapLevel, VideoData> videos;

private HMTask _loadingTask;
private bool _loadingCancelled;
Expand All @@ -40,12 +39,12 @@ private void Awake()
Instance = this;

autoDownload = Plugin.config.GetBool("Settings", "autoDownload", false, true);
SongLoader.SongsLoadedEvent += RetrieveAllVideoData;
Loader.SongsLoadedEvent += RetrieveAllVideoData;

DontDestroyOnLoad(gameObject);
}

public string GetVideoPath(IBeatmapLevel level)
public string GetVideoPath(IPreviewBeatmapLevel level)
{
VideoData vid;
if (videos.TryGetValue(level, out vid)) return GetVideoPath(vid);
Expand All @@ -57,19 +56,19 @@ public string GetVideoPath(VideoData video)
return Path.Combine(GetLevelPath(video.level), video.videoPath);
}

public VideoData GetVideo(IBeatmapLevel level)
public VideoData GetVideo(IPreviewBeatmapLevel level)
{
VideoData vid;
if (videos.TryGetValue(level, out vid)) return vid;
return null;
}

public static string GetLevelPath(IBeatmapLevel level)
public static string GetLevelPath(IPreviewBeatmapLevel level)
{
if (level is CustomLevel)
if (level is CustomPreviewBeatmapLevel)
{
// Custom song
return (level as CustomLevel).customSongInfo.path;
return (level as CustomPreviewBeatmapLevel).customLevelPath;
}
else
{
Expand All @@ -87,7 +86,7 @@ public static string GetLevelPath(IBeatmapLevel level)
}
}

public bool SongHasVideo(IBeatmapLevel level)
public bool SongHasVideo(IPreviewBeatmapLevel level)
{
return videos.ContainsKey(level);
}
Expand All @@ -114,16 +113,17 @@ public static void SaveVideoToDisk(VideoData video)
//}
}

private void RetrieveAllVideoData(SongLoader songLoader, List<CustomLevel> levels)
private void RetrieveAllVideoData(Loader songLoader, Dictionary<string, CustomPreviewBeatmapLevel> levels)
{
videos = new Dictionary<IBeatmapLevel, VideoData>();
RetrieveCustomLevelVideoData(songLoader, levels);
videos = new Dictionary<IPreviewBeatmapLevel, VideoData>();
List<CustomPreviewBeatmapLevel> LevelList = new List<CustomPreviewBeatmapLevel>(levels.Values);
RetrieveCustomLevelVideoData(LevelList);
RetrieveOSTVideoData();
}

private void RetrieveOSTVideoData()
{
BeatmapLevelSO[] levels = Resources.FindObjectsOfTypeAll<BeatmapLevelSO>().Where(x=> x.GetType() != typeof(CustomLevel)).ToArray();
BeatmapLevelSO[] levels = Resources.FindObjectsOfTypeAll<BeatmapLevelSO>().Where(x=> x.GetType() != typeof(CustomBeatmapLevel)).ToArray();

Action job = delegate
{
Expand Down Expand Up @@ -197,17 +197,17 @@ private void RetrieveOSTVideoData()
_loadingTask.Run();
}

private void RetrieveCustomLevelVideoData(SongLoader songLoader, List<CustomLevel> levels)
private void RetrieveCustomLevelVideoData(List<CustomPreviewBeatmapLevel> levels)
{
Action job = delegate
{
try
{
float i = 0;
foreach (CustomLevel level in levels)
foreach (CustomPreviewBeatmapLevel level in levels)
{
i++;
var songPath = level.customSongInfo.path;
var songPath = level.customLevelPath;
var results = Directory.GetFiles(songPath, "video.json", SearchOption.AllDirectories);
if (results.Length == 0)
{
Expand All @@ -222,7 +222,7 @@ private void RetrieveCustomLevelVideoData(SongLoader songLoader, List<CustomLeve
HMMainThreadDispatcher.instance.Enqueue(delegate
{
if (_loadingCancelled) return;
VideoData video = LoadVideo(result, level.difficultyBeatmapSets[0].difficultyBeatmaps[0].level);
VideoData video = LoadVideo(result, level);
if (video != null)
{
AddVideo(video);
Expand Down Expand Up @@ -266,7 +266,7 @@ public void DeleteVideo(VideoData video)
File.Delete(GetVideoPath(video));
}

private VideoData LoadVideo(string jsonPath, IBeatmapLevel level)
private VideoData LoadVideo(string jsonPath, IPreviewBeatmapLevel level)
{
var infoText = File.ReadAllText(jsonPath);
VideoData vid;
Expand Down