The Text Component
Text
The RelativePositioner Component
RelativePositioner
The AssetMultiplexer<ITexture2D> Component
AssetMultiplexer<ITexture2D>
-- Package definition to return to Scribunto - this allows us to define methods that can be called
-- when this module is targeted.
local p = {}
-- Type colors - RGB values to be included in the HTML output when a color is needed. This will be replaced with CSS at some point.
local typeColor =
{
User = '255, 128, 255',
Impulse = '179, 255, 255',
bool = '115, 115, 115',
AsyncImpulse = '204, 179, 255',
String = '245, 31, 31',
Dummy = '255, 0, 255',
IFormatProvider = '168, 143, 214',
float = '0, 255, 255',
ColorProfile = '255, 196, 54',
colorX = '255, 89, 0',
Component = '112, 76, 85',
float3 = '0, 255, 255',
float2 = '0, 255, 255',
ulong = '0, 255, 127',
int = '0, 255, 0',
Continuation = '255, 255, 178',
Slot = '191, 255, 127'
}
--- Method that generates the HTML output
-- @param frame A Scribunto frame instance. frame.args contains the parameters passed into the module call
function p.GenerateUI( frame )
-- Parse the JSON input, returning an empty array if no argument was passed
local fields = mw.text.jsonDecode(frame.args.Fields or '[]')
-- Create an HTML div element to contain our component UI
local componentContainer = mw.html.create( 'div' )
componentContainer
:attr('class', frame.args.Inline and '' or 'floatright')
:cssText('color: rgb(224, 224, 224); background-color: rgb(18, 20, 28); width: 256px; display: flex; flex-direction: column; align-items: stretch;')
:tag('div') -- HTML div to contain the component title
:cssText('color: rgb(247, 247, 112); background-color: rgb(43, 46, 54);padding: 10px 0px 10px 0px; text-align:center; font-weight: bold; flex-grow: 1;')
:wikitext(frame.args.Name)
:done() -- Close node title div
-- Iterate over each row, and populate it with the inputs/outputs. If the node is asymmetric,
-- the value passed for either input or output might be nil.
for i=1,#fields do
CreateField(componentContainer, fields[i])
end
-- Return the HTML generated above to the wiki page this script is invoked from.
return tostring(componentContainer) .. '[[Category:Components:All]]'
end
--- Creates a new ProtoFlux connector row in the output
-- @param Container The Scribunto HTML node we'll be creating this row inside of. Should be a container of some sort.
-- @param Field Table containing a Name, FieldType, and Type for the field on this row.
function CreateField(Container, Field)
local fieldRow = Container
:tag('div') -- HTML div to contain the field. We specify a min-height of 40px for consistency.
:cssText('display: flex; min-height: 40px;')
fieldRow
:tag('div') -- HTML div to contain the input and output labels in the connector row
:cssText( 'flex-grow: 2; overflow: hidden; display: flex; flex-direction: column; justify-content: space-between;')
:tag('div') -- HTML div to contain the input label
:attr('title', Input and (Field.Name .. ' <' .. Field.Type .. '>') or '') -- Add a basic mouseover description
:cssText('text-align: left; overflow: hidden; text-overflow: ellipsis; padding-left: 4px; border-right: 20px solid #11151d; border-bottom: 4px solid #11151d; border-top: 4px solid #11151d; background-color:' .. GetTypeColor(Input, 0.6) .. ';')
:wikitext( Field and Field.Name or '' )
:done() -- Close input label div
end
--- Returns an RGBA value representing the type color within Resonite
-- @param Connector Table containing a Name (Optional) and Type (Required) for the input/output attachment point.
-- @param Alpha The alpha to use in the RGBA value.
function GetTypeColor(Connector, Alpha)
return (Connector and 'rgba(' .. (typeColor[Connector.Type] or '0, 0, 0') .. ',' .. Alpha .. ')' or 'rgba(0, 0, 0, 0)')
end
return p