Template:ItemEffect: Difference between revisions

From He is Coming Official Wiki
Benjiminio (talk | contribs)
mNo edit summary
Benjiminio (talk | contribs)
mNo edit summary
 
Line 1: Line 1:
local p = {}
<includeonly>{{#invoke:ItemEffect|main|{{{1}}}}}</includeonly>
 
<noinclude>
function p.main(frame)
Usage: {{ItemEffect|Item Name}}
    local item = frame.args[1] or ""
Example: {{ItemEffect|Melon Bomb}}
    if item == "" then
</noinclude>
        return "No item specified"
    end
 
    -- Normalize item name (replace spaces with underscores)
    local safeItem = item:gsub(" ", "_")
 
    -- Build effect page title
    local effectPage = mw.title.new("He_is_Coming/" .. safeItem .. "/effect")
    if not effectPage or not effectPage.exists then
        return "Effect page not found"
    end
 
    -- Get the raw wikitext of the effect page
    local effectText = effectPage:getContent() or ""
 
    -- Get ColorText module
    local ColorText = mw.getContentModule("ColorText")
    if not ColorText or not ColorText.colors then
        return effectText  -- fallback: no coloring if ColorText missing
    end
 
    -- Replace all keywords dynamically
    for keyword, _ in pairs(ColorText.colors) do
        local colored = ColorText.main{args={keyword}}
        -- Replace whole words only, case-insensitive
        effectText = effectText:gsub("(%f[%w])"..keyword.."(%f[%W])", colored)
    end
 
    return effectText
end
 
return p

Latest revision as of 11:01, 14 November 2025


Usage: Lua error in package.lua at line 80: module 'Module:He_is_Coming/ColorText' not found.

Example: Lua error in package.lua at line 80: module 'Module:He_is_Coming/ColorText' not found.