Skip to content

TextStyle.setStyle mutates the given style parameter object #6863

Closed
jonesrussell/nishman
#6
@stormpanda

Description

@stormpanda

Version

  • Phaser Version: 3.80.1
  • Operating system: MacOS
  • Browser: all browsers

Description

https://github.com/phaserjs/phaser/blob/master/src/gameobjects/text/TextStyle.js

TextStyle.setStyle normalizes the given fontSize by adding "px" if it is just a number. However, the function will mutate the original given "style" parameter, which is a counterintuitive side-effect that is also unnecessary. This makes hard to define global font styles for reuse, since after the first setStyle call a font size of for example 32 (number) will be "32px" (string) afterwards, meaning it cannot be used for calculation of relative font sizes anymore.

The "style" parameter should not be mutated. Cloning it before changing it would fix the problem, I guess a shallow copy would also suffice.

Example Test Code

https://phaser.io/sandbox/zvb8G5ux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions