Viewing old revision of Module:TEST/Trade_Items
You are viewing an old revision of this page from 1/24/2026, 11:13:18 AM.
View latest versionNo documentation subpage (
/doc) found for this module.const Utils = await require("Utils");
const Game = await require("TEST/Game");
const { TooltipBuilder } = await require("TEST/Tooltip_Builder");
function renderTable(items) {
let wikitext = '';
let tooltips = "";
wikitext += '{| class="wiki-table" style="width: auto;"\n';
wikitext += '! Name !! Rarity !! Max Stack\n';
for (const id in items) {
const item = items[id];
wikitext += '|-\n';
const tooltipId = `TradeItem:${id}`;
// Name
wikitext += `| data-tooltip-id="${tooltipId}" | [[Trade Items/${item.name || id}|${item.name || id}]]\n`;
// Rarity
if (item.rarity) {
wikitext += `| ${Game.wikiRarity(item.rarity)}\n`;
} else {
wikitext += `| ${Game.wikiRarity("common")}\n`;
}
// Max Stack
if (item.stack?.max) {
wikitext += `| ${item.stack.max}\n`;
} else {
wikitext += `| 1\n`;
}
// Add tooltip
const tooltip = new TooltipBuilder(tooltipId);
tooltip.addLine(`'''${item.name || id}'''`);
if (item.description) {
const lines = item.description.replace(/\n{2,}/g, "\n").split('\n');
for (const line of lines) {
tooltip.addLine(line.replace(/<color=(.*?)>(.*?)<\/color>/g, "<span style='color:$1;'>$2</span>"));
}
}
tooltips += tooltip.build();
}
wikitext += '|}\n';
wikitext += tooltips;
return wikitext;
}
function renderNavbox(items) {
wikitext = '';
wikitext += `{| class="wiki-table navbox"\n`;
wikitext += `! Trade Items Navigation\n`;
const itemsList = [];
for (const id in items) {
const item = items[id];
itemsList.push(`[[Trade Items/${item.name || id}|${item.name || id}]]`);
}
wikitext += `|-\n`;
wikitext += `| ${itemsList.join(' • ')}\n`;
wikitext += `|}\n`;
return wikitext;
}
exports.TEST = async function () {
const { data, version } = await Utils.resolveData("Trade_Items", true);
if (Utils.isModuleEmpty(data)) {
return '⚠️ Trade item data is unavailable for all known versions.';
}
const sortedData = Utils.sortObjectByKey(data);
let output = '';
output += `''Data version: <code>${version}</code>''\n\n`;
output += renderTable(sortedData);
return output;
};
exports.TEST_navbox = async function () {
const { data, version } = await Utils.resolveData("Trade_Items", true);
if (Utils.isModuleEmpty(data)) {
return '⚠️ Trade item data is unavailable for all known versions.';
}
const sortedData = Utils.sortObjectByKey(data);
let output = '';
output += `''Data version: <code>${version}</code>''\n\n`;
output += renderNavbox(sortedData);
return output;
}