Skip to content

Commit

Permalink
Continued work on loader
Browse files Browse the repository at this point in the history
  • Loading branch information
Kylemc1413 committed May 26, 2019
1 parent f79f231 commit 618284c
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 7 deletions.
56 changes: 52 additions & 4 deletions Loader.cs
Expand Up @@ -14,6 +14,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using SongCore.Utilities;
using SongCore.OverrideClasses;
using LogSeverity = IPA.Logging.Logger.Level;
namespace SongCore
{
Expand All @@ -23,6 +24,13 @@ public class Loader : MonoBehaviour
public static event Action<Loader, List<CustomPreviewBeatmapLevel>> SongsLoadedEvent;
public static List<CustomPreviewBeatmapLevel> CustomLevels = new List<CustomPreviewBeatmapLevel>();
public static List<CustomPreviewBeatmapLevel> CustomWIPLevels = new List<CustomPreviewBeatmapLevel>();
public static SongCoreCustomLevelCollection CustomLevelsCollection { get; private set; }
public static SongCoreCustomLevelCollection WIPLevelsCollection { get; private set; }
public static SongCoreCustomBeatmapLevelPack CustomLevelsPack { get; private set; }
public static SongCoreCustomBeatmapLevelPack WIPLevelsPack { get; private set; }
public static SongCoreBeatmapLevelPackCollectionSO CustomBeatmapLevelPackCollectionSO { get; private set; }


public static bool AreSongsLoaded { get; private set; }
public static bool AreSongsLoading { get; private set; }
public static float LoadingProgress { get; private set; }
Expand All @@ -31,6 +39,7 @@ public class Loader : MonoBehaviour
private bool _loadingCancelled;

private static CustomLevelLoaderSO _customLevelLoader;
public static BeatmapLevelsModelSO BeatmapLevelsModelSO { get; private set; }
public static Sprite defaultCoverImage;
public static CachedMediaAsyncLoaderSO cachedMediaAsyncLoaderSO { get; private set; }
public static BeatmapCharacteristicCollectionSO beatmapCharacteristicCollection { get; private set; }
Expand Down Expand Up @@ -94,16 +103,49 @@ internal void OnSceneChanged(Scene oldScene, Scene newScene)
(float)defaultCoverTex.width, (float)defaultCoverTex.height), new Vector2(0.5f, 0.5f));
}
}
if (BeatmapLevelsModelSO == null)
{
BeatmapLevelsModelSO = Resources.FindObjectsOfTypeAll<BeatmapLevelsModelSO>().FirstOrDefault();
}
//Handle LevelPacks

if (CustomBeatmapLevelPackCollectionSO == null)
{
var beatmapLevelPackCollectionSO = Resources.FindObjectsOfTypeAll<BeatmapLevelPackCollectionSO>().FirstOrDefault();
CustomBeatmapLevelPackCollectionSO = SongCoreBeatmapLevelPackCollectionSO.ReplaceOriginal(beatmapLevelPackCollectionSO);
CustomLevelsCollection = new SongCoreCustomLevelCollection(CustomLevels.ToArray());
WIPLevelsCollection = new SongCoreCustomLevelCollection(CustomWIPLevels.ToArray());
CustomLevelsPack = new SongCoreCustomBeatmapLevelPack(CustomLevelLoaderSO.kCustomLevelPackPrefixId + "CustomLevels", "Custom Maps", defaultCoverImage, CustomLevelsCollection);
WIPLevelsPack = new SongCoreCustomBeatmapLevelPack(CustomLevelLoaderSO.kCustomLevelPackPrefixId + "CustomWIPLevels", "WIP Maps", UI.BasicUI.WIPIcon, WIPLevelsCollection);
CustomBeatmapLevelPackCollectionSO.AddLevelPack(CustomLevelsPack);
CustomBeatmapLevelPackCollectionSO.AddLevelPack(WIPLevelsPack);

// CustomBeatmapLevelPackSO = CustomBeatmapLevelPackSO.GetPack(CustomLevelCollectionSO);
// CustomBeatmapLevelPackCollectionSO.AddLevelPack(CustomBeatmapLevelPackSO);
// WIPCustomBeatmapLevelPackSO = CustomBeatmapLevelPackSO.GetPack(WIPCustomLevelCollectionSO, true);
// CustomBeatmapLevelPackCollectionSO.AddLevelPack(WIPCustomBeatmapLevelPackSO);
CustomBeatmapLevelPackCollectionSO.ReplaceReferences();
}
else
{
CustomBeatmapLevelPackCollectionSO.ReplaceReferences();
}
RefreshLevelPacks();
var soloFreePlay = Resources.FindObjectsOfTypeAll<SoloFreePlayFlowCoordinator>().FirstOrDefault();
LevelPacksViewController levelPacksViewController = soloFreePlay.GetField<LevelPacksViewController>("_levelPacksViewController");
levelPacksViewController.SetData(CustomBeatmapLevelPackCollectionSO, 0);

}



}


