Template:CorruptionsTable/doc: Difference between revisions

From Melvor Idle
(Update script to include data sort values and regex so manually replacing effect icons isn't necessary)
(Amend description handling to use localizations where possible, and wrap code in IIFE to allow re-running without re-declaration errors)
Line 2: Line 2:


<syntaxhighlight lang="javascript" line>
<syntaxhighlight lang="javascript" line>
const EFFECT_ICON_MODIFICATIONS = [{ effect: 'Bleed' }, { effect: 'Slow' }, { effect: 'Laceration' }, { effect: 'Ablaze' }, { effect: 'Blight' }, { effect: 'Fear' }, { effect: 'Silence' }];
(function () {
const LINKS_MODIFICATIONS = [ { effect: 'Attack Interval' },  { effect: 'Lifesteal' },  { effect: 'Accuracy Rating' },  { effect: 'Global Evasion' }];
const EFFECT_ICON_MODIFICATIONS = [{ effect: 'Bleed' }, { effect: 'Slow' }, { effect: 'Laceration' }, { effect: 'Ablaze' }, { effect: 'Blight' }, { effect: 'Fear' }, { effect: 'Silence' }];
const ICON_MODIFICATIONS = [ { effect: 'Unholy Prayers' }, { effect: 'Barrier' }, { effect: 'Abyssal Resistance' }];
const LINKS_MODIFICATIONS = [ { effect: 'Attack Interval' },  { effect: 'Lifesteal' },  { effect: 'Accuracy Rating' },  { effect: 'Global Evasion' }];
[...EFFECT_ICON_MODIFICATIONS, ...LINKS_MODIFICATIONS, ...ICON_MODIFICATIONS].forEach(x => x["regex"] = new RegExp("\\b" + x.effect + "\\b", "ig"));
const ICON_MODIFICATIONS = [ { effect: 'Unholy Prayers' }, { effect: 'Barrier' }, { effect: 'Abyssal Resistance' }];
[...EFFECT_ICON_MODIFICATIONS, ...LINKS_MODIFICATIONS, ...ICON_MODIFICATIONS].forEach(x => x["regex"] = new RegExp("\\b" + x.effect + "\\b", "ig"));


const modifyDescription = (text) => {
const modifyDescription = (text) => {
EFFECT_ICON_MODIFICATIONS.forEach((x, i) => { text = text.replace(x.regex, `{{EffectIcon|${x.effect}}}`); });
EFFECT_ICON_MODIFICATIONS.forEach((x, i) => { text = text.replace(x.regex, `{{EffectIcon|${x.effect}}}`); });
LINKS_MODIFICATIONS.forEach((x, i) => { text = text.replace(x.regex, `[[${x.effect}]]`); });
LINKS_MODIFICATIONS.forEach((x, i) => { text = text.replace(x.regex, `[[${x.effect}]]`); });
ICON_MODIFICATIONS.forEach((x, i) => { text = text.replace(x.regex, `{{Icon|${x.effect}}}`); });
ICON_MODIFICATIONS.forEach((x, i) => { text = text.replace(x.regex, `{{Icon|${x.effect}}}`); });
text = text.replace('Global Accuracy', '[[Accuracy Rating|Global Accuracy]]');
text = text.replace('Global Accuracy', '[[Accuracy Rating|Global Accuracy]]');
return text
return text
}
}


let results = [`<noinclude>{{/doc}}[[Category:Manual Tables]]</noinclude>\n{| class="wikitable sortable"\n|-\n! Min Monster Lvl\n! Effect`];
let results = [`<noinclude>{{/doc}}[[Category:Manual Tables]]</noinclude>\n{| class="wikitable sortable"\n|-\n! Min Monster Lvl\n! Effect`];
game.corruption.corruptionEffects.allRows.sort((a,b) => a.minMonsterLevel - b.minMonsterLevel).forEach(row => {
game.corruption.corruptionEffects.allRows.sort((a,b) => a.minMonsterLevel - b.minMonsterLevel).forEach(row => {
let description = modifyDescription(row.customDescription),
let description = modifyDescription(row.langStringID !== '' ? getLangString(row.langStringID) : row.customDescription),
monsterLevelReq = row.minMonsterLevel ? numberWithCommas(row.minMonsterLevel) : 'Starts Unlocked';
monsterLevelReq = row.minMonsterLevel ? numberWithCommas(row.minMonsterLevel) : 'Starts Unlocked';
results.push(`|data-sort-value="${row.minMonsterLevel}"| ${monsterLevelReq}\n| <span class="text-positive">${description}</span>`);
results.push(`|data-sort-value="${row.minMonsterLevel}"| ${monsterLevelReq}\n| <span class="text-positive">${description}</span>`);
});
});
let output = ``;results.forEach((alias, i) => output += alias + (i === results.length - 1 ? '\n|}' : `\n|-\n`));console.log(output);
let output = ``;results.forEach((alias, i) => output += alias + (i === results.length - 1 ? '\n|}' : `\n|-\n`));console.log(output);
self.nw?.Clipboard.get().set ? self.nw?.Clipboard?.get().set(output, 'text') : copy(output);
self.nw?.Clipboard.get().set ? self.nw?.Clipboard?.get().set(output, 'text') : copy(output);
})();
</syntaxhighlight>
</syntaxhighlight>

Revision as of 08:01, 9 October 2024

A script is used to generate the following table. To use, open the game and paste the below into the console. The outputs will be copied to your clipboard automatically. After running the script, 'edit source' on Template:CorruptionsTable then Ctrl+A and Ctrl+V. Look over the contents to ensure everything looks fine.

(function () {
	const EFFECT_ICON_MODIFICATIONS = [{ effect: 'Bleed' }, { effect: 'Slow' }, { effect: 'Laceration' }, { effect: 'Ablaze' }, { effect: 'Blight' }, { effect: 'Fear' }, { effect: 'Silence' }];
	const LINKS_MODIFICATIONS = [ { effect: 'Attack Interval' },  { effect: 'Lifesteal' },  { effect: 'Accuracy Rating' },  { effect: 'Global Evasion' }];
	const ICON_MODIFICATIONS = [ { effect: 'Unholy Prayers' }, { effect: 'Barrier' }, { effect: 'Abyssal Resistance' }];
	[...EFFECT_ICON_MODIFICATIONS, ...LINKS_MODIFICATIONS, ...ICON_MODIFICATIONS].forEach(x => x["regex"] = new RegExp("\\b" + x.effect + "\\b", "ig"));

	const modifyDescription = (text) => {
		EFFECT_ICON_MODIFICATIONS.forEach((x, i) => { text = text.replace(x.regex, `{{EffectIcon|${x.effect}}}`); });
		LINKS_MODIFICATIONS.forEach((x, i) => { text = text.replace(x.regex, `[[${x.effect}]]`); });
		ICON_MODIFICATIONS.forEach((x, i) => { text = text.replace(x.regex, `{{Icon|${x.effect}}}`); });
		text = text.replace('Global Accuracy', '[[Accuracy Rating|Global Accuracy]]');
		return text
	}

	let results = [`<noinclude>{{/doc}}[[Category:Manual Tables]]</noinclude>\n{| class="wikitable sortable"\n|-\n! Min Monster Lvl\n! Effect`];
	game.corruption.corruptionEffects.allRows.sort((a,b) => a.minMonsterLevel - b.minMonsterLevel).forEach(row => {
		let description = modifyDescription(row.langStringID !== '' ? getLangString(row.langStringID) : row.customDescription),
			monsterLevelReq = row.minMonsterLevel ? numberWithCommas(row.minMonsterLevel) : 'Starts Unlocked';
		results.push(`|data-sort-value="${row.minMonsterLevel}"| ${monsterLevelReq}\n| <span class="text-positive">${description}</span>`);
	});
	let output = ``;results.forEach((alias, i) => output += alias + (i === results.length - 1 ? '\n|}' : `\n|-\n`));console.log(output);
	self.nw?.Clipboard.get().set ? self.nw?.Clipboard?.get().set(output, 'text') : copy(output);
})();