mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 17:23:02 +00:00
Generate a single feature-icons.json and feature-icons.css. In the JSON, features with a line icon are indicated by the presence of a `line` property. PresetIcon looks for this to determine whether or not to add the `preset-icon-line` class. New line icons may be added by editing line-icons.json.
51 lines
1.8 KiB
JavaScript
51 lines
1.8 KiB
JavaScript
var fs = require('fs');
|
|
var path = require('path');
|
|
var sprite = require('node-sprite');
|
|
var _ = require('../js/lib/lodash');
|
|
|
|
var makipath = './node_modules/maki';
|
|
var lineIcons = require('./line-icons.json');
|
|
|
|
sprite.sprite('renders', { path: makipath }, function(err, makiSprite) {
|
|
if (err) process.exit(1);
|
|
|
|
// Move image files
|
|
fs.renameSync(path.join(makipath, makiSprite.filename()), './dist/img/maki-sprite.png');
|
|
|
|
// Generate CSS
|
|
var template = '.feature-{name}{background-position:-{x}px -{y}px;}\n';
|
|
var css = "/* This file is generated by make. Do NOT edit manually. */\n\n";
|
|
css += ".preset-icon{background-image:url(img/maki-sprite.png);background-repeat:no-repeat;width:24px;height:24px;}\n";
|
|
css += ".preset-icon-line{background-image:url(img/line-presets.png);background-repeat:no-repeat;width:60px;height:60px;}\n";
|
|
|
|
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];
|
|
|
|
if (image.width === 24) {
|
|
css += template.replace('{name}', image.name.replace('-24', ''))
|
|
.replace('{x}', image.positionX)
|
|
.replace('{y}', image.positionY);
|
|
}
|
|
});
|
|
|
|
template = '.preset-icon-line.feature-{name}{background-position:-{x}px -{y}px;}\n';
|
|
|
|
_.forEach(lineIcons, function(position, name) {
|
|
css += template.replace('{name}', name)
|
|
.replace('{x}', position[0])
|
|
.replace('{y}', position[1]);
|
|
|
|
images[name] = images[name] || {};
|
|
images[name].line = position;
|
|
});
|
|
|
|
fs.writeFileSync('./css/feature-icons.css', css);
|
|
fs.writeFileSync('./data/feature-icons.json', JSON.stringify(images));
|
|
});
|