Gorgon
Show / Hide Table of Contents

Class GorgonSpriteCodecCommon

A base class containing common codec functionality.

Inheritance
object
GorgonSpriteCodecCommon
GorgonV1SpriteBinaryCodec
GorgonV2SpriteCodec
GorgonV3SpriteBinaryCodec
GorgonV3SpriteJsonCodec
Implements
IGorgonSpriteCodec
IGorgonGraphicsObject
IGorgonNamedObject
Inherited Members
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: Gorgon.IO
Assembly: Gorgon.IO.Gorgon2D.dll
Syntax
public abstract class GorgonSpriteCodecCommon : IGorgonSpriteCodec, IGorgonGraphicsObject, IGorgonNamedObject

Constructors

| Edit this page View Source

GorgonSpriteCodecCommon(Gorgon2D, string, string)

Initializes a new instance of the GorgonSpriteCodecCommon class.

Declaration
protected GorgonSpriteCodecCommon(Gorgon2D renderer, string name, string description)
Parameters
Type Name Description
Gorgon2D renderer

The renderer used for resource handling.

string name

The codec name.

string description

The friendly description for the codec.

Exceptions
Type Condition
ArgumentNullException

Thrown when the renderer, or the name parameter is null.

ArgumentEmptyException

Thrown when the name parameter is empty.

Fields

| Edit this page View Source

CurrentFileHeader

The ID for the file header for the most current version of the sprite format.

Declaration
public static readonly ulong CurrentFileHeader
Field Value
Type Description
ulong
| Edit this page View Source

CurrentVersion

The highest currently supported version for sprite serialization.

Declaration
public static readonly Version CurrentVersion
Field Value
Type Description
Version

Properties

| Edit this page View Source

CanDecode

Property to return whether or not the codec can decode sprite data.

Declaration
public abstract bool CanDecode { get; }
Property Value
Type Description
bool
| Edit this page View Source

CanEncode

Property to return whether or not the codec can encode sprite data.

Declaration
public abstract bool CanEncode { get; }
Property Value
Type Description
bool
| Edit this page View Source

Codec

Property to return the abbreviated name of the codec (e.g. PNG).

Declaration
public string Codec { get; }
Property Value
Type Description
string
| Edit this page View Source

CodecDescription

Property to return the friendly description of the format.

Declaration
public string CodecDescription { get; }
Property Value
Type Description
string
| Edit this page View Source

FileExtensions

Property to return the common file extensions for this codec.

Declaration
public IReadOnlyList<GorgonFileExtension> FileExtensions { get; }
Property Value
Type Description
IReadOnlyList<GorgonFileExtension>
| Edit this page View Source

Graphics

Property to return the graphics interface that built this object.

Declaration
public GorgonGraphics Graphics { get; }
Property Value
Type Description
GorgonGraphics
| Edit this page View Source

Renderer

Property to return the renderer used to create objects.

Declaration
public Gorgon2D Renderer { get; }
Property Value
Type Description
Gorgon2D
| Edit this page View Source

Version

Property to return the version of sprite data that the codec supports.

Declaration
public abstract Version Version { get; }
Property Value
Type Description
Version

Methods

| Edit this page View Source

FromFile(string, GorgonTexture2DView)

Function to read the sprite data from a file on the physical file system.

Declaration
public GorgonSprite FromFile(string filePath, GorgonTexture2DView overrideTexture = null)
Parameters
Type Name Description
string filePath

The path to the file to read.

GorgonTexture2DView overrideTexture

[Optional] The texture to use as an override for the sprite.

Returns
Type Description
GorgonSprite

A new GorgonSprite.

Exceptions
Type Condition
ArgumentNullException

Thrown when the filePath parameter is null.

ArgumentEmptyException

Thrown when the filePath parameter is empty.

NotSupportedException

This method is not supported by this codec.

| Edit this page View Source

FromStream(Stream, GorgonTexture2DView, int?)

Function to read the sprite data from a stream.

Declaration
public GorgonSprite FromStream(Stream stream, GorgonTexture2DView overrideTexture = null, int? byteCount = null)
Parameters
Type Name Description
Stream stream

The stream containing the sprite.

GorgonTexture2DView overrideTexture

[Optional] The texture to use as an override for the sprite.

int? byteCount

[Optional] The number of bytes to read from the stream.

