Module:RaceData: Difference between revisions

From MB Wiki
Jump to navigation Jump to search
mNo edit summary
Tag: Reverted
mNo edit summary
 
(4 intermediate revisions by the same user not shown)
Line 160: Line 160:
}
}


-- Helper function to get light color variant
-- Function to get race info (for Template:RaceInfo)
function p.getLightColor(hexColor)
    if not hexColor or hexColor:len() ~= 7 then
        return "#F8F9FA"
    end
   
    local r = tonumber(hexColor:sub(2, 3), 16)
    local g = tonumber(hexColor:sub(4, 5), 16)
    local b = tonumber(hexColor:sub(6, 7), 16)
   
    if not r or not g or not b then
        return "#F8F9FA"
    end
   
    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
   
    if not hexColor or hexColor:len() ~= 7 then
        return "#333333"
    end
   
    local r = tonumber(hexColor:sub(2, 3), 16)
    local g = tonumber(hexColor:sub(4, 5), 16)
    local b = tonumber(hexColor:sub(6, 7), 16)
   
    if not r or not g or not b then
        return "#333333"
    end
   
    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 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 info with hover infobox (for Template:RaceInfo)
function p.getRaceInfo(frame)
function p.getRaceInfo(frame)
     local raceName = frame.args[1] or mw.text.trim(frame:getParent().args[1] or "")
     local raceName = frame.args[1] or mw.text.trim(frame:getParent().args[1] or "")
Line 236: Line 175:
      
      
     local color = race.color or categoryColors[race.category] or "#666666"
     local color = race.color or categoryColors[race.category] or "#666666"
     local lightColor = p.getLightColor(color)
     local pageName = race.displayName .. " (Race)"
    local darkColor = p.darkenColor(color, 20)
   
    local output = {}
      
      
     -- Start the hover container
     -- Build tooltip text
     table.insert(output, '<div class="race-hover-container">')
     local tooltipText = "<strong>" .. race.displayName .. "</strong>"
   
     tooltipText = tooltipText .. "<br><small>Category: " .. race.category .. "</small>"
    -- The clickable race link using MediaWiki link syntax
    -- Use class="new" to remove the "page does not exist" styling
    table.insert(output, '<span class="race-hover-trigger">')
    table.insert(output, '[[' .. race.displayName .. ' (Race)|<span class="race-link-inline" style="color: ' .. color .. ';">' .. race.displayName .. '</span>]]')
    table.insert(output, '</span>')
   
    -- The hidden infobox - appears ABOVE the text
    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
     if race.subrace then
         table.insert(output, '<tr><td><strong>Subrace:</strong></td><td>' .. race.subrace .. '</td></tr>')
         tooltipText = tooltipText .. "<br><small>Subrace: " .. race.subrace .. "</small>"
     end
     end
   
    -- Description row (if exists)
     if race.description then
     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>')
         tooltipText = tooltipText .. "<br><br>" .. race.description
     end
     end
    tooltipText = tooltipText .. '<br><br><small>Click for full race page →</small>'
      
      
    table.insert(output, '</table>')
     -- Create the tooltip container with proper MediaWiki link
   
     local output = '<span class="race-tooltip-container">'
     -- Footer with MediaWiki link
     output = output .. '[[' .. pageName .. '|<span class="race-link" style="color: ' .. color .. ';">' .. race.displayName .. '</span>]]'
     table.insert(output, '<div class="race-hover-footer">')
     output = output .. '<div class="race-tooltip">' .. tooltipText .. '</div>'
     table.insert(output, '[[' .. race.displayName .. ' (Race)|<span class="view-full-link" style="background-color: ' .. color .. ';">View Full Race Page</span>]]')
     output = output .. '</span>'
     table.insert(output, '</div>')
   
    table.insert(output, '</div>') -- Close content
     table.insert(output, '</div>') -- Close infobox
    table.insert(output, '</div>') -- Close container
      
      
     -- Add categories
     -- Add categories
     table.insert(output, '\n[[Category:' .. race.category .. ' Characters]]')
     output = output .. '[[Category:' .. race.category .. ' Characters]]'
     table.insert(output, '\n[[Category:' .. race.displayName .. ' Characters]]')
     output = output .. '[[Category:' .. race.displayName .. ' Characters]]'
      
      
     return table.concat(output, '')
     return output
end
end


