Skip to content

Add AssetPath::resolve() #9473

Closed
Closed
@viridia

Description

@viridia

What problem does this solve or what need does it fill?

Assets which contain references to other assets should support relative paths. This enables an entire group of linked assets to be moved around the filesystem without breaking the relationship.

To facilitate this, I propose adding a method to AssetPath which accepts a relative path string, and produces a new absolute path. Asset loaders can then use this method when resolving internal path references.

What solution would you like?

The resolve() method would take a single argument, which is a relative path string. It produces a new path using self as the base path, with the following rules:

  • If the relative path starts with "#", then the new path consists of the base path with the label portion replaced. This is used for paths that point to other assets within the same file.
  • If the relative path starts with "./" or "../", then the new path is computed relative to the directory of the asset path, using the standard path resolution rules. So if the base path is "a/b/c#d", and the relative path is "./x" then the new path is "a/b/x".
  • If the relative path starts with any other character, it is treated as an absolute path.

What alternative(s) have you considered?

This can also be done as a standalone function, however it's a pretty handy function to have, and is small, so I thought it would make sense to add this to Bevy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-AssetsLoad files from disk to use for things like images, models, and soundsC-UsabilityA targeted quality-of-life change that makes Bevy easier to useD-TrivialNice and easy! A great choice to get started with Bevy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions