Jump to content

Module:Infobox: Difference between revisions

From Logic World Wiki
No edit summary
D4VID (talk | contribs)
Fix License
 
(11 intermediate revisions by 3 users not shown)
Line 3: Line 3:
local p = {}
local p = {}


function p.component(frame)
-- TODO: Move to shared module
local args = frame:getParent().args
function unflattenArgs(flatArgs)
local args = {}
 
for k, v in pairs(flatArgs) do
  local parent = args
  for token in string.gmatch(k, "[^.]+%.") do
    local key = string.sub(token, 1, #token - 1)
    if parent[key] == nil then
      parent[key] = {}
    end
    parent = parent[key]
  end
  local name = string.match(k, "[^.]+$")
  parent[name] = v
end
return args
end
 
function p.component(frame, args)
local args = unflattenArgs(args or frame:getParent().args)
local headerStyle
local headerStyle
if args.headerstyle and args.headerstyle ~= '' then
if args.headerstyle and args.headerstyle ~= '' then
Line 16: Line 38:
bodyClass = "lw-infobox"
bodyClass = "lw-infobox"
}
}
:addImage( string.format("[[File:%s 512x512.png|200px]]", args.id), args.caption )
local image = args.image or args.id.."_thumbnail_render.png"
retval:addImage(string.format("[[File:%s|200px]]", image), args.caption)
:addHeader("Component info")
:addHeader("Component info")
:addRow("Internal ID", args.id)
:addRow("Internal ID", "<code>"..args.id.."</code>")
:addRow("Configurable", args.configurable == "1" and "Yes" or "No")
 
if args.io ~= nil then
io = args.io


if args.inputOutput ~= nil then
io = args.inputOutput
retval:addHeader("Input and output")
retval:addHeader("Input and output")
Line 36: Line 61:
if io.propagationDelay ~= nil then
if io.propagationDelay ~= nil then
local ticksStr = string.format("%i tick", io.propagationDelay)
local ticksStr = string.format("%i tick", io.propagationDelay)
if tonumber(args.propagationDelay) ~= 1 then
if tonumber(io.propagationDelay) ~= 1 then
ticksStr = ticksStr.."s"
ticksStr = ticksStr.."s"
end
end
Line 44: Line 69:


return retval
return retval
end
function p.mod(frame, args)
    local args = unflattenArgs(args or frame:getParent().args)
    local headerStyle
    if args.headerstyle and args.headerstyle ~= '' then
        headerStyle = string.format('background-color:%s;', args.headerstyle)
    else
        headerStyle = 'background-color:grey;'
    end
    local retval = capiunto.create{
        title = args.title,
        headerStyle = headerStyle,
        bodyClass = "lw-infobox"
    }
    if args.image ~= nil then
        retval:addImage(string.format("[[File:%s|200px]]", args.image), args.caption)
    end
    retval:addHeader("Mod info")
        :addRow("Author", string.format("[[User:%s]]", args.author))
        :addRow("ID", string.format("<code>%s</code>", args.id))
        :addRow("Download", string.format("[%s here]", args.download))
        :addRow("Preview", args.preview == "1" and "Yes" or "No")
        :addRow("License", args.license)
    return retval
end
end


return p
return p

Latest revision as of 16:34, 12 September 2025


local capiunto = require 'capiunto'

local p = {}

-- TODO: Move to shared module
function unflattenArgs(flatArgs)
	local args = {}

	for k, v in pairs(flatArgs) do
	  local parent = args
	
	  for token in string.gmatch(k, "[^.]+%.") do
	    local key = string.sub(token, 1, #token - 1)
	    if parent[key] == nil then
	      parent[key] = {}
	    end
	    parent = parent[key]
	  end
	
	  local name = string.match(k, "[^.]+$")
	  parent[name] = v
	end
	
	return args
end

function p.component(frame, args)
	local args = unflattenArgs(args or frame:getParent().args)
	local headerStyle
	if args.headerstyle and args.headerstyle ~= '' then
		headerStyle = string.format('background-color:%s;', args.headerstyle)
	else
		headerStyle = 'background-color:grey;'
	end
	local retval = capiunto.create{
		title = args.title,
		headerStyle = headerStyle,
		bodyClass = "lw-infobox"
	}
	
	local image = args.image or args.id.."_thumbnail_render.png"
	retval:addImage(string.format("[[File:%s|200px]]", image), args.caption)

	:addHeader("Component info")
	:addRow("Internal ID", "<code>"..args.id.."</code>")
	:addRow("Configurable", args.configurable == "1" and "Yes" or "No")

	if args.io ~= nil then
		io = args.io

		retval:addHeader("Input and output")
	
		if io.minInputs ~= io.maxInputs then
			retval:addRow("Input count", string.format("Adjustable from %i to %i", io.minInputs, io.maxInputs))
		else
			retval:addRow("Input count", io.minInputs)
		end
		
		retval:addRow("Output count", io.outputs)
	
		if io.propagationDelay ~= nil then
			local ticksStr = string.format("%i tick", io.propagationDelay)
			if tonumber(io.propagationDelay) ~= 1 then
				ticksStr = ticksStr.."s"
			end
			retval:addRow("Propagation delay", ticksStr)	
		end
	end

	return retval
end

function p.mod(frame, args)
    local args = unflattenArgs(args or frame:getParent().args)
    local headerStyle
    if args.headerstyle and args.headerstyle ~= '' then
        headerStyle = string.format('background-color:%s;', args.headerstyle)
    else
        headerStyle = 'background-color:grey;'
    end
    local retval = capiunto.create{
        title = args.title,
        headerStyle = headerStyle,
        bodyClass = "lw-infobox"
    }

    if args.image ~= nil then
        retval:addImage(string.format("[[File:%s|200px]]", args.image), args.caption)
    end
    retval:addHeader("Mod info")
        :addRow("Author", string.format("[[User:%s]]", args.author))
        :addRow("ID", string.format("<code>%s</code>", args.id))
        :addRow("Download", string.format("[%s here]", args.download))
        :addRow("Preview", args.preview == "1" and "Yes" or "No")
        :addRow("License", args.license)

    return retval
end

return p