Line 308: Line 216:
      
      
     local color = race.color or categoryColors[race.category] or "#666666"
     local color = race.color or categoryColors[race.category] or "#666666"
     local lightColor = p.getLightColor(color)
     local pageName = race.displayName .. " (Race)"
    local darkColor = p.darkenColor(color, 20)
      
      
     local output = {}
     local output = { '<table class="race-infobox" style="border: 2px solid ' .. color .. '; background: #f9f9f9; padding: 10px; margin: 10px 0; width: 300px; float: right; clear: right;">' }
      
      
     table.insert(output, '<div class="race-full-infobox" style="border-color: ' .. color .. ';">')
     table.insert(output, '<tr><th colspan="2" style="background: ' .. color .. '; color: white; padding: 8px; text-align: center;">Race Information</th></tr>')
    table.insert(output, '<div class="race-full-header" style="background: linear-gradient(135deg, ' .. color .. ' 0%, ' .. darkColor .. ' 100%);">')
     table.insert(output, '<tr><td style="padding: 8px; vertical-align: top;"><strong>Race Name:</strong></td><td style="padding: 8px;">' .. race.displayName .. '</td></tr>')
    table.insert(output, '<h2>Race Information</h2>')
     table.insert(output, '<tr><td style="padding: 8px; vertical-align: top;"><strong>Category:</strong></td><td style="padding: 8px;"><span style="background-color: ' .. color .. '; color: white; padding: 2px 6px; border-radius: 3px;">' .. race.category .. '</span></td></tr>')
    table.insert(output, '</div>')
     table.insert(output, '<div class="race-full-content" style="background-color: ' .. lightColor .. ';">')
    table.insert(output, '<div class="race-badge-large" style="background-color: ' .. color .. ';">' .. race.category .. '</div>')
    table.insert(output, '<table class="race-full-table">')
    table.insert(output, '<tr><td><strong>Race Name:</strong></td><td>' .. race.displayName .. '</td></tr>')
     table.insert(output, '<tr><td><strong>Category:</strong></td><td><span class="category-tag-large" style="background-color: ' .. color .. ';">' .. race.category .. '</span></td></tr>')
      
      
     if race.subrace then
     if race.subrace then
         table.insert(output, '<tr><td><strong>Subrace:</strong></td><td>' .. race.subrace .. '</td></tr>')
         table.insert(output, '<tr><td style="padding: 8px; vertical-align: top;"><strong>Subrace:</strong></td><td style="padding: 8px;">' .. race.subrace .. '</td></tr>')
     end
     end
      
      
     if race.description then
     if race.description then
         table.insert(output, '<tr><td><strong>Description:</strong></td><td>' .. race.description .. '</td></tr>')
         table.insert(output, '<tr><td style="padding: 8px; vertical-align: top;"><strong>Description:</strong></td><td style="padding: 8px; font-size: 0.9em;">' .. race.description .. '</td></tr>')
     end
     end
      
      
    table.insert(output, '<tr><td colspan="2" style="padding: 8px; border-top: 1px solid #ddd;"><strong>Characters:</strong><br/>[[Category:' .. race.displayName .. ' Characters|View all characters of this race]]</td></tr>')
     table.insert(output, '</table>')
     table.insert(output, '</table>')
    table.insert(output, '<div class="race-characters-section">')
    table.insert(output, '<h3>Characters of this Race</h3>')
    table.insert(output, '<div class="category-list">')
    table.insert(output, '{{#categorytree:' .. race.displayName .. ' Characters|depth=1|mode=pages}}')
    table.insert(output, '</div>')
    table.insert(output, '</div>')
    table.insert(output, '</div>')
    table.insert(output, '</div>')
      
      
     return table.concat(output, '')
     return table.concat(output, '')
Line 359: Line 253:
      
      
     local color = race.color or categoryColors[race.category] or "#666666"
     local color = race.color or categoryColors[race.category] or "#666666"
    local pageName = race.displayName .. " (Race)"
      
      
     local output = '<span class="race-link-badge">'
     local output = '<span class="race-badge" style="display: inline-block; background-color: ' .. color .. '; color: white; padding: 2px 8px; border-radius: 12px; font-size: 0.9em; font-weight: bold;">'
     output = output .. '[[' .. race.displayName .. ' (Race)|<span class="race-link" style="background-color: ' .. color .. ';">' .. race.displayName .. '</span>]]'
     output = output .. '[[' .. pageName .. '|' .. race.displayName .. ']]'
     output = output .. '</span>'
     output = output .. '</span>'
     output = output .. "\n[[Category:" .. race.category .. " Characters]]"
     output = output .. '[[Category:' .. race.category .. ' Characters]]'
   
    return output
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
 
