Module:RaceData

From MB Wiki
Revision as of 12:04, 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 raceData = {
    ["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"
    },
    
    ["Minx (Dragon-kin)"] = {
        displayName = "Minx (Dragon-kin)",
        category = "Minx",
        subrace = "Dragon-kin"
    },
    
    ["Mortal"] = {
        displayName = "Mortal",
        category = "Standard"
    },
    
    ["Minx"] = {
        displayName = "Minx",
        category = "Minx",
        subrace = "Base"
    },
    
    ["Elf"] = {
        displayName = "Elf",
        category = "Elven"
    },
    
    ["Banished (Giant)"] = {
        displayName = "Banished (Giant)",
        category = "Banished",
        subrace = "Giant"
    },
    
    ["Minx (Tiger)"] = {
        displayName = "Minx (Tiger)",
        category = "Minx",
        subrace = "Tiger"
    },
    
    ["Minx (Moon Cat)"] = {
        displayName = "Minx (Moon Cat)",
        category = "Minx",
        subrace = "Moon Cat"
    },
    
    ["Minx-Giant"] = {
        displayName = "Minx-Giant",
        category = "Hybrid",
        subrace = "Minx-Giant"
    },
    
    ["Mortal/Vampire"] = {
        displayName = "Mortal/Vampire",
        category = "Hybrid",
        subrace = "Mortal-Vampire"
    },
    
    ["Fox Minx"] = {
        displayName = "Fox Minx",
        category = "Minx",
        subrace = "Fox"
    },
    
    ["Gothic Demon"] = {
        displayName = "Gothic Demon",
        category = "Demonic",
        subrace = "Gothic"
    },
    
    -- Additional races from your demographics table
    ["Felinyan"] = {
        displayName = "Felinyan",
        category = "Feline"
    },
    
    ["Dwarf"] = {
        displayName = "Dwarf",
        category = "Dwarven"
    },
    
    ["Banished"] = {
        displayName = "Banished",
        category = "Banished"
    },
    
    ["Demonkind"] = {
        displayName = "Demonkind",
        category = "Demonic"
    },
    
    ["Siren"] = {
        displayName = "Siren",
        category = "Aquatic",
        subrace = "Moon Priestess"
    }
}

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 as wikitext
function p.raceInfo(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 output = "'''" .. race.displayName .. "'''\n"
    output = output .. "* Category: " .. race.category .. "\n"
    if race.subrace then
        output = output .. "* Subrace: " .. race.subrace .. "\n"
    end
    
    return output
end

-- Function to list all races
function p.listAllRaces()
    local races = {}
    
    for name, _ in pairs(raceData) do
        table.insert(races, name)
    end
    
    table.sort(races)
    
    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
end

-- Function to get races by category
function p.getRacesByCategory(frame)
    local category = frame.args[1] or mw.text.trim(frame:getParent().args[1] or "")
    
    if category == "" then
        return "Error: No category provided"
    end
    
    local races = {}
    
    for name, data in pairs(raceData) do
        if data.category == category then
            table.insert(races, name)
        end
    end
    
    table.sort(races)
    
    local output = "=== " .. category .. " Races ===\n"
    if #races == 0 then
        output = output .. "No races found in this category.\n"
    else
        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
end

return p