Polish spriting code

* Smaller make-sprite.json.
* Convert operation sprite data to JSON, eliminating
  fragile stylesheet grepping.
This commit is contained in:
John Firebaugh
2013-04-23 09:42:27 -07:00
parent 1021850300
commit d8751fad8d
8 changed files with 72 additions and 2448 deletions
+4 -2
View File
@@ -15,6 +15,7 @@ iD.data = {
path + 'data/presets/fields.json',
path + 'data/imperial.json',
path + 'data/maki-sprite.json',
path + 'data/operations-sprite.json',
path + 'data/locales.json',
path + 'dist/locales/en.json'
], d3.json, function (err, data) {
@@ -32,8 +33,9 @@ iD.data = {
},
imperial: data[8],
maki: data[9],
locales: data[10],
en: data[11]
operations: data[10],
locales: data[11],
en: data[12]
};
callback();
+1 -2383
View File
File diff suppressed because it is too large Load Diff
+14 -3
View File
@@ -7,9 +7,8 @@ var makipath = './node_modules/maki';
sprite.sprite('renders', { path: makipath }, function(err, makiSprite) {
if (err) process.exit(1);
// Move image and json files
// Move image files
fs.renameSync(path.join(makipath, makiSprite.filename()), './dist/img/maki-sprite.png');
fs.renameSync(path.join(makipath, 'renders.json'), './data/maki-sprite.json');
// Generate CSS
var template = '.maki-{name}{background-position:{x} {y};width:{w};height:{h};}\n';
@@ -24,6 +23,18 @@ sprite.sprite('renders', { path: makipath }, function(err, makiSprite) {
.replace('{w}', image.width + 'px')
.replace('{h}', image.height + 'px');
});
fs.writeFileSync('./css/maki-sprite.css', css);
// Generate JSON
var images = {};
makiSprite.images.forEach(function(image) {
var match = image.name.match(/(.*)-(12|18|24)/),
name = match[1],
size = match[2],
group = images[name] = images[name] || {};
group[size] = [image.positionX, image.positionY];
});
fs.writeFileSync('./data/maki-sprite.json', JSON.stringify(images));
});
+25
View File
@@ -0,0 +1,25 @@
{
"icon-operation-delete": [0, 140],
"icon-operation-circularize": [20, 140],
"icon-operation-straighten": [40, 140],
"icon-operation-split": [60, 140],
"icon-operation-disconnect": [80, 140],
"icon-operation-reverse": [100, 140],
"icon-operation-move": [120, 140],
"icon-operation-merge": [140, 140],
"icon-operation-orthogonalize": [160, 140],
"icon-operation-rotate": [180, 140],
"icon-operation-simplify": [200, 140],
"icon-operation-disabled-delete": [0, 160],
"icon-operation-disabled-circularize": [20, 160],
"icon-operation-disabled-straighten": [40, 160],
"icon-operation-disabled-split": [60, 160],
"icon-operation-disabled-disconnect": [80, 160],
"icon-operation-disabled-reverse": [100, 160],
"icon-operation-disabled-move": [120, 160],
"icon-operation-disabled-merge": [140, 160],
"icon-operation-disabled-orthogonalize": [160, 160],
"icon-operation-disabled-rotate": [180, 160],
"icon-operation-disabled-simplify": [200, 160]
}