Having Phaser Editor generate a static field for scene keys would be useful to maintain consistency throughout the codebase.
Advantages
For example, if I'm adding a scene using ScenePlugin.add:
this.scene.add('MyScene', MyScene);
Since providing a key is mandatory for this method, even if the MyScene class generated by the editor contains a super call where it passes the key, I need to manually pass the same key. But if the editor had generated a static property for it:
this.scene.add(MyScene.KEY, MyScene);
Warnings
It has happened to me before when I tried to retrieve a scene by running scene.get(MyScene.KEY) and got a circular import. Why? Because in order to retrieve the scene, I had to import its class, so I could get its key. There are situations where the code in your scene module references members in the current module. So, if the key was defined in an externalized place instead, like an enum or a namespace for example, you'd just need to import the key from there without importing the scene module.
In conclusion, while having the scene key statically defined in the class can be beneficial, it should also be used with care. Perhaps someone could think of a better way for Phaser Editor to generate scene keys?
Having Phaser Editor generate a static field for scene keys would be useful to maintain consistency throughout the codebase.
Advantages
For example, if I'm adding a scene using
ScenePlugin.add
:Since providing a key is mandatory for this method, even if the
MyScene
class generated by the editor contains asuper
call where it passes the key, I need to manually pass the same key. But if the editor had generated a static property for it:Warnings
It has happened to me before when I tried to retrieve a scene by running
scene.get(MyScene.KEY)
and got a circular import. Why? Because in order to retrieve the scene, I had to import its class, so I could get its key. There are situations where the code in your scene module references members in the current module. So, if the key was defined in an externalized place instead, like an enum or a namespace for example, you'd just need to import the key from there without importing the scene module.In conclusion, while having the scene key statically defined in the class can be beneficial, it should also be used with care. Perhaps someone could think of a better way for Phaser Editor to generate scene keys?