Module:HTMLComponents/draft

--[[

PLEASE DON'T CHANGE ANYTHING HERE OR IN THE PLAYER NAVBOX TEMPLATE WITHOUT KNOWING WHAT YOU ARE DOING, FIRST DISCUSSING IT, AND DRAFTING YOUR CHANGES IN Module:Components/Draft TO ENSURE THE CODE IS FUNCTIONAL. IF THIS CODE BREAKS, EVERY SINGLE PLAYER NAVBOX USING THIS CODE WILL STOP RENDERING.

THANKS <3

]]

local p = {}

local _common = require( "Module:Common" ) local _normalizeArgs = require( "Module:Arguments" ).normalize local mData = mw.loadData( "Module:HTMLComponents/data" )

function p.playerNavbox( frame ) local args = _normalizeArgs( frame, mData.player_navbox_args, { } ) local player = args.player if mw.title.new ( args.player ).exists and args.player_text_override == false then player =  ..		( ( args.player_color ) and ( 'color="' ..		args.player_color '">' .. args.player .. ' ' ) ) ..  end

local boxShadow = 'inset 0 1px ' .. args.border_color .. ( ( args.border_glow == 'true' )			and ( ', 0 0 10px ' .. args.border_color )			or '' ) .. '; '

return mw.html.create( 'div' ) :css( {			['clear'] = 'right',			['background'] = args.body_color,			['margin'] = '30px 15px 15px 15px',			['border-radius'] = args.border_radius .. 'px',		} ) :cssText( ( ( args.text_shadow == true ) and	( 'text-shadow: ' .. args.text_shadow_offset .. ' ' .. args.text_shadow_color .. '; ' ) or '' ) )		:tag( 'div' ) :css( {				['overflow'] = 'hidden',				['border'] = '1px solid ' .. args.border_color,				['border-radius'] = args.border_radius .. 'px',				['margin'] = '1px',				['text-align'] = 'center',			} ) :cssText( _common.boxShadow(boxShadow) ) :tag( 'div' ) :css( {					['overflow'] = 'hidden',					['padding'] = '0.2em',					['vertical-align'] = "center",					['font-size'] = '1.1em',					['white-space'] = 'nowrap',					['background'] = args.header_color,					['border-radius'] = args.border_radius .. 'px 0 0',					['color'] = args.header_font_color				} ) :wikitext( 'Played by: ' .. player ) :done :tag( 'div' ) :css( 'padding', '0.2em 0.5em' ) :wikitext( tostring( _getCharacterStatusString( frame, args ) ) ) :allDone end

function _getCharacterStatusString(frame, args) local margin = mw.html.create ( 'span' ) :css ({	['margin-left'] = '7px' }) local hr = nil if not args.tabbed then hr = mw.html.create ( 'hr' ) :css ({				['border'] = "1px solid " .. args.horizontal_rule_color,				['border-radius'] = "10px",				['margin'] = "0 20px 0 20px"			}) :cssText (				( ( args.horizontal_rule_glow == "true" ) and ( _common.boxShadow( '0 0 10px' ) ..						args.horizontal_rule_color					) or '' )			) end local death = frame:expandTemplate{ title="Status", args={ "D" } } --		Yeah, this looks weird, but I want each field to be self-explanatory		AND indexable which isn't, to my knowledge, cleanly achiveable in Lua.		Ick. local characters = { [1] = {			['Active'] = {} },		[2] = {			['Inactive'] = {} },		[3] = {			['Deceased'] = {} },		[4] = {			['Other'] = {} }	}	local i = 1 while args[i] do		local s = _common.getCharacterStatus( args[i] ) local characterText = mw.html.create ( 'span' ) :css ( {				['font-size'] = '0.8em',				['color'] = args.body_font_color			} ) :wikitext ( args[i]	) local characterHTML = mw.html.create ( 'span' ) :tag ( 'span' ) :wikitext (					 ..					tostring(characterText) ..  ..					(s == "Deceased" and death or '')			   ) if s == "Active" then table.insert( characters[1][s], characterHTML ) elseif s == "Inactive" then table.insert( characters[2][s], characterHTML ) elseif s == "Deceased" then table.insert( characters[3][s], characterHTML ) elseif s == "Unknown" -- change to "Other" then table.insert( characters[4]['Other'], characterHTML ) end i = i+1 end local seperatorText = mw.html.create ( 'span' ) :css ( {			['font-size'] = '0.8em',			['color'] = args.separator_color		} ) :wikitext ( ' • ' ) for i, value in ipairs(characters) do		local k, v = next(value) if #v > 0 then -- Create outer div local node = mw.html.create ( 'div' ) :css ({					['margin'] = '10px 50px 10px 50px'				}) if not args.tabbed then node :tag( 'div' ) :css ({							['color'] = args[mw.ustring.lower(k) .. '_font_color'],							['font-size'] = '1.0em',							['margin-bottom'] = '5px'						}) :tag ( 'b' ) :wikitext ( k .. 'Characters:' ) :newline :allDone end for j, character in ipairs(v) do				if j ~= #v then character:node ( seperatorText ) end --Append to outer div node:node( character ) end node:node ( margin ) if not args.tabbed then for j=i+1, #characters do					local _, v = next(characters[j]) if #v > 0 then node:node ( hr ) break end end end -- Node to output --characterOutput:node ( node ) if not args.tabbed then characters[i] = node:allDone else characters[i] = k .. '=' .. tostring(node) for j=i, #characters do					if characters[j] then characters[i] = characters[i] .. '|-|'						break end end end else characters[i] = "" end end local parserArgs = {} if not args.tabbed then return mw.html.create ( 'div' ) :node ( characters[1] ) :node ( characters[2] ) :node ( characters[3] ) :node ( characters[4] ) :allDone else for i=1, #characters do			if characters[i] then table.insert(parserArgs, characters[i]) end end return frame:callParserFunction{ name="#tag:tabber", args={ table.concat(parserArgs) }} end end

