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

tiny-export

v0.7.0

Published

Export tool for Tiny - Arduboy sprite and scene editor

Downloads

6

Readme

Tiny Export

Export tool for Tiny - Arduboy sprite and scene editor.

Install

mkdir thing
cd thing
npm init -f
npm intall tiny-export

Usage

Create config for your export:

// config.js
const path = require('path');

const root = __dirname;

module.exports =  {
  target: path.join(root, 'src'),
  cache:  {
    payload: path.join(root, 'payload-cache.json'),
    readable: path.join(root, 'payload-readable.json')
  },
  url: 'https://...your-app-id.cloudfunctions.net/export-project',
  token: 'token for project you want to export'
};

Create fetch.js which will fetch and cache locally your current project (sprites, scenes):

// fetch.js
let config = require('./config');
let { run } = require('tiny-export');

run(config, async runtime => {

  await runtime.fetch();

});

Run fetch:

node ./fetch.js

Create generate.js which will take cached json and generate C++ code:

// generate.js
let config = require('./config');
let { run } = require('tiny-export');
let path = require('path');

let local = filename => path.join(__dirname, filename);

run(config, async runtime => {

  let payload = await runtime.project();

  let pair = async (filename, props) => {
    let file = ext => runtime.render(local(`templates/${filename}.${ext}.ejs`), props);
    await Promise.all([
      runtime.write(`${filename}.cpp`, file('cpp')),
      runtime.write(`${filename}.h`, file('h'))
    ]);
  }

  await pair('tiny', payload);

});

For this example I'm generating tiny.cpp and tiny.h using tiny.cpp.ejs and tiny.h.ejs (which are identical for this example):

<%# templates/tiny.cpp.ejs %>
<%# templates/tiny.h.ejs %>
namespace Tiny {
  // Project: <%= title %>

  // Sprites
<% project.sprites.forEach(sprite => { %>
  // <%= sprite.index %>: <%= sprite.identifier %> <%= sprite.size.width %> <%= sprite.size.height %>
<% }) %>
}

Run generate:

node ./generate.js

For more decent export example, see https://github.com/ampatspell/tiny/tree/master/player/tiny/generate

API

Project

let project = runtime.project();
  • project.titleString
  • project.propertiesProperties
  • project.modelsArray<Sprite|Scene|Layer|Node>
  • project.spritesArray<Sprite>
  • project.scenesArray<Scene>

Entity

let project = runtime.project();
project.models.forEach(entity => {
  //
});
  • entity.idString
  • entity.typeString
  • entity.identifierString
  • entity.classifiedString
  • entity.indexNumber
  • entity.propertiesProperties

Sprite

let project = runtime.project();
project.sprites.forEach(sprite => {
  //
});
  • sprite.size{ width, height }
  • sprite.framesArray<Frame>
  • sprite.loopsArray<Loop>
  • sprite.toPlusMaskString()String

Frame

let project = runtime.project();
let sprite = project.sprites.byIdentifier('weirdo');
sprite.frames.forEach(frame => {
  //
});
  • frame.bytesBytes

Bytes

let project = runtime.project();
let frame = project.sprites.byIdentifier('weirdo').frames.byIdentifier('idle');
let bytes = frame.bytes;
  • bytes.size{ width, height }
  • bytes.rawArray<Number>
  • bytes.toPlusMaskString()String
  • bytes.toBitmapString()String

Loop

let project = runtime.project();
let sprite = project.sprites.byIdentifier('weirdo');
sprite.loops.forEach(loop => {
  //
});
  • loop.framesArray<Frame>
  • loop.toFrameIndexes()Array<Number>
  • loop.toFrameIndexesString()String

Scene

let project = runtime.project();
project.scenes.forEach(scene => {
  //
});
  • scene.backgroundblack, white, transparent
  • scene.nameString
  • scene.size{ width, height }
  • scene.layersArray<Layer>

Layer

let project = runtime.project();
let scene = project.sceneByIdentifier('01');
scene.layers.forEach(layer => {
  //
});
  • layer.identifierString
  • layer.typepixel, grid
  • layer.grid{ width, heigt } if type is grid
  • layer.nodesArray<Node>

Node

let project = runtime.project();
let scene = project.scenes.byIdentifier('01');
let layer = scene.layers.byIdentifier('background');
  • node.position{ x, y }
  • node.alignment{ horizontal: 'left', vertical: 'top' }
  • node.flip{ horizontal: false', vertical: false }
  • node.colorString (for fill type)
  • node.spriteSprite (for sprite/.. types)
  • node.frameFrame (for sprite/frame type)
  • node.loopLoop (for sprite/loop type)
  • node.invertBoolean (for sprite/.. type)
  • node.omitString (for sprite/.. type)

Properties

let project = runtime.project();
let properties = project.properties;
  • properties.allObject
  • properties.keysArray<String>
  • properties.get(key, defaultValue)any

Bytes

let width = 4;
let bytes = [ 0, 1, 2, 2, 2, 1, 0, 0 ];
//
//      y
//  0,0 | 0 1 2 3
// x -- +---------+
//    0 | 0 1 2 2 |
//    1 | 2 1 0 0 |
//      +---------+
//
export const Pixel = {
  transparent: 0,
  white: 1,
  black: 2
};