Closed PhaserEditor2D closed 4 years ago
Done.
Now you can enable the Use container folder as a prefix for new asset keys parameter. It is in the global preferences (**Window > Preferences > Phaser Editor > Asset Pack Editor). By default it is disabled.
So, if that parameter is enabled, then when you add new assets it will use the name of the container folder of the asset pack as the prefix of the new key. For example, if you add a file background.png
and the asset pack file is in the folder level3
, then the new key will be level3.background
.
This will be included in the next release, that we want to release soon. However, please, apply this patch I attach here to check it is working as you expect.
Download this file: patch-2.1.4-0.zip
Uncompress it. It contains the phasereditor.assetpack.core_2.1.4.20191016.jar
and phasereditor.assetpack.ui.editor_2.1.4.20191016.jar
files.
Close the editor.
Copy and paste them in the plugins
folder of the editor, to replace the old files.
Start the editor again, but using the script Debug.bat
in the root folder. It cleans the plugins cache. Do this just the first time.
If you find any problem please reopen this issue.
(from client)
One issue I saw with the prefix patch:
It adds the prefix to everything, including the scene file and animations pack.
At least with the scene file, appending a prefix to it seems to break something, as manually removing the prefix from the scene file fixes it again.
The problem is that in the case of sceneFile
assets, the key should be the same as the class name. See the Phaser docs:
For a Scene File it's vitally important that the key matches the class name in the JavaScript file.
More here: https://photonstorm.github.io/phaser3-docs/Phaser.Loader.LoaderPlugin.html#sceneFile__anchor
So you have to change the asset key manually or disable the automatic prefix.
The other option we have is to ignore the automatic prefix in case of scene files. What do you think?
It sounds like ignoring the prefix for scene files might be a viable solution.
Scene files are usually few and far between, whereas image/sprite assets can be numerous. With a small number of scenes, manually making sure scene file keys are unique shouldn't be too much effort.
Just an idea, but if the key must match the class name, it sounds like if the prefix started with a capital letter and ended with an underscore, it may accept the prefix for the scene file? For example, if the containing folder name was "level01" and the resulting prefix was "Level01_", then the class name of the scene file ended up being "Level01_Scene1" it might accept that as a valid class name?
I know it won't accept periods in class names, not totally sure about underscores.
It sounds like ignoring the prefix for scene files might be a viable solution.
Yes, I agree.
For example, if the containing folder name was "level01" and the resulting prefix was "Level01_", then the class name of the scene file ended up being "Level01_Scene1" it might accept that as a valid class name?
It may work if you create the scene and add it to the asset pack at the same time, but auto-prefix works even if you add a pre-made scene file, so in that case, the user has to rename the class. I think that ignoring the prefix in case of scene files is a practical solution.
Hi @rgmoorer please unpack the files I attach here and copy them into the plugins
folder.
Remember to restart the editor with the Debug.bat
script. Please tell me if it works now.
Sorry for the late reply, yeah looks like that works well. Readding the scene file doesn't append a prefix to it.
I do think that a prefix with an underscore rather than a period would make more sense, since the js renames the period to an underscore anyways since periods cannot be in variable names.
Also, it would be nice if we have the option to not append the prefix to the var name. Var names do not need to be unique between scenes, and it adds a lot of extra typing when the var name becomes longer.
Yes, it makes sense. I will work on it. Thanks!
Done. If the "Use container folder as prefix..." preference is enabled, then the objects added to the scene will ignore the folder name prefix. Please, test this patch:
The patch also fixes #139
By the way, the name of the objects already present in the scene are not changed, only a new added object will skip using the prefix in its name.
Looks good on both 138 and 139 thanks!
(Client request)