public void RefreshLevelPacks()
{
BeatmapLevelsModelSO.SetField("_loadedBeatmapLevelPackCollection", CustomBeatmapLevelPackCollectionSO);
BeatmapLevelsModelSO.SetField("_allLoadedBeatmapLevelPackCollection", CustomBeatmapLevelPackCollectionSO);
BeatmapLevelsModelSO.UpdateLoadedPreviewLevels();
}
public void RefreshSongs(bool fullRefresh = true)
{
if (SceneManager.GetActiveScene().name != "MenuCore") return;
Expand All @@ -128,6 +170,7 @@ public void RefreshSongs(bool fullRefresh = true)
}
}


//LevelPacks Handling


Expand All @@ -141,6 +184,7 @@ private void RetrieveAllSongs(bool fullRefresh)
if (fullRefresh)
{
CustomLevels.Clear();
CustomWIPLevels.Clear();
}

Action job = delegate
Expand Down Expand Up @@ -250,9 +294,13 @@ private void RetrieveAllSongs(bool fullRefresh)
var orderedList = CustomLevels.OrderBy(x => x.songName);
CustomLevels = orderedList.ToList();
CustomWIPLevels.AddRange(wipLevelList);
orderedList = CustomWIPLevels.OrderBy(x => x.songName);
CustomWIPLevels = orderedList.ToList();
var ordereWIPList = CustomWIPLevels.OrderBy(x => x.songName);
CustomWIPLevels = ordereWIPList.ToList();

//Level Packs
CustomLevelsCollection.UpdatePreviewLevels(CustomLevels.ToArray());
WIPLevelsCollection.UpdatePreviewLevels(CustomWIPLevels.ToArray());
RefreshLevelPacks();

