Module:ComponentMethods: Difference between revisions

From Resonite Wiki
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..."
 
Format parameters
Line 1: Line 1:
-- test in console:
-- 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.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.main(mw.getCurrentFrame():newChild{title="Template:Table ComponentMethods",args={"Resize(size, filtering)", "size:int,int2:Scaling factor.;filtering:Filtering:Resampling method.", "Replaces the 2D texture with a scaled copy, resampled using the given filtering method. Scales separately in the X and Y axes when an int2 is passed."}}: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={}})
-- =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={}})


Line 7: Line 8:
function p.main(frame)
function p.main(frame)
local templateFrame = frame:getParent()
local templateFrame = frame:getParent()
 
local body = ""
local body = ""
local i = 0
local i = 0
Line 21: Line 22:
end
end


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


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


body = body .. "|-\n"
body = body .. "|-\n"
body = body .. "|<code>" .. name .. "</code> " .. rest .. "\n"
body = body .. "|<code>" .. name .. "</code> " .. rest .. "\n"
body = body .. "|" .. (hasParams and params or "''none''") .. "\n"
if noParams then
body = body .. "|''none''\n"
else
body = body .. "|"
local first = false
repeat
local _, paramEnd = params:find(";")
paramEnd = paramEnd or #params + 1
local param = params:sub(0, paramEnd - 1)
local name, types, desc = param:match("([^:]*):([^:]*):(.*)")
 
body = body .. "<code>" .. name .. "</code>&nbsp;:&nbsp;"
 
local first = true
for t in types:gmatch("([^,]+)") do
if not first then body = body .. '&nbsp;or&nbsp;' end
-- use custom link if specified
if t:match("^%[%[.+]]$") then
body = body .. t
else
body = body .. "[[Type:" .. t .. "|" .. t .. "]]"
end
first = false
end
body = body .. "<br>" .. desc .. '\n'
 
params = params:sub(paramEnd + 1)
until #params == 0
end
body = body .. "|" .. description .. "\n"
body = body .. "|" .. description .. "\n"
i = i + 1
i = i + 1
end
end
 
return body
return body
end
end

Revision as of 04:34, 15 July 2024

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.main(mw.getCurrentFrame():newChild{title="Template:Table ComponentMethods",args={"Resize(size, filtering)", "size:int,int2:Scaling factor.;filtering:Filtering:Resampling method.", "Replaces the 2D texture with a scaled copy, resampled using the given filtering method. Scales separately in the X and Y axes when an int2 is passed."}}: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 _, nameEnd = method:find(")")
		local name = mw.text.trim(method:sub(1, nameEnd)):gsub(" +", "&nbsp;")
		local rest = mw.text.trim(method:sub(nameEnd + 1))

		params = mw.text.trim(params)
		local noParams = #params == 0

		body = body .. "|-\n"
		body = body .. "|<code>" .. name .. "</code> " .. rest .. "\n"
		if noParams then
			body = body .. "|''none''\n"
		else
			body = body .. "|"
			local first = false
			repeat
				local _, paramEnd = params:find(";")
				paramEnd = paramEnd or #params + 1
				local param = params:sub(0, paramEnd - 1)
				local name, types, desc = param:match("([^:]*):([^:]*):(.*)")

				body = body .. "<code>" .. name .. "</code>&nbsp;:&nbsp;"

				local first = true
				for t in types:gmatch("([^,]+)") do
					if not first then body = body .. '&nbsp;or&nbsp;' end
					-- use custom link if specified
					if t:match("^%[%[.+]]$") then
						body = body .. t
					else
						body = body .. "[[Type:" .. t .. "|" .. t .. "]]"
					end
					first = false
				end
				body = body .. "<br>" .. desc .. '\n'

				params = params:sub(paramEnd + 1)
			until #params == 0
		end
		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