Git Product home page Git Product logo

dmisharp's Introduction

DMISharp
DMISharp

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.

dmisharp's People

Contributors

anturk avatar bobbah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

anturk

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.