ATLYSS TechPendium

Module:TEST/Trade Items

Viewing old revision of Module:TEST/Trade_Items

You are viewing an old revision of this page from 1/22/2026, 11:05:54 AM.

View latest version
No documentation subpage (/doc) found for this module.
const Utils = await require("Utils");
const Versions = await require("TEST/Versions");
const LatestGameVersion = Versions.latest;
const VersionEntries = Versions.versions || [];

function renderTable(items) {
    let wikitext = '';

    wikitext += '{| class="wiki-table"\n';
    wikitext += '! Name !! Rarity\n';

    for (const id in items) {
        const item = items[id];

        wikitext += '|-\n';

        // Name
        wikitext += `| '''${item.name || id}'''\n`;

        // Rarity
        if (item.rarity) {
            wikitext += `| {{Rarity|${item.rarity}}}\n`;
        } else {
            wikitext += `| {{Rarity|common}}\n`;
        }
    }

    wikitext += '|}\n';
    return wikitext;
}

exports.TEST = async function (props = {}) {
    let DATA = await require(`TEST/Trade_Items/data/${LatestGameVersion}`);
    let usedVersion = LatestGameVersion;

    // Fallback: iterate versions list in order
    if (Utils.isModuleEmpty(DATA)) {
        for (const entry of VersionEntries) {
            const v = entry.id;
            const candidate = await require(`TEST/Trade_Items/data/${v}`);

            if (!Utils.isModuleEmpty(candidate)) {
                DATA = candidate;
                usedVersion = v;
                break;
            }
        }
    }

    if (Utils.isModuleEmpty(DATA)) {
        return '⚠️ Trade item data is unavailable for all known versions.';
    }

    let output = '';
    output += `''Data version: <code>${usedVersion}</code>''\n\n`;
    output += renderTable(DATA);

    return output;
};
Last Edited by LiveGobe on 1/22/2026, 11:05:54 AM