Module:Emotes

From Dune: Awakening Community Wiki
Jump to navigation Jump to search

Module:Emotes

Renders a sortable wikitable of emotes defined in Module:Emotes/data with translatable display strings from MessageBundle:Emotes and other relevant MessageBundles.

This module provides the following function(s):

  • list - renders all emotes, or a subset filtered by source, as a wikitable inside a collapsible section.

Usage

List all emotes

By default, all emotes are shown, sorted by display name.

{{#invoke:Emotes|list}}

Filter by source

A source name can be provided to show only emotes matching that source. The Source column is omitted from the output, since it would be redundant once filtered.

{{#invoke:Emotes|list|Lost Harvest}}

Emotes that are available by default (default in the dataset) are filtered the same way:

{{#invoke:Emotes|list|Default}}

The filter value is slugified before matching, so it does not need to exactly match the casing/formatting used in Module:Emotes/data.

Set heading level

By default, the section heading renders as h3. To override this, pass a value to the heading parameter.

{{#invoke:Emotes|list|heading=2}}

Render expanded

The section may auto-collapse depending on the number of items listed. To force the section expanded regardless of count, pass a truthy value to the expanded parameter.

{{#invoke:Emotes|list|expanded=yes}}

Render without the collapsible wrapper

To output the bare content with no heading, count marker, or collapsible section, pass a truthy value to the bare parameter.

{{#invoke:Emotes|list|bare=yes}}

Parameters

list

1 (optional)
string
Source name to filter by. Slugified before matching against the source token's slug half in Module:Emotes/data.
Returns an error message if no emotes match.
heading (optional)
integer
Heading level for the generated heading. Defaults to 3, i.e. h3.
Must be an integer between 1 and 6. Invalid or out-of-range values fall back to the default.
expanded (optional)
boolean
If specified with a truthy value, output will be expanded by default.
Valid values:
true
yes
1
bare (optional)
boolean
If specified with a truthy value, returns only the content, with no heading, count marker, or collapsible wrapper.

Notes

list

  • Display strings are resolved via MessageBundle:Emotes using the page's current language, keyed by each emote's id (as <ID>-name and <ID>-description).
  • All column headers and section titles resolve via MessageBundle:Labels.
  • Source values are rendered as wikilinks to their English-titled page, except default, which is shown as plain text since it has no corresponding page.
  • Output is wrapped in a shared collapsible section (see newCollapsibleSection() in Module:Common). A count marker (Total: <INTEGER>) appears between the heading and the content and stays visible regardless of collapse state. The section auto-collapses by default once the item count exceeds 6; pass expanded=yes to override.

local p = {}

local common = require("Module:Common")
local data = require("Module:Emotes/data")

-- ---------- Data ----------

local SORTED_EMOTES = {}
for _, emote in ipairs(data) do
    emote.displayName = common.translate("Emotes", emote.id .. "-name")
    SORTED_EMOTES[#SORTED_EMOTES + 1] = emote
end

table.sort(SORTED_EMOTES, function(a, b) return a.displayName < b.displayName end)

-- ---------- Rendering ----------

local function renderTable(list, showSource)
    local table_ = common.newSortableTable()
    local headerRow = table_:tag("tr")

    headerRow:tag("th"):addClass("unsortable"):wikitext(common.translate("Labels", "icon"))
    headerRow:tag("th"):wikitext(common.translate("Labels", "name"))
    headerRow:tag("th"):addClass("unsortable"):wikitext(common.translate("Labels", "description"))

    if showSource then
        headerRow:tag("th"):wikitext(common.translate("Labels", "source"))
    end

    headerRow:tag("th"):wikitext(common.translate("Labels", "version"))

    for _, emote in ipairs(list) do
        local displayDescription = common.translate("Emotes", emote.id .. "-description")

        local row = table_:tag("tr")

        row:tag("td"):css("min-width", "128px"):wikitext(string.format("[[File:%s|128px]]", emote.image))
        row:tag("td"):css("font-weight", "bold"):wikitext(emote.displayName)
        row:tag("td"):css("text-align", "left"):wikitext(displayDescription)

        if showSource then
            row:tag("td"):wikitext(common.renderSource(emote.source))
        end

        row:tag("td"):wikitext(common.renderVersion(emote.version))
    end

    return table_
end

-- ---------- Interface ----------

function p.list(frame)
    local args = frame.args

    local rawSource = common.trim(args[1])
    local sourceFilter = rawSource ~= "" and common.slugify(rawSource) or ""

    local filtered = SORTED_EMOTES

    if sourceFilter ~= "" then
        filtered = {}
        for _, emote in ipairs(SORTED_EMOTES) do
            if common.sourceMatches(emote.source, sourceFilter) then filtered[#filtered + 1] = emote end
        end

        if #filtered == 0 then return common.error("No emotes match source: <code>%s</code>", rawSource) end
    end

    local showSource = sourceFilter == ""

    local table_ = renderTable(filtered, showSource)

    if common.isTruthy(args.bare) then return tostring(table_) end

    local title = common.translate("Labels", "emotes", nil, true)

    local outer, content = common.newCollapsibleSection(title, #filtered, args.heading, args.expanded)
    content:node(table_)

    return tostring(outer)
end

return p