DMISharp 2.1.0

Prefix Reserved
dotnet add package DMISharp --version 2.1.0                
NuGet\Install-Package DMISharp -Version 2.1.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DMISharp" Version="2.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DMISharp --version 2.1.0                
#r "nuget: DMISharp, 2.1.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DMISharp as a Cake Addin
#addin nuget:?package=DMISharp&version=2.1.0

// Install DMISharp as a Cake Tool
#tool nuget:?package=DMISharp&version=2.1.0                

<h1 align="center"> <img src="./dmisharp.png" alt="DMISharp" width="256"/> <br/> DMISharp </h1>

DMISharp is a .NET 8.0 library for easily interacting with the BYOND DMI file format.

Developed with ease-of-use in mind, this library provides a simple means for importing, modifying, and exporting DMI files. Internally, images are handled using ImageSharp, a fantastic open-source library from SixLabors.

Installation

Install the current stable release from Nuget.

NuGet

Getting Started

Important things to note:

  • Always dispose DMIFile / DMIState objects. They use unmanaged memory for their sprites.

Ingesting a DMI file from a path:

using var file = new DMIFile("test.dmi")
// do cool things

Ingesting a DMI file from a stream:

// Getting a memory stream from a database with the DMI file's data in the response
using var dmiData = database.GetFile("test.dmi")
using var file = new DMIFile(dmiData)
// do more cool things

Sorting a DMI file's states alphabetically, and saving the resulting DMI file:

using var file = new DMIFile("unsorted_states.dmi")
file.SortStates();
file.Save("sorted_states.dmi");

Sorting a DMI file's states using a provided comparer, and saving the resulting DMI file to a memory stream:

using var stream = new MemoryStream()
using var file = new DMIFile("unsorted_states.dmi")
file.SortStates(new CoolCustomComparer());
file.Save(stream);

Creating a new DMI file with 32x32 pixel states, and creating 3 states from 3 source images:

using var newDMI = new DMIFile(32, 32)
var sourceData = new List<string>() { "sord", "sordvert", "steve32" };

foreach (var source in sourceData)
{
    var img = Image.Load<Rgba32>($@"Data/Input/SourceImages/{source}.png");
    var newState = new DMIState(source, DirectionDepth.One, 1, 32, 32);
    newState.SetFrame(img, 0);
    newDMI.AddState(newState);
}

newDMI.Save(@"Data/Output/minecraft.dmi");

Creating a new DMI file with 32x32 pixel states, creating a state, and then modifying that state's frame and direction depth:

using var newDMI = new DMIFile(32, 32)

// Create state
var img = Image.Load<Rgba32>($@"Data/Input/SourceImages/steve32.png");
var newState = new DMIState("steve32", DirectionDepth.One, 1, 32, 32);
newState.SetFrame(img, 0);
newDMI.AddState(newState);

// Modifying state
newDMI.States.First().SetDirectionDepth(DirectionDepth.Four);
newDMI.States.First().SetFrameCount(10);

// At this point you would add the new frames for each direction, otherwise
// you cannot save the file.

// Saving
newDMI.Save(@"Data/Output/minecraft.dmi");

Questions?

Feel free to contact me on Discord at @bobbahbrown with any questions or concerns. Additionally, I can be found in the /tg/station discord server.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.0 131 7/22/2024
2.0.2 293 7/8/2023
2.0.2-alpha.1 84 7/7/2023
2.0.1 162 7/7/2023
2.0.0 179 7/7/2023
1.7.0 79,927 3/13/2022
1.6.2 465 3/15/2021
1.6.1 374 3/10/2021
1.6.0 365 3/10/2021
1.5.1 377 1/18/2021
1.5.0 391 11/27/2020
1.4.1 617 11/5/2019
1.4.0 533 10/9/2019
1.3.4 551 10/8/2019
1.3.3 547 10/4/2019
1.3.2 550 10/4/2019
1.3.1 539 10/4/2019
1.2.1 534 10/4/2019
1.1.2 624 6/29/2019
1.1.0 594 6/29/2019
1.0.2 572 6/29/2019

See notes for this release on GitHub: https://github.com/bobbahbrown/DMISharp/releases/tag/2.1.0