Module:Test: Difference between revisions

From Resonite Wiki
mNo edit summary
mNo edit summary
Line 21: Line 21:
   :attr( 'width', "256px" )
   :attr( 'width', "256px" )
   :tag( 'tr' )
   :tag( 'tr' )
  :attr( 'style', 'height:50px')
   :tag( 'th' )
   :tag( 'th' )
     :attr('width', '20%')
     :attr('width', '20%')
Line 45: Line 46:
  Container
  Container
   :tag( 'tr' )
   :tag( 'tr' )
  :attr( 'height', '20px' )
   :tag( 'td' ) -- The Input binding post
   :tag( 'td' ) -- The Input binding post
     :attr( 'rowspan', '2' )
     :attr( 'rowspan', '2' )

Revision as of 04:08, 13 January 2024

Documentation for this module may be created at Module:Test/doc

local p = {}

local typeColor = 
{
 User = 'rgb(255, 128, 255)',
 Impulse = 'rgb(179, 255, 255)',
 Boolean = 'rgb(115, 115, 115)'
}

local mt = {__index = function () return "rgba(0,0,0,0)" end}
setmetatable(typeColor, mt)

function p.ProtoFlux( frame )
 local inputsDecode = mw.text.jsonDecode( frame.args.Inputs );
 local outputsDecode = mw.text.jsonDecode( frame.args.Outputs );

 local protofluxContainer = mw.html.create( 'table' )
 
 protofluxContainer
  :attr( 'style', '-webkit-text-stroke: 1px black;' )
  :attr( 'width', "256px" )
  :tag( 'tr' )
  :attr( 'style', 'height:50px')
   :tag( 'th' )
    :attr('width', '20%')
    :done()
   :tag( 'th' )
    :attr('width', '60%')
    :wikitext(frame.args.Name)
    :done()
   :tag( 'th')
    :attr('width', '20%');

 local maxRows = math.max(#inputsDecode, #outputsDecode)
 for i=1,maxRows,1 do
  CreateIORow(protofluxContainer, inputsDecode[i], outputsDecode[i]);
 end
 

 return tostring(protofluxContainer);

end

-- Each Input/Output row is really 2 rows high. 
function CreateIORow(Container, Input, Output)
 Container
  :tag( 'tr' )
   :tag( 'td' ) -- The Input binding post
    :attr( 'rowspan', '2' )
    :attr( 'style', 'background-color:' .. typeColor[Input.Type])
    :done()
   :tag( 'td' ) -- The Input name
    :attr( 'style', 'text-align: left; background-color:' .. typeColor[Input.Type] )
    :wikitext( Input.Name )
    :done()
   :tag( 'td' ) -- The Output binding post
    :attr( 'rowspan', '2' )
    :attr( 'style', 'background-color:' .. (Output and typeColor[Output.Type] or 'rgba(0,0,0,0)') )
    :done()
   :done()
  :tag( 'tr')
  :attr( 'height', '20px' )
   :tag( 'td' )
    :attr( 'style', 'text-align: right; background-color:' .. (Output and typeColor[Output.Type] or 'rgba(0,0,0,0)') )
    :wikitext( Output and Output.Name or '' )
    :done()
   
end

return p