Module:AbilityTable: Difference between revisions

Jump to navigation Jump to search
Vergir (talk | contribs)
refactor abilitytable to use submodules
Vergir (talk | contribs)
consolidate three note formatters into two: enrich_notes_full and enrich_notes_compact (with help from vergir-bot LLM)
Line 46: Line 46:


-- ============================================================
-- ============================================================
-- Human-note formatters
-- Note enrichment
-- ============================================================
-- ============================================================


-- Capitalises the first letter of a human note before merging (full-table mode).
-- Merges auto-generated and human notes for full-table mode.
local function human_note_full(note)
-- Capitalizes human note, joins with ". ", ensures trailing period.
     if not note or note == "" then return note end
local function enrich_notes_full(extra, human_note)
    return note:sub(1,1):upper() .. note:sub(2)
     if human_note then
        human_note = human_note:sub(1,1):upper() .. human_note:sub(2)
        extra["Notes"] = extra["Notes"] and (extra["Notes"] .. ". " .. human_note) or human_note
    end
    if extra["Notes"] and extra["Notes"]:sub(-1) ~= "." then
        extra["Notes"] = extra["Notes"] .. "."
    end
end
end


-- Ensures the final merged Notes string ends with "." (full-table mode).
-- Merges auto-generated and human notes for compact mode.
local function ensure_period(s)
-- Decapitalizes human note (skips T{N} prefixes like "T1 slow"),
    if not s or s == "" then return s end
-- joins with "; ", strips trailing period.
    if s:sub(-1) ~= "." then s = s .. "." end
local function enrich_notes_compact(extra, human_note)
    return s
     if human_note then
end
        local first = human_note:sub(1,1)
 
        if first:match("%u") and not human_note:sub(2,2):match("%d") then
-- Compact mode: decapitalise first letter unless it looks like a tier prefix
            human_note = first:lower() .. human_note:sub(2)
-- (e.g. "T1", "T2"). Also strips any trailing ".".
        end
local function human_note_compact(note)
        if human_note:sub(-1) == "." then human_note = human_note:sub(1, -2) end
     if not note or note == "" then return note end
        extra["Notes"] = extra["Notes"] and (extra["Notes"] .. "; " .. human_note) or human_note
    local first = note:sub(1,1)
    if first:match("%u") and not note:sub(2,2):match("%d") then
        note = first:lower() .. note:sub(2)
     end
     end
    if note:sub(-1) == "." then note = note:sub(1, -2) end
    return note
end
end


Line 225: Line 226:


                 local extra = get_cells(ability)
                 local extra = get_cells(ability)
                 if stat_notes and stat_notes[name] then
                 enrich_notes_compact(extra, stat_notes and stat_notes[name])
                    local human = human_note_compact(stat_notes[name])
                    extra["Notes"] = extra["Notes"] and (extra["Notes"] .. "; " .. human) or human
                end


                 local note = extra["Notes"]
                 local note = extra["Notes"]
Line 279: Line 277:


         local extra = get_cells(ability)
         local extra = get_cells(ability)
 
         enrich_notes_full(extra, stat_notes and stat_notes[ability["Name"]])
         if stat_notes and stat_notes[ability["Name"]] then
            local human = human_note_full(stat_notes[ability["Name"]])
            extra["Notes"] = extra["Notes"] and (extra["Notes"] .. ". " .. human) or human
        end
        extra["Notes"] = ensure_period(extra["Notes"])


         local row = '| class="ability-table-cell-hero" | '    .. hero_cell
         local row = '| class="ability-table-cell-hero" | '    .. hero_cell