Module:RaceData: Difference between revisions

From MB Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 1: Line 1:
local p = {}
local p = {}
local categoryColors = {
    ["Standard"] = "#4CAF50",     
    ["Elven"] = "#9C27B0",       
    ["Minx"] = "#FF9800",         
    ["Feline"] = "#795548",       
    ["Dwarven"] = "#607D8B",     
    ["Banished"] = "#F44336",     
    ["Demonic"] = "#9C27B0",     
    ["Aquatic"] = "#2196F3",     
    ["Hybrid"] = "#FF5722",       
}


local raceData = {
local raceData = {
Line 5: Line 17:
         displayName = "Banished (Frog)",
         displayName = "Banished (Frog)",
         category = "Banished",
         category = "Banished",
         subrace = "Frog"
         subrace = "Frog",
        color = "#F44336"
     },
     },
      
      
     ["Human"] = {
     ["Human"] = {
         displayName = "Human",
         displayName = "Human",
         category = "Standard"
         category = "Standard",
        color = "#4CAF50"
     },
     },
      
      
Line 16: Line 30:
         displayName = "Banished (Armor Spirit)",
         displayName = "Banished (Armor Spirit)",
         category = "Banished",
         category = "Banished",
         subrace = "Armor Spirit"
         subrace = "Armor Spirit",
        color = "#F44336"
     },
     },
      
      
Line 22: Line 37:
         displayName = "Minx (Dragon-kin)",
         displayName = "Minx (Dragon-kin)",
         category = "Minx",
         category = "Minx",
         subrace = "Dragon-kin"
         subrace = "Dragon-kin",
        color = "#FF9800"
     },
     },
      
      
     ["Mortal"] = {
     ["Mortal"] = {
         displayName = "Mortal",
         displayName = "Mortal",
         category = "Standard"
         category = "Standard",
        color = "#4CAF50"
     },
     },
      
      
Line 33: Line 50:
         displayName = "Minx",
         displayName = "Minx",
         category = "Minx",
         category = "Minx",
         subrace = "Base"
         subrace = "Base",
        color = "#FF9800"
     },
     },
      
      
     ["Elf"] = {
     ["Elf"] = {
         displayName = "Elf",
         displayName = "Elf",
         category = "Elven"
         category = "Elven",
        color = "#9C27B0"
     },
     },
      
      
Line 44: Line 63:
         displayName = "Banished (Giant)",
         displayName = "Banished (Giant)",
         category = "Banished",
         category = "Banished",
         subrace = "Giant"
         subrace = "Giant",
        color = "#F44336"
     },
     },
      
      
Line 50: Line 70:
         displayName = "Minx (Tiger)",
         displayName = "Minx (Tiger)",
         category = "Minx",
         category = "Minx",
         subrace = "Tiger"
         subrace = "Tiger",
        color = "#FF9800"
     },
     },
      
      
Line 56: Line 77:
         displayName = "Minx (Moon Cat)",
         displayName = "Minx (Moon Cat)",
         category = "Minx",
         category = "Minx",
         subrace = "Moon Cat"
         subrace = "Moon Cat",
        color = "#FF9800"
     },
     },
      
      
Line 62: Line 84:
         displayName = "Minx-Giant",
         displayName = "Minx-Giant",
         category = "Hybrid",
         category = "Hybrid",
         subrace = "Minx-Giant"
         subrace = "Minx-Giant",
        color = "#FF5722"
     },
     },
      
      
Line 68: Line 91:
         displayName = "Mortal/Vampire",
         displayName = "Mortal/Vampire",
         category = "Hybrid",
         category = "Hybrid",
         subrace = "Mortal-Vampire"
         subrace = "Mortal-Vampire",
        color = "#FF5722"
     },
     },
      
      
Line 74: Line 98:
         displayName = "Fox Minx",
         displayName = "Fox Minx",
         category = "Minx",
         category = "Minx",
         subrace = "Fox"
         subrace = "Fox",
        color = "#FF9800"
     },
     },
      
      
