Jump to content

Module:ShaderDoc: Difference between revisions

From HedgeDocs
Justin113D (talk | contribs)
Created page with "--This module provides several functions used in the "Shader_Documentation" template local shader_doc = {} --[[ shader_link_list This function produces a bullet list of links to shaders Usage: {{#invoke:ShaderDoc|game=game_name|shaders=shader_a,shader_b,shader_c,etc}} parameters: game: The shader link prefix shaders: A comma separated list of shaders to list ]] function shader_docshader_link_list( frame ) local new_args = shader_doc_getParameters..."
 
Justin113D (talk | contribs)
FIxed bugs
Line 13: Line 13:


Usage:
Usage:
{{#invoke:ShaderDoc|game=game_name|shaders=shader_a,shader_b,shader_c,etc}}
{{#invoke:ShaderDoc|shader_link_list|game=game_name|shaders=shader_a,shader_b,shader_c,etc}}


parameters:
parameters:
Line 19: Line 19:
     shaders: A comma separated list of shaders to list
     shaders: A comma separated list of shaders to list
]]
]]
function shader_docshader_link_list( frame )
function shader_doc.shader_link_list( frame )
     local new_args = shader_doc_getParameters( frame.args, {'game'}, {'shaders'} );
     local game = frame.args['game'];
    local game = new_args['game'];
     local shaders = frame.args['shaders'];
     local shaders = new_args['shaders'];


     if game == nil then
     if game == nil then
         return shader_doc_error( 'Game not specified' );
         return shader_doc._error( 'Game not specified' );
     end
     end


     if shaders == nil then
     if shaders == nil then
         return shader_doc_error( 'Shaders not specified' );
         return shader_doc._error( 'Shaders not specified' );
     end
     end


Line 41: Line 40:
     return result;
     return result;


end
--[[
Helper function that populates the argument list given that user may need to use a mix of
named and unnamed parameters.  This is relevant because named parameters are not
identical to unnamed parameters due to string trimming, and when dealing with strings
we sometimes want to either preserve or remove that whitespace depending on the application.
]]
function shader_doc_getParameters( frame_args, arg_list )
local new_args = {};
local index = 1;
local value;
for i,arg in ipairs( arg_list ) do
value = frame_args[arg]
if value == nil then
value = frame_args[index];
index = index + 1;
end
new_args[arg] = value;
end
return new_args;
end
end


Line 69: Line 45:
Helper function to handle error messages.
Helper function to handle error messages.
]]
]]
function shader_doc_error( error_str )
function shader_doc._error( error_str )
local frame = mw.getCurrentFrame();
local frame = mw.getCurrentFrame();
local error_category = frame.args.error_category or 'Errors reported by Module String';
local error_category = frame.args.error_category or 'Errors reported by Module String';
Line 75: Line 51:
local no_category = frame.args.no_category or false;
local no_category = frame.args.no_category or false;


if shader_doc_getBoolean(ignore_errors) then
if shader_doc._getBoolean(ignore_errors) then
return '';
return '';
end
end


local error_str = '<strong class="error">String Module Error: ' .. error_str .. '</strong>';
local error_str = '<strong class="error">String Module Error: ' .. error_str .. '</strong>';
if error_category ~= '' and not shader_doc_getBoolean( no_category ) then
if error_category ~= '' and not shader_doc._getBoolean( no_category ) then
error_str = '[[Category:' .. error_category .. ']]' .. error_str;
error_str = '[[Category:' .. error_category .. ']]' .. error_str;
end
end
Line 90: Line 66:
Helper Function to interpret boolean strings
Helper Function to interpret boolean strings
]]
]]
function shader_doc_getBoolean( boolean_str )
function shader_doc._getBoolean( boolean_str )
local boolean_value;
local boolean_value;


Line 108: Line 84:
return boolean_value
return boolean_value
end
end
return shader_doc;

Revision as of 14:28, 17 August 2025

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

--[[

This module provides several functions used in the "Shader_Documentation" template

]]

local shader_doc = {}

--[[
shader_link_list

This function produces a bullet list of links to shaders

Usage:
{{#invoke:ShaderDoc|shader_link_list|game=game_name|shaders=shader_a,shader_b,shader_c,etc}}

parameters:
    game: The shader link prefix
    shaders: A comma separated list of shaders to list
]]
function shader_doc.shader_link_list( frame )
    local game = frame.args['game'];
    local shaders = frame.args['shaders'];

    if game == nil then
        return shader_doc._error( 'Game not specified' );
    end

    if shaders == nil then
        return shader_doc._error( 'Shaders not specified' );
    end

    local shader_list = mw.text.split( shaders, ',' );
    local result = '';

    for _, shader in ipairs( shader_list ) do
        result = result .. '* ' .. shader .. '\n';
    end

    return result;

end

--[[
Helper function to handle error messages.
]]
function shader_doc._error( error_str )
	local frame = mw.getCurrentFrame();
	local error_category = frame.args.error_category or 'Errors reported by Module String';
	local ignore_errors = frame.args.ignore_errors or false;
	local no_category = frame.args.no_category or false;

	if shader_doc._getBoolean(ignore_errors) then
		return '';
	end

	local error_str = '<strong class="error">String Module Error: ' .. error_str .. '</strong>';
	if error_category ~= '' and not shader_doc._getBoolean( no_category ) then
		error_str = '[[Category:' .. error_category .. ']]' .. error_str;
	end

	return error_str;
end

--[[
Helper Function to interpret boolean strings
]]
function shader_doc._getBoolean( boolean_str )
	local boolean_value;

	if type( boolean_str ) == 'string' then
		boolean_str = boolean_str:lower();
		if boolean_str == 'false' or boolean_str == 'no' or boolean_str == '0'
				or boolean_str == '' then
			boolean_value = false;
		else
			boolean_value = true;
		end
	elseif type( boolean_str ) == 'boolean' then
		boolean_value = boolean_str;
	else
		error( 'No boolean value found' );
	end
	return boolean_value
end

return shader_doc;
Cookies help us deliver our services. By using our services, you agree to our use of cookies.