Returns
Type Description
GorgonSprite

A new GorgonSprite.

Exceptions
Type Condition
ArgumentNullException

Thrown when the stream parameter is null.

GorgonException

Thrown if the stream is write only.

EndOfStreamException

Thrown if the current stream position, plus the size of the data exceeds the length of the stream.

NotSupportedException

This method is not supported by this codec.

| Edit this page View Source

GetAssociatedTextureName(Stream)

Function to retrieve the name of the associated texture.

Declaration
public string GetAssociatedTextureName(Stream stream)
Parameters
Type Name Description
Stream stream

The stream containing the texture data.

Returns
Type Description
string

The name of the texture associated with the sprite, or null if no texture was found.

Exceptions
Type Condition
ArgumentNullException

Thrown if the stream parameter is null

GorgonException

Thrown if the stream is write only.

EndOfStreamException

Thrown if the current stream position, plus the size of the data exceeds the length of the stream.

NotSupportedException

This method is not supported by this codec.

| Edit this page View Source

IsReadable(Stream)

Function to determine if the data in a stream is readable by this codec.

Declaration
public bool IsReadable(Stream stream)
Parameters
Type Name Description
Stream stream

The stream containing the data.

Returns
Type Description
bool

true if the data can be read, or false if not.

Exceptions
Type Condition
ArgumentNullException

Thrown when the stream parameter is null.

GorgonException

Thrown if the stream is write only.

EndOfStreamException

Thrown if the current stream position, plus the size of the data exceeds the length of the stream.

NotSupportedException

This method is not supported by this codec.

| Edit this page View Source

OnGetAssociatedTextureName(Stream)

Function to retrieve the name of the associated texture.

Declaration
protected abstract string OnGetAssociatedTextureName(Stream stream)
Parameters
Type Name Description
Stream stream

The stream containing the texture data.

Returns
Type Description
string

The name of the texture associated with the sprite, or null if no texture was found.

| Edit this page View Source

OnIsReadable(Stream)

Function to determine if the data in a stream is readable by this codec.

Declaration
protected abstract bool OnIsReadable(Stream stream)
Parameters
Type Name Description
Stream stream

The stream containing the data.

Returns
Type Description
bool

true if the data can be read, or false if not.

| Edit this page View Source

OnReadFromStream(Stream, int, GorgonTexture2DView)

Function to read the sprite data from a stream.

Declaration
protected abstract GorgonSprite OnReadFromStream(Stream stream, int byteCount, GorgonTexture2DView overrideTexture)
Parameters
Type Name Description
Stream stream

The stream containing the sprite.

int byteCount

The number of bytes to read from the stream.

GorgonTexture2DView overrideTexture

[Optional] The texture to assign to the sprite instead of the texture associated with the name stored in the file.

Returns
Type Description
GorgonSprite

A new GorgonSprite.

| Edit this page View Source

OnSaveToStream(GorgonSprite, Stream)

Function to save the sprite data to a stream.

Declaration
protected abstract void OnSaveToStream(GorgonSprite sprite, Stream stream)
Parameters
Type Name Description
GorgonSprite sprite

The sprite to serialize into the stream.

Stream stream

The stream that will contain the sprite.

| Edit this page View Source

Save(GorgonSprite, Stream)

Function to save the sprite data to a stream.

Declaration
public void Save(GorgonSprite sprite, Stream stream)
Parameters
Type Name Description
GorgonSprite sprite

The sprite to serialize into the stream.

Stream stream

The stream that will contain the sprite.

Exceptions
Type Condition
ArgumentNullException

Thrown when the sprite, or the stream parameter is null.

GorgonException

Thrown if the stream is read only.

NotSupportedException

This method is not supported by this codec.

| Edit this page View Source

Save(GorgonSprite, string)

Function to save the sprite data to a file on a physical file system.

Declaration
public void Save(GorgonSprite sprite, string filePath)
Parameters
Type Name Description
GorgonSprite sprite

The sprite to serialize into the file.

string filePath

The path to the file to write.

Exceptions
Type Condition
ArgumentNullException

Thrown when the filePath parameter is null.

ArgumentEmptyException

Thrown when the filePath parameter is empty.

NotSupportedException

This method is not supported by this codec.

Implements

IGorgonSpriteCodec
IGorgonGraphicsObject
IGorgonNamedObject

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