Module:ItemEffect: Difference between revisions
From He is Coming Official Wiki
Benjiminio (talk | contribs) Created page with "local p = {} function p.main(frame) local item = frame.args[1] or "" if item == "" then 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 wik..." |
Benjiminio (talk | contribs) mNo edit summary |
||
| Line 1: | Line 1: | ||
-- Module:ItemEffect | |||
local p = {} | local p = {} | ||
-- List of keywords & colors comes from ColorText | |||
local colorModule = require("Module:ColorText") -- Adjusted for subspace if needed | |||
-- Main function: fetch effect content and color keywords | |||
function p.main(frame) | function p.main(frame) | ||
local | local itemName = frame.args[1] or "" | ||
if | if itemName == "" then return "" end | ||
-- | -- Construct the effect page title under He_is_Coming | ||
local | local effectTitle = mw.title.new(itemName .. "/effect", "He_is_Coming") | ||
if not | if not effectTitle or not effectTitle.exists then | ||
return "Effect page not found" | return "Effect page not found: " .. itemName .. "/effect" | ||
end | end | ||
local effectContent = effectTitle:getContent() or "" | |||
local | if effectContent == "" then return "(No effect text)" end | ||
-- | -- Color each keyword using ColorText | ||
local | local function colorKeyword(word) | ||
return colorModule.main({ args = { word } }) | |||
return | |||
end | end | ||
-- | -- Simple pattern to find keywords (adjust if needed) | ||
-- Only match 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 | |||
end | return colorKeyword(w) | ||
else | |||
return w | |||
end | |||
end) | |||
return | return effectContent | ||
end | end | ||
return p | return p | ||
Revision as of 11:13, 14 November 2025
Documentation for this module may be created at Module:ItemEffect/doc
-- Module:ItemEffect
local p = {}
-- List of keywords & colors comes from ColorText
local colorModule = require("Module:ColorText") -- Adjusted for subspace if needed
-- 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 effect page title under He_is_Coming
local effectTitle = mw.title.new(itemName .. "/effect", "He_is_Coming")
if not effectTitle or not effectTitle.exists then
return "Effect page not found: " .. itemName .. "/effect"
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
-- Simple pattern to find keywords (adjust if needed)
-- Only match 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