-- Function to get all races in a category
function p.getRaceCategory(frame)
    local category = frame.args[1] or mw.text.trim(frame:getParent().args[1] or "")
   
    if category == "" then
        return "Error: No category specified"
    end
   
    local output = "== " .. category .. " Races ==\n\n"
    local found = false
   
    for raceName, race in pairs(raceData) do
        if race.category == category then
            found = true
            local color = race.color or categoryColors[race.category] or "#666666"
            output = output .. '=== <span style="color: ' .. color .. ';">' .. race.displayName .. '</span> ===\n'
            output = output .. '* [[' .. race.displayName .. ' (Race)|View Race Page]]\n'
            output = output .. '* [[:Category:' .. race.displayName .. ' Characters|View ' .. race.displayName .. ' Characters]]\n\n'
        end
    end
   
    if not found then
        return "Error: Category '" .. category .. "' not found or has no races"
    end
      
      
     return output
     return output

Latest revision as of 10:24, 22 January 2026

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",
        description = "Frog-like banished creatures with amphibious abilities."
    },
    
    ["Human"] = {
        displayName = "Human",
        category = "Standard",
        color = "#4CAF50",
        description = "Standard human race with versatile capabilities."
    },
    
    ["Banished (Armor Spirit)"] = {
        displayName = "Banished (Armor Spirit)",
        category = "Banished",
        subrace = "Armor Spirit",
        color = "#F44336",
        description = "Spiritual beings bound to armor, cast out from their realm."
    },
    
    ["Minx (Dragon-kin)"] = {
        displayName = "Minx (Dragon-kin)",
        category = "Minx",
        subrace = "Dragon-kin",
        color = "#FF9800",
        description = "Dragon-blooded minx with draconic features."
    },
    
    ["Mortal"] = {
        displayName = "Mortal",
        category = "Standard",
        color = "#4CAF50",
        description = "Mortal beings with finite lifespans and diverse backgrounds."
    },
    
    ["Minx"] = {
        displayName = "Minx",
        category = "Minx",
        subrace = "Base",
        color = "#FF9800",
        description = "Base minx race with feline characteristics."
    },
    
    ["Elf"] = {
        displayName = "Elf",
        category = "Elven",
        color = "#9C27B0",
        description = "Elegant, long-lived beings with affinity for nature and magic."
    },
    
    ["Banished (Giant)"] = {
        displayName = "Banished (Giant)",
        category = "Banished",
        subrace = "Giant",
        color = "#F44336",
        description = "Gigantic banished beings with immense strength."
    },
    
    ["Minx (Tiger)"] = {
        displayName = "Minx (Tiger)",
        category = "Minx",
        subrace = "Tiger",
        color = "#FF9800",
        description = "Tiger-striped minx with predatory instincts."
    },
    
    ["Minx (Moon Cat)"] = {
        displayName = "Minx (Moon Cat)",
        category = "Minx",
        subrace = "Moon Cat",
        color = "#FF9800",
        description = "Lunar-aligned minx with mystical abilities."
    },
    
    ["Minx-Giant"] = {
        displayName = "Minx-Giant",
        category = "Hybrid",
        subrace = "Minx-Giant",
        color = "#FF5722",
        description = "Hybrid of Minx and Giant characteristics."
    },
    
    ["Mortal/Vampire"] = {
        displayName = "Mortal/Vampire",
        category = "Hybrid",
        subrace = "Mortal-Vampire",
        color = "#FF5722",
        description = "Hybrid beings with both mortal and vampiric traits."
    },
    
    ["Fox Minx"] = {
        displayName = "Fox Minx",
        category = "Minx",
        subrace = "Fox",
        color = "#FF9800",
        description = "Fox-like minx with cunning and agility."
    },
    
    ["Gothic Demon"] = {
        displayName = "Gothic Demon",
        category = "Demonic",
        subrace = "Gothic",
        color = "#9C27B0",
        description = "Dark, gothic-themed demonic beings."
    },
    
    ["Felinyan"] = {
        displayName = "Felinyan",
        category = "Feline",
        color = "#795548",
        description = "Feline humanoids with graceful movements."
    },
    
    ["Dwarf"] = {
        displayName = "Dwarf",
        category = "Dwarven",
        color = "#607D8B",
        description = "Stout, sturdy beings skilled in craftsmanship."
    },
    
    ["Banished"] = {
        displayName = "Banished",
        category = "Banished",
        color = "#F44336",
        description = "Beings cast out from their original realms."
    },
    
    ["Demonkind"] = {
        displayName = "Demonkind",
        category = "Demonic",
        color = "#9C27B0",
        description = "Demonic beings with infernal powers."
    },
    
    ["Siren"] = {
        displayName = "Siren",
        category = "Aquatic",
        subrace = "Moon Priestess",
        color = "#2196F3",
        description = "Aquatic beings with enchanting voices and lunar connections."
    }
}

