Module:ComponentMethods

From Resonite Wiki
Revision as of 02:21, 15 July 2024 by Bluigi (talk | contribs) (Created page with "-- test in console: -- =p.main(mw.getCurrentFrame():newChild{title="Template:Table ComponentMethods",args={" SetUpRenderer() *", " ", " Attaches components for a default PBS_Metallic material and MeshRenderer referencing this mesh."}}:newChild{title="Module:Test",args={}}) -- =p.footnote(mw.getCurrentFrame():newChild{title="Template:Table ComponentMethods",args={" SetUpRenderer() *", " ", " Attaches components for a default [[PBS_Metallic...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

-- test in console:
-- =p.main(mw.getCurrentFrame():newChild{title="Template:Table ComponentMethods",args={" SetUpRenderer()  *", " ", " Attaches components for a default [[PBS_Metallic]] material and [[Component:MeshRenderer|MeshRenderer]] referencing this mesh."}}:newChild{title="Module:Test",args={}})
-- =p.footnote(mw.getCurrentFrame():newChild{title="Template:Table ComponentMethods",args={" SetUpRenderer()  *", " ", " Attaches components for a default [[PBS_Metallic]] material and [[Component:MeshRenderer|MeshRenderer]] referencing this mesh."}}:newChild{title="Module:Test",args={}})

local p = {}

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

	while true do
		local argI = i * 3 + 1
		local method = templateFrame.args[argI]
		local params = templateFrame.args[argI + 1]
		local description = templateFrame.args[argI + 2]

		if not description then
			break
		end

		local _, j = method:find(")")
		local name = mw.text.trim(method:sub(1, j))
		local rest = mw.text.trim(method:sub(j + 1))

		local hasParams = mw.text.trim(params):len() > 0

		body = body .. "|-\n"
		body = body .. "|<code>" .. name .. "</code> " .. rest .. "\n"
		body = body .. "|" .. (hasParams and params or "''none''") .. "\n"
		body = body .. "|" .. description .. "\n"
		i = i + 1
	end
	
	return body
end

function p.footnote(frame)
	local templateFrame = frame:getParent()

	local body = ""
	local anyHidden = false
	local i = 0

	while true do
		local method = templateFrame.args[3 * i + 1]
		
		if not method then
			break
		end

		local _, j = method:find(")")
		if method:sub(j + 1):find("*") then
			anyHidden = true
			break
		end

		i = i + 1
	end
	
	if anyHidden then
		body = body .. "''* Methods marked with an asterisk are invisible in the inspector by default.''"
	end

	return body
end

return p