phaserjs / phaserjs/phaser

AnimationManager toJSON() errors when stringified indirectly

Open
#7,307 0 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.