Template:Disambiguation/doc: Difference between revisions

From Melvor Idle
m (Added newlines for equipment template to make it easier to sift through the results)
(Add Fishing and Thieving areas; Add support for Earth Golem (AoD); Move skills back into "Others" category)
 
(29 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 [[Ancient]].


An example of this would be [[Siren]]
The below script will search all current [[Template:Icon|Icon Templates]] in v1.3.1 (except for Synergies) 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.


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.
To use the script, copy and paste the script into the console. The script can then be run with <code>disambiguation(searchTerm, returnEquipmentTemplate)</code> where <code>searchTerm</code> is the disambiguation page you're about to create (with proper capitalization) and <code>returnEquipmentTemplate</code> is a Boolean (true/false) for whether you want to return a template for [[Template:EquipmentTableFromList/doc]] instead, defaulting to false.
 
Upon running the function, the outputs will be pasted into the console while also being copied to the clipboard. If the results look good (more than a single item) then begin creating the disambiguation page. The results should be manually checked for any erroring or incorrect templates before creating the page.
 
The results should be cleaned up a bit. 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'. If an entire equipment set is shown, it should be linked to the appropriate Equipment page (such as [[Adamant Equipment]]).


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 //
function disambiguation(searchTerm, returnEquipmentTemplate=false) {
let searchTerm = 'Siren'; // The proper capitalization of the search term
let search = (item) => !item.isModded && item.name.toLowerCase().includes(searchTerm.toLowerCase());
let returnEquipmentTemplate = false; // returns a template for {{EquipmentTableFromList}} instead
let wikiIcon = (item, icon, extras, postText) => {
// End of Settings //
numResults++;
let lcSearchTerm = searchTerm.toLowerCase();
if (!returnEquipmentTemplate) {
const search = (obj) => obj.name?.toLowerCase().includes(lcSearchTerm);
extras = extras.replaceAll('${NAME}', `${item.name}`);
const wikiIcon = (obj, icon, extras) => {
let name = item.id === 'melvorAoD:EarthGolem' ? 'Earth Golem (AoD)' : item.name;
if (!returnEquipmentTemplate)
name = name.replace('Potion I', 'Potion');
return `*${obj.namespace?.includes('TotH') ? '{{TotH}}' : obj.namespace?.includes('AoD') ? '{{AoD}}' : ''}{{${icon}|${obj.name}${extras}}}`;
let expIcon = `${item.namespace.includes('TotH') ? ' {{TotH}}' : item.namespace.includes('AoD') ? ' {{AoD}}' : item.namespace.includes('ItA') ? ' {{ItA}}' : ' {{Melvor}}'}`;
else
let iconTemplate = icon === 'Link' ? ` [[${extras}]]` : ` {{${icon}|${name}${extras}}}`;
return obj.name;
return `*${expIcon}${iconTemplate}${postText}`;
}
}
const pushResults = (obj) => {
return `|${item.name}`;
if (obj.arr.length > 0 && !returnEquipmentTemplate && obj.header !== '')
}
results.push(obj.header);
let pushResults = (arr, header, icon, extras='', postText='') => {
obj.arr.forEach(item => results.push(wikiIcon(item, obj.iconType, obj.extras || '')));
if (arr.length > 0 && !returnEquipmentTemplate && !results.includes(header))
results += header;
arr.forEach(item => {
if (!returnEquipmentTemplate || item.validSlots !== undefined)
results += `\n${wikiIcon(item, icon, extras, postText)}`;
});
}
let results = '', numResults = 0;
if (returnEquipmentTemplate) results += `{{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 += `{{Disam}}\n{{UserContentVersion|${gameVersion.substr(1)}}}\n\n'''${searchTerm}''' may refer to:`;
pushResults(game.items.weapons.filter(x => search(x) && !x.validSlots.includes('Quiver')), '\n== Equipment ==', 'ItemIcon');
pushResults(game.items.equipment.filter(x => search(x) && x.validSlots.includes('Quiver')), '\n== Equipment ==', 'ItemIcon');
pushResults(game.items.equipment.filter(x => search(x) && !(x instanceof WeaponItem) && !x.validSlots.includes('Quiver')), '\n== Equipment ==', 'ItemIcon');
pushResults(game.items.filter(x => x.validSlots == undefined && !(x instanceof OpenableItem) && !(x instanceof BoneItem) && !(x instanceof SoulItem) && !(x instanceof FoodItem) && !['potion_ii', 'potion_iii', 'potion_iv'].some(y => x.id.toLowerCase().includes(y)) && search(x)), '\n== Items ==', 'ItemIcon');
pushResults(game.items.openables.filter(x => search(x)), '\n== Openables ==', 'ItemIcon');
pushResults(game.items.bones.filter(x => search(x)), '\n== Bones ==', 'ItemIcon');
pushResults(game.items.souls.filter(x => search(x)), '\n== Souls ==', 'ItemIcon');
pushResults(game.items.food.filter(x => search(x)), '\n== Food ==', 'ItemIcon');
pushResults(game.monsters.filter(x => search(x)), '\n== Monsters ==', 'MonsterIcon');
pushResults(game.combatAreas.filter(x => search(x)), '\n== Combat Areas ==', 'ZoneIcon');
pushResults(game.attackSpellbooks.allObjects.filter(x => search(x)), '\n== Spells & Spellbooks ==', 'SpellbookIcon');
pushResults([...game.attackSpells.allObjects, ...game.curseSpells.allObjects, ...game.auroraSpells.allObjects, ...game.altMagic.actions.allObjects].filter(x => search(x)), '\n== Spells & Spellbooks ==', 'SpellIcon');
pushResults(game.shop.purchases.filter(x => x.contains.items?.length !== 1 && !x.contains.itemCharges && search(x)), '\n== Purchases ==', 'UpgradeIcon');
pushResults(game.prayers.filter(x => search(x)), '\n== Prayers ==', 'PrayerIcon');
pushResults([...game.township.buildings.allObjects, ...game.township.seasons.allObjects, ...game.township.biomes.allObjects, ...game.township.resources.allObjects].filter(x => !['melvorF:GP', 'melvorItA:AP'].includes(x.id) && search(x)), '\n== Township ==', 'TownshipIcon');
pushResults(game.astrology.actions.filter(x => search(x)), '\n== Skill Actions ==', 'ConstellationIcon', '', ' (Constellation)');
pushResults(game.agility.actions.filter(x => search(x)), '\n== Skill Actions ==', 'AgilityIcon', '', ' (Agility Obstacle)');
pushResults(game.thieving.actions.filter(x => search(x)), '\n== Skill Actions ==', 'Icon', '|type=thieving', ' (Thieving NPC)');
pushResults(game.thieving.areas.filter(x => search(x)), '\n== Skill Actions ==', 'Link', 'Thieving#${NAME}|${NAME}', ' (Thieving Area)');
pushResults(game.fishing.areas.filter(x => search(x)), '\n== Skill Actions ==', 'Link', 'Fishing#${NAME}|${NAME}', ' (Fishing Area)');
pushResults(game.pets.filter(x => search(x)), '\n== Pets ==', 'PetIcon');
pushResults(game.combatEffects.allObjects.filter(x => ['Shadeveil', 'Ablaze', 'Affliction', 'Barrier Burn', 'Bleed', 'Burn', 'Deadly Poison', 'Eldritch Curse', 'Fear', 'Freeze', 'Frostburn', 'Laceration', 'Nulled', 'Poison', 'Shock', 'Silence', 'Sleep', 'Slow', 'Stun', 'Toxin', 'Voidburst', 'Wither'].includes(x.name) && search(x)), '\n== Combat Effects ==', 'EffectIcon');
pushResults(game.skills.filter(x => search(x)), '\n== Others ==', 'Skill');
pushResults(game.currencies.allObjects.filter(x => search(x)), '\n== Others ==', 'Icon');
pushResults(game.gamemodes.allObjects.filter(x => !x.isEvent && x.id !== 'melvorD:Unset' && search(x)), '\n== Others ==', 'Icon');
pushResults(game.combat.slayerTask.categories.allObjects.filter(x => search(x)), '\n== Others ==', 'Link', 'Slayer#${NAME}|${NAME}', ' Slayer Tier');
if (cloudManager.hasAoDEntitlementAndIsEnabled)
pushResults(game.cartography.worldMaps.getObjectByID('melvorAoD:Melvor').pointsOfInterest.filter(x => search(x)), '\n== Others ==', 'POIIcon');
if (returnEquipmentTemplate) results += '\n}}';
self.nw?.Clipboard.get().set ? self.nw?.Clipboard?.get().set(results, 'text') : copy(results);
console.log(results);
notifyPlayer(game.attack, `Copied ${numResults} results for ${searchTerm} to clipboard`, 'success', 0);
}
}
let results = [];
if (returnEquipmentTemplate) results.push(`{{V|${gameVersion.substr(1)}}}\n\n{{EquipmentTableFromList`);
if (!returnEquipmentTemplate) results.push(`{{V|${gameVersion.substr(1)}}}{{Disam}}\n`, `'''${searchTerm}''' may refer to:`);
pushResults({arr: game.items.equipment.filter(x => search(x)), 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.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.combatAreas.allObjects, ...game.slayerAreas.allObjects, ...game.dungeons.allObjects].filter(x => search(x)), header: '', 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: '', iconType: 'PetIcon'});
pushResults({arr: game.astrology.actions.filter(x => search(x)), header: '', iconType: 'ConstellationIcon'});
pushResults({arr: game.agility.actions.filter(x => search(x)), header: '', iconType: 'AgilityIcon'});
pushResults({arr: game.skills.filter(x => search(x)), header: '', iconType: 'Icon', extras: '|type=thieving'});
if (cloudManager.hasAoDEntitlementAndIsEnabled)
pushResults({arr: game.cartography.worldMaps.getObjectByID('melvorAoD:Melvor').pointsOfInterest.filter(x => search(x)), header: '', 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)
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 09:03, 2 November 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 Ancient.

The below script will search all current Icon Templates in v1.3.1 (except for Synergies) 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 the script into the console. The script can then be run with disambiguation(searchTerm, returnEquipmentTemplate) where searchTerm is the disambiguation page you're about to create (with proper capitalization) and returnEquipmentTemplate is a Boolean (true/false) for whether you want to return a template for Template:EquipmentTableFromList/doc instead, defaulting to false.

Upon running the function, the outputs will be pasted into the console while also being copied to the clipboard. If the results look good (more than a single item) then begin creating the disambiguation page. The results should be manually checked for any erroring or incorrect templates before creating the page.

The results should be cleaned up a bit. 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'. If an entire equipment set is shown, it should be linked to the appropriate Equipment page (such as Adamant Equipment).

function disambiguation(searchTerm, returnEquipmentTemplate=false) {
	let search = (item) => !item.isModded && item.name.toLowerCase().includes(searchTerm.toLowerCase());
	let wikiIcon = (item, icon, extras, postText) => {
		numResults++;
		if (!returnEquipmentTemplate) {
			extras = extras.replaceAll('${NAME}', `${item.name}`);
			let name = item.id === 'melvorAoD:EarthGolem' ? 'Earth Golem (AoD)' : item.name;
			name = name.replace('Potion I', 'Potion');
			let expIcon = `${item.namespace.includes('TotH') ? ' {{TotH}}' : item.namespace.includes('AoD') ? ' {{AoD}}' : item.namespace.includes('ItA') ? ' {{ItA}}' : ' {{Melvor}}'}`;
			let iconTemplate = icon === 'Link' ? ` [[${extras}]]` : ` {{${icon}|${name}${extras}}}`;
			return `*${expIcon}${iconTemplate}${postText}`;
		}
		return `|${item.name}`;
	}
	let pushResults = (arr, header, icon, extras='', postText='') => {
		if (arr.length > 0 && !returnEquipmentTemplate && !results.includes(header))
			results += header;
		arr.forEach(item => {
			if (!returnEquipmentTemplate || item.validSlots !== undefined)
				results += `\n${wikiIcon(item, icon, extras, postText)}`;
		});
	}
	let results = '', numResults = 0;
	if (returnEquipmentTemplate) results += `{{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 += `{{Disam}}\n{{UserContentVersion|${gameVersion.substr(1)}}}\n\n'''${searchTerm}''' may refer to:`;
	pushResults(game.items.weapons.filter(x => search(x) && !x.validSlots.includes('Quiver')), '\n== Equipment ==', 'ItemIcon');
	pushResults(game.items.equipment.filter(x => search(x) && x.validSlots.includes('Quiver')), '\n== Equipment ==', 'ItemIcon');
	pushResults(game.items.equipment.filter(x => search(x) && !(x instanceof WeaponItem) && !x.validSlots.includes('Quiver')), '\n== Equipment ==', 'ItemIcon');
	pushResults(game.items.filter(x => x.validSlots == undefined && !(x instanceof OpenableItem) && !(x instanceof BoneItem) && !(x instanceof SoulItem) && !(x instanceof FoodItem) && !['potion_ii', 'potion_iii', 'potion_iv'].some(y => x.id.toLowerCase().includes(y)) && search(x)), '\n== Items ==', 'ItemIcon');
	pushResults(game.items.openables.filter(x => search(x)), '\n== Openables ==', 'ItemIcon');
	pushResults(game.items.bones.filter(x => search(x)), '\n== Bones ==', 'ItemIcon');
	pushResults(game.items.souls.filter(x => search(x)), '\n== Souls ==', 'ItemIcon');
	pushResults(game.items.food.filter(x => search(x)), '\n== Food ==', 'ItemIcon');
	pushResults(game.monsters.filter(x => search(x)), '\n== Monsters ==', 'MonsterIcon');
	pushResults(game.combatAreas.filter(x => search(x)), '\n== Combat Areas ==', 'ZoneIcon');
	pushResults(game.attackSpellbooks.allObjects.filter(x => search(x)), '\n== Spells & Spellbooks ==', 'SpellbookIcon');
	pushResults([...game.attackSpells.allObjects, ...game.curseSpells.allObjects, ...game.auroraSpells.allObjects, ...game.altMagic.actions.allObjects].filter(x => search(x)), '\n== Spells & Spellbooks ==', 'SpellIcon');
	pushResults(game.shop.purchases.filter(x => x.contains.items?.length !== 1 && !x.contains.itemCharges && search(x)), '\n== Purchases ==', 'UpgradeIcon');
	pushResults(game.prayers.filter(x => search(x)), '\n== Prayers ==', 'PrayerIcon');
	pushResults([...game.township.buildings.allObjects, ...game.township.seasons.allObjects, ...game.township.biomes.allObjects, ...game.township.resources.allObjects].filter(x => !['melvorF:GP', 'melvorItA:AP'].includes(x.id) && search(x)), '\n== Township ==', 'TownshipIcon');
	pushResults(game.astrology.actions.filter(x => search(x)), '\n== Skill Actions ==', 'ConstellationIcon', '', ' (Constellation)');
	pushResults(game.agility.actions.filter(x => search(x)), '\n== Skill Actions ==', 'AgilityIcon', '', ' (Agility Obstacle)');
	pushResults(game.thieving.actions.filter(x => search(x)), '\n== Skill Actions ==', 'Icon', '|type=thieving', ' (Thieving NPC)');
	pushResults(game.thieving.areas.filter(x => search(x)), '\n== Skill Actions ==', 'Link', 'Thieving#${NAME}|${NAME}', ' (Thieving Area)');
	pushResults(game.fishing.areas.filter(x => search(x)), '\n== Skill Actions ==', 'Link', 'Fishing#${NAME}|${NAME}', ' (Fishing Area)');
	pushResults(game.pets.filter(x => search(x)), '\n== Pets ==', 'PetIcon');
	pushResults(game.combatEffects.allObjects.filter(x => ['Shadeveil', 'Ablaze', 'Affliction', 'Barrier Burn', 'Bleed', 'Burn', 'Deadly Poison', 'Eldritch Curse', 'Fear', 'Freeze', 'Frostburn', 'Laceration', 'Nulled', 'Poison', 'Shock', 'Silence', 'Sleep', 'Slow', 'Stun', 'Toxin', 'Voidburst', 'Wither'].includes(x.name) && search(x)), '\n== Combat Effects ==', 'EffectIcon');
	pushResults(game.skills.filter(x => search(x)), '\n== Others ==', 'Skill');
	pushResults(game.currencies.allObjects.filter(x => search(x)), '\n== Others ==', 'Icon');
	pushResults(game.gamemodes.allObjects.filter(x => !x.isEvent && x.id !== 'melvorD:Unset' && search(x)), '\n== Others ==', 'Icon');
	pushResults(game.combat.slayerTask.categories.allObjects.filter(x => search(x)), '\n== Others ==', 'Link', 'Slayer#${NAME}|${NAME}', ' Slayer Tier');
	if (cloudManager.hasAoDEntitlementAndIsEnabled)
		pushResults(game.cartography.worldMaps.getObjectByID('melvorAoD:Melvor').pointsOfInterest.filter(x => search(x)), '\n== Others ==', 'POIIcon');
	if (returnEquipmentTemplate) results += '\n}}';
	self.nw?.Clipboard.get().set ? self.nw?.Clipboard?.get().set(results, 'text') : copy(results);
	console.log(results);
	notifyPlayer(game.attack, `Copied ${numResults} results for ${searchTerm} to clipboard`, 'success', 0);
}