Skip to content

Conversation

@marklundin
Copy link
Member

@marklundin marklundin commented Oct 24, 2025

Adds support for referencing types from within playcanvas. This allows scripts to include direct references to playcanvas values. Fixes #16 and this issue

We can now use imported values for enum types. Tests included.

/** @enum {number} */
const ToneMapping = {
    LINEAR: TONEMAP_LINEAR,
    FILMIC: TONEMAP_FILMIC,
    HEJL: TONEMAP_HEJL,
    ACES: TONEMAP_ACES,
    ACES2: TONEMAP_ACES2,
    NEUTRAL: TONEMAP_NEUTRAL
};

Note, this also removes the playcanvas.d.ts from the tests and resolves instead to the playcanvas in node_modeules

- Updated the attribute parser to correctly handle TypeScript enums, including imported constants.
- Enhanced the getLiteralValue function to prioritize type checking for imported constants.
- Added support for enums in the test fixtures, validating the integration with playcanvas.
- Introduced playcanvas as a dependency in package.json and package-lock.json.

This update improves the parsing of enums and ensures compatibility with the latest playcanvas features.
- Replaced the fallback in `resolveIdentifier` to return `undefined` instead of a literal value.
- Refactored enum definitions in test fixtures to utilize new tone mapping constants from playcanvas.
- Updated tests to validate the new enum structure and ensure correct default values for tone mapping attributes.

This change enhances the clarity and functionality of enum handling in the codebase.
@marklundin marklundin self-assigned this Oct 24, 2025
@marklundin marklundin added the enhancement New feature or request label Oct 24, 2025
@marklundin marklundin requested a review from a team October 24, 2025 15:27
@marklundin marklundin changed the title Feat external refs Add support for external references Oct 24, 2025
@marklundin marklundin requested a review from kpal81xd October 27, 2025 11:55
@mvaligursky
Copy link
Collaborator

Fantastic news, I'll update my script that could use this when this is out!

@mvaligursky
Copy link
Collaborator

is everything ok here?
Screenshot 2025-10-30 at 15 02 10

- Introduced a new function `getPlaycanvasTypes` to load Playcanvas type definitions directly from `node_modules`.
- Updated `parseAttributes` and `getAttributes` functions to utilize the loaded Playcanvas types instead of relying on a local fixture file.
- Removed the `playcanvas.d.ts` fixture file as it is no longer needed.

This change streamlines type handling and ensures that the latest Playcanvas definitions are used in the project.
@marklundin
Copy link
Member Author

marklundin commented Nov 4, 2025

@mvaligursky This was using a a copy of playcanvas.d.ts for the tests. Have removed this, it's now using the node_modules copy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support constant refs

3 participants