Module: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:
-- Module:ItemEffect
local p = {}
local p = {}


-- Require the ColorText module
-- Require your existing ColorText module
local colorModule = require("Module:ColorText")
local color = require("He_is_Coming/ColorText")


-- Main function: fetch effect content and color keywords
-- Fetch the 'effect' parameter from the Infobox template of an item
function p.main(frame)
function p.main(frame)
     local itemName = frame.args[1] or ""
     local itemName = frame.args[1] or ""
     if itemName == "" then return "" end
     if itemName == "" then
        return "Error: no item specified"
    end


     -- Normalize item name: replace spaces with underscores
     -- Build the template frame name
     local normalizedName = itemName:gsub(" ", "_")
     local templateName = "Template:" .. itemName
 
     local templateFrame = mw.getContentFrame(templateName)
     -- Construct the full page path (subpage under He_is_Coming)
     if not templateFrame then
     local pageName = "He_is_Coming/" .. normalizedName .. "/effect"
        return "Error: item page or template not found"
 
     end
    -- Get the page object
     local effectTitle = mw.title.new(pageName)


     -- Check page exists
     -- Attempt to get the 'effect' parameter from the template
     if not effectTitle or not effectTitle.exists then
     local effectText = templateFrame:getParameter("effect") or ""
        return "Effect page not found: " .. pageName
    end


    -- Fetch content
     if effectText == "" then
    local effectContent = effectTitle:getContent() or ""
         return "Effect not found on item page"
     if effectContent == "" then
         return "(No effect text)"
     end
     end


     -- Color each keyword using ColorText
     -- Pass effect text to ColorText for keyword highlighting
     effectContent = effectContent:gsub("%w+", function(word)
     return color.main({ args = { effectText } })
        local lower = word:lower()
        if colorModule.colors and colorModule.colors[lower] then
            -- Use the ColorText module to color this keyword
            return colorModule.main({ args = { word } })
        else
            return word
        end
    end)
 
    return effectContent
end
end


return p
return p

Revision as of 11:37, 14 November 2025

Documentation for this module may be created at Module:ItemEffect/doc

local p = {}

-- Require your existing ColorText module
local color = require("He_is_Coming/ColorText")

-- Fetch the 'effect' parameter from the Infobox template of an item
function p.main(frame)
    local itemName = frame.args[1] or ""
    if itemName == "" then
        return "Error: no item specified"
    end

    -- Build the template frame name
    local templateName = "Template:" .. itemName
    local templateFrame = mw.getContentFrame(templateName)
    if not templateFrame then
        return "Error: item page or template not found"
    end

    -- Attempt to get the 'effect' parameter from the template
    local effectText = templateFrame:getParameter("effect") or ""

    if effectText == "" then
        return "Effect not found on item page"
    end

    -- Pass effect text to ColorText for keyword highlighting
    return color.main({ args = { effectText } })
end

return p