Skip to content

feat: add type safe entity names file #1107

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

Merged
merged 4 commits into from
Apr 22, 2025
Merged

Conversation

gonpombo8
Copy link
Contributor

@gonpombo8 gonpombo8 commented Apr 22, 2025

Entity Names Type Generation

Description

This PR introduces a new feature to automatically generate TypeScript definitions for entity names in the scene. It simplifies referencing scene entities by name with full type safety and IDE autocompletion support.

Implementation Details

  • Added a new function generateEntityNamesType to create a TypeScript file with string literal types for entity names
  • Automatically generates this file whenever the scene composite is saved
  • Creates both a string literal union type and a constant object for better developer experience
  • Entity names are properly sanitized for valid TypeScript identifiers

Benefits

  • Type safety when referencing entities by name in code
  • Autocomplete support in IDE for all named entities in the scene
  • Prevents runtime errors from typos in entity name strings
  • Makes refactoring entity names easier as TypeScript will catch all references

Example Usage

import { EntityNames } from '../assets/scene/entity-names'

// Auto-completion support via constant object
const GroundBoedoOrNull = engine.getEntityOrNullByName(EntityNames.Ground_Boedo1) 
const GroundBoedo = engine.getEntityByName<EntityNames>(EntityNames.Ground_Boedo1)
console.log(GroundBoedo)

This implementation helps reduce runtime errors and improves the developer experience when working with named entities in Decentraland scenes.

Copy link

cloudflare-workers-and-pages bot commented Apr 22, 2025

Deploying js-sdk-toolchain with  Cloudflare Pages  Cloudflare Pages

Latest commit: 68542c1
Status: ✅  Deploy successful!
Preview URL: https://db29fa42.js-sdk-toolchain.pages.dev
Branch Preview URL: https://feat-generate-name-type-safe.js-sdk-toolchain.pages.dev

View logs

Copy link
Contributor

github-actions bot commented Apr 22, 2025

Test this pull request

  • The @dcl/sdk package can be tested in scenes by running

    npm install "https://sdk-team-cdn.decentraland.org/@dcl/js-sdk-toolchain/branch/feat/generate-name-type-safe/dcl-sdk-7.8.5-14603846583.commit-63e7a5a.tgz"
  • To test with npx init

    export SDK_COMMANDS="https://sdk-team-cdn.decentraland.org/@dcl/js-sdk-toolchain/branch/feat/generate-name-type-safe/dcl-sdk-commands-7.8.5-14603846583.commit-63e7a5a.tgz"
    npx $SDK_COMMANDS init
  • The @dcl/inspector package can be tested by visiting this url

    • Or by installing it via NPM
    npm install "https://sdk-team-cdn.decentraland.org/@dcl/js-sdk-toolchain/branch/feat/generate-name-type-safe/@dcl/inspector/dcl-inspector-7.8.5-14603846583.commit-63e7a5a.tgz"
  • The /changerealm command to test test in-world

    /changerealm https://sdk-team-cdn.decentraland.org/ipfs/feat/generate-name-type-safe-e2e
    
  • You can preview this build entering:
    https://playground.decentraland.org/?sdk-branch=feat/generate-name-type-safe

