Module:ItemEffect: Difference between revisions

From He is Coming Official Wiki
Benjiminio (talk | contribs)
mNo edit summary
Benjiminio (talk | contribs)
mNo edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
-- Module:ItemEffect
local p = {}
local p = {}


-- List of keywords & colors comes from ColorText
-- Require the ColorText module using full path
local colorModule = require("Module:ColorText") -- Adjusted for subspace if needed
local color = require("Module:He_is_Coming/ColorText")


-- Main function: fetch effect content and color keywords
-- Fetch the 'effect' parameter from the item's infobox template
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


     -- Construct the effect page title under He_is_Coming
     -- Attempt to get the content of the item's template
     local effectTitle = mw.title.new(itemName .. "/effect", "He_is_Coming")
     local templateName = "Template:" .. itemName
     if not effectTitle or not effectTitle.exists then
    local templateFrame = mw.getContentFrame(templateName)
         return "Effect page not found: " .. itemName .. "/effect"
     if not templateFrame then
         return "Error: item page or template not found"
     end
     end


     local effectContent = effectTitle:getContent() or ""
    -- Get the 'effect' parameter
     if effectContent == "" then return "(No effect text)" end
     local effectText = templateFrame:getParameter("effect") or ""
 
     if effectText == "" then
    -- Color each keyword using ColorText
        return "Effect not found on item page"
    local function colorKeyword(word)
        return colorModule.main({ args = { word } })
     end
     end


     -- Simple pattern to find keywords (adjust if needed)
     -- Pass effect text to ColorText module for keyword highlighting
     -- Only match words that exist in ColorText's color table
     -- ColorText expects a table with args[1] containing the text
    effectContent = effectContent:gsub("%w+", function(w)
    return color.main({ args = { effectText } })
        local lower = w:lower()
        if colorModule.colors and colorModule.colors[lower] then
            return colorKeyword(w)
        else
            return w
        end
    end)
 
    return effectContent
end
end


return p
return p

Latest revision as of 11:41, 14 November 2025

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

local p = {}

-- Require the ColorText module using full path
local color = require("Module:He_is_Coming/ColorText")

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

    -- Attempt to get the content of the item's template
    local templateName = "Template:" .. itemName
    local templateFrame = mw.getContentFrame(templateName)
    if not templateFrame then
        return "Error: item page or template not found"
    end

    -- Get the 'effect' parameter
    local effectText = templateFrame:getParameter("effect") or ""
    if effectText == "" then
        return "Effect not found on item page"
    end

    -- Pass effect text to ColorText module for keyword highlighting
    -- ColorText expects a table with args[1] containing the text
    return color.main({ args = { effectText } })
end

return p