PhaserEditor2D / PhaserEditor

A friendly IDE to develop HTML5 games based on the Phaser framework.
https://phasereditor2d.com
Eclipse Public License 1.0
327 stars 45 forks source link

Asset Pack: use container folder as prefix for new keys #138

Closed PhaserEditor2D closed 4 years ago

PhaserEditor2D commented 4 years ago

(Client request)

Yes this is what I have been doing, simply adding a prefix to the keys manually.

This would be handy, as I have a project with multiple levels, each with their own unique assets and pack file. However, each one also has a "background" and other objects that may take on the same name but are different assets, for example a "couch". A couch in level 2 may look different from a couch from level 3, but must have unique keynames.

Having the ability for it to automatically append a "level2" or a "level3" prefix to each key for each level's pack file avoids any conflicts in key names between levels.

PhaserEditor2D commented 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.

image

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

If you find any problem please reopen this issue.

PhaserEditor2D commented 4 years ago

(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.

PhaserEditor2D commented 4 years ago

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?

rgmoorer commented 4 years ago

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.

PhaserEditor2D commented 4 years ago

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.

PhaserEditor2D commented 4 years ago

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.

patch-2.1.5-2.zip

rgmoorer commented 4 years ago

Sorry for the late reply, yeah looks like that works well. Readding the scene file doesn't append a prefix to it.

rgmoorer commented 4 years ago

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.

PhaserEditor2D commented 4 years ago

Yes, it makes sense. I will work on it. Thanks!

PhaserEditor2D commented 4 years ago

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:

patch-2.1.5-3.zip

The patch also fixes #139

PhaserEditor2D commented 4 years ago

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.

rgmoorer commented 4 years ago

Looks good on both 138 and 139 thanks!