Core Library - Varollo/aseprite-importer GitHub Wiki


Core Library

This section explains the installation process and use of the Core module of the Library.

1. Installation Process

There are many ways to install the package, here are some:

1.1 .NET CLI

Open your terminal of choice and past the following command:

dotnet add package AsepriteImporter

1.2 Package Manager

On Visual Studio, open the Package Manager Console.

Tools > NuGet Package Manager > Package Manager Console

Package Manager Console

And paste the following command:

NuGet\Install-Package AsepriteImporter

1.3 Package Reference

Edit your project file (.csproj) and paste this line:

<PackageReference Include="AsepriteImporter"/>

2. Loading the Sprite Sheet Data

First, don't forget to include the code bellow at the top your file:

using Varollo.AsepriteImporter;

When you want to load a sprite sheet data file, call the method LoadJsonData, on the AsepriteDataLoader static class, passing in the path to the .json file, like this:

const string PATH = "root/directory/data.json";

private AsepriteSheet LoadMyData()
{
    AsepriteSheet sheetData = AsepriteDataLoader.LoadJsonData(PATH);

    return sheetData;
}

This will load the file using System.IO and automatically parse it into a AsepriteSheet object using the Json.Net library, by Newtonsoft.

You can also opt to parse the data through a string containing the json, using the ParseJsonData method:

private AsepriteSheet LoadMyData()
{
    string json = LoadJsonInternally();

    AsepriteSheet sheetData = AsepriteDataLoader.ParseJsonData(json);

    return sheetData;
}

Documentation Page.

3. Reading the Frames of a Sprite Sheet Data

You can read the frame data deserialized into a AsepriteSheet object in three different ways:

3.1 Accessing the Frames Array

One way to access all frames in the sprite sheet, is through the property Frames, that stores in an Array the data for every frame in the sheet.

EXAMPLE:

private void LogFrameNames(AsepriteSheet sheet)
{
  foreach(AsepriteFrame frame in sheet.Frames)
  {
    System.Console.WriteLine(frame.Name);
  }
}

Documentation Page.

3.2 Using the frame Index

When you need to access a frame knowing its index in the sheet Frame array, the easiest way to get its information is through the AsepriteSheet indexer, passing in the frame index as a parameter.

EXAMPLE:

private void LogFirstFrameName(AsepriteSheet sheet)
{
  AsepriteFrame frame = sheet[0];
  System.Console.WriteLine(frame.Name);
}

Documentation Page.

3.3 Getting the Animation Frames by Name

To filter the frames of a specific animation, you can also use the AsepriteSheet indexer, this time, passing the Name of the animation.

You can find more information about grouping frames of the same animation here.

EXAMPLE:

private void LogFrameNamesOfAnimation(AsepriteSheet sheet, string animationName)
{
  foreach(AsepriteFrame frame in sheet[animationName])
  {
    System.Console.WriteLine(frame.Name);
  }
}

Documentation Page.

4. Checking if the Sprite Sheet includes an Animation

To check if the sprite sheet contains an animation of a certain name, the simplest way is through the AsepriteSheet method HasAnimation(string).

EXAMPLE:

private void LogTrueIfAnimationIsPresent(AsepriteSheet sheet, string animationName)
{
  System.Console.WriteLine(sheet.HasAnimation(animationName));
}

Documentation Page.

5. Accessing the Metadata

If your .json file contains Aseprite generated Metadata, and you need to retrieve any information from it, you can do so through the AsepriteSheet property MetaData.

More information about configuring the generated Metadata on Aseprite can be found on the Aseprite section.

EXAMPLE:

private void LogAsepriteVersion(AsepriteSheet sheet)
{
  System.Console.WriteLine(sheet.MetaData ?? "No metadata present...");
}

Documentation Page.

6. Full Documentation

To go more in depth about all the Core library's methods and classes, you may find the full documentation here.


By Varollo.

⚠️ **GitHub.com Fallback** ⚠️