npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@v0rt4c/spr

v0.1.1

Published

This is a module that can read/write tibia .SPR files. Supported versions 3.0 -> 10.56

Downloads

1

Readme

@v0rt4c/spr

This library can (parse/read) and write binary .SPR files from Tibia. Supported .SPR versions are those that came included in Tibia clients 3.0 -> 10.56. The library is primarily intended to be used as a tool when building applications that work with these .SPR binary files. No external dependencies are needed and the library should work on NodeJS, in the browser and Deno.

https://spreditor.online is an example of an application that uses this library to read, edit & compile .SPR files.

With this library alone you cannot convert the sprites into actual image files like .PNG or .BMP. However, with the parsed data that this library gives you (like the RGBA arrays) you can easily create this functionality yourself.

How to use:

[Functions]

read

@Params

buffer - (Uint8Array)
cb - (Callback function)

Returns:

{ 
    signature: number,
    count: number,
    sprites: Array<{
        id: number,
        rgba: Uint8Array
    }>
} 

The read function takes 2 parameters:

buffer

The buffer param is the actual sprite file buffer. It has to be an Uint8Array. Uint8Array was chosen for compatability between NodeJS, Browsers & Deno. You can load the buffer into your app however you'd like.

cb

The cb param is a callback function. It is used to receive updates about the read process. The callback function will be executed each time a sprite has been parsed. It receives one argument with information about the status of the read process. The info object looks like this:

{
    reading: number; // Current sprite id being read
    total: number;   // Total nr of sprites
    progressPercent: number;
}

NodeJS example

const { read } = require('@ot/spr');
const fs = require('fs');

const sprBuffer = fs.readFileSync('./Tibia.spr');
const parsedSPR = read(new Uint8Array(spr.buffer));
console.log(parsedSPR);

Parsed result:

{
  signature: 1102703238,
  count: 9999,
  sprites: [
    { id: 1, rgba: [Uint8Array] },
    { id: 2, rgba: [Uint8Array] },
    { id: 3, rgba: [Uint8Array] },
    { id: 4, rgba: [Uint8Array] },
    { id: 5, rgba: [Uint8Array] },
    { id: 6, rgba: [Uint8Array] }
    ...
    ...
    ...
  ]
}

compress

This function is used to compress the rgba arrays of each sprite back into their original compressed format.
You should use this function before writing the sprites back to a .SPR file.

@Params

data - Array<{ id: number; rgba: Uint8Array}>
cb - (Callback function)

Returns:

[
    { id: number, cPixels: Uint8Array },
    ...
    ...
    ...
]

NodeJS example

const { read, compress } = require('@ot/spr');
const fs = require('fs');

const sprBuffer = fs.readFileSync('./Tibia.spr');
const parsedSPR = read(new Uint8Array(spr.buffer));
const compressedSPRS = compress(parsedSPR.sprites);
console.log(compressedSPRS);

Parsed result:

[
    { id: 1, cPixels: Uint8Array },
    { id: 2, cPixels: Uint8Array },
    { id: 3, cPixels: Uint8Array },
    { id: 4, cPixels: Uint8Array },
    { id: 5, cPixels: Uint8Array },
    { id: 6, cPixels: Uint8Array },
    ...
    ...
    ...
]

write

@Params

signature - (number)
version - (number)
data - Array<{ id: number, cPixels: Uint8Array }>
cb - (Callback function)

Returns:
The new .SPR buffer in a Uint8Array. It's up to you how you save it to disk.

NodeJS example

const { read, compress, write } = require('@ot/spr');
const fs = require('fs');

const sprBuffer = fs.readFileSync('./Tibia.spr');
const parsedSPR = read(new Uint8Array(spr.buffer));
const compressedSPRS = compress(parsedSPR.sprites);
const newSPRbuffer = write(compressedSPRS);
fs.writeFileSync('Tibia.spr', newSPRbuffer);