JannisX11 / snowstorm

Minecraft Bedrock Particle Generator
https://snowstorm.app
GNU General Public License v3.0
150 stars 25 forks source link

Texture search improvements. #93

Closed Nusiq closed 1 month ago

Nusiq commented 1 month ago

This PR adds additional potential paths to check when looking for textures.

Current Situation

In the current version of Snowstorm, the textures can be located in two places, in relation to the path of the particle file. The selection of the path to check depends on the existence of the folder called "particles" in the path of the particle file.


A) If the path contains the "particles" folder, then Snowstorm looks for the texture in the subdirectory of that path's parent (using the path specified in the particle file).

Example: Particle file path: C:/some/path/particles/some/path/my_particle.json Path specified in the particle file: textures/particle/my_texture.png Texture path expected by snowstorm: C:/some/path/textures/particle/my_texture.png.

This is the best solution if someone is working in a resource pack.

B) If the path doesn't contain "particles" folder, then Snowstorm looks in the same directory as the particle file.

Example: Particle file path: C:/some/path/abcd/some/path/my_particle.json Path specified in the particle file: textures/particle/my_texture.png Texture path expected by snowstorm: C:/some/path/abcd/some/path/textures/particle/my_texture.png.


Snowstorm never checks both of the paths.

Changes Implemented in this PR

I suggest 2 changes: A) Always check all potential texture path candidates when searching for the texture (with some candidates having priority over others). B) Add a new texture file candidate - the texture file, with the name that matches the name of the texture specified in the particle file, and in the same directory as that particle file.

Example: Particle file path: C:/some/path/abcd/some/path/my_particle.json Path specified in the particle file: textures/particle/my_texture.png Texture path to check by Snowstorm (when the other paths fail): C:/some/path/abcd/some/path/my_texture.png.


This enables working in a simplified project structure where the particle files are kept in the same location as the texture they use. For example:

Nusiq commented 1 month ago

I also noticed that currently Snowstorm searches for particles folder using the path_arr.indexOf('particles'). This might cause unexpected issues, when there is multiple 'particles' in the path.

I think it's not that improbable that someone would create a project called 'particles' and have a resource pack in that project. In that case the path to a particle file could look like:

I didn't implement that change in my PR but I suggest to switching to lastIndexOf.

This also applies to saving textures, which I think is a new feature of Snowstorm (?).