Module:RaceData

From MB Wiki
Revision as of 12:16, 20 January 2026 by Ais (talk | contribs)
Jump to navigation Jump to search

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

local p = {}

local categoryColors = {
    ["Standard"] = "#4CAF50",      
    ["Elven"] = "#9C27B0",         
    ["Minx"] = "#FF9800",          
    ["Feline"] = "#795548",        
    ["Dwarven"] = "#607D8B",       
    ["Banished"] = "#F44336",      
    ["Demonic"] = "#9C27B0",       
    ["Aquatic"] = "#2196F3",       
    ["Hybrid"] = "#FF5722",        
}

local raceData = {
    ["Banished (Frog)"] = {
        displayName = "Banished (Frog)",
        category = "Banished",
        subrace = "Frog",
        color = "#F44336"
    },
    
    ["Human"] = {
        displayName = "Human",
        category = "Standard",
        color = "#4CAF50"
    },
    
    ["Banished (Armor Spirit)"] = {
        displayName = "Banished (Armor Spirit)",
        category = "Banished",
        subrace = "Armor Spirit",
        color = "#F44336"
    },
    
    ["Minx (Dragon-kin)"] = {
        displayName = "Minx (Dragon-kin)",
        category = "Minx",
        subrace = "Dragon-kin",
        color = "#FF9800"
    },
    
    ["Mortal"] = {
        displayName = "Mortal",
        category = "Standard",
        color = "#4CAF50"
    },
    
    ["Minx"] = {
        displayName = "Minx",
        category = "Minx",
        subrace = "Base",
        color = "#FF9800"
    },
    
    ["Elf"] = {
        displayName = "Elf",
        category = "Elven",
        color = "#9C27B0"
    },
    
    ["Banished (Giant)"] = {
        displayName = "Banished (Giant)",
        category = "Banished",
        subrace = "Giant",
        color = "#F44336"
    },
    
    ["Minx (Tiger)"] = {
        displayName = "Minx (Tiger)",
        category = "Minx",
        subrace = "Tiger",
        color = "#FF9800"
    },
    
    ["Minx (Moon Cat)"] = {
        displayName = "Minx (Moon Cat)",
        category = "Minx",
        subrace = "Moon Cat",
        color = "#FF9800"
    },
    
    ["Minx-Giant"] = {
        displayName = "Minx-Giant",
        category = "Hybrid",
        subrace = "Minx-Giant",
        color = "#FF5722"
    },
    
    ["Mortal/Vampire"] = {
        displayName = "Mortal/Vampire",
        category = "Hybrid",
        subrace = "Mortal-Vampire",
        color = "#FF5722"
    },
    
    ["Fox Minx"] = {
        displayName = "Fox Minx",
        category = "Minx",
        subrace = "Fox",
        color = "#FF9800"
    },
    
    ["Gothic Demon"] = {
        displayName = "Gothic Demon",
        category = "Demonic",
        subrace = "Gothic",
        color = "#9C27B0"
    },
    
    ["Felinyan"] = {
        displayName = "Felinyan",
        category = "Feline",
        color = "#795548"
    },
    
    ["Dwarf"] = {
        displayName = "Dwarf",
        category = "Dwarven",
        color = "#607D8B"
    },
    
    ["Banished"] = {
        displayName = "Banished",
        category = "Banished",
        color = "#F44336"
    },
    
    ["Demonkind"] = {
        displayName = "Demonkind",
        category = "Demonic",
        color = "#9C27B0"
    },
    
    ["Siren"] = {
        displayName = "Siren",
        category = "Aquatic",
        subrace = "Moon Priestess",
        color = "#2196F3"
    }
}

-- Function to get race data
function p.getRace(frame)
    local raceName = frame.args[1] or mw.text.trim(frame:getParent().args[1] or "")
    
    if raceName == "" then
        return "Error: No race name provided"
    end
    
    local race = raceData[raceName]
    
    if not race then
        return "Error: Race '" .. raceName .. "' not found in database"
    end
    
    return race
end