local function _getTabHtml(wikitext, subpage) return mw.html.create ( 'div' ) :css ( {			['min-width'] = '5em',			['float'] = 'left',			['border'] = '2px solid #0B6F63',			['border-radius'] = '10px',			['padding'] = '0.8em',			['height'] = '50px',			['margin'] = '2px'		} ) :cssText (			subpage and "background-color: #00F8B9;"			or "color: #999;"		) :tag ( 'div' ) :css ( {				['display'] = 'flex',				['align-items'] = 'center',				['justify-content'] = 'center',				['height'] = '100%',				['text-transform'] = 'uppercase'			} ) :cssText (				subpage and "color: #0c0b1f; font-weight: bold;"				or "text-align: center; width: 100%;"			) :wikitext ( wikitext ) :allDone end

function p.tabs(frame) local tabs = {} local tab1Main = frame:getParent.args["tab1_main"] ~= 'false' local currentPage = mw.title.getCurrentTitle local NAMESPACE = currentPage.nsText local SUBPAGENAME = currentPage.subpageText local PAGENAME= currentPage.text local BASEPAGENAME = currentPage.baseText local function _getSubpageWikitext(text) return "" .. text .. "" end

local function _getBasepageWikitext(text) return "" .. text .. "" end local i = 0 local lastIndex = 0 tabs[1] = 'overview' for k, v in pairs(frame:getParent.args) do		if k ~= "tab1_main" then local m = k:match("^tab(%d+)")-- or k:match("") if m then tabs[tonumber(m)] = v				i = i+1 if tonumber(m) > lastIndex then lastIndex = tonumber(m) end end if i > 30 then error(					"More than 30 tabs have been provided..." .. 					"Are you sure you need that many?"				) end end end for i=2, lastIndex do		if not tabs[i] then for j=i+1, lastIndex do				if tabs[j] then tabs[i] = tabs[j] tabs[j] = nil break end end end end

local html = mw.html.create( 'div' ) --css ( {			['clear'] = 'both'		} ) :tag ( 'div' ) :css ( {				['display'] = 'flex',				['justify-content'] = 'center',				['flex-wrap'] = 'wrap',				['margin-bottom'] = '15px'			} ) :tag ( 'div' ) :css ( {					['clear'] = 'both'				} ) --} )	if SUBPAGENAME == ( ( tab1Main ) and tabs[1] or PAGENAME ) then		if not tab1Main and SUBPAGENAME == tabs[1] then			html:node (	_getTabHtml ( tabs[1], true ) )		else			html:node (	_getTabHtml ( _getSubpageWikitext( tabs[1] ), false ) )		end	else		if tab1Main then			html:node ( _getTabHtml(					_getBasepageWikitext( tabs[1] ),					BASEPAGENAME == PAGENAME				) )		else			html:node ( _getTabHtml(					_getSubpageWikitext( tabs[1] ),					SUBPAGENAME == tabs[1]				) )		end	end	for i=2, #tabs do		if SUBPAGENAME == tabs[i] then			html:node ( _getTabHtml( _getSubpageWikitext( tabs[i] ), true ) )		else			html:node ( _getTabHtml( _getSubpageWikitext( tabs[i] ), false ) )		end	end	return html:allDone--:wikitext("Namespace: " .. NAMESPACE .. " " ..	--"Subpage Name: " .. SUBPAGENAME .. " " ..	--"Page Name: " .. PAGENAME .. " " ..	--"Basepage Name: " .. BASEPAGENAME .. " tab1Main=" .. (tab1Main and "true" or "false")) end

return p