Line 80: Line 105:
         displayName = "Gothic Demon",
         displayName = "Gothic Demon",
         category = "Demonic",
         category = "Demonic",
         subrace = "Gothic"
         subrace = "Gothic",
        color = "#9C27B0"
     },
     },
      
      
    -- Additional races from your demographics table
     ["Felinyan"] = {
     ["Felinyan"] = {
         displayName = "Felinyan",
         displayName = "Felinyan",
         category = "Feline"
         category = "Feline",
        color = "#795548"
     },
     },
      
      
     ["Dwarf"] = {
     ["Dwarf"] = {
         displayName = "Dwarf",
         displayName = "Dwarf",
         category = "Dwarven"
         category = "Dwarven",
        color = "#607D8B"
     },
     },
      
      
     ["Banished"] = {
     ["Banished"] = {
         displayName = "Banished",
         displayName = "Banished",
         category = "Banished"
         category = "Banished",
        color = "#F44336"
     },
     },
      
      
     ["Demonkind"] = {
     ["Demonkind"] = {
         displayName = "Demonkind",
         displayName = "Demonkind",
         category = "Demonic"
         category = "Demonic",
        color = "#9C27B0"
     },
     },
      
      
Line 107: Line 136:
         displayName = "Siren",
         displayName = "Siren",
         category = "Aquatic",
         category = "Aquatic",
         subrace = "Moon Priestess"
         subrace = "Moon Priestess",
        color = "#2196F3"
     }
     }
}
}


-- Function to get race data
function p.getRace(frame)
function p.getRace(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 127: Line 158:
end
end


-- Function to get race info as wikitext
-- Function to get race infobox with color coding
function p.raceInfo(frame)
function p.getRaceInfobox(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 141: Line 172:
     end
     end
      
      
     local output = "'''" .. race.displayName .. "'''\n"
    local color = race.color or categoryColors[race.category] or "#666666"
     output = output .. "* Category: " .. race.category .. "\n"
    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
     if race.subrace then
         output = output .. "* Subrace: " .. race.subrace .. "\n"
         output = output .. '<tr><td><strong>Subrace:</strong></td><td>' .. race.subrace .. '</td></tr>\n'
     end
     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
     return output
end
end


-- Function to list all races
-- Function to get race link with colored badge
function p.listAllRaces()
function p.getRaceLink(frame)
     local races = {}
     local raceName = frame.args[1] or mw.text.trim(frame:getParent().args[1] or "")
      
      
     for name, _ in pairs(raceData) do
     if raceName == "" then
         table.insert(races, name)
         return "[[Category:Unknown Race]]"
     end
     end
      
      
     table.sort(races)
     local race = raceData[raceName]
      
      
     local output = "== Available Races ==\n"
     if not race then
    for _, raceName in ipairs(races) do
         return "[[Category:Unknown Race]]"
        local race = raceData[raceName]
         output = output .. "* [[" .. race.displayName .. " (Race)|" .. race.displayName .. "]] - " .. race.category
        if race.subrace then
            output = output .. " (" .. race.subrace .. ")"
        end
        output = output .. "\n"
     end
     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
     return output
end
end


-- Function to get races by category
-- Helper function to get light color variant
function p.getRacesByCategory(frame)
function p.getLightColor(hexColor)
     local category = frame.args[1] or mw.text.trim(frame:getParent().args[1] or "")
    -- 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)
      
      
     if category == "" then
     r = math.floor(r * (100 - percent) / 100)
        return "Error: No category provided"
    g = math.floor(g * (100 - percent) / 100)
     end
     b = math.floor(b * (100 - percent) / 100)
      
      
     local races = {}
    return string.format("#%02X%02X%02X", r, g, b)
end
 
-- Function to get colored category list
function p.getColoredCategories()
     local output = "== Race Categories ==\n"
      
      
     for name, data in pairs(raceData) do
    -- Group races by category
         if data.category == category then
    local categories = {}
             table.insert(races, name)
     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
         end
        table.insert(categories[race.category].races, race.displayName)
     end
     end
      
      
     table.sort(races)
     -- Display each category
   
    for categoryName, categoryData in pairs(categories) do
    local output = "=== " .. category .. " Races ===\n"
        output = output .. '\n=== <span style="color: ' .. categoryData.color .. ';">' .. categoryName .. '</span> ===\n'
    if #races == 0 then
         table.sort(categoryData.races)
         output = output .. "No races found in this category.\n"
         for _, raceName in ipairs(categoryData.races) do
    else
             output = output .. '* [[' .. raceName .. ' (Race)|' .. raceName .. ']]\n'
         for _, raceName in ipairs(races) do
            local race = raceData[raceName]
             output = output .. "* [[" .. race.displayName .. " (Race)|" .. race.displayName .. "]]"
            if race.subrace then
                output = output .. " (" .. race.subrace .. ")"
            end
            output = output .. "\n"
         end
         end
     end
     end

Revision as of 12:16, 20 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"
    },
    
    ["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