From fa5c0dd75cb77722a193bfce2913c26a2cdb4025 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Mon, 9 Feb 2015 13:55:59 -0600 Subject: [PATCH] Added sprite task back in --- Gruntfile.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++-- package.json | 1 + 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 8ce1e4d575..0a7229f083 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -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'); diff --git a/package.json b/package.json index e4a95d0486..b51e51715f 100644 --- a/package.json +++ b/package.json @@ -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",