Jump to content

Module:ItemTooltip

From Apogea Wiki
Revision as of 21:23, 27 January 2026 by Jayarrowz (talk | contribs) (Item toolip module)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Module:ItemTooltip

This module displays styled item tooltip panels for wiki pages.

Basic Usage

{{#invoke:ItemTooltip|display
|name=Item Name
|rarity=common
|damage=10
|weight=5
}}

Parameters

Parameter Required Description
name Yes The item's display name (also used for sprite)
rarity No common, uncommon, rare, epic, or legendary (default: common)
type No Item type shown in brackets, e.g., "Dagger", "Large Weapons"
description No Flavor text (shown in green/jade color)
float No "right" or "left" (default: right)
spriteSize No Sprite size in pixels (default: 64)

Stats

Parameter Bonus Parameter Description
damage damageBonus Damage value
armor armorBonus Armor value
defense defenseBonus Defense value
range rangeBonus Range value
attackspeed attackspeedBonus Attack speed (negative values show in red)
movespeed movespeedBonus Movement speed
hpRegen hpRegenBonus HP regeneration
mpRegen mpRegenBonus MP regeneration
size - Size value (e.g., "8/10")
weight - Weight in oz (just the number)

Special Properties

Parameter Description
special Special effect text (shown in blue), e.g., "Fills you for 340 seconds"
action Action hint, e.g., "right-click to eat"
category Additional category, e.g., "Special Foods"

Rarity Colors

Rarity Color Example
common Silver Template:Color
uncommon Mint/Green Template:Color
rare Sky Blue Template:Color
epic Pink Template:Color
legendary Gold Template:Color

Rarity Shortcuts

You can use shortcut functions instead of specifying rarity:

{{#invoke:ItemTooltip|common|name=Basic Sword|...}}
{{#invoke:ItemTooltip|uncommon|name=Silver Dagger|...}}
{{#invoke:ItemTooltip|rare|name=Crossbow|...}}
{{#invoke:ItemTooltip|epic|name=Battle Axe|...}}
{{#invoke:ItemTooltip|legendary|name=Excalibur|...}}

Examples

Common Food Item

{{#invoke:ItemTooltip|display
|name=Blueberry Muffin
|rarity=common
|damage=2
|movespeed=1
|hpRegen=12
|mpRegen=8
|weight=10.5
|special=Fills you for 340 seconds
|action=right-click to eat
|category=Special Foods
}}

Weapon with Bonus Stats

{{#invoke:ItemTooltip|display
|name=Broadsword
|rarity=common
|range=2
|damage=27
|damageBonus=4
|attackspeed=-3
|defense=5
|size=8/10
|weight=75
|type=Large Weapons
}}

Uncommon Weapon

{{#invoke:ItemTooltip|uncommon
|name=Silver Dagger
|type=Dagger
|description=For rituals.
|damage=4
|attackspeed=3
|size=2/10
|weight=5.6
}}

Rare Weapon

{{#invoke:ItemTooltip|rare
|name=Crossbow
|type=Crossbow
|range=61
|damage=4
|attackspeed=-3
|defense=2
|size=9/10
|weight=22.4
}}

Epic Weapon

{{#invoke:ItemTooltip|epic
|name=Battle Axe
|type=Large Axe
|description=A nhordic axe.
|range=4
|damage=44
|attackspeed=-1
|defense=4
|size=8/10
|weight=45
}}

Legendary Tool

{{#invoke:ItemTooltip|legendary
|name=Shovel
|type=Tools
|description=Used to open holes.
|damage=11
|defense=5
|size=6/10
|weight=13
}}

Stat Colors

Float Position

By default, tooltips float to the right. Use float=left to position on the left side:

{{#invoke:ItemTooltip|display
|name=Item Name
|float=left
|...
}}

-- Module:ItemTooltip
-- Displays game item tooltips with stats and rarity styling
-- Usage: {{#invoke:ItemTooltip|display|name=Item Name|...}}

local p = {}

-- Rarity color mapping
local rarityColors = {
    common = "silver",
    uncommon = "mint",
    rare = "sky",
    epic = "pink",
    legendary = "gold"
}

-- Rarity display names
local rarityNames = {
    common = "Common item.",
    uncommon = "Uncommon item.",
    rare = "Rare item.",
    epic = "Epic item.",
    legendary = "Legendary item."
}

-- Format a stat line with positive/negative coloring
local function formatStat(label, value)
    if not value or value == "" then
        return nil
    end
    
    local numValue = tonumber(value)
    local colorClass, prefix
    
    if numValue then
        if numValue >= 0 then
            colorClass = "color-conifer"
            prefix = "+"
        else
            colorClass = "color-coral"
            prefix = ""  -- negative sign already included
        end
        return string.format('<p>%s: <span class="%s">%s%s</span></p>', label, colorClass, prefix, value)
    else
        -- Non-numeric value (like "2/10" for size)
        return string.format('<p>%s: %s</p>', label, value)
    end
end

-- Format a plain text line
local function formatLine(text, colorClass)
    if not text or text == "" then
        return nil
    end
    if colorClass then
        return string.format('<p class="%s">%s</p>', colorClass, text)
    else
        return string.format('<p>%s</p>', text)
    end
end

-- Main display function
function p.display(frame)
    local args = frame.args
    
    -- Get parameters
    local name = args.name or "Unknown Item"
    local rarity = string.lower(args.rarity or "common")
    local itemType = args.type or ""
    local description = args.description or ""
    local spriteSize = args.spriteSize or "64"
    local float = args.float or "right"  -- Default to right side
    
    -- Stats
    local damage = args.damage
    local defense = args.defense
    local range = args.range
    local attackspeed = args.attackspeed
    local movespeed = args.movespeed
    local hpRegen = args.hpRegen
    local mpRegen = args.mpRegen
    local size = args.size
    local weight = args.weight
    
    -- Special properties
    local special = args.special  -- e.g., "Fills you for 340 seconds"
    local action = args.action    -- e.g., "Right-click to eat"
    local category = args.category -- e.g., "Special Foods"
    
    -- Get rarity color
    local rarityColor = rarityColors[rarity] or "silver"
    local rarityText = rarityNames[rarity] or ""
    
    -- Build the tooltip HTML
    local html = {}
    
    -- Container with float
    table.insert(html, string.format('<div class="tooltip-panel font-apogea-long" style="float:%s; margin-left:%s; margin-bottom:10px; clear:%s;">', 
        float, 
        float == "right" and "15px" or "0",
        float))
    
    -- Sprite
    table.insert(html, string.format('{{Sprite|%s|%s}}', name, spriteSize))
    
    -- Item name with rarity color
    table.insert(html, string.format('<p class="font-bitcell color-%s">%s</p>', rarityColor, name))
    
    -- Description (jade color)
    if description ~= "" then
        table.insert(html, formatLine(description, "color-jade"))
    end
    
    -- Stats (in typical order)
    local statLines = {
        formatStat("Range", range),
        formatStat("Damage", damage),
        formatStat("Attackspeed", attackspeed),
        formatStat("Defense", defense),
        formatStat("Movespeed", movespeed),
        formatStat("Hp Regen", hpRegen),
        formatStat("Mp Regen", mpRegen)
    }
    
    for _, line in ipairs(statLines) do
        if line then
            table.insert(html, line)
        end
    end
    
    -- Size
    if size and size ~= "" then
        table.insert(html, string.format('<p>Size: %s</p>', size))
    end
    
    -- Weight
    if weight and weight ~= "" then
        table.insert(html, string.format('<p>It weighs %s oz.</p>', weight))
    end
    
    -- Special property (columbia blue)
    if special and special ~= "" then
        table.insert(html, formatLine(special, "color-columbia"))
    end
    
    -- Rarity text
    if rarity ~= "common" then
        table.insert(html, formatLine(rarityText, "color-" .. rarityColor))
    end
    
    -- Action hint
    if action and action ~= "" then
        table.insert(html, formatLine("[" .. action .. "]", "color-silver"))
    end
    
    -- Item type/category
    if itemType ~= "" then
        table.insert(html, formatLine("[" .. itemType .. "]", "color-silver"))
    end
    
    if category and category ~= "" then
        table.insert(html, formatLine("[" .. category .. "]", "color-silver"))
    end
    
    table.insert(html, '</div>')
    
    -- Return as wikitext (the Sprite template will be processed by MediaWiki)
    return frame:preprocess(table.concat(html, '\n'))
end

-- Quick display for common items
function p.common(frame)
    frame.args.rarity = "common"
    return p.display(frame)
end

function p.uncommon(frame)
    frame.args.rarity = "uncommon"
    return p.display(frame)
end

function p.rare(frame)
    frame.args.rarity = "rare"
    return p.display(frame)
end

function p.epic(frame)
    frame.args.rarity = "epic"
    return p.display(frame)
end

function p.legendary(frame)
    frame.args.rarity = "legendary"
    return p.display(frame)
end

return p