Raft Wiki
Advertisement

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

local phase = 0 -- Allows to make 2 phases of inserting the info
local phasetest = 0 -- Allows to make 3 phases per item. 
--[[ phasetest
0 - componentname
1 - componentlangcode
2 - componenttranslation (won't work)
3 - componentamount
]]
-- Start of the actual module
local p = {} 

	-- Start of the main function
	
	function p.componentsTabs( f )
		local args = f
		if f == mw.getCurrentFrame() then
			args = f:getParent().args
		end
		
		local item1 = args[1] or ''
		local item2 = args[2] or ''
		local item3 = args[3] or ''
		local item4 = args[4] or ''
		local item5 = args[5] or ''
		local lang = args[6] or ''
		
		local components = {}
		for component in mw.text.gsplit( item1, '%s*;%s*' ) do -- This seperates component name from component amount.
			if component == '' then
				--table.insert( components, '<span><br></span>' )
			else
				-- Phase 0 (componentName)
				if phase == 0 then
					table.insert( components, '<div class="componentsimage" width="64px">[[File:'..component..'.png|center|48px|link='..component..''..lang..']]</div></td><td style="padding:0;"><div style="font-size:115%;" class="components"><b>[['..component..''..lang..']]</b>')
				else
				-- Phase 1 (componentAmount)
					table.insert( components, '<span style="float: right; padding: 0 15px 0 9px;"><b>'..component..'</b></span></div>')
				end
				phase = phase + 1
			end
		end

		for component in mw.text.gsplit( item2, '%s*;%s*' ) do -- This seperates component name from component amount.
			if component == '' then
				--table.insert( components, '<span><br></span>' )
			else
				-- Phase 2 (componentName)
				if phase == 2 then
					table.insert( components, '</td></tr><tr><td width="75"><div class="componentsimage" width="64px">[[File:'..component..'.png|center|48px|link='..component..''..lang..']]</div></td><td style="padding:0;"><div style="font-size:115%;" class="components"><b>[['..component..''..lang..']]</b>')
				else
				-- Phase 3 (componentAmount)
					table.insert( components, '<span style="float: right; padding: 0 15px 0 9px;"><b>'..component..'</b></span></div>')
				end
				phase = phase + 1
			end
		end
		
		for component in mw.text.gsplit( item3, '%s*;%s*' ) do -- This seperates component name from component amount.
			if component == '' then
				--table.insert( components, '<span><br></span>' )
			else
				-- Phase 4 (componentName)
				if phase == 4 then
					table.insert( components, '</td></tr><tr><td width="75"><div class="componentsimage" width="64px">[[File:'..component..'.png|center|48px|link='..component..''..lang..']]</div></td><td style="padding:0;"><div style="font-size:115%;" class="components"><b>[['..component..''..lang..']]</b>')
				else
				-- Phase 5 (componentAmount)
					table.insert( components, '<span style="float: right; padding: 0 15px 0 9px;"><b>'..component..'</b></span></div>')
				end
				phase = phase + 1
			end
		end
		
		for component in mw.text.gsplit( item4, '%s*;%s*' ) do -- This seperates component name from component amount.
			if component == '' then
				--table.insert( components, '<span><br></span>' )
			else
				-- Phase 6 (componentName)
				if phase == 6 then
					table.insert( components, '</td></tr><tr><td width="75"><div class="componentsimage" width="64px">[[File:'..component..'.png|center|48px|link='..component..''..lang..']]</div></td><td style="padding:0;"><div style="font-size:115%;" class="components"><b>[['..component..''..lang..']]</b>')
				else
				-- Phase 7 (componentAmount)
					table.insert( components, '<span style="float: right; padding: 0 15px 0 9px;"><b>'..component..'</b></span></div>')
				end
				phase = phase + 1
			end
		end

		for component in mw.text.gsplit( item5, '%s*;%s*' ) do -- This seperates component name from component amount.
			if component == '' then
				--table.insert( components, '<span><br></span>' )
			else
				-- Phase 8 (componentName)
				if phase == 8 then
					table.insert( components, '</td></tr><tr><td width="75"><div class="componentsimage" width="64px">[[File:'..component..'.png|center|48px|link='..component..''..lang..']]</div></td><td style="padding:0;"><div style="font-size:115%;" class="components"><b>[['..component..''..lang..']]</b>')
				else
				-- Phase 9 (componentAmount)
					table.insert( components, '<span style="float: right; padding: 0 15px 0 9px;"><b>'..component..'</b></span></div>')
				end
				phase = phase + 1
			end
		end		
		return '' .. table.concat( components ) .. ''
	end
		
	-- A test to not include "/lc" in image file
	
	-- Problem - Parsing in Modules work differently then wikitext one. That being said, function cannot be simply inserted into table.
	function p.test( f )
		local args = f
		if f == mw.getCurrentFrame() then
			args = f:getParent().args
		end
		local item1 = args[1] or ''
		local item2 = args[2] or ''
		local item3 = args[3] or ''
		local item4 = args[4] or ''
		local item5 = args[5] or ''
		
		local components = {}
		for component in mw.text.gsplit( item1, '%s*;%s*' ) do -- This seperates component name from component amount.
			if component == '' then
				--table.insert( components, '<span><br></span>' )
			else
				
				-- Phase 0 (componentName)
				local body = mw.html.create( 'div' ):addClass( 'testcontainer' )
				if phase == 0 then
					table.insert( components, '<div class="componentsimage" width="64px">[[File:' +
						body:wikitext (
						f:callParserFunction( 'Sandbox', { 
							title = '' ..component.. '',
							xx = ''
						} )
					) +
					'}}.png|center|48px|link='..component..''..lang..']]</div></td><td style="padding:0;"><div style="font-size115%;" class="components"><b>[['..component..''..lang..']]</b>')
					else
						-- Phase 1 (componentAmount)
					table.insert( components, '<span style="float: right; padding: 0 15px 0 9px;"><b>'..component..'</b></span></div>')
				end
				phase = phase + 1
			end
		end
		for component in mw.text.gsplit( item2, '%s*;%s*' ) do -- This seperates component name from component amount.
			if component == '' then
				--table.insert( components, '<span><br></span>' )
			else
				-- Phase 2 (componentName)
				if phase == 2 then
					table.insert( components, '</td></tr><tr><td width="75"><div class="componentsimage" width="64px">[[File:'..component..'.png|center|48px|link='..component..''..lang..']]</div></td><td style="padding:0;"><div style="font-size:115%;" class="components"><b>[['..component..''..lang..']]</b>')
				else
				-- Phase 3 (componentAmount)
					table.insert( components, '<span style="float: right; padding: 0 15px 0 9px;"><b>'..component..'</b></span></div>')
				end
				phase = phase + 1
			end
		end
		
		for component in mw.text.gsplit( item3, '%s*;%s*' ) do -- This seperates component name from component amount.
			if component == '' then
				--table.insert( components, '<span><br></span>' )
			else
				-- Phase 4 (componentName)
				if phase == 4 then
					table.insert( components, '</td></tr><tr><td width="75"><div class="componentsimage" width="64px">[[File:'..component..'.png|center|48px|link='..component..''..lang..']]</div></td><td style="padding:0;"><div style="font-size:115%;" class="components"><b>[['..component..''..lang..']]</b>')
				else
				-- Phase 5 (componentAmount)
					table.insert( components, '<span style="float: right; padding: 0 15px 0 9px;"><b>'..component..'</b></span></div>')
				end
				phase = phase + 1
			end
		end
		
		for component in mw.text.gsplit( item4, '%s*;%s*' ) do -- This seperates component name from component amount.
			if component == '' then
				--table.insert( components, '<span><br></span>' )
			else
				-- Phase 6 (componentName)
				if phase == 6 then
					table.insert( components, '</td></tr><tr><td width="75"><div class="componentsimage" width="64px">[[File:'..component..'.png|center|48px|link='..component..''..lang..']]</div></td><td style="padding:0;"><div style="font-size:115%;" class="components"><b>[['..component..''..lang..']]</b>')
				else
				-- Phase 7 (componentAmount)
					table.insert( components, '<span style="float: right; padding: 0 15px 0 9px;"><b>'..component..'</b></span></div>')
				end
				phase = phase + 1
			end
		end

		for component in mw.text.gsplit( item5, '%s*;%s*' ) do -- This seperates component name from component amount.
			if component == '' then
				--table.insert( components, '<span><br></span>' )
			else
				-- Phase 8 (componentName)
				if phase == 8 then
					table.insert( components, '</td></tr><tr><td width="75"><div class="componentsimage" width="64px">[[File:'..component..'.png|center|48px|link='..component..''..lang..']]</div></td><td style="padding:0;"><div style="font-size:115%;" class="components"><b>[['..component..''..lang..']]</b>')
				else
				-- Phase 9 (componentAmount)
					table.insert( components, '<span style="float: right; padding: 0 15px 0 9px;"><b>'..component..'</b></span></div>')
				end
				phase = phase + 1
			end
		end		
		return '' .. table.concat( components ) .. ''
	end
return p
Advertisement