Module:MCColor: Difference between revisions

From RetroMC
Jump to navigation Jump to search
No edit summary
Tag: Reverted
(Undo revision 2521 by Thecow275 (talk))
Tag: Undo
Line 1: Line 1:
local data = mw.loadData('Module:MCColor/data')
local data = mw.loadData('Module:MCColor/data')
local p = {}
local p = {}
local datakey = "wikicolor"


--[ Thecow275's MC-Color Module V2]--
--[ Thecow275's MC-Color Module V2]--
Line 32: Line 31:
         return ''
         return ''
     else
     else
           return MCColorData[datakey] or ''
           return MCColorData.wikicolor or ''
end
end
end
end


return p
return p

Revision as of 13:46, 19 February 2024

text


local data = mw.loadData('Module:MCColor/data')
local p = {}

--[ Thecow275's MC-Color Module V2]--

-- Trim whitespace from args, and treat blank args as nil
local function preprocessArg(s)
    if not s then
        return nil
    end
    s = s:match('^%s*(.-)%s*$') -- trim whitespace
    if s == '' then
        return nil
    else
        return s
    end
end

function p.main(frame)
    local args = frame.args
    local mccolor = preprocessArg(args[1])

    -- Check for blank mccolor arguments
    if not mccolor then
        return ''
    end

    -- Get the data for the specified mccolor
    local MCColorData = data[mccolor]
    if not MCColorData then
        return ''
    else
           return MCColorData.wikicolor or ''
end
end

return p