playcanvas / playcanvas/editor

Improve script parsing scope to support dynamically added attributes

Open
#760 0 comments 1 reaction 1 assignee View on GitHub

@marklundin is already working on this.

Since Feb 14, 2024.

area: editor interface area: scripts area: templates enhancement
Dominant language
TypeScript
Stars
1.3k
Forks
215
Avg merge
1d 29m
Merged PRs (30d)
30

Description

Sometimes, I want to have enumeration in code bind to script attributes. It turns out, I can have it with something like this:

const FXType = {
    UNIT_SPAWN : 'unit-spawn',
    UNIT_DESTROY : 'unit-destroy',
    IMPACT_FIREBALL : 'impact-fireball',

    getKeyArray : function() {
        const value = []
        for (const k in FXType) {
            if (k === 'getKeyArray') continue;
            value.push(k)
        }
        return value
    }
}

FXType.getKeyArray().forEach(v => {
    Fxpool.attributes.add(v, {type : 'asset', assetType : 'template'})
})

this is fine and dandy. However, if I later want to have a enum attribute in some other script:

SomeScript.attributes.add('impactFX', {type : 'string', enum : FXType.getKeyArray().map(v => { return {[v] : v}})})

I get this:
chrome_xuX3mqK8AO

would be so helpful to bind this enum value somewhere else, in fact, in a lot of places. That would help to improve quality of code in small to medium size projects by a huge margin.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.