Module:RaceData

From MB Wiki
Revision as of 09:40, 21 January 2026 by Ais (talk | contribs)
Jump to navigation Jump to search

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

-- Function to get race info with hover infobox - SIMPLER VERSION
function p.getRaceInfo(frame)
    local raceName = frame.args[1] or mw.text.trim(frame:getParent().args[1] or "")
    
    if raceName == "" then
        return '<span class="race-error">Unknown Race</span>[[Category:Unknown Race]]'
    end
    
    local race = raceData[raceName]
    
    if not race then
        return '<span class="race-error">Race Not Found</span>[[Category:Unknown Race]]'
    end
    
    local color = race.color or categoryColors[race.category] or "#666666"
    local lightColor = p.getLightColor(color)
    local darkColor = p.darkenColor(color, 20)
    
    local output = {}
    
    table.insert(output, '<div class="race-hover-container">')
    
    -- The clickable race link
    table.insert(output, '<span class="race-hover-trigger">')
    table.insert(output, '<a href="/wiki/' .. mw.uri.encode(race.displayName) .. ' (Race)" class="race-link-inline" style="color: ' .. color .. ';">')
    table.insert(output, race.displayName)
    table.insert(output, '</a>')
    table.insert(output, '</span>')
    
    -- The hidden infobox
    table.insert(output, '<div class="race-hover-infobox" style="border-color: ' .. color .. ';">')
    
    -- Header
    table.insert(output, '<div class="race-hover-header" style="background: linear-gradient(135deg, ' .. color .. ' 0%, ' .. darkColor .. ' 100%);">')
    table.insert(output, '<h4>' .. race.displayName .. '</h4>')
    table.insert(output, '</div>')
    
    -- Content
    table.insert(output, '<div class="race-hover-content" style="background-color: ' .. lightColor .. ';">')
    table.insert(output, '<table class="race-hover-table">')
    
    -- Category row
    table.insert(output, '<tr><td><strong>Category:</strong></td><td><span class="category-badge-small" style="background-color: ' .. color .. ';">' .. race.category .. '</span></td></tr>')
    
    -- Subrace row (if exists)
    if race.subrace then
        table.insert(output, '<tr><td><strong>Subrace:</strong></td><td>' .. race.subrace .. '</td></tr>')
    end
    
    -- Description row (if exists)
    if race.description then
        table.insert(output, '<tr><td colspan="2" style="padding-top: 10px; font-size: 0.9em; line-height: 1.4; color: #555;">' .. race.description .. '</td></tr>')
    end
    
    table.insert(output, '</table>')
    
    -- Footer
    table.insert(output, '<div class="race-hover-footer">')
    table.insert(output, '<a href="/wiki/' .. mw.uri.encode(race.displayName) .. ' (Race)" class="view-full-link" style="background-color: ' .. color .. ';">View Full Race Page</a>')
    table.insert(output, '</div>')
    
    table.insert(output, '</div>') -- Close content
    table.insert(output, '</div>') -- Close infobox
    table.insert(output, '</div>') -- Close container
    
    -- Add categories
    table.insert(output, '\n[[Category:' .. race.category .. ' Characters]]')
    table.insert(output, '\n[[Category:' .. race.displayName .. ' Characters]]')
    
    return table.concat(output, '')
end