Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated TilemapLayer TypeScript objects couldn't be set to class/public scope, or set Hit Area due to possible null value #295

Closed
lucem-sequamur opened this issue Oct 21, 2023 · 1 comment

Comments

@lucem-sequamur
Copy link

Version

  • Phaser Editor 2D Version: v3.63.0
  • Operating System: Windows 10
  • Web Browser and version: Microsoft Edge Version 118.0.2088.61 (Official build) (64-bit)

Description

The editor uses (method) Phaser.Tilemaps.Tilemap.createLayer(layerID: string | number, tileset: string | Phaser.Tilemaps.Tileset | string[] | Phaser.Tilemaps.Tileset[], x?: number | undefined, y?: number | undefined): Phaser.Tilemaps.TilemapLayer | null to create TilemapLayer objects in generated code, which is recognized as a nullable value in TypeScript. When setting the object to class/public scope from editor, the null safety check would show compilation error because the field demands non-null value. Additionally, other features of this component, such as setting the Hit Area also demands non-null value, causing the same compilation error.

Possible solution

Maybe give the user an option to set (any) components to be not null. For example, in the inspector panel, under variable, add a checkbox "not null", and add ! to the end of the variable instantiation in the generated code when this checkbox is selected.

@PhaserEditor2D
Copy link
Owner

Done. It now generates the code with the non-null assertion operator (!)

const tile_Layer = map.createLayer("Tile Layer 1", ["tileset"], 0, 0)!;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants