AnimationManager toJSON() errors when stringified indirectly
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 40.3k
- Forks
- 7.2k
- PR merge metrics
- No merged PRs in 30d
Description
Version
- Phaser Version: 4.1.0
Description
If the Animation Manager is stringified indirectly, toJSON() will probably error because it interprets its key argument as animation identifier.
This came up when someone used a serialization library on a scene.
Example Test Code
In a scene:
JSON.stringify([ this.anims ]) // → toJSON("0")
// Uncaught TypeError: can't access property "toJSON", this.anims.get(...) is undefined
JSON.stringify({ anims: this.anims }) // → toJSON("anims")
// Uncaught TypeError: can't access property "toJSON", this.anims.get(...) is undefined
Additional Information
Probably best to remove the key argument from toJSON() and add a getJSON(animKey) method instead.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the Animation Manager's toJSON implementation and trace how JSON.stringify([this.anims]) and JSON.stringify({ anims: this.anims }) pass arguments to it. Verify that indirect serialization no longer treats the property key as an animation identifier, while direct animation JSON retrieval still works, using focused tests for both examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100