forked from krzysztof-o/spritesheet.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d99e21
commit 74bbdf9
Showing
15 changed files
with
262 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
node_modules | ||
npm-debug.log | ||
.idea | ||
*.iml | ||
export | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,48 @@ | ||
#!/usr/bin/env node | ||
module.exports = require('./lib/spritesheet'); | ||
var generator = require('./lib/generator'); | ||
var async = require('async'); | ||
|
||
module.exports = generate; | ||
|
||
if (!module.parent) { | ||
//todo: command line usage | ||
} | ||
} | ||
|
||
/** | ||
* generates spritesheet | ||
* @param {string[]} files path to image files | ||
* @param {object} options | ||
* @param {string} options.name name of the generated spritesheet | ||
* @param {string} options.path path to the generated spritesheet | ||
* @param {boolean} options.square texture should be square | ||
* @param {boolean} options.powerOfTwo texture's size (both width and height) should be a power of two | ||
* @param {function} callback | ||
*/ | ||
function generate(files, options, callback) { | ||
files = files.map(function (name) { | ||
return {name: name}; | ||
}); | ||
options = options || {}; | ||
options.imageFile = options.name + '.png'; | ||
options.dataFile = options.name + '.xml'; | ||
options.path = options.path ? options.path + '/' : ''; | ||
options.square = options.square || true; | ||
options.powerOfTwo = options.powerOfTwo || true; | ||
|
||
|
||
async.waterfall([ | ||
function (callback) { | ||
generator.getImagesSizes(files, callback); | ||
}, | ||
function (files, callback) { | ||
generator.determineCanvasSize(files, options, callback); | ||
}, | ||
function (options, callback) { | ||
generator.generateImage(files, options, callback); | ||
}, | ||
function (callback) { | ||
generator.generateData(files, options, callback); | ||
} | ||
], | ||
callback); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<TextureAtlas imagePath=""> | ||
|
||
<SubTexture name="/Users/Krzysztof/dev/projects/spritesheet.js/test/fixtures/50x50.jpg" x="0" y="0" width="50" height="50"/> | ||
|
||
<SubTexture name="/Users/Krzysztof/dev/projects/spritesheet.js/test/fixtures/100x100.jpg" x="0" y="0" width="100" height="100"/> | ||
|
||
<SubTexture name="/Users/Krzysztof/dev/projects/spritesheet.js/test/fixtures/200x200.jpg" x="0" y="0" width="200" height="200"/> | ||
|
||
<SubTexture name="/Users/Krzysztof/dev/projects/spritesheet.js/test/fixtures/500x500.jpg" x="0" y="0" width="500" height="500"/> | ||
|
||
</TextureAtlas> |
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
var generator = require('../lib/generator'); | ||
var expect = require('expect.js'); | ||
var fs = require('fs'); | ||
|
||
|
||
describe('generator', function () { | ||
|
||
describe('getImagesSizes', function () { | ||
it('should return image sizes', function (done) { | ||
var FILES = [ | ||
{name: __dirname + '/fixtures/50x50.jpg'}, | ||
{name: __dirname + '/fixtures/100x100.jpg'}, | ||
{name: __dirname + '/fixtures/200x200.jpg'}, | ||
{name: __dirname + '/fixtures/500x500.jpg'} | ||
]; | ||
|
||
generator.getImagesSizes(FILES, function (err, files) { | ||
expect(err).to.be(null); | ||
|
||
expect(files[0].width).to.equal(50); | ||
expect(files[0].height).to.equal(50); | ||
|
||
expect(files[1].width).to.equal(100); | ||
expect(files[1].height).to.equal(100); | ||
|
||
expect(files[2].width).to.equal(200); | ||
expect(files[2].height).to.equal(200); | ||
|
||
expect(files[3].width).to.equal(500); | ||
expect(files[3].height).to.equal(500); | ||
|
||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('determineCanvasSize', function () { | ||
var FILES = [ | ||
{name: __dirname + '/fixtures/50x50.jpg', width: 50, height: 50}, | ||
{name: __dirname + '/fixtures/100x100.jpg', width: 100, height: 100}, | ||
{name: __dirname + '/fixtures/200x200.jpg', width: 200, height: 200}, | ||
{name: __dirname + '/fixtures/500x500.jpg', width: 500, height: 500} | ||
]; | ||
|
||
it('should return square canvas', function (done) { | ||
var options = {square: true, powerOfTwo: false}; | ||
generator.determineCanvasSize(FILES, options, function (err) { | ||
expect(err).to.be(null); | ||
expect(options.width).to.equal(options.height); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('should return square canvas', function (done) { | ||
var options = {square: false, powerOfTwo: false}; | ||
generator.determineCanvasSize(FILES, options, function (err) { | ||
expect(err).to.be(null); | ||
expect(options.width).not.to.equal(options.height); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should return power of two', function (done) { | ||
var options = {square: false, powerOfTwo: true}; | ||
generator.determineCanvasSize(FILES, options, function (err) { | ||
expect(err).to.be(null); | ||
expect(options.width).to.equal(1024); | ||
expect(options.height).to.equal(512); | ||
done(); | ||
}); | ||
}); | ||
|
||
}); | ||
|
||
describe('generateImage', function () { | ||
var FILES = [ | ||
{name: __dirname + '/fixtures/50x50.jpg', width: 50, height: 50, x: 0, y: 0}, | ||
{name: __dirname + '/fixtures/100x100.jpg', width: 100, height: 100, x: 0, y: 0}, | ||
{name: __dirname + '/fixtures/200x200.jpg', width: 200, height: 200, x: 0, y: 0}, | ||
{name: __dirname + '/fixtures/500x500.jpg', width: 500, height: 500, x: 0, y: 0} | ||
]; | ||
|
||
it('should generate image file', function (done) { | ||
var options = {width: 100, height: 100, path: __dirname + '/', imageFile: 'test.png'}; | ||
generator.generateImage(FILES, options, function (err) { | ||
expect(err).to.be(null); | ||
expect(fs.existsSync(__dirname + '/test.png')).to.be.ok(); | ||
done(); | ||
}); | ||
}); | ||
|
||
after(function () { | ||
fs.unlinkSync(__dirname + '/test.png'); | ||
}); | ||
}); | ||
|
||
describe('generateData', function () { | ||
var FILES = [ | ||
{name: __dirname + '/fixtures/50x50.jpg', width: 50, height: 50, x: 0, y: 0}, | ||
{name: __dirname + '/fixtures/100x100.jpg', width: 100, height: 100, x: 0, y: 0}, | ||
{name: __dirname + '/fixtures/200x200.jpg', width: 200, height: 200, x: 0, y: 0}, | ||
{name: __dirname + '/fixtures/500x500.jpg', width: 500, height: 500, x: 0, y: 0} | ||
]; | ||
|
||
it('should generate data file', function (done) { | ||
var options = {path: __dirname + '/', dataFile: 'test.xml'}; | ||
generator.generateData(FILES, options, function (err) { | ||
expect(err).to.be(null); | ||
expect(fs.existsSync(__dirname + '/test.xml')).to.be.ok(); | ||
done(); | ||
}); | ||
}); | ||
|
||
after(function () { | ||
fs.unlinkSync(__dirname + '/test.xml'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
var spritesheet = require('../index'); | ||
var assert = require('assert'); | ||
var expect = require('expect.js'); | ||
var fs = require('fs'); | ||
|
||
describe('spritesheet.js', function () { | ||
|
||
it('should generate xml file', function (done) { | ||
spritesheet([__dirname + '/fixtures/100x100.jpg'], {name: 'test', path: __dirname}, function (err) { | ||
expect(err).to.be(null); | ||
expect(fs.existsSync(__dirname + '/test.xml')).to.be.ok(); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('should generate png file', function (done) { | ||
spritesheet([__dirname + '/fixtures/100x100.jpg'], {name: 'test', path: __dirname}, function (err) { | ||
expect(err).to.be(null); | ||
expect(fs.existsSync(__dirname + '/test.png')).to.be.ok(); | ||
done(); | ||
}); | ||
}); | ||
|
||
after(function () { | ||
fs.unlinkSync(__dirname + '/test.xml'); | ||
fs.unlinkSync(__dirname + '/test.png'); | ||
}); | ||
|
||
}); | ||
|
Oops, something went wrong.