diff --git a/README.md b/README.md index 61bcb2a1..e04fc7c8 100644 --- a/README.md +++ b/README.md @@ -70,8 +70,10 @@ After that the script will output a list of all traits it could find, and asks y When you did this the script, will continue to ask you which trait should be the next layer. Imagine it like the different layers in Photoshop and you are selecting the order of those. -Next you will enter a name for all you files. -This names will be used in the Metadata as well as in the script to make weighting the traits easier. +The next input lets you decide if you want to use filenames as traits names, or to define custom names for each trait. + +If you selected the last option, you will enter a name for all you files. +These names will be used in the Metadata as well as in the script to make weighting the traits easier. Example: If you have a file name bg1.png the script will ask you to name it. If its just a white background you could name it "White". The next step is the weighting of your traits. diff --git a/bin/index.js b/bin/index.js index f5d86e50..f86cc369 100755 --- a/bin/index.js +++ b/bin/index.js @@ -27,6 +27,7 @@ let seen = []; let metaData = {}; let config = { metaData: {}, + useCustomNames: null, deleteDuplicates: null, generateMetadata: null, }; @@ -80,6 +81,7 @@ async function main() { loadingDirectories.succeed(); loadingDirectories.clear(); await traitsOrder(true); + await customNamesPrompt(); await asyncForEach(traits, async trait => { await setNames(trait); }); @@ -268,25 +270,49 @@ async function traitsOrder(isFirst) { await traitsOrder(false); } +//SELECT IF WE WANT TO SET CUSTOM NAMES FOR EVERY TRAITS OR USE FILENAMES +async function customNamesPrompt() { + if (config.useCustomNames !== null) return; + let { useCustomNames } = await inquirer.prompt([ + { + type: 'list', + name: 'useCustomNames', + message: 'How should be constructed the names of the traits?', + choices: [ + { name: 'Use filenames as traits names', value: 0 }, + { name: 'Choose custom names for each trait', value: 1 }, + ], + }, + ]); + config.useCustomNames = useCustomNames; +} + //SET NAMES FOR EVERY TRAIT async function setNames(trait) { - names = config.names || names; - const files = await getFilesForTrait(trait); - const namePrompt = []; - files.forEach((file, i) => { - if (config.names && config.names[file] !== undefined) return; - namePrompt.push({ - type: 'input', - name: trait + '_name_' + i, - message: 'What should be the name of the trait shown in ' + file + '?', + if (config.useCustomNames) { + names = config.names || names; + const files = await getFilesForTrait(trait); + const namePrompt = []; + files.forEach((file, i) => { + if (config.names && config.names[file] !== undefined) return; + namePrompt.push({ + type: 'input', + name: trait + '_name_' + i, + message: 'What should be the name of the trait shown in ' + file + '?', + }); }); - }); - const selectedNames = await inquirer.prompt(namePrompt); - files.forEach((file, i) => { - if (config.names && config.names[file] !== undefined) return; - names[file] = selectedNames[trait + '_name_' + i]; - }); - config.names = {...config.names, ...names}; + const selectedNames = await inquirer.prompt(namePrompt); + files.forEach((file, i) => { + if (config.names && config.names[file] !== undefined) return; + names[file] = selectedNames[trait + '_name_' + i]; + }); + config.names = {...config.names, ...names}; + } else { + const files = fs.readdirSync(basePath + '/' + trait); + files.forEach((file, i) => { + names[file] = file.split('.')[0]; + }); + } } //SET WEIGHTS FOR EVERY TRAIT