Repository navigation
Support all AssetPack sound aliases - #285
Conversation
zbdd
left a comment
There was a problem hiding this comment.
Thanks for this, the alias handling looks right and the tests look good.
One thing before we merge. close() sets _sounds to null, and Object.values(this._sounds) throws on null, so after sound.close() any of removeAll(), stopAll() or a second close() throws a TypeError. On main all three are fine because for...in over null just does nothing.
Can you guard removeAll() and stopAll() against _sounds being null, and add a test that calls removeAll(), stopAll() and close() after close()? init() again afterwards so the rest of the suite still has a working library.
|
Pushed a guard for the Thanks for the fix. |
- close() sets _sounds to null and Object.values(null) throws, so removeAll(), stopAll() and a second close() threw a TypeError after close() - Test calls all three after close() on both backends
c0ab63e to
6cb418f
Compare
Backport of #285 (cherry picked from commit 102bf4c) - Cause: v5.x registered an Assets-loaded sound under its first alias only, so the other names from `Assets.add(['a', 'b'], url)` or a bundle `{ name: ['a', 'b'] }` couldn't be played. A sound under two names was destroyed twice by `removeAll()` (#128's crash), and unloading a bundle asset with two names threw. - Fix: register every alias. The first name is unchanged (`alias[0]`, or the basename when PixiJS passes no alias), so a URL load keeps its old name on every PixiJS 7 version: the basename on 7.0.x and the full URL where PixiJS passes it as the alias. Main's basename rule for URL loads and its `entry !== src` filter aren't ported. `unload` removes the alias that still maps to the sound, or destroys the sound. `remove()` deletes every key for the sound, and `removeAll()`/`stopAll()` act once per sound. The guards after `close()` are for parity with main; v5.x didn't throw there. - Tests: `test/soundAsset.test.ts` ported to PixiJS 7 bundles (`{ name, srcs }`), plus v5.x cases for the URL-load name, unloading a bundle asset with two names, `removeAll()` with one sound under two names, and empty aliases. Both backends. Co-authored-by: StitchAndGlitchStudio <stitchandglitchstudio@gmail.com>
AssetPack manifests can expose multiple aliases for the same sound, but the sound loader only registers the first entry. This leaves alternate aliases in the PixiJS Assets cache without matching entries in SoundLibrary.
This change:
Tests cover WebAudio and HTMLAudio loading, playback lookup, unloading, direct URL fallback, reassigned aliases, removeAll, and stopAll.
Fixes #282.