Jump to content

Module:ItemTooltip: Difference between revisions

From Apogea Wiki
Jayarrowz (talk | contribs)
Item toolip module
 
Jayarrowz (talk | contribs)
No edit summary
Line 22: Line 22:
     legendary = "Legendary item."
     legendary = "Legendary item."
}
}
-- Helper to get args from either direct invoke or template
local function getArgs(frame)
    local args = {}
   
    -- Try parent frame first (when called via template)
    local parent = frame:getParent()
    if parent and parent.args then
        for k, v in pairs(parent.args) do
            args[k] = v
        end
    end
   
    -- Then overlay direct args (these take priority)
    if frame.args then
        for k, v in pairs(frame.args) do
            args[k] = v
        end
    end
   
    return args
end


-- Format a stat line with positive/negative coloring
-- Format a stat line with positive/negative coloring
Line 61: Line 83:
-- Main display function
-- Main display function
function p.display(frame)
function p.display(frame)
     local args = frame.args
     local args = getArgs(frame)
      
      
     -- Get parameters
     -- Get parameters
Line 95: Line 117:
      
      
     -- Container with float
     -- 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;">',  
     table.insert(html, string.format('<div class="tooltip-panel font-apogea-long" style="float:%s; margin-%s:15px; margin-bottom:10px;">',  
         float,  
         float,  
         float == "right" and "15px" or "0",
         float == "right" and "left" or "right"))
        float))
      
      
     -- Sprite
     -- Sprite
Line 107: Line 128:
      
      
     -- Description (jade color)
     -- Description (jade color)
     if description ~= "" then
     if description and description ~= "" then
         table.insert(html, formatLine(description, "color-jade"))
         table.insert(html, formatLine(description, "color-jade"))
     end
     end
      
      
     -- Stats (in typical order)
     -- Stats (in typical order)
     local statLines = {
     if damage and damage ~= "" then
         formatStat("Range", range),
         table.insert(html, formatStat("Damage", damage))
        formatStat("Damage", damage),
    end
        formatStat("Attackspeed", attackspeed),
    if movespeed and movespeed ~= "" then
         formatStat("Defense", defense),
         table.insert(html, formatStat("Movespeed", movespeed))
        formatStat("Movespeed", movespeed),
    end
         formatStat("Hp Regen", hpRegen),
    if hpRegen and hpRegen ~= "" then
         formatStat("Mp Regen", mpRegen)
         table.insert(html, formatStat("Hp Regen", hpRegen))
     }
    end
      
    if mpRegen and mpRegen ~= "" then
    for _, line in ipairs(statLines) do
         table.insert(html, formatStat("Mp Regen", mpRegen))
        if line then
     end
            table.insert(html, line)
     if range and range ~= "" then
         end
        table.insert(html, formatStat("Range", range))
    end
    if attackspeed and attackspeed ~= "" then
        table.insert(html, formatStat("Attackspeed", attackspeed))
    end
    if defense and defense ~= "" then
         table.insert(html, formatStat("Defense", defense))
     end
     end
      
      
Line 170: Line 197:
-- Quick display for common items
-- Quick display for common items
function p.common(frame)
function p.common(frame)
     frame.args.rarity = "common"
     local args = getArgs(frame)
     return p.display(frame)
    args.rarity = "common"
     return p._display(frame, args)
end
end


function p.uncommon(frame)
function p.uncommon(frame)
     frame.args.rarity = "uncommon"
     local args = getArgs(frame)
     return p.display(frame)
    args.rarity = "uncommon"
     return p._display(frame, args)
end
end


function p.rare(frame)
function p.rare(frame)
     frame.args.rarity = "rare"
     local args = getArgs(frame)
     return p.display(frame)
    args.rarity = "rare"
     return p._display(frame, args)
end
end


function p.epic(frame)
function p.epic(frame)
     frame.args.rarity = "epic"
     local args = getArgs(frame)
     return p.display(frame)
    args.rarity = "epic"
     return p._display(frame, args)
end
end


function p.legendary(frame)
function p.legendary(frame)
     frame.args.rarity = "legendary"
     local args = getArgs(frame)
     return p.display(frame)
    args.rarity = "legendary"
     return p._display(frame, args)
end
 
-- Internal display with pre-fetched args
function p._display(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"
   
    -- 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
    local action = args.action
    local category = args.category
   
    -- Get rarity color
    local rarityColor = rarityColors[rarity] or "silver"
    local rarityText = rarityNames[rarity] or ""
   
    -- Build the tooltip HTML
    local html = {}
   
    table.insert(html, string.format('<div class="tooltip-panel font-apogea-long" style="float:%s; margin-%s:15px; margin-bottom:10px;">',
        float,
        float == "right" and "left" or "right"))
   
    table.insert(html, string.format('{{Sprite|%s|%s}}', name, spriteSize))
    table.insert(html, string.format('<p class="font-bitcell color-%s">%s</p>', rarityColor, name))
   
    if description and description ~= "" then
        table.insert(html, formatLine(description, "color-jade"))
    end
   
    if damage and damage ~= "" then
        table.insert(html, formatStat("Damage", damage))
    end
    if movespeed and movespeed ~= "" then
        table.insert(html, formatStat("Movespeed", movespeed))
    end
    if hpRegen and hpRegen ~= "" then
        table.insert(html, formatStat("Hp Regen", hpRegen))
    end
    if mpRegen and mpRegen ~= "" then
        table.insert(html, formatStat("Mp Regen", mpRegen))
    end
    if range and range ~= "" then
        table.insert(html, formatStat("Range", range))
    end
    if attackspeed and attackspeed ~= "" then
        table.insert(html, formatStat("Attackspeed", attackspeed))
    end
    if defense and defense ~= "" then
        table.insert(html, formatStat("Defense", defense))
    end
   
    if size and size ~= "" then
        table.insert(html, string.format('<p>Size: %s</p>', size))
    end
   
    if weight and weight ~= "" then
        table.insert(html, string.format('<p>It weighs %s oz.</p>', weight))
    end
   
    if special and special ~= "" then
        table.insert(html, formatLine(special, "color-columbia"))
    end
   
    if rarity ~= "common" then
        table.insert(html, formatLine(rarityText, "color-" .. rarityColor))
    end
   
    if action and action ~= "" then
        table.insert(html, formatLine("[" .. action .. "]", "color-silver"))
    end
   
    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 frame:preprocess(table.concat(html, '\n'))
end
end


return p
return p

Revision as of 21:38, 27 January 2026

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."
}

