src/muncher/import.js
// The monster setting is less vigorous!
The monster setting is less vigorous!
The monster setting is less vigorous!
async function looseItemNameMatch(item, items, loose = false, monster = false) {
  let matchingItem = items.find((matchItem) => {
    let activationMatch = false;
    const alternativeNames = (((matchItem.flags || {}).ddbimporter || {}).dndbeyond || {}).alternativeNames;
    const extraNames = (alternativeNames) ? matchItem.flags.ddbimporter.dndbeyond.alternativeNames : [];
    const itemActivationProperty = Object.prototype.hasOwnProperty.call(item.data, 'activation');
    const matchItemActivationProperty = Object.prototype.hasOwnProperty.call(item.data, 'activation');
    if (itemActivationProperty && item.data?.activation?.type == "") {
      activationMatch = true;
    } else if (matchItemActivationProperty && itemActivationProperty) {
      activationMatch = matchItemActivationProperty && itemActivationProperty;
    } else if (!itemActivationProperty) {
      activationMatch = true;
    }
    const nameMatch = item.name === matchItem.name || extraNames.includes(item.name);
    const isMatch = nameMatch && item.type === matchItem.type && activationMatch;
    return isMatch;
  });
  if (!matchingItem && monster) {
    matchingItem = items.find(
      (matchItem) => {
        const monsterNames = getMonsterNames(matchItem.name);
        const monsterMatch = (monsterNames.includes(item.name.toLowerCase())) &&
          MONSTER_TYPES.includes(matchItem.type) &&
          INVENTORY_TYPES.includes(item.type);
        return monsterMatch;
      });
  }
  if (!matchingItem && loose) {
    const looseNames = getLooseNames(item.name);
    matchingItem = items.find(
      (matchItem) =>
        (looseNames.includes(matchItem.name.toLowerCase()) || looseNames.includes(matchItem.name.toLowerCase().replace(" armor", ""))) &&
        INVENTORY_TYPES.includes(item.type) &&
        INVENTORY_TYPES.includes(matchItem.type)
    );
    if (!matchingItem) {
      matchingItem = items.find(
        (matchItem) => looseNames.includes(matchItem.name.split("(")[0].trim().toLowerCase())
      );
    }
  }
  return matchingItem;
}
async function looseItemNameMatch ( item , items , loose = false , monster = false ) { let matchingItem = items . find ( ( matchItem ) => { let activationMatch = false ; const alternativeNames = ( ( ( matchItem . flags || { } ) . ddbimporter || { } ) . dndbeyond || { } ) . alternativeNames ; const extraNames = ( alternativeNames ) ? matchItem . flags . ddbimporter . dndbeyond . alternativeNames : [ ] ; const itemActivationProperty = Object . prototype . hasOwnProperty . call ( item . data , 'activation' ) ; const matchItemActivationProperty = Object . prototype . hasOwnProperty . call ( item . data , 'activation' ) ; if ( itemActivationProperty && item . data ?. activation ?. type == "" ) { activationMatch = true ; } else if ( matchItemActivationProperty && itemActivationProperty ) { activationMatch = matchItemActivationProperty && itemActivationProperty ; } else if ( ! itemActivationProperty ) { activationMatch = true ; } const nameMatch = item . name === matchItem . name || extraNames . includes ( item . name ) ; const isMatch = nameMatch && item . type === matchItem . type && activationMatch ; return isMatch ; } ) ; if ( ! matchingItem && monster ) { matchingItem = items . find ( ( matchItem ) => { const monsterNames = getMonsterNames ( matchItem . name ) ; const monsterMatch = ( monsterNames . includes ( item . name . toLowerCase ( ) ) ) && MONSTER_TYPES . includes ( matchItem . type ) && INVENTORY_TYPES . includes ( item . type ) ; return monsterMatch ; } ) ; } if ( ! matchingItem && loose ) { const looseNames = getLooseNames ( item . name ) ; matchingItem = items . find ( ( matchItem ) => ( looseNames . includes ( matchItem . name . toLowerCase ( ) ) || looseNames . includes ( matchItem . name . toLowerCase ( ) . replace ( " armor" , "" ) ) ) && INVENTORY_TYPES . includes ( item . type ) && INVENTORY_TYPES . includes ( matchItem . type ) ) ; if ( ! matchingItem ) { matchingItem = items . find ( ( matchItem ) => looseNames . includes ( matchItem . name . split ( "(" ) [ 0 ] . trim ( ) . toLowerCase ( ) ) ) ; } } return matchingItem ; }
The monster setting is less vigorous!
The monster setting is less vigorous!
// first pass is a strict match // I can't remember why I added this. Maybe I was concerned about identical named items with // different activation times? // maybe I just want to check it exists? // causing issues so changed. // activationMatch = matchItem.data.activation.type === item.data.activation.type; // console.warn(`lose monster match ${item.name}`); // console.log(item); // console.log(items); // console.log(`matchItem ${matchItem.name}`); // console.log(monsterNames); // console.log(monsterMatch); // console.log(matchingItem); // lets go loosey goosey on matching equipment, we often get types wrong // super loose name match! // still no matching item, lets do a final pass