Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use filenames instead of custom names for traits #14

Merged
merged 1 commit into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
58 changes: 42 additions & 16 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ let seen = [];
let metaData = {};
let config = {
metaData: {},
useCustomNames: null,
deleteDuplicates: null,
generateMetadata: null,
};
Expand Down Expand Up @@ -80,6 +81,7 @@ async function main() {
loadingDirectories.succeed();
loadingDirectories.clear();
await traitsOrder(true);
await customNamesPrompt();
await asyncForEach(traits, async trait => {
await setNames(trait);
});
Expand Down Expand Up @@ -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
Expand Down