Gondwana Game Engine Development (master) - 2.6.1
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
Gondwana.Assets.AssetsFile Class Referencesealed

Represents an asset file used by the engine, providing functionality to load, manage, and save assets. More...

Inheritance diagram for Gondwana.Assets.AssetsFile:

Public Member Functions

void Add (AssetTypes type, string name, Func< Stream > streamFactory)
 Adds an asset file entry to the collection with the specified type, name, and stream factory.
void Add (AssetTypes type, string filePath, string? name=null)
 Adds an asset file to the engine with the specified type and file path.
void Add (AssetTypes type, string name, Stream stream)
 Adds an asset file entry to the collection with the specified type, name, and source stream.
void Remove (AssetTypes type, string name)
 Removes the specified asset file entry from the collection.
Stream? Get (AssetTypes type, string name)
 Retrieves a stream for the specified asset type and name.
IEnumerable< AssetsFileEntry > GetAllEntries ()
 Retrieves all entries from the asset file.
void Save ()
 Saves the current set of entries to a zip file at the specified file path.
void Dispose ()
 Releases all resources used by the AssetsFile instance.

Static Public Member Functions

static void ClearAll ()
 Releases all assets held by the application and clears the internal collection of asset files.
static void Validate (string path, string? password=null, bool testData=true)
 Strictly validates an existing bundle's entry keys and archive integrity. Unlike runtime loading, rejects unrecognized and duplicate entries.
static AssetsFile LoadOrCreate (string path, string? password=null, bool encrypt=false)
 Loads an existing asset file from the specified path or creates a new one if the file does not exist.
static AssetsFile LoadOrCreate (string path, string? password, bool encrypt, bool register)
 Loads or creates an asset file, optionally without adding it to the runtime collection. Authoring hosts can own detached packages without changing runtime state.
static AssetsFile Load (Stream stream, string? password=null, bool register=true)
 Loads an existing asset file from a readable stream.
static AssetsFile Load (Stream stream, string? password, bool register, string? sourcePath)
 Loads a buffered archive with an optional reconstructible source path.

Properties

static IReadOnlyList< AssetsFile > AllAssetsFiles [get]
 Gets a read-only list of registered AssetsFile instances.
string FilePath = string.Empty [get]
 Gets the file path associated with the current instance.
string? Password [get]
 Gets the password associated with the current instance.
bool UseEncryption [get]
 Gets a value indicating whether encryption is enabled for the current operation.
string? SourcePath [get]
 Gets the archive's reconstructible origin, including an optional stream origin.
Stream? this[AssetTypes type, string name] [get]
 Gets the stream associated with the specified asset type and name.

Detailed Description

Represents an asset file used by the engine, providing functionality to load, manage, and save assets.

The AssetsFile class allows for the creation, loading, and management of asset files used by the engine. It supports encryption, asset retrieval by type and name, and saving assets to a zip file. Instances are registered by default and can be accessed via the static AllAssetsFiles property.

Definition at line 17 of file AssetsFile.cs.

Member Function Documentation

◆ Add() [1/3]

void Gondwana.Assets.AssetsFile.Add ( AssetTypes type,
string filePath,
string? name = null )

Adds an asset file to the engine with the specified type and file path.

The asset is stored using its full file name, including extension, unless an explicit name is provided.

Parameters
typeThe type of the asset file to add.
filePathThe full path to the asset file. Must not be null or empty.
nameThe name to use for the asset file. If null, the file name will be used.

Definition at line 320 of file AssetsFile.cs.

◆ Add() [2/3]

void Gondwana.Assets.AssetsFile.Add ( AssetTypes type,
string name,
Func< Stream > streamFactory )

Adds an asset file entry to the collection with the specified type, name, and stream factory.

If an entry with the same type and name already exists, it will be replaced with the new stream data. The provided factory is invoked immediately and its contents are buffered in memory.

Parameters
typeThe type of the asset file to add.
nameThe name of the asset file to add. Cannot be null or empty.
streamFactoryA factory method that provides a Stream for the asset file.

Definition at line 300 of file AssetsFile.cs.

◆ Add() [3/3]

void Gondwana.Assets.AssetsFile.Add ( AssetTypes type,
string name,
Stream stream )

Adds an asset file entry to the collection with the specified type, name, and source stream.

The provided stream is read immediately and buffered in memory. Subsequent access returns a new read-only stream over the buffered bytes.

Parameters
typeThe type of the asset file to add.
nameThe name of the asset file to add. Cannot be null or empty.
streamThe source stream containing the asset data. Must be readable.
Exceptions
ArgumentNullExceptionThrown if stream is null.
ArgumentExceptionThrown if name is null or empty.

Definition at line 342 of file AssetsFile.cs.

◆ ClearAll()

void Gondwana.Assets.AssetsFile.ClearAll ( )
static

Releases all assets held by the application and clears the internal collection of asset files.

Definition at line 29 of file AssetsFile.cs.

◆ Dispose()

void Gondwana.Assets.AssetsFile.Dispose ( )

Releases all resources used by the AssetsFile instance.

Definition at line 494 of file AssetsFile.cs.

◆ Get()

Stream? Gondwana.Assets.AssetsFile.Get ( AssetTypes type,
string name )

Retrieves a stream for the specified asset type and name.

