Added sprite task back in

This commit is contained in:
Blade Barringer 2015-02-09 13:55:59 -06:00
parent ac4dbf6eec
commit fa5c0dd75c
2 changed files with 57 additions and 2 deletions

View file

@ -2,6 +2,57 @@
var _ = require('lodash');
module.exports = function(grunt) {
// Ported from shared
// So this sucks. Mobile Safari can't render image files > 1024x1024*3, so we have to break it down to multiple
// files in this hack approach. See https://github.com/Ensighten/grunt-spritesmith/issues/67#issuecomment-34786248
var images = grunt.file.expand('common/img/sprites/spritesmith/**/*.png');
// var totalDims = {width:0,height:0};
// _.each(images, function(img){
// var dims = sizeOf(img);
// if(!dims.width || !dims.height) console.log(dims);
// totalDims.width += dims.width;
// totalDims.height += dims.height;
// })
var COUNT = 6;//Math.ceil( (totalDims.width * totalDims.height) / (1024*1024*3) );
//console.log({totalDims:totalDims,COUNT:COUNT});
var sprite = {};
_.times(COUNT, function(i){
var sliced = images.slice(i * (images.length/COUNT), (i+1) * images.length/COUNT)
sprite[''+i] = {
src: sliced,
dest: 'common/dist/sprites/spritesmith'+i+'.png',
destCss: 'common/dist/sprites/spritesmith'+i+'.css',
engine: 'phantomjssmith',
algorithm: 'binary-tree',
padding:1,
cssTemplate: 'common/css/css.template.mustache',
cssVarMap: function (sprite) {
// For hair, skins, beards, etc. we want to output a '.customize-options.WHATEVER' class, which works as a
// 60x60 image pointing at the proper part of the 90x90 sprite.
// We set up the custom info here, and the template makes use of it.
if (sprite.name.match(/hair|skin|beard|mustach|shirt|flower/) || sprite.name=='head_0') {
sprite.custom = {
px: {
offset_x: "-" + (sprite.x + 25) + "px",
offset_y: "-" + (sprite.y + 15) + "px",
width: "" + 60 + "px",
height: "" + 60 + "px"
}
}
}
if (~sprite.name.indexOf('shirt'))
sprite.custom.px.offset_y = "-" + (sprite.y + 30) + "px"; // even more for shirts
}
/*,cssOpts: {
cssClass: function (item) {
return '.' + item.name; //'.sprite-' + item.name;
}
}*/
}
});
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
@ -37,9 +88,12 @@ module.exports = function(grunt) {
},
clean: {
build: ['website/build']
build: ['website/build'],
sprites: ['common/dist/sprites']
},
sprite: sprite,
stylus: {
build: {
options: {
@ -118,7 +172,6 @@ module.exports = function(grunt) {
logConcurrentOutput: true
}
}
});
//Load build files from public/manifest.json
@ -174,6 +227,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-nodemon');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-spritesmith');
grunt.loadNpmTasks('grunt-hashres');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('git-changelog');

View file

@ -26,6 +26,7 @@
"grunt-contrib-watch": "~0.6.1",
"grunt-hashres": "~0.4.1",
"grunt-nodemon": "~0.3.0",
"grunt-spritesmith": "~3.5.0",
"icalendar": "git://github.com/lefnire/node-icalendar#master",
"in-app-purchase": "^0.2.0",
"jade": "~1.7.0",