Module:MCColor: Difference between revisions

From RetroMC
Jump to navigation Jump to search
(New module code possibly at some point, lets just see if this actually works first)
 
m (Thecow275 moved page Module:MCColor2 to Module:MCColor without leaving a redirect)
 
(13 intermediate revisions by the same user not shown)
Line 1: Line 1:
local data = mw.loadData('Module:MCColor/data')
local p = {}
local p = {}


-- Load the MCColor/data table
--[ Thecow275's MC-Color Module V2]--
local data = mw.loadData('Module:MCColor/data')
 
-- 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)
function p.main(frame)
     local args = frame.args
     local args = frame.args
     local mccolor = args[1] -- Minecraft Color Code
     local mccolor = preprocessArg(args[1])


     -- Check if the provided mccolor exists in the data table
     -- Check for blank mccolor arguments
    if not mccolor then
        return ''
    end
 
    -- Get the data for the specified mccolor
     local MCColorData = data[mccolor]
     local MCColorData = data[mccolor]
     if not MCColorData then
     if not MCColorData then
         return '' -- Return an empty string if the color is not found
         return ''
     end
     else
 
          return MCColorData.wikicolor or ''
    -- Return the colorcode
end
    return MCColorData.wikicolor or ''
end
end


return p
return p

Latest revision as of 14:15, 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