Gorgon
Show / Hide Table of Contents

Interface IGorgonContentLoader

Loads Gorgon2D specific content from an editor file system.

Namespace: Gorgon.IO
Assembly: Gorgon.Editor.API.dll
Syntax
public interface IGorgonContentLoader
Remarks

This provides a set of convenience methods to load Gorgon2D content such as sprites from an editor file system.

important

These methods load the data using the layout and metadata information as provided by the default plug ins for the editor. Custom plug ins for sprite data, etc... may not work with these methods unless those plug ins follow the same file layout as the default plug ins.

Properties

| Edit this page View Source

ExternalAnimationCodecs

Property to return a list of codecs that can be used to load animation content data.

Declaration
IList<IGorgonAnimationCodec> ExternalAnimationCodecs { get; }
Property Value
Type Description
IList<IGorgonAnimationCodec>
Remarks

Codecs added here are for external codecs. All built-in codecs for Gorgon will not appear in this list and are always used when loading files.

If a codec in the list has the same fully qualified type name as a built-in Gorgon codec, then the external codec type will be used instead.

| Edit this page View Source

ExternalImageCodecs

Property to return a list of codecs that can be used to load image content data.

Declaration
IList<IGorgonImageCodec> ExternalImageCodecs { get; }
Property Value
Type Description
IList<IGorgonImageCodec>
Remarks

Codecs added here are for external codecs. All built-in codecs for Gorgon will not appear in this list and are always used when loading files.

If a codec in the list has the same fully qualified type name as a built-in Gorgon codec, then the external codec type will be used instead.

| Edit this page View Source

ExternalSpriteCodecs

Property to return a list of codecs that can be used to load sprite content data.

Declaration
IList<IGorgonSpriteCodec> ExternalSpriteCodecs { get; }
Property Value
Type Description
IList<IGorgonSpriteCodec>
Remarks

Codecs added here are for external codecs. All built-in codecs for Gorgon will not appear in this list and are always used when loading files.

If a codec in the list has the same fully qualified type name as a built-in Gorgon codec, then the external codec type will be used instead.

| Edit this page View Source

TextureCache

Property to return the texture cache for the loader.

Declaration
GorgonTextureCache<GorgonTexture2D> TextureCache { get; }
Property Value
Type Description
GorgonTextureCache<GorgonTexture2D>

Methods

| Edit this page View Source

GetDependencyFiles(string)

Function to retrieve the dependencies for a file.

Declaration
IReadOnlyDictionary<string, IReadOnlyList<IGorgonVirtualFile>> GetDependencyFiles(string path)
Parameters
Type Name Description
string path

The path to the file.

Returns
Type Description
IReadOnlyDictionary<string, IReadOnlyList<IGorgonVirtualFile>>

A dictionary containing the dependencies as where the key is the dependency category, and a list of IGorgonVirtualFile entries for that group.

Remarks

This will return a list of files as a IGorgonVirtualFile for a dependency category. The category list returned by the dictionarye entry value will only contain files that exist in the file system. Files that do not exist will not be returned.

| Edit this page View Source

GetFileAttributes(string)

Function to retrieve the attributes for a file in the editor file system.

Declaration
IReadOnlyDictionary<string, string> GetFileAttributes(string path)
Parameters
Type Name Description
string path

The path to the file.

Returns
Type Description
IReadOnlyDictionary<string, string>

A read only dictionary containing the attributes as a key/value pair.

Remarks

This will return the list of attributes assigned to a file in the editor file system. This metadata can be used by external applications to determine how to handle the file.

| Edit this page View Source

IsDirectoryExcluded(string)

Function to determine if a directory has been marked as excluded.

Declaration
bool IsDirectoryExcluded(string path)
Parameters
Type Name Description
string path

The path to the directory.

Returns
Type Description
bool

true if the directory has been marked as excluded by the editor, or false if not.

Remarks

The editor can mark specific directories as "excluded" so they are not included with packed files. However, sometimes it is useful to be able to query this data for other purposes. This method provides the user with the ability to determine if a directory is excluded and then they may take action depending on the result.

| Edit this page View Source

LoadAnimationAsync(string, IEnumerable<GorgonTexture2DView>)

Function to load an animation from the editor file system.

Declaration
Task<IGorgonAnimation> LoadAnimationAsync(string path, IEnumerable<GorgonTexture2DView> textureOverrides = null)
Parameters
Type Name Description
string path

The path to the animation content.

IEnumerable<GorgonTexture2DView> textureOverrides

[Optional] The textures used to override the textures for a texture track in the animation.

Returns
Type Description
Task<IGorgonAnimation>

A new IGorgonAnimation containing the animation data from the file system.

Remarks

This method will load a IGorgonAnimation from a Gorgon Editor file system mounted as a IGorgonFileSystem.

If the animation is not in a format known by Gorgon, then users should add the IGorgonAnimationCodec for reading the sprite data to the ExternalAnimationCodecs list. Doing this will allow a user to create a custom image codec plug in and use that to read animation data.

