Module:ComponentFields

From Resonite Wiki
Revision as of 03:32, 1 March 2024 by PJB (talk | contribs) (Don't bold for advanced types)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This module is used to implement the logic of Template:Table ComponentFields and Template:Table TypeFields. Don't use it anywhere else please thank.


-- test in console:
-- =p.main(mw.getCurrentFrame():newChild{title="Template:Table ComponentFields",args={"FixTransformsEnabled", "Bool", "Clamps IK transforms to reasonable values and Resets IK every update."}}:newChild{title="Module:Test",args={}})
-- =p.main(mw.getCurrentFrame():newChild{title="Template:Table ComponentFields",args={"FixTransformsEnabled", "Bool", "Clamps IK transforms to reasonable values and Resets IK every update.", ["TypeStringAdvanced0"] = "true"}}:newChild{title="Module:Test",args={}})

local p = {}

function p.main(frame)
	local body = ""
	
	local templateFrame = frame:getParent()
	local i = 0

	while true do
		local argI = i * 3 + 1
		local name = templateFrame.args[argI]
		local type = templateFrame.args[argI + 1]
		local description = templateFrame.args[argI + 2]
		local typeString = templateFrame.args["TypeString"..i] or type
		local typeStringAdvanced = templateFrame.args["TypeAdv"..i]

		if name == nil then
			break
		end

		description = mw.text.trim(description)

		body = body.."|-\n"
		body = body.."|<code>"..name.."</code>\n"
		if typeStringAdvanced == "true" then
			body = body.."|"..typeString.."\n"
		else
			body = body.."|'''[[Type:"..type.."|"..typeString.."]]'''\n"
		end
		body = body.."|"..description.."\n"
		i = i + 1
	end
	
	return body
end

return p