Module:ItemEffect: Difference between revisions
From He is Coming Official Wiki
Benjiminio (talk | contribs) mNo edit summary |
Benjiminio (talk | contribs) mNo edit summary |
||
| Line 2: | Line 2: | ||
local p = {} | local p = {} | ||
-- | -- Require the ColorText module | ||
local colorModule = require("Module:ColorText") | local colorModule = require("Module:ColorText") | ||
-- Main function: fetch effect content and color keywords | -- Main function: fetch effect content and color keywords | ||
| Line 10: | Line 10: | ||
if itemName == "" then return "" end | if itemName == "" then return "" end | ||
-- Construct the | -- Construct the full subpage path | ||
local | local pageName = "He_is_Coming/" .. itemName .. "/effect" | ||
local effectTitle = mw.title.new(pageName) | |||
if not effectTitle or not effectTitle.exists then | if not effectTitle or not effectTitle.exists then | ||
return "Effect page not found: " .. | return "Effect page not found: " .. pageName | ||
end | end | ||
local effectContent = effectTitle:getContent() or "" | local effectContent = effectTitle:getContent() or "" | ||
if effectContent == "" then return "(No effect text)" end | if effectContent == "" then | ||
return "(No effect text)" | |||
end | |||
-- Color each keyword using ColorText | -- Color each keyword using ColorText | ||
| Line 24: | Line 28: | ||
end | end | ||
-- | -- Replace words that exist in ColorText's color table | ||
effectContent = effectContent:gsub("%w+", function(w) | effectContent = effectContent:gsub("%w+", function(w) | ||
local lower = w:lower() | local lower = w:lower() | ||
Revision as of 11:18, 14 November 2025
Documentation for this module may be created at Module:ItemEffect/doc
-- Module:ItemEffect
local p = {}
-- Require the ColorText module
local colorModule = require("Module:ColorText")
-- Main function: fetch effect content and color keywords
function p.main(frame)
local itemName = frame.args[1] or ""
if itemName == "" then return "" end
-- Construct the full subpage path
local pageName = "He_is_Coming/" .. itemName .. "/effect"
local effectTitle = mw.title.new(pageName)
if not effectTitle or not effectTitle.exists then
return "Effect page not found: " .. pageName
end
local effectContent = effectTitle:getContent() or ""
if effectContent == "" then
return "(No effect text)"
end
-- Color each keyword using ColorText
local function colorKeyword(word)
return colorModule.main({ args = { word } })
end
-- Replace words that exist in ColorText's color table
effectContent = effectContent:gsub("%w+", function(w)
local lower = w:lower()
if colorModule.colors and colorModule.colors[lower] then
return colorKeyword(w)
else
return w
end
end)
return effectContent
end
return p