-- Function to get race infobox with color coding
function p.getRaceInfobox(frame)
    local raceName = frame.args[1] or mw.text.trim(frame:getParent().args[1] or "")
    
    if raceName == "" then
        return "Error: No race name provided"
    end
    
    local race = raceData[raceName]
    
    if not race then
        return "Error: Race '" .. raceName .. "' not found"
    end
    
    local color = race.color or categoryColors[race.category] or "#666666"
    local lightColor = p.getLightColor(color)
    
    local output = ""
    
    output = output .. '<div class="race-mini-infobox" style="border-color: ' .. color .. ';">\n'
    output = output .. '<div class="race-header" style="background: linear-gradient(135deg, ' .. color .. ' 0%, ' .. p.darkenColor(color, 20) .. ' 100%);">\n'
    output = output .. '<h3>Race Information</h3>\n'
    output = output .. '</div>\n'
    output = output .. '<div class="race-content" style="background-color: ' .. lightColor .. ';">\n'
    output = output .. '<div class="race-badge" style="background-color: ' .. color .. ';">' .. race.category .. '</div>\n'
    output = output .. '<table class="race-info-table">\n'
    output = output .. '<tr><td><strong>Race:</strong></td><td>' .. race.displayName .. '</td></tr>\n'
    output = output .. '<tr><td><strong>Category:</strong></td><td><span class="category-tag" style="background-color: ' .. color .. ';">' .. race.category .. '</span></td></tr>\n'
    
    if race.subrace then
        output = output .. '<tr><td><strong>Subrace:</strong></td><td>' .. race.subrace .. '</td></tr>\n'
    end
    
    output = output .. '</table>\n'
    output = output .. '<div class="race-footer">\n'
    output = output .. '<a href="/wiki/' .. race.displayName .. ' (Race)" class="race-link">View Full Race Page</a>\n'
    output = output .. '</div>\n'
    output = output .. '</div>\n'
    output = output .. '</div>\n'
    
    return output
end

-- Function to get race link with colored badge
function p.getRaceLink(frame)
    local raceName = frame.args[1] or mw.text.trim(frame:getParent().args[1] or "")
    
    if raceName == "" then
        return "[[Category:Unknown Race]]"
    end
    
    local race = raceData[raceName]
    
    if not race then
        return "[[Category:Unknown Race]]"
    end
    
    local color = race.color or categoryColors[race.category] or "#666666"
    
    local output = ""
    
    -- Create colored badge link
    output = output .. '<span class="race-link-badge">'
    output = output .. '<a href="/wiki/' .. race.displayName .. ' (Race)" class="race-link" style="background-color: ' .. color .. ';">'
    output = output .. race.displayName
    output = output .. '</a>'
    output = output .. '</span>'
    
    -- Add category
    output = output .. "\n[[Category:" .. race.category .. " Characters]]"
    
    return output
end

-- Helper function to get light color variant
function p.getLightColor(hexColor)
    -- Convert hex to RGB
    local r = tonumber(hexColor:sub(2, 3), 16)
    local g = tonumber(hexColor:sub(4, 5), 16)
    local b = tonumber(hexColor:sub(6, 7), 16)
    
    -- Lighten by mixing with white (80% white, 20% original)
    r = math.floor(r * 0.2 + 255 * 0.8)
    g = math.floor(g * 0.2 + 255 * 0.8)
    b = math.floor(b * 0.2 + 255 * 0.8)
    
    return string.format("#%02X%02X%02X", r, g, b)
end

-- Helper function to darken color
function p.darkenColor(hexColor, percent)
    percent = percent or 20
    local r = tonumber(hexColor:sub(2, 3), 16)
    local g = tonumber(hexColor:sub(4, 5), 16)
    local b = tonumber(hexColor:sub(6, 7), 16)
    
    r = math.floor(r * (100 - percent) / 100)
    g = math.floor(g * (100 - percent) / 100)
    b = math.floor(b * (100 - percent) / 100)
    
    return string.format("#%02X%02X%02X", r, g, b)
end

-- Function to get colored category list
function p.getColoredCategories()
    local output = "== Race Categories ==\n"
    
    -- Group races by category
    local categories = {}
    for _, race in pairs(raceData) do
        if not categories[race.category] then
            categories[race.category] = {
                color = race.color or categoryColors[race.category] or "#666666",
                races = {}
            }
        end
        table.insert(categories[race.category].races, race.displayName)
    end
    
    -- Display each category
    for categoryName, categoryData in pairs(categories) do
        output = output .. '\n=== <span style="color: ' .. categoryData.color .. ';">' .. categoryName .. '</span> ===\n'
        table.sort(categoryData.races)
        for _, raceName in ipairs(categoryData.races) do
            output = output .. '* [[' .. raceName .. ' (Race)|' .. raceName .. ']]\n'
        end
    end
    
    return output
end

return p