tiny-export
v0.7.0
Published
Export tool for Tiny - Arduboy sprite and scene editor
Downloads
8
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.title
→String
project.properties
→Properties
project.models
→Array<Sprite|Scene|Layer|Node>
project.sprites
→Array<Sprite>
project.scenes
→Array<Scene>
Entity
let project = runtime.project();
project.models.forEach(entity => {
//
});
entity.id
→String
entity.type
→String
entity.identifier
→String
entity.classified
→String
entity.index
→Number
entity.properties
→Properties
Sprite
let project = runtime.project();
project.sprites.forEach(sprite => {
//
});
sprite.size
→{ width, height }
sprite.frames
→Array<Frame>
sprite.loops
→Array<Loop>
sprite.toPlusMaskString()
→String
Frame
let project = runtime.project();
let sprite = project.sprites.byIdentifier('weirdo');
sprite.frames.forEach(frame => {
//
});
frame.bytes
→Bytes
Bytes
let project = runtime.project();
let frame = project.sprites.byIdentifier('weirdo').frames.byIdentifier('idle');
let bytes = frame.bytes;
bytes.size
→{ width, height }
bytes.raw
→Array<Number>
bytes.toPlusMaskString()
→String
bytes.toBitmapString()
→String
Loop
let project = runtime.project();
let sprite = project.sprites.byIdentifier('weirdo');
sprite.loops.forEach(loop => {
//
});
loop.frames
→Array<Frame>
loop.toFrameIndexes()
→Array<Number>
loop.toFrameIndexesString()
→String
Scene
let project = runtime.project();
project.scenes.forEach(scene => {
//
});
scene.background
→black
,white
,transparent
scene.name
→String
scene.size
→{ width, height }
scene.layers
→Array<Layer>
Layer
let project = runtime.project();
let scene = project.sceneByIdentifier('01');
scene.layers.forEach(layer => {
//
});
layer.identifier
→String
layer.type
→pixel
,grid
layer.grid
→{ width, heigt }
if type isgrid
layer.nodes
→Array<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.color
→String
(forfill
type)node.sprite
→Sprite
(forsprite/..
types)node.frame
→Frame
(forsprite/frame
type)node.loop
→Loop
(forsprite/loop
type)node.invert
→Boolean
(forsprite/..
type)node.omit
→String
(forsprite/..
type)
Properties
let project = runtime.project();
let properties = project.properties;
properties.all
→Object
properties.keys
→Array<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
};