Template:Disambiguation/doc: Difference between revisions
From Melvor Idle
m (Added expansion icons into output results) |
(Added Alt Magic spells to script) |
||
(15 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
An example of this would be [[Siren]] | An example of this would be [[Siren]] | ||
The below script will search all current [[Template:Icon|Icon Templates]] in v1.2.2 (except for Synergies, Spellbooks and Currencies) for the given <code>searchTerm</code> then output an array of the results in valid Icon Template format with expansion icons | The below script will search all current [[Template:Icon|Icon Templates]] in v1.2.2 (except for Synergies, Spellbooks (not Spells) and Currencies) for the given <code>searchTerm</code> then output an array of the results in valid Icon Template format with expansion icons. | ||
This may result in some duplicates between | This may result in some duplicates between ItemIcons and UpdateIcons, such as Iron Sieve which is both an Item and Purchase. | ||
<syntaxhighlight lang="javascript" line> | <syntaxhighlight lang="javascript" line> | ||
let searchTerm = ''.toLowerCase(); | // Settings // | ||
let searchTerm = 'Siren'; // The proper capitalization of the search term | |||
const | let returnEquipmentTemplate = false; // returns a template for {{EquipmentTableFromList}} instead | ||
// End of Settings // | |||
const search = (item) => !item.isModded && item.name.toLowerCase().includes(searchTerm.toLowerCase()); | |||
const wikiIcon = (item, icon, extras) => { | |||
if (!returnEquipmentTemplate) | |||
return `*${item.namespace.includes('TotH') ? '{{TotH}}' : item.namespace.includes('AoD') ? '{{AoD}}' : item.namespace.includes('ItA') ? '{{ItA}}' : ''}{{${icon}|${item.name}${extras}}}`; | |||
return item.name; | |||
} | |||
const pushResults = (arr, header, icon, extras='') => { | |||
if (arr.length > 0 && !returnEquipmentTemplate && !results.includes(header)) | |||
results.push(header); | |||
arr.forEach(item => { | |||
if (!returnEquipmentTemplate || item.validSlots !== undefined) | |||
results.push(wikiIcon(item, icon, extras)); | |||
}); | |||
} | |||
let results = []; | let results = []; | ||
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`); | |||
game. | if (!returnEquipmentTemplate) results.push(`{{Disam}}{{V|${gameVersion.substr(1)}}}\n`, `'''${searchTerm}''' may refer to:`); | ||
game. | pushResults(game.items.weapons.filter(x => search(x) && !x.validSlots.includes('Quiver')), '===Equipment===', 'ItemIcon'); | ||
game. | pushResults(game.items.equipment.filter(x => search(x) && x.validSlots.includes('Quiver')), '===Equipment===', 'ItemIcon'); | ||
game. | pushResults(game.items.equipment.filter(x => search(x) && !(x instanceof WeaponItem) && !x.validSlots.includes('Quiver')), '===Equipment===', 'ItemIcon'); | ||
pushResults(game.items.filter(x => x.validSlots === undefined && !(x instanceof OpenableItem) && !(x instanceof BoneItem) && !(x instanceof FoodItem) && search(x)), '===Items===', 'ItemIcon'); | |||
pushResults(game.items.openables.filter(x => search(x)), '===Openables===', 'ItemIcon'); | |||
game. | pushResults(game.items.bones.filter(x => search(x)), '===Bones===', 'ItemIcon'); | ||
game. | pushResults(game.items.food.filter(x => search(x)), '===Food===', 'ItemIcon'); | ||
game. | pushResults(game.monsters.filter(x => search(x)), '===Combat===', 'MonsterIcon'); | ||
game. | pushResults([...game.combatAreas.allObjects, ...game.slayerAreas.allObjects, ...game.dungeons.allObjects].filter(x => search(x)), '===Combat===', 'ZoneIcon'); | ||
game. | pushResults([...game.standardSpells.allObjects, ...game.ancientSpells.allObjects, ...game.archaicSpells.allObjects, ...game.curseSpells.allObjects, ...game.auroraSpells.allObjects, ...game.altMagic.actions.allObjects].filter(x => search(x)), '===Spells===', 'SpellIcon'); | ||
game. | pushResults(game.shop.purchases.filter(x => search(x)), '===Purchases===', 'UpgradeIcon'); | ||
game. | pushResults(game.prayers.filter(x => search(x)), '===Prayers===', 'PrayerIcon'); | ||
game. | pushResults([...game.township.buildings.allObjects, ...game.township.seasons.allObjects, ...game.township.biomes.allObjects, ...game.township.resources.allObjects].filter(x => search(x)), '===Township===', 'TownshipIcon'); | ||
game. | pushResults(game.skills.filter(x => search(x)), '===Others===', 'Skill'); | ||
game. | pushResults(game.pets.filter(x => search(x)), '===Others===', 'PetIcon'); | ||
game. | pushResults(game.astrology.actions.filter(x => search(x)), '===Others===', 'ConstellationIcon'); | ||
game. | pushResults(game.agility.actions.filter(x => search(x)), '===Others===', 'AgilityIcon'); | ||
game. | pushResults(game.thieving.actions.filter(x => search(x)), '===Others===', 'Icon', '|type=thieving'); | ||
if (cloudManager.hasAoDEntitlementAndIsEnabled) | if (cloudManager.hasAoDEntitlementAndIsEnabled) | ||
game.cartography.worldMaps.getObjectByID('melvorAoD:Melvor').pointsOfInterest.filter(x => search(x)) | pushResults(game.cartography.worldMaps.getObjectByID('melvorAoD:Melvor').pointsOfInterest.filter(x => search(x)), '===Others===', 'POIIcon'); | ||
results. | let outputString = ``; | ||
results.forEach((str, i) => { outputString += (returnEquipmentTemplate ? i > 0 ? `\n|${str}` : `${str}` : `${str}\n`) }); | |||
if (returnEquipmentTemplate) outputString += '\n}}'; | |||
copy(outputString);console.log(outputString); | |||
notifyPlayer(game.attack, `Copied results for ${searchTerm} to clipboard`, 'success', 0); | |||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 20:21, 1 June 2024
Template that is used on Disambiguation pages. These are pages that are created to differentiate between multiple other pages with the same or a similar name.
An example of this would be Siren
The below script will search all current Icon Templates in v1.2.2 (except for Synergies, Spellbooks (not Spells) and Currencies) for the given searchTerm
then output an array of the results in valid Icon Template format with expansion icons.
This may result in some duplicates between ItemIcons and UpdateIcons, such as Iron Sieve which is both an Item and Purchase.
// Settings //
let searchTerm = 'Siren'; // The proper capitalization of the search term
let returnEquipmentTemplate = false; // returns a template for {{EquipmentTableFromList}} instead
// End of Settings //
const search = (item) => !item.isModded && item.name.toLowerCase().includes(searchTerm.toLowerCase());
const wikiIcon = (item, icon, extras) => {
if (!returnEquipmentTemplate)
return `*${item.namespace.includes('TotH') ? '{{TotH}}' : item.namespace.includes('AoD') ? '{{AoD}}' : item.namespace.includes('ItA') ? '{{ItA}}' : ''}{{${icon}|${item.name}${extras}}}`;
return item.name;
}
const pushResults = (arr, header, icon, extras='') => {
if (arr.length > 0 && !returnEquipmentTemplate && !results.includes(header))
results.push(header);
arr.forEach(item => {
if (!returnEquipmentTemplate || item.validSlots !== undefined)
results.push(wikiIcon(item, icon, extras));
});
}
let results = [];
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:`);
pushResults(game.items.weapons.filter(x => search(x) && !x.validSlots.includes('Quiver')), '===Equipment===', 'ItemIcon');
pushResults(game.items.equipment.filter(x => search(x) && x.validSlots.includes('Quiver')), '===Equipment===', 'ItemIcon');
pushResults(game.items.equipment.filter(x => search(x) && !(x instanceof WeaponItem) && !x.validSlots.includes('Quiver')), '===Equipment===', 'ItemIcon');
pushResults(game.items.filter(x => x.validSlots === undefined && !(x instanceof OpenableItem) && !(x instanceof BoneItem) && !(x instanceof FoodItem) && search(x)), '===Items===', 'ItemIcon');
pushResults(game.items.openables.filter(x => search(x)), '===Openables===', 'ItemIcon');
pushResults(game.items.bones.filter(x => search(x)), '===Bones===', 'ItemIcon');
pushResults(game.items.food.filter(x => search(x)), '===Food===', 'ItemIcon');
pushResults(game.monsters.filter(x => search(x)), '===Combat===', 'MonsterIcon');
pushResults([...game.combatAreas.allObjects, ...game.slayerAreas.allObjects, ...game.dungeons.allObjects].filter(x => search(x)), '===Combat===', 'ZoneIcon');
pushResults([...game.standardSpells.allObjects, ...game.ancientSpells.allObjects, ...game.archaicSpells.allObjects, ...game.curseSpells.allObjects, ...game.auroraSpells.allObjects, ...game.altMagic.actions.allObjects].filter(x => search(x)), '===Spells===', 'SpellIcon');
pushResults(game.shop.purchases.filter(x => search(x)), '===Purchases===', 'UpgradeIcon');
pushResults(game.prayers.filter(x => search(x)), '===Prayers===', 'PrayerIcon');
pushResults([...game.township.buildings.allObjects, ...game.township.seasons.allObjects, ...game.township.biomes.allObjects, ...game.township.resources.allObjects].filter(x => search(x)), '===Township===', 'TownshipIcon');
pushResults(game.skills.filter(x => search(x)), '===Others===', 'Skill');
pushResults(game.pets.filter(x => search(x)), '===Others===', 'PetIcon');
pushResults(game.astrology.actions.filter(x => search(x)), '===Others===', 'ConstellationIcon');
pushResults(game.agility.actions.filter(x => search(x)), '===Others===', 'AgilityIcon');
pushResults(game.thieving.actions.filter(x => search(x)), '===Others===', 'Icon', '|type=thieving');
if (cloudManager.hasAoDEntitlementAndIsEnabled)
pushResults(game.cartography.worldMaps.getObjectByID('melvorAoD:Melvor').pointsOfInterest.filter(x => search(x)), '===Others===', 'POIIcon');
let outputString = ``;
results.forEach((str, i) => { outputString += (returnEquipmentTemplate ? i > 0 ? `\n|${str}` : `${str}` : `${str}\n`) });
if (returnEquipmentTemplate) outputString += '\n}}';
copy(outputString);console.log(outputString);
notifyPlayer(game.attack, `Copied results for ${searchTerm} to clipboard`, 'success', 0);