@gonpombo8 gonpombo8 enabled auto-merge (squash) April 22, 2025 20:01
@gonpombo8 gonpombo8 disabled auto-merge April 22, 2025 20:07
@gonpombo8 gonpombo8 force-pushed the feat/generate-name-type-safe branch from 4e33155 to eee89b4 Compare April 22, 2025 20:07
@gonpombo8 gonpombo8 enabled auto-merge (squash) April 22, 2025 20:13
@gonpombo8 gonpombo8 force-pushed the feat/generate-name-type-safe branch from eee89b4 to 68542c1 Compare April 22, 2025 20:18
@gonpombo8 gonpombo8 merged commit a5e11cb into main Apr 22, 2025
9 checks passed
@gonpombo8 gonpombo8 deleted the feat/generate-name-type-safe branch April 22, 2025 20:29
kuruk-mm added a commit that referenced this pull request Jun 19, 2025
* update left/right click button behaviour on renderer (#1078)

* update left/right click button behaviour on renderer

* remove gizmo right click button

* fixed review comments

* remove desktop client (OLD) option (#1083)

* select "Scene" in tree on startup (#1082)

* update left/right click button behaviour on renderer

* select 'Scene' in tree on startup

* add refresh button for Assets (#1085)

* support border in uitransforms (#1084)

* support border in uitransforms

* fix build

* change protocol to experimental

* use main protocol

* fix snapshots test

* fix tests

* fix coverage

* update protocol

* export useEffect & useState (#1089)

* export useEffect & useState

* fix tests

* fix: Animation weight value (#1090)

* fix: Animation weight value

* fix: Animation weight and speed default value

* revert .vscode/settings.json

* lint

* update .crdt

* fix models removal when using filters (#1088)

* add video player to syncEntities (#1097)

* add skip-auth-screen & landscape-terrain-enabled options for preview (#1096)

* chore: Add check local packages action (#1092)

* chore: Update asset-packs package

* fix: Allow dev package

* chore: Move check no local packages to a GHAction

* chore: Update asset-packs package

* fix: Convert TS file to CJS

* fix: GHAction comment id

* chore: Move local dependencies check to ci pipeline

* fix: debug downloaded files

* chore: Enhance message

* chore: simplify comment dependencies logic

* chore: Generate comment.md to properly show in the PR

* fix: string comment

* fix: error detection

* fix: check exit code

* fix: catch exit code

* chore: Update @dcl/asset-packs

* remove AudioSource component from not sync list (#1099)

* add entity highlight when selected (#1103)

* fix: Handle components schemas errors (#1098)

* fix: Basic view TweenComponent to better handle empty entities

* fix: Sync external changes

* feat: Add Default Basic View Field

* fix: Add SyncComponents to Smart Items when using the AdminTools (#1100)

* chore: Update @dcl/asset-packs package

* fix: Update createEnumEntityId

* feat: Add new util addSyncComponentsToEntities to add the Synccomponent and Network component to multiple entities

* fix: Tests

* chore: Update @dcl/asset-packs package

* fix: Remove components for actions that doesn't create components on the fly

* fix: Add a validation to avoid include Tween and Transform in the SyncComponent at the same time

* chore: Update @dcl/asset-packs

* update @dcl/[email protected] (#1106)

* feat: add type safe entity names file (#1107)

* feat: add type safe entity names file

* fix build:

* simplify enum types

* update tests

* fix bad merge issue with onChange

* feat: change shortcut for rotating camera (#1110)

Co-authored-by: Alejandra Levy <[email protected]>

* fix Texture being flipped vertically (#1111)

* add video screen (#1105)

* add video screen

* update asset-packs package

* update ui

* update asset-packs

* update asset-packs

* fix ui styles

* fix volume and losing focus

* update assert-packs

* bump asset-packs

* feat: add search param to actions dropdown (#1113)

* feat: add search param to actions dropdown
* feat: add searchable in Trigger Action and Trigger Basic View

* feat: show selected entity first on dropdown (#1112)

* feat: show selected entity first on dropdown

* feat: remove unused import and reorder import

* Update packages/@dcl/inspector/src/components/ui/EntityField/EntityField.tsx

Co-authored-by: Gabriel Díaz <[email protected]>
Signed-off-by: Alejandra Levy <[email protected]>

* feat: update method

---------

Signed-off-by: Alejandra Levy <[email protected]>
Co-authored-by: Gabriel Díaz <[email protected]>

* Support jpg textures (#1114)

* feat: support jpg & jpge textures

* feat: support jpg and jpeg for all images inputs

* feat: update validation for textures

* feat: Update regez to support .jpg and .jpge extensions

* feat: fix lint issues

* feat: add validation on input change

* feat: change regex to pass tests

* feat: update validation on component

* feat: add error message for invalid URL and stop validating empty field

* feat: update message

* Update global value on Audio Source component (#1119)

* feat: update global value & validate source input only where there's a value

* feat: remove debugger

* Support global prop on play sound action (#1120)

* feat: support global prop on play sound action

* feat: update pacjkage json

* feat: update package json and fix issues

* feat: install asset packs version

* feat: update asset pack version

* feat: install asset packs version on inspector

* feat: remove asset packs from root package.json

* feat: update package-lock

* fix enter scene callback not being fired if there is no onLeaveCb (#1124)

* fix enter scene callback not being fired if there is no onLeaveCb

* fix tests and update asset-packs

* feat: cursor position info (#1123)

* Updated protocol and added test for the new PrimaryPointerInfo component

* Lint-fix pass

* fix play video not updaing src property (#1129)

* add default emotes (#1132)

* feat: 4088 add z-index support for ui elements (#1127)

* Updated protocol pointers to dev branch

* Added zIndex to the react-ecs component and test

(cherry picked from commit 7ea5cfd)

* Added opacity property to ui elements

* Fixed tests

* Updated protocol

* Updated snapshots

* Removed redundant definitions. Added test coverage

* Adjusted the default value in test

* ui transform  test wip

* Added more tests. Refactored parseUiTransform utility function to properly handle the new properties

* Deep clean and snapshot

* Removed redundant tests, removed redundant defaults definitions.

* Updated snapshots

* Updated default value for opacity and updated snapshots

* feat: Update asset packs package (#1135)

* update protocol from protocol-squad branch
add "make update-protocol-squad"

* fixes and update crdt snapshots

* reduce coverage to 90% for protocol-squad branch

* update protocol (add setUiFocus)

---------

Signed-off-by: Alejandra Levy <[email protected]>
Co-authored-by: Nicolas Echezarreta <[email protected]>
Co-authored-by: Gon Pombo <[email protected]>
Co-authored-by: Gabriel Díaz <[email protected]>
Co-authored-by: Alejandra Levy <[email protected]>
Co-authored-by: Alejandra Levy <[email protected]>
Co-authored-by: Alejandro Alvarez Melucci <[email protected]>
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

Successfully merging this pull request may close these issues.

2 participants