-- Function to get race info (for Template:RaceInfo)
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 pageName = race.displayName .. " (Race)"
    
    -- Build tooltip text
    local tooltipText = "<strong>" .. race.displayName .. "</strong>"
    tooltipText = tooltipText .. "<br><small>Category: " .. race.category .. "</small>"
    if race.subrace then
        tooltipText = tooltipText .. "<br><small>Subrace: " .. race.subrace .. "</small>"
    end
    if race.description then
        tooltipText = tooltipText .. "<br><br>" .. race.description
    end
    tooltipText = tooltipText .. '<br><br><small>Click for full race page →</small>'
    
    -- Create the tooltip container with proper MediaWiki link
    local output = '<span class="race-tooltip-container">'
    output = output .. '[[' .. pageName .. '|<span class="race-link" style="color: ' .. color .. ';">' .. race.displayName .. '</span>]]'
    output = output .. '<div class="race-tooltip">' .. tooltipText .. '</div>'
    output = output .. '</span>'
    
    -- Add categories
    output = output .. '[[Category:' .. race.category .. ' Characters]]'
    output = output .. '[[Category:' .. race.displayName .. ' Characters]]'
    
    return output
end

-- Function to get race infobox for race pages
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 pageName = race.displayName .. " (Race)"
    
    local output = { '<table class="race-infobox" style="border: 2px solid ' .. color .. '; background: #f9f9f9; padding: 10px; margin: 10px 0; width: 300px; float: right; clear: right;">' }
    
    table.insert(output, '<tr><th colspan="2" style="background: ' .. color .. '; color: white; padding: 8px; text-align: center;">Race Information</th></tr>')
    table.insert(output, '<tr><td style="padding: 8px; vertical-align: top;"><strong>Race Name:</strong></td><td style="padding: 8px;">' .. race.displayName .. '</td></tr>')
    table.insert(output, '<tr><td style="padding: 8px; vertical-align: top;"><strong>Category:</strong></td><td style="padding: 8px;"><span style="background-color: ' .. color .. '; color: white; padding: 2px 6px; border-radius: 3px;">' .. race.category .. '</span></td></tr>')
    
    if race.subrace then
        table.insert(output, '<tr><td style="padding: 8px; vertical-align: top;"><strong>Subrace:</strong></td><td style="padding: 8px;">' .. race.subrace .. '</td></tr>')
    end
    
    if race.description then
        table.insert(output, '<tr><td style="padding: 8px; vertical-align: top;"><strong>Description:</strong></td><td style="padding: 8px; font-size: 0.9em;">' .. race.description .. '</td></tr>')
    end
    
    table.insert(output, '<tr><td colspan="2" style="padding: 8px; border-top: 1px solid #ddd;"><strong>Characters:</strong><br/>[[Category:' .. race.displayName .. ' Characters|View all characters of this race]]</td></tr>')
    table.insert(output, '</table>')
    
    return table.concat(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 pageName = race.displayName .. " (Race)"
    
    local output = '<span class="race-badge" style="display: inline-block; background-color: ' .. color .. '; color: white; padding: 2px 8px; border-radius: 12px; font-size: 0.9em; font-weight: bold;">'
    output = output .. '[[' .. pageName .. '|' .. race.displayName .. ']]'
    output = output .. '</span>'
    output = output .. '[[Category:' .. race.category .. ' Characters]]'
    
    return output
end

return p