playcanvas / playcanvas/editor
Improve script parsing scope to support dynamically added attributes
Open
@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:

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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.