Template:Disambiguation/doc: Difference between revisions

From Melvor Idle
m (Fixed combat areas being doubled)
(Fixed foods being duplicated. Added the starting 2 headers for equipment table 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 = 'Sand'; // The proper capitalization of the search term
let returnEquipmentTemplate = false; // returns a template for {{EquipmentTableFromList}} instead
let returnEquipmentTemplate = false; // returns a template for {{EquipmentTableFromList}} instead
// End of Settings //
// End of Settings //
Line 28: Line 28:
}
}
let results = [];
let results = [];
if (returnEquipmentTemplate) results.push(`{{V|${gameVersion.substr(1)}}}\n\n{{EquipmentTableFromList`);
if (returnEquipmentTemplate) results.push(`{{V|${gameVersion.substr(1)}}}\n\n==${searchTerm} Equipment==\n===Weapons===\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)), header: '===Equipment===', iconType: 'ItemIcon'});
pushResults({arr: game.items.weapons.filter(x => search(x) && !x.name.includes('Arrow')), header: '===Equipment===', iconType: 'ItemIcon'});
pushResults({arr: game.items.equipment.filter(x => search(x) && !(x instanceof WeaponItem) && !x.validSlots.includes('Quiver')), header: '===Equipment===', iconType: 'ItemIcon'});
pushResults({arr: game.items.equipment.filter(x => search(x) && !(x instanceof WeaponItem) && !x.name.includes('Arrow')), header: '===Equipment===', iconType: 'ItemIcon'});
pushResults({arr: game.items.equipment.filter(x => search(x) && x.validSlots.includes('Quiver')), header: '===Equipment===', iconType: 'ItemIcon'});
pushResults({arr: game.items.equipment.filter(x => search(x) && x.name.includes('Arrow')), header: '===Equipment===', iconType: '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({arr: game.items.filter(x => x.validSlots === undefined && !(x instanceof OpenableItem) && !(x instanceof BoneItem) && !(x instanceof FoodItem) && search(x)), header: '===Items===', iconType: 'ItemIcon'});
pushResults({arr: game.items.openables.filter(x => search(x)), header: '===Openables===', iconType: 'ItemIcon'});
pushResults({arr: game.items.openables.filter(x => search(x)), header: '===Openables===', iconType: 'ItemIcon'});
pushResults({arr: game.items.bones.filter(x => search(x)), header: '===Bones===', iconType: 'ItemIcon'});
pushResults({arr: game.items.bones.filter(x => search(x)), header: '===Bones===', iconType: 'ItemIcon'});
pushResults({arr: game.items.food.filter(x => search(x)), header: '===Food===', iconType: 'ItemIcon'});
pushResults({arr: game.items.food.filter(x => search(x)), header: '===Food===', iconType: 'ItemIcon'});
pushResults({arr: game.items.food.filter(x => search(x)), header: '===Food===', iconType: 'ItemIcon'});
pushResults({arr: game.monsters.filter(x => search(x)), header: '===Combat===', iconType: 'MonsterIcon'});
pushResults({arr: game.monsters.filter(x => search(x)), header: '===Combat===', iconType: 'MonsterIcon'});

Revision as of 10:23, 30 May 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 = 'Sand'; // The proper capitalization of the search term
let returnEquipmentTemplate = false; // returns a template for {{EquipmentTableFromList}} instead
// End of Settings //
let lcSearchTerm = searchTerm.toLowerCase();
const search = (obj) => obj.name?.toLowerCase().includes(lcSearchTerm);
const wikiIcon = (obj, icon, extras) => {
	if (!returnEquipmentTemplate)
		return `*${obj.namespace?.includes('TotH') ? '{{TotH}}' : obj.namespace?.includes('AoD') ? '{{AoD}}' : ''}{{${icon}|${obj.name}${extras}}}`;
	else
		return obj.name;
}
const pushResults = (obj) => {
	if (obj.arr.length > 0 && !returnEquipmentTemplate && !results.includes(obj.header))
		results.push(obj.header);
	obj.arr.forEach(item => {
		if (!returnEquipmentTemplate || item.validSlots !== undefined)
			results.push(wikiIcon(item, obj.iconType, obj.extras || ''));
	});
}
let results = [];
if (returnEquipmentTemplate) results.push(`{{V|${gameVersion.substr(1)}}}\n\n==${searchTerm} Equipment==\n===Weapons===\n{{EquipmentTableFromList`);
if (!returnEquipmentTemplate) results.push(`{{Disam}}{{V|${gameVersion.substr(1)}}}\n`, `'''${searchTerm}''' may refer to:`);
pushResults({arr: game.items.weapons.filter(x => search(x) && !x.name.includes('Arrow')), header: '===Equipment===', iconType: 'ItemIcon'});
pushResults({arr: game.items.equipment.filter(x => search(x) && !(x instanceof WeaponItem) && !x.name.includes('Arrow')), header: '===Equipment===', iconType: 'ItemIcon'});
pushResults({arr: game.items.equipment.filter(x => search(x) && x.name.includes('Arrow')), header: '===Equipment===', iconType: '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({arr: game.items.openables.filter(x => search(x)), header: '===Openables===', iconType: 'ItemIcon'});
pushResults({arr: game.items.bones.filter(x => search(x)), header: '===Bones===', iconType: 'ItemIcon'});
pushResults({arr: game.items.food.filter(x => search(x)), header: '===Food===', iconType: 'ItemIcon'});
pushResults({arr: game.monsters.filter(x => search(x)), header: '===Combat===', iconType: 'MonsterIcon'});
pushResults({arr: [...game.combatAreas.allObjects, ...game.slayerAreas.allObjects, ...game.dungeons.allObjects].filter(x => search(x)), header: '===Combat===', iconType: '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({arr: game.shop.purchases.filter(x => search(x)), header: '===Purchases===', iconType: 'UpgradeIcon'});
pushResults({arr: game.prayers.filter(x => search(x)), header: '===Prayers===', iconType: '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({arr: game.skills.filter(x => search(x)), header: '===Others===', iconType: 'Skill'});
pushResults({arr: game.pets.filter(x => search(x)), header: '===Others===', iconType: 'PetIcon'});
pushResults({arr: game.astrology.actions.filter(x => search(x)), header: '===Others===', iconType: 'ConstellationIcon'});
pushResults({arr: game.agility.actions.filter(x => search(x)), header: '===Others===', iconType: 'AgilityIcon'});
pushResults({arr: game.thieving.actions.filter(x => search(x)), header: '===Others===', iconType: 'Icon', extras: '|type=thieving'});
if (cloudManager.hasAoDEntitlementAndIsEnabled)
	pushResults({arr: game.cartography.worldMaps.getObjectByID('melvorAoD:Melvor').pointsOfInterest.filter(x => search(x)), header: '===Others===', iconType: '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);