node-scripts/utils.js
/**
 * Creates and array with all names of food, potions and relative items in their branches
 * 
 * @returns {string[]}
 */
Creates and array with all names of food, potions and relative items in their branches

@returns {string[]}
Creates and array with all names of food potions and relative items in their branches @returns { string [] }
function createArrayOfAllFoodAndPotions() {
  let allNames = [];
  let baseNames = getAllFoodAndPotionNames();
  let treeItems = fs.readFileSync('./static/jsonAutomatic/foodAndPotionsTreeItems.json');
  treeItems = JSON.parse(treeItems);
  for (let item of treeItems) {
    const addResoruces = (craftResources) => {
      if (Array.isArray(craftResources)) {
        craftResources.forEach(resource => allNames.push(resource['@uniquename']));
      } else {
        allNames.push(craftResources['@uniquename']);
      }
    };
    addResoruces(item.craftingrequirements.craftresource);
    if ('enchantments' in item) {
      const enchantment = item.enchantments.enchantment;
      if (Array.isArray(enchantment)) {
        enchantment.forEach(ench => addResoruces(ench.craftingrequirements.craftresource))
      } else {
        addResoruces(enchantment.craftingrequirements.craftresource)
      }
    }
  }
  const generateSubtiersUpTo = (baseName, highestSubtier) => {
    let names = [];
    for (let subtier = 0; subtier <= highestSubtier; subtier++) {
      names.push(`${baseName}${subtier > 0 ? '@' + subtier : ''}`);
    }
    return names;
  }
  baseNames.forEach((baseName) => {
    if (baseName.includes('POTION')) {
      allNames.push(...generateSubtiersUpTo(baseName, 1));
      return;
    }
    if (baseName.includes('MEAL')) {
      allNames.push(...generateSubtiersUpTo(baseName, 3));
      return;
    }
    allNames.push(baseName);
  });
  return allNames;
}
function createArrayOfAllFoodAndPotions ( ) { let allNames = [ ] ; let baseNames = getAllFoodAndPotionNames ( ) ; let treeItems = fs . readFileSync ( './static/jsonAutomatic/foodAndPotionsTreeItems.json' ) ; treeItems = JSON . parse ( treeItems ) ; for ( let item of treeItems ) { const addResoruces = ( craftResources ) => { if ( Array . isArray ( craftResources ) ) { craftResources . forEach ( resource => allNames . push ( resource [ '@uniquename' ] ) ) ; } else { allNames . push ( craftResources [ '@uniquename' ] ) ; } } ; addResoruces ( item . craftingrequirements . craftresource ) ; if ( 'enchantments' in item ) { const enchantment = item . enchantments . enchantment ; if ( Array . isArray ( enchantment ) ) { enchantment . forEach ( ench => addResoruces ( ench . craftingrequirements . craftresource ) ) } else { addResoruces ( enchantment . craftingrequirements . craftresource ) } } } const generateSubtiersUpTo = ( baseName , highestSubtier ) => { let names = [ ] ; for ( let subtier = 0 ; subtier <= highestSubtier ; subtier ++ ) { names . push ( ` ${ baseName } ${ subtier > 0 ? '@' + subtier : '' } ` ) ; } return names ; } baseNames . forEach ( ( baseName ) => { if ( baseName . includes ( 'POTION' ) ) { allNames . push ( ... generateSubtiersUpTo ( baseName , 1 ) ) ; return ; } if ( baseName . includes ( 'MEAL' ) ) { allNames . push ( ... generateSubtiersUpTo ( baseName , 3 ) ) ; return ; } allNames . push ( baseName ) ; } ) ; return allNames ; }
Creates and array with all names of food, potions and relative items in their branches
Creates and array with all names of food potions and relative items in their branches
// Push food and potions resources