Adding ability to parse custom sizes from opts for wallpaper.

This commit is contained in:
Matt Swensen 2016-11-25 17:13:25 -07:00
parent 977917475f
commit 8e13998e2f

@ -1,8 +1,53 @@
import weightedRandom from './weighted-random';
import svg2png from 'svg2png';
const defaultBlockSize = 36;
const getSizesFromOptOrDefault = opt => {
if (opt) {
const unparsedSizes = Array.isArray(opt) ? opt : [opt];
return unparsedSizes.map(unparsedSize => {
const results = /(\d+)x(\d+)/.exec(unparsedSize)
if (results) {
const w = parseInt(results[1], 10);
const h = parseInt(results[2], 10);
const s = w / Math.round(w / defaultBlockSize);
return {
w: w,
h: h,
s: s,
};
}
else {
throw new Error(`Malformed resolution argument: ${unparsedSize}`);
}
});
}
else {
return [
{
w: 2880,
h: 1800,
s: defaultBlockSize,
},
{
w: 750,
h: 1334,
s: defaultBlockSize,
}
];
}
};
export const render = (colors, options) => {
try {
var sizes = getSizesFromOptOrDefault(options['themer-wallpaper-block-wave-size']);
}
catch(e) {
return [Promise.reject(e.message)];
}
const colorWeights = new Map([
['accent0', 1],
['accent1', 1],
@ -24,14 +69,6 @@ export const render = (colors, options) => {
const colorSets = [{ name: 'dark', colors: colors.dark }, { name: 'light', colors: colors.light }].filter(colorSet => !!colorSet.colors);
const sizes = [ // TODO: get from args with this and a device being the default
{
w: 2880,
h: 1800,
s: 36,
},
];
const deepFlatten = arr => arr.reduce((cumulative, inner) => cumulative.concat(Array.isArray(inner) ? deepFlatten(inner) : inner), []);
return deepFlatten(colorSets.map(colorSet => sizes.map(size => {