Load user's playlists and print confirmation
This commit is contained in:
parent
752419121f
commit
7c3bd4109e
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using IPA;
|
using IPA;
|
||||||
using IPALogger = IPA.Logging.Logger;
|
using IPALogger = IPA.Logging.Logger;
|
||||||
|
|
||||||
@ -23,7 +24,42 @@ namespace Setlist
|
|||||||
[OnStart]
|
[OnStart]
|
||||||
public void OnApplicationStart()
|
public void OnApplicationStart()
|
||||||
{
|
{
|
||||||
Log.Info("Hello World");
|
try
|
||||||
|
{
|
||||||
|
var playlists = BeatSaberPlaylistsLib.PlaylistManager.DefaultManager.GetAllPlaylists(
|
||||||
|
includeChildren: true,
|
||||||
|
out AggregateException loadErrors);
|
||||||
|
|
||||||
|
if (loadErrors != null)
|
||||||
|
{
|
||||||
|
Log.Error(loadErrors.Message);
|
||||||
|
foreach (var inner in loadErrors.InnerExceptions)
|
||||||
|
{
|
||||||
|
Log.Error(inner.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (playlists == null || playlists.Length == 0)
|
||||||
|
{
|
||||||
|
Log.Info("No playlists loaded (or playlist library not initialized yet).");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var playlist in playlists)
|
||||||
|
{
|
||||||
|
var hasSyncUrl = false;
|
||||||
|
if (playlist.TryGetCustomData("syncURL", out var syncObj) && syncObj is string url)
|
||||||
|
{
|
||||||
|
hasSyncUrl = !string.IsNullOrWhiteSpace(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.Info($"Playlist \"{playlist.Title}\": hasSyncUrl={hasSyncUrl}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error(ex.ToString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[OnExit]
|
[OnExit]
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||||
<RootNamespace>Setlist</RootNamespace>
|
<RootNamespace>Setlist</RootNamespace>
|
||||||
<AssemblyName>Setlist</AssemblyName>
|
<AssemblyName>Setlist</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>portable</DebugType>
|
<DebugType>portable</DebugType>
|
||||||
@ -89,6 +89,10 @@
|
|||||||
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.VRModule.dll</HintPath>
|
<HintPath>$(BeatSaberDir)\Beat Saber_Data\Managed\UnityEngine.VRModule.dll</HintPath>
|
||||||
<Private>False</Private>
|
<Private>False</Private>
|
||||||
</Reference>
|
</Reference>
|
||||||
|
<Reference Include="BeatSaberPlaylistsLib">
|
||||||
|
<HintPath>$(BeatSaberDir)\Libs\BeatSaberPlaylistsLib.dll</HintPath>
|
||||||
|
<Private>False</Private>
|
||||||
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Plugin.cs" />
|
<Compile Include="Plugin.cs" />
|
||||||
@ -107,7 +111,7 @@
|
|||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net472">
|
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net48">
|
||||||
<Version>1.0.3</Version>
|
<Version>1.0.3</Version>
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
"description": "Syncs playlists with external sources.",
|
"description": "Syncs playlists with external sources.",
|
||||||
"gameVersion": "1.40.8",
|
"gameVersion": "1.40.8",
|
||||||
"dependsOn": {
|
"dependsOn": {
|
||||||
"BSIPA": "^4.3.0"
|
"BSIPA": "^4.3.0",
|
||||||
|
"BeatSaberPlaylistsLib": "^1.7.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
82
docs/playlistmanager-add-map.md
Normal file
82
docs/playlistmanager-add-map.md
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
For reference, the source code is in `~/src/rithik-b/PlaylistManager`.
|
||||||
|
|
||||||
|
Here is how “add this map to a playlist” is wired in this repo.
|
||||||
|
|
||||||
|
### 1. User clicks Add (opens the picker)
|
||||||
|
|
||||||
|
The Add button on the level detail screen calls `AddPlaylistModalController.ShowModal()`:
|
||||||
|
|
||||||
|
```64:70:PlaylistManager/UI/ViewControllers/LevelDetailButtonsViewController.cs
|
||||||
|
[UIAction("add-button-click")]
|
||||||
|
private void OpenAddModal()
|
||||||
|
{
|
||||||
|
addPlaylistController.ShowModal();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`ShowModal` parses the BSML if needed, opens the modal, and lists playlists from the default lib manager:
|
||||||
|
|
||||||
|
```97:103:PlaylistManager/UI/ViewControllers/AddPlaylistModalController.cs
|
||||||
|
internal void ShowModal()
|
||||||
|
{
|
||||||
|
Parse();
|
||||||
|
parserParams.EmitEvent("close-modal");
|
||||||
|
parserParams.EmitEvent("open-modal");
|
||||||
|
ShowPlaylistsForManager(PlaylistLibUtils.playlistManager);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. User picks a playlist row — that is where the map is actually added
|
||||||
|
|
||||||
|
The real work is in `AddPlaylistModalController.OnCellSelect`: after navigating folders, choosing a playlist calls **`IPlaylist.Add(...)`** from **BeatSaberPlaylistsLib**, then persists and notifies:
|
||||||
|
|
||||||
|
```165:204:PlaylistManager/UI/ViewControllers/AddPlaylistModalController.cs
|
||||||
|
[UIAction("select-cell")]
|
||||||
|
private void OnCellSelect(TableView tableView, int index)
|
||||||
|
{
|
||||||
|
playlistTableData.TableView.ClearSelection();
|
||||||
|
// Folder Selected
|
||||||
|
if (index < childManagers.Count)
|
||||||
|
{
|
||||||
|
ShowPlaylistsForManager(childManagers[index]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
index -= childManagers.Count;
|
||||||
|
var selectedPlaylist = childPlaylists[index];
|
||||||
|
IPlaylistSong playlistSong;
|
||||||
|
if (HighlightDifficulty)
|
||||||
|
{
|
||||||
|
playlistSong = selectedPlaylist.Add(standardLevelDetailViewController.beatmapLevel, standardLevelDetailViewController.beatmapKey);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
playlistSong = selectedPlaylist.Add(standardLevelDetailViewController.beatmapLevel);
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
selectedPlaylist.RaisePlaylistChanged();
|
||||||
|
parentManager.StorePlaylist(selectedPlaylist);
|
||||||
|
popupModalsController.ShowOkModal(modalTransform, string.Format("Song successfully added to {0}", selectedPlaylist.Title), null, animateParentCanvas: false);
|
||||||
|
// TODO: Doesn't refresh the sprite.
|
||||||
|
Events.RaisePlaylistSongAdded(playlistSong, selectedPlaylist);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
popupModalsController.ShowOkModal(modalTransform, "An error occured while adding song to playlist.", null, animateParentCanvas: false);
|
||||||
|
Plugin.Log.Critical(string.Format("An exception was thrown while adding a song to a playlist.\nException Message: {0}", e.Message));
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
ShowPlaylistsForManager(parentManager);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
So:
|
||||||
|
|
||||||
|
- **PlaylistManager code**: `AddPlaylistModalController.OnCellSelect` (orchestration, UI, `StorePlaylist`, `Events.RaisePlaylistSongAdded`).
|
||||||
|
- **Library code**: `selectedPlaylist.Add(...)` — implementation of how the entry is stored lives in **BeatSaberPlaylistsLib** (`IPlaylist`), not in this repository.
|
||||||
|
|
||||||
|
There is no other `.Add(` on a playlist for this flow in the grep results; removing a song is the parallel path in `LevelDetailButtonsViewController.RemoveSong()`.
|
||||||
Loading…
x
Reference in New Issue
Block a user