Attempts exact match first, then falls back to base-name matching without extension.

Parameters
typeThe type of the asset to retrieve.
nameThe name of the asset to retrieve. May include or omit the file extension.
Returns
A Stream containing the asset data if a match is found; otherwise, null.

Definition at line 406 of file AssetsFile.cs.

◆ GetAllEntries()

IEnumerable< AssetsFileEntry > Gondwana.Assets.AssetsFile.GetAllEntries ( )

Retrieves all entries from the asset file.

Returns
An IEnumerable<T> containing all entries in the asset file.

Definition at line 440 of file AssetsFile.cs.

◆ Load() [1/2]

AssetsFile Gondwana.Assets.AssetsFile.Load ( Stream stream,
string? password,
bool register,
string? sourcePath )
static

Loads a buffered archive with an optional reconstructible source path.

Parameters
streamThe readable archive stream.
passwordThe optional archive password.
registerWhether to register the archive.
sourcePathA path identifying the stream origin. Does not open or write that path.
Returns
The buffered archive.

Definition at line 144 of file AssetsFile.cs.

◆ Load() [2/2]

AssetsFile Gondwana.Assets.AssetsFile.Load ( Stream stream,
string? password = null,
bool register = true )
static

Loads an existing asset file from a readable stream.

The stream is consumed immediately and is not retained or disposed by the returned AssetsFile. Archive contents are buffered in memory, so the caller may dispose the source stream as soon as this method returns.

Parameters
streamThe stream containing the GAF archive.
passwordThe optional archive password.
registerWhether to add this instance to AllAssetsFiles.
Returns
The loaded package, owned by the caller.

◆ LoadOrCreate() [1/2]

AssetsFile Gondwana.Assets.AssetsFile.LoadOrCreate ( string path,
string? password,
bool encrypt,
bool register )
static

Loads or creates an asset file, optionally without adding it to the runtime collection. Authoring hosts can own detached packages without changing runtime state.

Parameters
pathThe asset file path to load or create.
passwordThe optional archive password.
encryptWhether saves use encryption.
registerWhether to add this instance to AllAssetsFiles.
Returns
The loaded or newly created package, owned by the caller.

Definition at line 96 of file AssetsFile.cs.

◆ LoadOrCreate() [2/2]

AssetsFile Gondwana.Assets.AssetsFile.LoadOrCreate ( string path,
string? password = null,
bool encrypt = false )
static

Loads an existing asset file from the specified path or creates a new one if the file does not exist.

Parameters
pathThe file path of the asset file to load or create. Cannot be null, empty, or whitespace.
passwordAn optional password used to secure the asset file. Can be null if no password is required.
encryptA value indicating whether the asset file should use encryption. Defaults to false.
Returns
An AssetsFile instance representing the loaded or newly created asset file.
Exceptions
ArgumentExceptionThrown if path is null, empty, or consists only of whitespace.

◆ Remove()

void Gondwana.Assets.AssetsFile.Remove ( AssetTypes type,
string name )

Removes the specified asset file entry from the collection.

Parameters
typeThe type of the asset file to remove.
nameThe name of the asset file to remove. Cannot be null or empty.

Definition at line 371 of file AssetsFile.cs.

◆ Save()

void Gondwana.Assets.AssetsFile.Save ( )

Saves the current set of entries to a zip file at the specified file path.

Definition at line 449 of file AssetsFile.cs.

◆ Validate()

void Gondwana.Assets.AssetsFile.Validate ( string path,
string? password = null,
bool testData = true )
static

Strictly validates an existing bundle's entry keys and archive integrity. Unlike runtime loading, rejects unrecognized and duplicate entries.

Parameters
pathExisting bundle to inspect.
passwordOptional password for protected entries.
testDataWhether to decompress and verify all payload data; false checks structure and keys only.

Definition at line 50 of file AssetsFile.cs.

Property Documentation

◆ AllAssetsFiles

IReadOnlyList<AssetsFile> Gondwana.Assets.AssetsFile.AllAssetsFiles
staticget

Gets a read-only list of registered AssetsFile instances.

Definition at line 24 of file AssetsFile.cs.

◆ FilePath

string Gondwana.Assets.AssetsFile.FilePath = string.Empty
get

Gets the file path associated with the current instance.

Definition at line 172 of file AssetsFile.cs.

◆ Password

string? Gondwana.Assets.AssetsFile.Password
get

Gets the password associated with the current instance.

Definition at line 178 of file AssetsFile.cs.

◆ SourcePath

string? Gondwana.Assets.AssetsFile.SourcePath
get

Gets the archive's reconstructible origin, including an optional stream origin.

File-backed archives use FilePath. Anonymous streams have no source path.

Definition at line 189 of file AssetsFile.cs.

◆ this[AssetTypes type, string name]

Stream? Gondwana.Assets.AssetsFile.this[AssetTypes type, string name]
get

Gets the stream associated with the specified asset type and name.

Parameters
typeThe type of the asset file to retrieve.
nameThe name of the asset within the specified type.
Returns
A readable stream if found; otherwise, null.

Definition at line 393 of file AssetsFile.cs.

◆ UseEncryption

bool Gondwana.Assets.AssetsFile.UseEncryption
get

Gets a value indicating whether encryption is enabled for the current operation.

Definition at line 184 of file AssetsFile.cs.