Module:RaceData: Difference between revisions

From MB Wiki
Jump to navigation Jump to search
(Created page with "local p = {} local raceData = { -- Original list from your conversation ["Banished (Frog)"] = { displayName = "Banished (Frog)", category = "Banished", subrace = "Frog" }, ["Human"] = { displayName = "Human", category = "Standard" }, ["Banished (Armor Spirit)"] = { displayName = "Banished (Armor Spirit)", category = "Banished", subrace = "Armor Spirit" }, ["Min...")
 
mNo edit summary
 
(13 intermediate revisions by the same user not shown)
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 = {
    -- Original list from your conversation
     ["Banished (Frog)"] = {
     ["Banished (Frog)"] = {
         displayName = "Banished (Frog)",
         displayName = "Banished (Frog)",
         category = "Banished",
         category = "Banished",
         subrace = "Frog"
         subrace = "Frog",
        color = "#F44336",
        description = "Frog-like banished creatures with amphibious abilities."
     },
     },
      
      
     ["Human"] = {
     ["Human"] = {
         displayName = "Human",
         displayName = "Human",
         category = "Standard"
         category = "Standard",
        color = "#4CAF50",
        description = "Standard human race with versatile capabilities."
     },
     },
      
      
Line 17: Line 32:
         displayName = "Banished (Armor Spirit)",
         displayName = "Banished (Armor Spirit)",
         category = "Banished",
         category = "Banished",
         subrace = "Armor Spirit"
         subrace = "Armor Spirit",
        color = "#F44336",
        description = "Spiritual beings bound to armor, cast out from their realm."
     },
     },
      
      
Line 23: Line 40:
         displayName = "Minx (Dragon-kin)",
         displayName = "Minx (Dragon-kin)",
         category = "Minx",
         category = "Minx",
         subrace = "Dragon-kin"
         subrace = "Dragon-kin",
        color = "#FF9800",
        description = "Dragon-blooded minx with draconic features."
     },
     },
      
      
     ["Mortal"] = {
     ["Mortal"] = {
         displayName = "Mortal",
         displayName = "Mortal",
         category = "Standard"
         category = "Standard",
        color = "#4CAF50",
        description = "Mortal beings with finite lifespans and diverse backgrounds."
     },
     },
      
      
Line 34: Line 55:
         displayName = "Minx",
         displayName = "Minx",
         category = "Minx",
         category = "Minx",
         subrace = "Base"
         subrace = "Base",
        color = "#FF9800",
        description = "Base minx race with feline characteristics."
     },
     },
      
      
     ["Elf"] = {
     ["Elf"] = {
         displayName = "Elf",
         displayName = "Elf",
         category = "Elven"
         category = "Elven",
        color = "#9C27B0",
        description = "Elegant, long-lived beings with affinity for nature and magic."
     },
     },
      
      
Line 45: Line 70:
         displayName = "Banished (Giant)",
         displayName = "Banished (Giant)",
         category = "Banished",
         category = "Banished",
         subrace = "Giant"
         subrace = "Giant",
        color = "#F44336",
        description = "Gigantic banished beings with immense strength."
     },
     },
      
      
Line 51: Line 78:
         displayName = "Minx (Tiger)",
         displayName = "Minx (Tiger)",
         category = "Minx",
         category = "Minx",
         subrace = "Tiger"
         subrace = "Tiger",
        color = "#FF9800",
        description = "Tiger-striped minx with predatory instincts."
     },
     },
      
      
Line 57: Line 86:
         displayName = "Minx (Moon Cat)",
         displayName = "Minx (Moon Cat)",
         category = "Minx",
         category = "Minx",
         subrace = "Moon Cat"
         subrace = "Moon Cat",
        color = "#FF9800",
        description = "Lunar-aligned minx with mystical abilities."
     },
     },
      
      
Line 63: Line 94:
         displayName = "Minx-Giant",
         displayName = "Minx-Giant",
         category = "Hybrid",
         category = "Hybrid",
         subrace = "Minx-Giant"
         subrace = "Minx-Giant",
        color = "#FF5722",
        description = "Hybrid of Minx and Giant characteristics."
     },
     },
      
      
Line 69: Line 102:
         displayName = "Mortal/Vampire",
         displayName = "Mortal/Vampire",
         category = "Hybrid",
         category = "Hybrid",
         subrace = "Mortal-Vampire"
         subrace = "Mortal-Vampire",
        color = "#FF5722",
        description = "Hybrid beings with both mortal and vampiric traits."
     },
     },
      
      
