Template:Disambiguation/doc: Difference between revisions

From Melvor Idle
m (Swapped version and disam templates in script)
m (Added `includeModifiers` in equipment template)
 
(15 intermediate revisions by 2 users not shown)
Line 1: Line 1:
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.
Template that is used on [[:Category:Disambiguation|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]]
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 (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.
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 ItemIcons and UpdateIcons, such as Iron Sieve which is both an Item and Purchase.
 
To use the script, copy and paste it into the console and change the <code>searchTerm</code> to the disambiguation page you're about to create. Upon hitting enter, the outputs will be pasted into the console while also being copied to the clipboard. If the results look good (not a single item or there's a bunch of random items with 1 clear choice for what the user was looking for) then begin creating the disambiguation page. The results will need a manual check before creating the page. Items that include 'Dusty' should not be included with 'Dust' however 'Stardust' is fine due to how relevant the item is. Certain category names may be changed if that category only contains 1 type of object, such as 'Combat' to 'Combat Areas' or 'Others' to 'Points of Interest'.
 
For <code>returnEquipmentTemplate</code>, see [[Template:EquipmentTableFromList/doc]].


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>
// Settings //
// Settings //
let searchTerm = 'Siren'; // The proper capitalization of the search term
let searchTerm = 'Siren'; // The proper capitalization of the search term
let returnEquipmentTemplate = false; // returns a template for {{EquipmentTableFromList}} instead
let returnEquipmentTemplate = true; // 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.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 && obj.header !== '')
if (arr.length > 0 && !returnEquipmentTemplate && !results.includes(header))
results.push(obj.header);
results.push(header);
obj.arr.forEach(item => results.push(wikiIcon(item, obj.iconType, obj.extras || '')));
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{{EquipmentTableFromList`);
if (returnEquipmentTemplate) results.push(`{{UserContentVersion|${gameVersion.substr(1)}}}\n\n=${searchTerm} Equipment=\n==Melee Weapons==\n{{EquipmentTableFromList\n\n}}\n==Ranged Weapons & Ammo==\n{{EquipmentTableFromList\n\n}}\n==Armour==\n{{EquipmentTableFromList\n|includeModifiers=false`);
if (!returnEquipmentTemplate) results.push(`{{Disam}}{{V|${gameVersion.substr(1)}}}\n`, `'''${searchTerm}''' may refer to:`);
if (!returnEquipmentTemplate) results.push(`{{Disam}}{{UserContentVersion|${gameVersion.substr(1)}}}\n`, `'''${searchTerm}''' may refer to:`);
pushResults({arr: game.items.equipment.filter(x => search(x)), header: '===Equipment===', iconType: 'ItemIcon'});
pushResults(game.items.weapons.filter(x => search(x) && !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.equipment.filter(x => search(x) && x.validSlots.includes('Quiver')), '==Equipment==', 'ItemIcon');
pushResults({arr: game.items.openables.filter(x => search(x)), header: '===Openables===', iconType: 'ItemIcon'});
pushResults(game.items.equipment.filter(x => search(x) && !(x instanceof WeaponItem) && !x.validSlots.includes('Quiver')), '==Equipment==', 'ItemIcon');
pushResults({arr: game.items.bones.filter(x => search(x)), header: '===Bones===', 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.food.filter(x => search(x)), header: '===Food===', iconType: 'ItemIcon'});
pushResults(game.items.openables.filter(x => search(x)), '==Openables==', 'ItemIcon');
pushResults({arr: game.items.food.filter(x => search(x)), header: '===Food===', iconType: 'ItemIcon'});
pushResults(game.items.bones.filter(x => search(x)), '==Bones==', 'ItemIcon');
pushResults({arr: game.monsters.filter(x => search(x)), header: '===Combat===', iconType: 'MonsterIcon'});
pushResults(game.items.food.filter(x => search(x)), '==Food==', 'ItemIcon');
pushResults({arr: [...game.combatAreas.allObjects, ...game.combatAreas.allObjects, ...game.slayerAreas.allObjects, ...game.dungeons.allObjects].filter(x => search(x)), header: '', iconType: 'ZoneIcon'});
pushResults(game.monsters.filter(x => search(x)), '==Combat==', 'MonsterIcon');
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.combatAreas.filter(x => search(x)), '==Combat==', 'ZoneIcon');
pushResults({arr: game.shop.purchases.filter(x => search(x)), header: '===Purchases===', iconType: 'UpgradeIcon'});
pushResults([...game.attackSpells.allObjects, ...game.curseSpells.allObjects, ...game.auroraSpells.allObjects, ...game.altMagic.actions.allObjects].filter(x => search(x)), '==Spells==', 'SpellIcon');
pushResults({arr: game.prayers.filter(x => search(x)), header: '===Prayers===', iconType: 'PrayerIcon'});
pushResults(game.shop.purchases.filter(x => search(x)), '==Purchases==', 'UpgradeIcon');
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.prayers.filter(x => search(x)), '==Prayers==', 'PrayerIcon');
pushResults({arr: game.skills.filter(x => search(x)), header: '===Others===', iconType: 'Skill'});
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.pets.filter(x => search(x)), header: '', iconType: 'PetIcon'});
pushResults(game.skills.filter(x => search(x)), '==Others==', 'Skill');
pushResults({arr: game.astrology.actions.filter(x => search(x)), header: '', iconType: 'ConstellationIcon'});
pushResults(game.pets.filter(x => search(x)), '==Others==', 'PetIcon');
pushResults({arr: game.agility.actions.filter(x => search(x)), header: '', iconType: 'AgilityIcon'});
pushResults(game.astrology.actions.filter(x => search(x)), '==Others==', 'ConstellationIcon');
pushResults({arr: game.skills.filter(x => search(x)), header: '', iconType: 'Icon', extras: '|type=thieving'});
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)
if (cloudManager.hasAoDEntitlementAndIsEnabled)
pushResults({arr: game.cartography.worldMaps.getObjectByID('melvorAoD:Melvor').pointsOfInterest.filter(x => search(x)), header: '', 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}}';
if (returnEquipmentTemplate) outputString += '\n}}';
copy(outputString);console.log(outputString);
self.nw?.Clipboard.get().set ? self.nw?.Clipboard?.get().set(outputString, 'text') : copy(outputString);
notifyPlayer(game.attack, `Copied results for ${searchTerm} to clipboard`, 'success', 0)
console.log(outputString);
notifyPlayer(game.attack, `Copied results for ${searchTerm} to clipboard`, 'success', 0);
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 10:19, 20 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.

To use the script, copy and paste it into the console and change the searchTerm to the disambiguation page you're about to create. Upon hitting enter, the outputs will be pasted into the console while also being copied to the clipboard. If the results look good (not a single item or there's a bunch of random items with 1 clear choice for what the user was looking for) then begin creating the disambiguation page. The results will need a manual check before creating the page. Items that include 'Dusty' should not be included with 'Dust' however 'Stardust' is fine due to how relevant the item is. Certain category names may be changed if that category only contains 1 type of object, such as 'Combat' to 'Combat Areas' or 'Others' to 'Points of Interest'.

For returnEquipmentTemplate, see Template:EquipmentTableFromList/doc.

// Settings //
let searchTerm = 'Siren'; // The proper capitalization of the search term
let returnEquipmentTemplate = true; // 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(`{{UserContentVersion|${gameVersion.substr(1)}}}\n\n=${searchTerm} Equipment=\n==Melee Weapons==\n{{EquipmentTableFromList\n\n}}\n==Ranged Weapons & Ammo==\n{{EquipmentTableFromList\n\n}}\n==Armour==\n{{EquipmentTableFromList\n|includeModifiers=false`);
if (!returnEquipmentTemplate) results.push(`{{Disam}}{{UserContentVersion|${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.filter(x => search(x)), '==Combat==', 'ZoneIcon');
pushResults([...game.attackSpells.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}}';
self.nw?.Clipboard.get().set ? self.nw?.Clipboard?.get().set(outputString, 'text') : copy(outputString);
console.log(outputString);
notifyPlayer(game.attack, `Copied results for ${searchTerm} to clipboard`, 'success', 0);