1
0
Fork 0

Added support for loading defaults from recipe

This commit is contained in:
Joost De Cock 2019-07-24 21:58:29 +02:00
parent 391894b5a3
commit 3a20d35b56
6 changed files with 41 additions and 12 deletions

View file

@ -1,7 +1,17 @@
import optionType from "../optionType";
const optionDefault = option => {
const optionDefault = (name, option, recipe) => {
let type = optionType(option);
let factor = type === "pct" ? 100 : 1;
// Default from recipe?
if (
recipe &&
typeof recipe.settings !== "undefined" &&
typeof recipe.settings.options !== "undefined" &&
typeof recipe.settings.options[name] !== "undefined"
)
return Math.round(10 * recipe.settings.options[name] * factor) / 10;
switch (type) {
case "constant":
return option;