Jump to content

Module:SmartMobLinks

From Drifters Almanac
Revision as of 07:31, 28 May 2025 by Mildew (talk | contribs)

Documentation for this module may be created at Module:SmartMobLinks/doc

local p = {}

-- Returns a <ul> of pretty links from a comma-delimited list of mob paths
function p.fromDelimited(frame)
    local raw = frame.args[1] or ""
    local delimiter = frame.args.delimiter or ","
    local items = mw.text.split(raw, delimiter)
    -- Use none list style to control markers manually
    local output = { '<ul style="margin-left: 1em; list-style-type: none; padding-left: 0;">' }

    for _, entry in ipairs(items) do
        local fullPath = mw.text.trim(entry)
        if fullPath ~= "" then
            -- Parse prefix (Mob or Named Mob) and the rest of the path
            local prefix, rest = string.match(fullPath, "^(.-)/(.+)$")
            if not rest then
                prefix = nil
                rest = fullPath
            end

            -- Separate name and zone if present
            local base, zone = string.match(rest, "^(.-)/(.+)$")
            local label = rest
            if base and zone then
                label = base .. " (" .. zone .. ")"
            end

            -- Determine marker for named mobs
            local marker = ""
            if prefix == "Named Mob" then
                marker = " ★"  -- star after link for named mobs
            end

            -- Format the list item without default bullet
            table.insert(output, string.format('<li style="margin-bottom: 0.5em;">[[%s|%s]]%s</li>', fullPath, label, marker))
        end
    end

    table.insert(output, '</ul>')
    return table.concat(output, "\n")
end

return p