Module:ColorParse: Difference between revisions

1,468 bytes added ,  22:04, 24 May 2020
basic implementation of beta shaders
m (Protected "Module:ColorParse": High traffic page ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
(basic implementation of beta shaders)
Line 2: Line 2:


local luatable = require'Module:Color'
local luatable = require'Module:Color'
local textutil = require'Module:Text Utility'
local process_args = require'Module:ProcessArgs'
local process_args = require'Module:ProcessArgs'
local stringbyte, stringchar = string.byte, string.char


--[Utility stuff]--
--[Utility stuff]--
Line 24: Line 26:
end
end


function strtotbl(str)
    tbl = {stringbyte(str, 1, #str)}
    for i = 1, #tbl do
        tbl[i] = stringchar(tbl[i])
    end
    return tbl
end


function p.linebreaks(frame)
function p.linebreaks(frame)
Line 93: Line 102:
   return '<b>' .. (returntext or '') .. '</b>'
   return '<b>' .. (returntext or '') .. '</b>'
   end
   end
end
-- Beta Parse --
function p.shader(text, colors, type)
    -- split the colors into a list
    colorlist = textutil.split(colors, '-')
    -- check shader type:
    -- default    | if pattern is shorter than text, text will remain uncolored (y)
    -- sequence    | pattern will repeat until text is over
    -- alternation | pattern will stretch to fit word length (?)
    type = type or 'default'
    strtbl = strtotbl(text)
    finaltbl = {}
    if type == 'sequence' then
        overflowbehavior = function(f)
        e = f%#colorlist
        if e == 0 then e = #colorlist end
        return colorlist[e]
        end
    else
        overflowbehavior = function(f) return 'y' end
    end
    for i=1, #strtbl do
      if i > #colorlist then
          hexcolor = overflowbehavior(i)
      else
          hexcolor = colorlist[i]
      end
      finaltbl[i] = "<span style=\"color: " .. luatable.parse(hexcolor) .. ";\">"  .. strtbl[i].. "</span>"
      --i = i+1
     
    end
    return table.concat(finaltbl)
    --return colorlist[3%#strtbl]
end
function p.test()
    --return p.shader('structural', 'Y-y-K-y-Y', 'alternation')
    return p.shader('Stopsvalinn', 'R-r-K-y-Y', 'sequence')
end
end


return p
return p