AreSongsLoaded = true;
AreSongsLoading = false;
Expand Down
64 changes: 64 additions & 0 deletions OverrideClasses/SongCoreBeatmapLevelPackCollectionSO.cs
@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SongCore.Utilities;
using UnityEngine;
namespace SongCore.OverrideClasses
{
public class SongCoreBeatmapLevelPackCollectionSO : BeatmapLevelPackCollectionSO
{
internal List<CustomBeatmapLevelPack> _customBeatmapLevelPacks = new List<CustomBeatmapLevelPack>();

public static SongCoreBeatmapLevelPackCollectionSO ReplaceOriginal(BeatmapLevelPackCollectionSO original)
{
var newCollection = CreateInstance<SongCoreBeatmapLevelPackCollectionSO>();
// newCollection._allBeatmapLevelPacks.AddRange((BeatmapLevelPackSO[])original.GetField("_beatmapLevelPacks"));
//Figure out how to properly add the preview song packs
List<IBeatmapLevelPack> levelPacks = new List<IBeatmapLevelPack>();
levelPacks.AddRange((BeatmapLevelPackSO[])original.GetField("_beatmapLevelPacks"));
levelPacks.AddRange((PreviewBeatmapLevelPackSO[])original.GetField("_previewBeatmapLevelPack"));
newCollection._allBeatmapLevelPacks = levelPacks.ToArray();


newCollection.UpdateArray();
newCollection.ReplaceReferences();
return newCollection;
}

public void ReplaceReferences()
{

var soloFreePlay = Resources.FindObjectsOfTypeAll<SoloFreePlayFlowCoordinator>().FirstOrDefault();
if (soloFreePlay != null)
{
soloFreePlay.SetPrivateField("_levelPackCollection", this);
}

var partyFreePlay = Resources.FindObjectsOfTypeAll<PartyFreePlayFlowCoordinator>().FirstOrDefault();
if (partyFreePlay != null)
{
partyFreePlay.SetPrivateField("_levelPackCollection", this);
}

}

public void AddLevelPack(CustomBeatmapLevelPack pack)
{
_customBeatmapLevelPacks.Add(pack);
UpdateArray();
ReplaceReferences();
}

private void UpdateArray()
{
var packs = _allBeatmapLevelPacks.ToList();
foreach (var c in _customBeatmapLevelPacks)
if (!packs.Contains(c))
packs.Add(c);
_allBeatmapLevelPacks = packs.ToArray();
}

}
}
21 changes: 21 additions & 0 deletions OverrideClasses/SongCoreCustomBeatmapLevelPack.cs
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SongCore.OverrideClasses
{
public class SongCoreCustomBeatmapLevelPack : CustomBeatmapLevelPack
{
public SongCoreCustomBeatmapLevelPack(string packID, string packName, UnityEngine.Sprite coverImage, CustomBeatmapLevelCollection customBeatmapLevelCollection) : base(packID, packName, coverImage, customBeatmapLevelCollection)
{

}

public void UpdateLevelCollection(CustomBeatmapLevelCollection newLevelCollection)
{
_customBeatmapLevelCollection = newLevelCollection;
}
}
}
21 changes: 21 additions & 0 deletions OverrideClasses/SongCoreCustomLevelCollection.cs
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SongCore.OverrideClasses
{
public class SongCoreCustomLevelCollection : CustomBeatmapLevelCollection
{
// public readonly List<CustomPreviewBeatmapLevel> _levels = new List<CustomPreviewBeatmapLevel>();
public SongCoreCustomLevelCollection(CustomPreviewBeatmapLevel[] customPreviewBeatmapLevels) : base(customPreviewBeatmapLevels)
{
}

public void UpdatePreviewLevels(CustomPreviewBeatmapLevel[] levels)
{
_customPreviewBeatmapLevels = levels;
}
}
}
7 changes: 4 additions & 3 deletions SongCore.csproj
Expand Up @@ -124,6 +124,9 @@
<Compile Include="HarmonyPatches\StandardLevelDetailViewRefreshContent.cs" />
<Compile Include="HarmonyPatches\LoadingPatches.cs" />
<Compile Include="Loader.cs" />
<Compile Include="OverrideClasses\SongCoreCustomBeatmapLevelPack.cs" />
<Compile Include="OverrideClasses\SongCoreBeatmapLevelPackCollectionSO.cs" />
<Compile Include="OverrideClasses\SongCoreCustomLevelCollection.cs" />
<Compile Include="Plugin.cs" />
<Compile Include="ProgressBar.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down Expand Up @@ -163,9 +166,7 @@
<EmbeddedResource Include="Icons\MissingChar.png" />
<EmbeddedResource Include="Icons\squek.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="OverrideClasses\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy /Y "$(TargetDir)$(TargetFileName)" "C:\Program Files (x86)\Steam\steamapps\common\Beat Saber\Plugins"</PostBuildEvent>
Expand Down

0 comments on commit 618284c

Please sign in to comment.