-- Helper to get args from either direct invoke or template
local function getArgs(frame)
    local args = {}
    
    -- Try parent frame first (when called via template)
    local parent = frame:getParent()
    if parent and parent.args then
        for k, v in pairs(parent.args) do
            args[k] = v
        end
    end
    
    -- Then overlay direct args (these take priority)
    if frame.args then
        for k, v in pairs(frame.args) do
            args[k] = v
        end
    end
    
    return args
end

-- 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 = getArgs(frame)
    
    -- 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-%s:15px; margin-bottom:10px;">', 
        float, 
        float == "right" and "left" or "right"))
    
    -- 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 and description ~= "" then
        table.insert(html, formatLine(description, "color-jade"))
    end
    
    -- Stats (in typical order)
    if damage and damage ~= "" then
        table.insert(html, formatStat("Damage", damage))
    end
    if movespeed and movespeed ~= "" then
        table.insert(html, formatStat("Movespeed", movespeed))
    end
    if hpRegen and hpRegen ~= "" then
        table.insert(html, formatStat("Hp Regen", hpRegen))
    end
    if mpRegen and mpRegen ~= "" then
        table.insert(html, formatStat("Mp Regen", mpRegen))
    end
    if range and range ~= "" then
        table.insert(html, formatStat("Range", range))
    end
    if attackspeed and attackspeed ~= "" then
        table.insert(html, formatStat("Attackspeed", attackspeed))
    end
    if defense and defense ~= "" then
        table.insert(html, formatStat("Defense", defense))
    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)
    local args = getArgs(frame)
    args.rarity = "common"
    return p._display(frame, args)
end

function p.uncommon(frame)
    local args = getArgs(frame)
    args.rarity = "uncommon"
    return p._display(frame, args)
end

function p.rare(frame)
    local args = getArgs(frame)
    args.rarity = "rare"
    return p._display(frame, args)
end

function p.epic(frame)
    local args = getArgs(frame)
    args.rarity = "epic"
    return p._display(frame, args)
end

function p.legendary(frame)
    local args = getArgs(frame)
    args.rarity = "legendary"
    return p._display(frame, args)
end

-- Internal display with pre-fetched args
function p._display(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"
    
    -- 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
    local action = args.action
    local category = args.category
    
    -- Get rarity color
    local rarityColor = rarityColors[rarity] or "silver"
    local rarityText = rarityNames[rarity] or ""
    
    -- Build the tooltip HTML
    local html = {}
    
    table.insert(html, string.format('<div class="tooltip-panel font-apogea-long" style="float:%s; margin-%s:15px; margin-bottom:10px;">', 
        float, 
        float == "right" and "left" or "right"))
    
    table.insert(html, string.format('{{Sprite|%s|%s}}', name, spriteSize))
    table.insert(html, string.format('<p class="font-bitcell color-%s">%s</p>', rarityColor, name))
    
    if description and description ~= "" then
        table.insert(html, formatLine(description, "color-jade"))
    end
    
    if damage and damage ~= "" then
        table.insert(html, formatStat("Damage", damage))
    end
    if movespeed and movespeed ~= "" then
        table.insert(html, formatStat("Movespeed", movespeed))
    end
    if hpRegen and hpRegen ~= "" then
        table.insert(html, formatStat("Hp Regen", hpRegen))
    end
    if mpRegen and mpRegen ~= "" then
        table.insert(html, formatStat("Mp Regen", mpRegen))
    end
    if range and range ~= "" then
        table.insert(html, formatStat("Range", range))
    end
    if attackspeed and attackspeed ~= "" then
        table.insert(html, formatStat("Attackspeed", attackspeed))
    end
    if defense and defense ~= "" then
        table.insert(html, formatStat("Defense", defense))
    end
    
    if size and size ~= "" then
        table.insert(html, string.format('<p>Size: %s</p>', size))
    end
    
    if weight and weight ~= "" then
        table.insert(html, string.format('<p>It weighs %s oz.</p>', weight))
    end
    
    if special and special ~= "" then
        table.insert(html, formatLine(special, "color-columbia"))
    end
    
    if rarity ~= "common" then
        table.insert(html, formatLine(rarityText, "color-" .. rarityColor))
    end
    
    if action and action ~= "" then
        table.insert(html, formatLine("[" .. action .. "]", "color-silver"))
    end
    
    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 frame:preprocess(table.concat(html, '\n'))
end

return p