Template:Disambiguation/doc: Difference between revisions

m
Cleaned up script a bit, removed Menu template
(Added Menu to the bottom of the template. Excluded modded items)
m (Cleaned up script a bit, removed Menu template)
Line 8: Line 8:
<syntaxhighlight lang="javascript" line>
<syntaxhighlight lang="javascript" line>
// Settings //
// Settings //
let searchTerm = 'Siren'; // The proper capitalization of the search term
let searchTerm = 'Ancient'; // The proper capitalization of the search term
let returnEquipmentTemplate = false; // true returns a template for {{EquipmentTableFromList}} instead
let returnEquipmentTemplate = false; // returns a template for {{EquipmentTableFromList}} instead
// End of Settings //
// End of Settings //
let lcSearchTerm = searchTerm.toLowerCase();
const search = (item) => !item.isModded && item.name.toLowerCase().includes(searchTerm.toLowerCase());
const search = (obj) => !obj.isModded && obj.name?.toLowerCase().includes(lcSearchTerm);
const wikiIcon = (item, icon, extras) => {
const wikiIcon = (obj, icon, extras) => {
if (!returnEquipmentTemplate)
if (!returnEquipmentTemplate)
return `*${obj.namespace?.includes('TotH') ? '{{TotH}}' : obj.namespace?.includes('AoD') ? '{{AoD}}' : ''}{{${icon}|${obj.name}${extras}}}`;
return `*${item.namespace.includes('TotH') ? '{{TotH}}' : item.namespace.includes('AoD') ? '{{AoD}}' : item.namespace.includes('ItA') ? '{{ItA}}' : ''}{{${icon}|${item.name}${extras}}}`;
else
return item.name;
return obj.name;
}
}
const pushResults = (obj) => {
const pushResults = (arr, header, icon, extras='') => {
if (obj.arr.length > 0 && !returnEquipmentTemplate && !results.includes(obj.header))
if (arr.length > 0 && !returnEquipmentTemplate && !results.includes(header))
results.push(obj.header);
results.push(header);
obj.arr.forEach(item => {
arr.forEach(item => {
if (!returnEquipmentTemplate || item.validSlots !== undefined)
if (!returnEquipmentTemplate || item.validSlots !== undefined)
results.push(wikiIcon(item, obj.iconType, obj.extras || ''));
results.push(wikiIcon(item, icon, extras));
});
});
}
}
Line 30: Line 28:
if (returnEquipmentTemplate) results.push(`{{V|${gameVersion.substr(1)}}}\n\n==${searchTerm} Equipment==\n===Melee Weapons===\n{{EquipmentTableFromList\n\n}}\n===Ranged Weapons and Ammo===\n{{EquipmentTableFromList\n\n}}\n===Armour===\n{{EquipmentTableFromList`);
if (returnEquipmentTemplate) results.push(`{{V|${gameVersion.substr(1)}}}\n\n==${searchTerm} Equipment==\n===Melee Weapons===\n{{EquipmentTableFromList\n\n}}\n===Ranged Weapons and Ammo===\n{{EquipmentTableFromList\n\n}}\n===Armour===\n{{EquipmentTableFromList`);
if (!returnEquipmentTemplate) results.push(`{{Disam}}{{V|${gameVersion.substr(1)}}}\n`, `'''${searchTerm}''' may refer to:`);
if (!returnEquipmentTemplate) results.push(`{{Disam}}{{V|${gameVersion.substr(1)}}}\n`, `'''${searchTerm}''' may refer to:`);
pushResults({arr: game.items.weapons.filter(x => search(x) && !x.validSlots.includes('Quiver')), header: '===Equipment===', iconType: 'ItemIcon'});
pushResults(game.items.weapons.filter(x => search(x) && !x.validSlots.includes('Quiver')), '===Equipment===', 'ItemIcon');
pushResults({arr: game.items.equipment.filter(x => search(x) && x.validSlots.includes('Quiver')), header: '===Equipment===', iconType: 'ItemIcon'});
pushResults(game.items.equipment.filter(x => search(x) && x.validSlots.includes('Quiver')), '===Equipment===', 'ItemIcon');
pushResults({arr: game.items.equipment.filter(x => search(x) && !(x instanceof WeaponItem) && !x.validSlots.includes('Quiver')), header: '===Equipment===', iconType: 'ItemIcon'});
pushResults(game.items.equipment.filter(x => search(x) && !(x instanceof WeaponItem) && !x.validSlots.includes('Quiver')), '===Equipment===', 'ItemIcon');
pushResults({arr: game.items.filter(x => x.validSlots === undefined && !(x instanceof OpenableItem) && !(x instanceof BoneItem) && !(x instanceof FoodItem) && search(x)), header: '===Items===', iconType: 'ItemIcon'});
pushResults(game.items.filter(x => x.validSlots === undefined && !(x instanceof OpenableItem) && !(x instanceof BoneItem) && !(x instanceof FoodItem) && search(x)), '===Items===', 'ItemIcon');
pushResults({arr: game.items.openables.filter(x => search(x)), header: '===Openables===', iconType: 'ItemIcon'});
pushResults(game.items.openables.filter(x => search(x)), '===Openables===', 'ItemIcon');
pushResults({arr: game.items.bones.filter(x => search(x)), header: '===Bones===', iconType: 'ItemIcon'});
pushResults(game.items.bones.filter(x => search(x)), '===Bones===', 'ItemIcon');
pushResults({arr: game.items.food.filter(x => search(x)), header: '===Food===', iconType: 'ItemIcon'});
pushResults(game.items.food.filter(x => search(x)), '===Food===', 'ItemIcon');
pushResults({arr: game.monsters.filter(x => search(x)), header: '===Combat===', iconType: 'MonsterIcon'});
pushResults(game.monsters.filter(x => search(x)), '===Combat===', 'MonsterIcon');
pushResults({arr: [...game.combatAreas.allObjects, ...game.slayerAreas.allObjects, ...game.dungeons.allObjects].filter(x => search(x)), header: '===Combat===', iconType: 'ZoneIcon'});
pushResults([...game.combatAreas.allObjects, ...game.slayerAreas.allObjects, ...game.dungeons.allObjects].filter(x => search(x)), '===Combat===', 'ZoneIcon');
pushResults({arr: [...game.standardSpells.allObjects, ...game.ancientSpells.allObjects, ...game.archaicSpells.allObjects, ...game.curseSpells.allObjects, ...game.auroraSpells.allObjects].filter(x => search(x)), header: '===Spells===', iconType: 'SpellIcon'});
pushResults([...game.standardSpells.allObjects, ...game.ancientSpells.allObjects, ...game.archaicSpells.allObjects, ...game.curseSpells.allObjects, ...game.auroraSpells.allObjects].filter(x => search(x)), '===Spells===', 'SpellIcon');
pushResults({arr: game.shop.purchases.filter(x => search(x)), header: '===Purchases===', iconType: 'UpgradeIcon'});
pushResults(game.shop.purchases.filter(x => search(x)), '===Purchases===', 'UpgradeIcon');
pushResults({arr: game.prayers.filter(x => search(x)), header: '===Prayers===', iconType: 'PrayerIcon'});
pushResults(game.prayers.filter(x => search(x)), '===Prayers===', 'PrayerIcon');
pushResults({arr: [...game.township.buildings.allObjects, ...game.township.seasons.allObjects, ...game.township.biomes.allObjects, ...game.township.resources.allObjects].filter(x => search(x)), header: '===Township===', iconType: 'TownshipIcon'});
pushResults([...game.township.buildings.allObjects, ...game.township.seasons.allObjects, ...game.township.biomes.allObjects, ...game.township.resources.allObjects].filter(x => search(x)), '===Township===', 'TownshipIcon');
pushResults({arr: game.skills.filter(x => search(x)), header: '===Others===', iconType: 'Skill'});
pushResults(game.skills.filter(x => search(x)), '===Others===', 'Skill');
pushResults({arr: game.pets.filter(x => search(x)), header: '===Others===', iconType: 'PetIcon'});
pushResults(game.pets.filter(x => search(x)), '===Others===', 'PetIcon');
pushResults({arr: game.astrology.actions.filter(x => search(x)), header: '===Others===', iconType: 'ConstellationIcon'});
pushResults(game.astrology.actions.filter(x => search(x)), '===Others===', 'ConstellationIcon');
pushResults({arr: game.agility.actions.filter(x => search(x)), header: '===Others===', iconType: 'AgilityIcon'});
pushResults(game.agility.actions.filter(x => search(x)), '===Others===', 'AgilityIcon');
pushResults({arr: game.thieving.actions.filter(x => search(x)), header: '===Others===', iconType: 'Icon', extras: '|type=thieving'});
pushResults(game.thieving.actions.filter(x => search(x)), '===Others===', 'Icon', '|type=thieving');
if (cloudManager.hasAoDEntitlementAndIsEnabled)
if (cloudManager.hasAoDEntitlementAndIsEnabled)
pushResults({arr: game.cartography.worldMaps.getObjectByID('melvorAoD:Melvor').pointsOfInterest.filter(x => search(x)), header: '===Others===', iconType: 'POIIcon'});
pushResults(game.cartography.worldMaps.getObjectByID('melvorAoD:Melvor').pointsOfInterest.filter(x => search(x)), '===Others===', 'POIIcon');
let outputString = ``;
let outputString = ``;
results.forEach((str, i) => { outputString += (returnEquipmentTemplate ? i > 0 ? `\n|${str}` : `${str}` : `${str}\n`) });
results.forEach((str, i) => { outputString += (returnEquipmentTemplate ? i > 0 ? `\n|${str}` : `${str}` : `${str}\n`) });
if (returnEquipmentTemplate) outputString += '\n}}\n';
if (returnEquipmentTemplate) outputString += '\n}}';
outputString += `\n{{Menu}}`;
copy(outputString);console.log(outputString);
copy(outputString);console.log(outputString);
notifyPlayer(game.attack, `Copied results for ${searchTerm} to clipboard`, 'success', 0);
notifyPlayer(game.attack, `Copied results for ${searchTerm} to clipboard`, 'success', 0);
</syntaxhighlight>
</syntaxhighlight>