When the textureOverrides contains a list of textures, the loader will override any matching textures in any texture tracks within the animation. This allows user defined pre loading of texture data for an animation. The textures in the textureOverrides list will be matched by name to the key TextureName. If the texture is matched with one from the override list, then it will be used for the key. Otherwise, the codec will load the appropriate texture via other means.

Technical info

Plug ins must generate the following metadata for the files in the editor file system.

The animation file metadata must have the following attributes: Type with a value set to the AnimationType, and an attribute called AnimationCodec with the fully qualified type name of the animation codec as its value or the animation will not load.

| Edit this page View Source

LoadImage(string)

Function to load an image from the editor file system.

Declaration
IGorgonImage LoadImage(string path)
Parameters
Type Name Description
string path

The path to the image content.

Returns
Type Description
IGorgonImage

A new IGorgonImage containing the image data from the file system.

Remarks

This method will load a IGorgonImage from a Gorgon Editor file system mounted as a IGorgonFileSystem.

If the image is not in a format known by Gorgon, then users should add the IGorgonImageCodec for reading the sprite data to the ExternalImageCodecs list. Doing this will allow a user to create a custom image codec plug in and use that to read image data.

Technical info

Plug ins must generate the following metadata for the files in the editor file system.

The texture file metadata must have the following attributes: Type with a value set to the ImageType, and an attribute called ImageCodec with the fully qualified type name of the image codec as its value or the texure will not load.

If the image file has been marked as premultiplied in the editor, then the texture will be converted to use premultiplied alpha when loading. This is only done when the texture is read from the file system, cached textures are left as-is.

| Edit this page View Source

LoadSpriteAsync(string, GorgonTexture2DView)

Function to load sprite content from the editor file system.

Declaration
Task<GorgonSprite> LoadSpriteAsync(string path, GorgonTexture2DView overrideTexture = null)
Parameters
Type Name Description
string path

The path to the sprite to load.

GorgonTexture2DView overrideTexture

[Optional] When supplied, this will override the associated texture for the sprite.

Returns
Type Description
Task<GorgonSprite>

The GorgonSprite content for the file system.

Remarks

This method will load a GorgonSprite from a Gorgon Editor file system mounted as a IGorgonFileSystem.

Providing the overrideTexture will skip the texture loading and use the texture passed in. In this case, the texture return value will be null as it is assumed the user already knows about the texture resource and is managing the lifetime of the texture elsewhere.

If the sprite is not in a format known by Gorgon, then users should add the IGorgonSpriteCodec for reading the sprite data to the ExternalSpriteCodecs list. Doing this will allow a user to create a custom sprite codec plug in and use that to read sprite data.

Technical info

Plug ins must generate the following metadata for the files in the editor file system.

The sprite file metadata must have the following attributes: Type with a value of "Sprite", and SpriteCodec, and its associated texture must have a dependency type of Image or else the sprite will not load.

The associated texture file metadata must have the following attributes: Type with a value of "Image", and ImageCodec or the texure will not load.

If the associated texture file has been marked as premultiplied in the editor, then the texture will be converted to use premultiplied alpha when loading. This is only done when the texture is read from the file system, cached textures are left as-is.

important

Regarding sprite textures: Gorgon will use the GorgonTextureCache<T> object to cache any textures loaded from the file system. This cache is exposed to the user via the TextureCache property. It is up to the developer to ensure the cache is managed correctly for their applications.

| Edit this page View Source

LoadTextureAsync(string, bool)

Function to load an image as a texture from the editor file system.

Declaration
Task<GorgonTexture2D> LoadTextureAsync(string path, bool cache = true)
Parameters
Type Name Description
string path

The path to the image context.

bool cache

[Optional] true to use the texture cache, false to load a new instance.

Returns
Type Description
Task<GorgonTexture2D>

A new GorgonTexture2D containing the image data from the file system.

Remarks

This method will load a GorgonTexture2D from a Gorgon Editor file system mounted as a IGorgonFileSystem.

If the texture image is not in a format known by Gorgon, then users should add the IGorgonImageCodec for reading the sprite data to the ExternalImageCodecs list. Doing this will allow a user to create a custom image codec plug in and use that to read image data.

If the cache parameter is set to true, then this method will load the data from the TextureCache. If the texture data is not in the cache, then it will be added to the cache and returned. If the parameter is set to false, then the image data will be loaded as a new texture outside of the cache and it will be the responsibility of the developer to manage its lifetime.

Technical info

Plug ins must generate the following metadata for the files in the editor file system.

The texture file metadata must have the following attributes: Type with a value set to the ImageType, and an attribute called ImageCodec with the fully qualified type name of the image codec as its value or the texure will not load.

If the image file has been marked as premultiplied in the editor, then the texture will be converted to use premultiplied alpha when loading. This is only done when the texture is read from the file system, cached textures are left as-is.

Extension Methods

GorgonDebugExtensions.ValidateObject<T>(T, string)
GorgonNullExtensions.AsNullable<T>(object)
GorgonNullExtensions.IfNull<T>(object, T)
GorgonNullExtensions.IsNull(object)
  • Edit this page
  • View Source
In this article
Back to top Copyright 2023 - Licensed under the MIT license by Michael Winsor (Tape_Worm).
Send comments on this topic to the author