Code review
This commit is contained in:
@@ -79,4 +79,39 @@ 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()`.
|
||||
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()`.
|
||||
|
||||
## hooking into the process
|
||||
|
||||
### 1. Subscribe to PlaylistManager’s public event (simplest)
|
||||
|
||||
After a successful add from the **Add to playlist** UI, PlaylistManager raises a **public static** event:
|
||||
|
||||
```16:18:PlaylistManager/Utilities/Events.cs
|
||||
/// <summary>
|
||||
/// Raised when an <see cref="BeatSaberPlaylistsLib.Types.IPlaylistSong"/> is added to an <see cref="BeatSaberPlaylistsLib.Types.IPlaylist"/>
|
||||
/// </summary>
|
||||
public static event Action<BeatSaberPlaylistsLib.Types.IPlaylistSong, BeatSaberPlaylistsLib.Types.IPlaylist> playlistSongAdded;
|
||||
```
|
||||
|
||||
It is invoked **after** `RaisePlaylistChanged()` and `StorePlaylist()` succeed:
|
||||
|
||||
```187:194:PlaylistManager/UI/ViewControllers/AddPlaylistModalController.cs
|
||||
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);
|
||||
}
|
||||
```
|
||||
|
||||
In your plugin: add a **reference to `PlaylistManager.dll`**, a **manifest dependency** on PlaylistManager, then subscribe in `OnEnable` (or menu init) and unsubscribe in `OnDisable`:
|
||||
|
||||
- Namespace: `PlaylistManager.Utilities`
|
||||
- Type: `Events`
|
||||
- Event: `playlistSongAdded`
|
||||
- Handler signature: `(IPlaylistSong song, IPlaylist playlist)` from `BeatSaberPlaylistsLib.Types`
|
||||
|
||||
**Caveat:** This is only raised for adds that go through **this** code path. It is the **only** `RaisePlaylistSongAdded` call site in the repo, so adds done only via BeatSaberPlaylistsLib (or another mod) will **not** fire this event.
|
||||
|
||||
Reference in New Issue
Block a user