Line 75: Line 110:
         displayName = "Fox Minx",
         displayName = "Fox Minx",
         category = "Minx",
         category = "Minx",
         subrace = "Fox"
         subrace = "Fox",
        color = "#FF9800",
        description = "Fox-like minx with cunning and agility."
     },
     },
      
      
Line 81: Line 118:
         displayName = "Gothic Demon",
         displayName = "Gothic Demon",
         category = "Demonic",
         category = "Demonic",
         subrace = "Gothic"
         subrace = "Gothic",
        color = "#9C27B0",
        description = "Dark, gothic-themed demonic beings."
     },
     },
      
      
    -- Additional races from your demographics table
     ["Felinyan"] = {
     ["Felinyan"] = {
         displayName = "Felinyan",
         displayName = "Felinyan",
         category = "Feline"
         category = "Feline",
        color = "#795548",
        description = "Feline humanoids with graceful movements."
     },
     },
      
      
     ["Dwarf"] = {
     ["Dwarf"] = {
         displayName = "Dwarf",
         displayName = "Dwarf",
         category = "Dwarven"
         category = "Dwarven",
        color = "#607D8B",
        description = "Stout, sturdy beings skilled in craftsmanship."
     },
     },
      
      
     ["Banished"] = {
     ["Banished"] = {
         displayName = "Banished",
         displayName = "Banished",
         category = "Banished"
         category = "Banished",
        color = "#F44336",
        description = "Beings cast out from their original realms."
     },
     },
      
      
     ["Demonkind"] = {
     ["Demonkind"] = {
         displayName = "Demonkind",
         displayName = "Demonkind",
         category = "Demonic"
         category = "Demonic",
        color = "#9C27B0",
        description = "Demonic beings with infernal powers."
     },
     },
      
      
Line 108: Line 154:
         displayName = "Siren",
         displayName = "Siren",
         category = "Aquatic",
         category = "Aquatic",
         subrace = "Moon Priestess"
         subrace = "Moon Priestess",
        color = "#2196F3",
        description = "Aquatic beings with enchanting voices and lunar connections."
     }
     }
}
}


-- Function to get race data
-- Function to get race info (for Template:RaceInfo)
function p.getRace(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 "")
      
      
     if raceName == "" then
     if raceName == "" then
         return "Error: No race name provided"
         return '<span class="race-error">Unknown Race</span>[[Category:Unknown Race]]'
     end
     end
      
      
Line 123: Line 171:
      
      
     if not race then
     if not race then
         return "Error: Race '" .. raceName .. "' not found in database"
         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
     end
    tooltipText = tooltipText .. '<br><br><small>Click for full race page →</small>'
      
      
     return race
    -- 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
end


-- Function to get race info as wikitext
-- Function to get race infobox for race pages
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 143: Line 215:
     end
     end
      
      
     local output = "'''" .. race.displayName .. "'''\n"
    local color = race.color or categoryColors[race.category] or "#666666"
     output = output .. "* Category: " .. race.category .. "\n"
    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
     if race.subrace then
         output = output .. "* Subrace: " .. race.subrace .. "\n"
         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
      
      
     return output
     if race.description then
end
         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>')
 
-- Function to list all races
function p.listAllRaces()
    local races = {}
   
    for name, _ in pairs(raceData) do
         table.insert(races, name)
     end
     end
      
      
     table.sort(races)
     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>')
    local output = "== Available Races ==\n"
    for _, raceName in ipairs(races) do
        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
      
      
     return output
     return table.concat(output, '')
end
end


-- Function to get races by category
-- Function to get race link with colored badge
function p.getRacesByCategory(frame)
function p.getRaceLink(frame)
     local category = 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 "")
      
      
     if category == "" then
     if raceName == "" then
         return "Error: No category provided"
         return "[[Category:Unknown Race]]"
     end
     end
      
      
     local races = {}
     local race = raceData[raceName]
      
      
     for name, data in pairs(raceData) do
     if not race then
        if data.category == category then
         return "[[Category:Unknown Race]]"
            table.insert(races, name)
         end
     end
     end
      
      
     table.sort(races)
     local color = race.color or categoryColors[race.category] or "#666666"
    local pageName = race.displayName .. " (Race)"
      
      
     local output = "=== " .. category .. " Races ===\n"
     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;">'
    if #races == 0 then
     output = output .. '[[' .. pageName .. '|' .. race.displayName .. ']]'
        output = output .. "No races found in this category.\n"
    output = output .. '</span>'
     else
    output = output .. '[[Category:' .. race.category .. ' Characters]]'
        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
      
      
     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