Module:SkillDetails: Difference between revisions

From Eco - English Wiki
[unchecked revision][unchecked revision]
m 1 revision imported
Adding Credit
Line 1: Line 1:
-- Credit: Original SkillDetails was created by Fyre (FishAus) then edited by Scotty (ZeelNightwolf).
local p = {}
local p = {}



Revision as of 16:47, 27 August 2020

This module provides the back end functionality of the Template:SkillDetails.

If the template is passed, this module creates a list using details from the following Modules:

Credit

Original SkillDetails was created by Fyre (FishAus) then edited by Scotty (ZeelNightwolf).


-- Credit: Original SkillDetails was created by Fyre (FishAus) then edited by Scotty (ZeelNightwolf).

local p = {}

-- Grabs args from the parent frame
-- Trims and parses the args into a table, then returns the table
function norm()
    local origArgs = mw.getCurrentFrame():getParent().args
    local args = {}
    
    for k, v in pairs( origArgs ) do
        v = mw.text.trim( tostring( v ) )
        if v ~= '' then
            args[k] = v
        end
    end
    
    return args
end

function p.benefits( benTable )
	local function istable(t) return type(t) == 'table' end
	local builder = '<div style=\"column-count:2;-moz-column-count:2;-webkit-column-count:2\"><small>'
	for i,v in pairs(benTable) do
		builder = builder .. '\n* \'\'\'[[' .. i .. ']]\'\'\': '
		local count = 1
		for a,b in ipairs(v) do	
			if istable(b) then 				
				for c,d in ipairs(b) do										
					if c == 1 then
						builder = builder .. '\'\'[[' .. d .. ']]\'\''						
						if count ~= #v then
							builder = builder .. ' and '
						end
						if count == #v then
							builder = builder .. ' cost and craft time ' .. b[2]:lower() 
							if b[3] ~= nil then
								builder = builder .. ' by ' .. b[3]
							end
						end	
						count = count + 1
					end			
				end				
			else
				if a == 1 then	
					builder = builder .. b
				end
				if a == 2 then
					builder = builder .. ' ' .. b:lower()
					if v[3] ~= nil then
						builder = builder .. ' by '
					end
				end
				if a == 3 then
					builder = builder .. b .. '. <br />'
				end
			end
		end
	end
	
	return builder .. '</small></div>'
end

-- Main entry point for the Module
function p.main()
    -- get args from the Template
    local args = norm()
    
	if args.skill == nil or args.skill == '' then
        return '\'skill\' must be specified.'
    end
	
    -- assign variables for plant
    local skill = args.skill
	
	
    -- load list of recipes
    local skillData = require( "Module:Skills" )
    local skillTable = skillData.skills[skill]
    if skillTable == nil then
		return skill .. ' could not be found in Module:Skills.'
	end    
	
	local wikibox = ''
	-- Profession Skill 
	if skillTable.root == true then
		wikibox = wikibox .. '==Unlocks==\n'
		wikibox = wikibox .. '{| class=\"wikitable\"  \n'
		wikibox = wikibox .. '! style="width: 5em; text-align: center;" |Level \n'
		wikibox = wikibox .. '! style="width: 10em;" |Skill Unlocks \n'
		wikibox = wikibox .. '|- \n'
		wikibox = wikibox .. '| 0 \n'
		wikibox = wikibox .. '| '
		if skillTable.level0Unlocks.skillUnlocks ~= nil then
			for i,v in pairs(skillTable.level0Unlocks.skillUnlocks) do
				wikibox = wikibox .. skillTable.level0Unlocks.skillUnlocks[i] .. '<br />'
			end
		end
		wikibox = wikibox .. '\n'
		wikibox = wikibox .. '|}\n\n'
	end
		

	-- Specialty
	if skillTable.root ~= true and skillTable.specialty == true then		
		local anyBenefits = skillTable.benefitsLevel1 ~= nil or skillTable.benefitsLevel2 ~= nil or skillTable.benefitsLevel3 ~= nil or skillTable.benefitsLevel4 ~= nil or skillTable.benefitsLevel5 ~= nil or skillTable.benefitsLevel0 ~= nil
		
		wikibox = wikibox .. '==Unlocks==\n'
		wikibox = wikibox .. '{| class=\"wikitable\" \n'
		wikibox = wikibox .. '! Level \n'
		wikibox = wikibox .. '! Crafting Unlocks \n'
		if anyBenefits then 
			wikibox = wikibox .. '! Benefits \n'
		end	
		
		wikibox = wikibox .. '|- \n'
		wikibox = wikibox .. '| 0\n'
		wikibox = wikibox .. '| '
		if skillTable.level0Unlocks ~= nil then	
			if skillTable.level0Unlocks.recipeUnlocks ~= nil then
				for i,v in pairs(skillTable.level0Unlocks.recipeUnlocks) do
					wikibox = wikibox .. skillTable.level0Unlocks.recipeUnlocks[i] .. '<br />'
				end
			wikibox = wikibox .. '\n'
			wikibox = wikibox .. '| '
			end
		else
			wikibox = wikibox .. '\n'
			wikibox = wikibox .. '| '
		end
		if anyBenefits then
			wikibox = wikibox .. '| '
			if skillTable.benefitsLevel0 ~= nil then
				wikibox = wikibox .. p.benefits( skillTable.benefitsLevel0 )
			end
			wikibox = wikibox .. '\n'
		end
		
		
		wikibox = wikibox .. '|- \n'	
		wikibox = wikibox .. '| 1\n'
		wikibox = wikibox .. '| '
		if skillTable.level1Unlocks ~= nil then	
			if skillTable.level1Unlocks.recipeUnlocks ~= nil then
				for i,v in pairs(skillTable.level1Unlocks.recipeUnlocks) do
					wikibox = wikibox .. skillTable.level1Unlocks.recipeUnlocks[i] .. '<br />'
				end
			wikibox = wikibox .. '\n'
			wikibox = wikibox .. '| '
			end
		else
			wikibox = wikibox .. '\n'
			wikibox = wikibox .. '| '
		end
		if anyBenefits then
			wikibox = wikibox .. '| '
			if skillTable.benefitsLevel1 ~= nil then
				wikibox = wikibox .. p.benefits( skillTable.benefitsLevel1 )
			end
			wikibox = wikibox .. '\n'
		end
		
		wikibox = wikibox .. '|- \n'	
		wikibox = wikibox .. '| 2\n'
		wikibox = wikibox .. '| '
		if skillTable.level2Unlocks ~= nil then	
			if skillTable.level2Unlocks.recipeUnlocks ~= nil then
				for i,v in pairs(skillTable.level2Unlocks.recipeUnlocks) do
					wikibox = wikibox .. skillTable.level2Unlocks.recipeUnlocks[i] .. '<br />'
				end
			wikibox = wikibox .. '\n'
			wikibox = wikibox .. '| '
			end
		else
			wikibox = wikibox .. '\n'
			wikibox = wikibox .. '| '
		end
		if anyBenefits then
			wikibox = wikibox .. '| '
			if skillTable.benefitsLevel2 ~= nil then
				wikibox = wikibox .. p.benefits( skillTable.benefitsLevel2 )
			end
			wikibox = wikibox .. '\n'
		end
		
		wikibox = wikibox .. '|- \n'	
		wikibox = wikibox .. '| 3\n'
		wikibox = wikibox .. '| '
		if skillTable.level3Unlocks ~= nil then	
			if skillTable.level3Unlocks.recipeUnlocks ~= nil then
				for i,v in pairs(skillTable.level3Unlocks.recipeUnlocks) do
					wikibox = wikibox .. skillTable.level3Unlocks.recipeUnlocks[i] .. '<br />'
				end
			wikibox = wikibox .. '\n'
			wikibox = wikibox .. '| '
			end
		else
			wikibox = wikibox .. '\n'
			wikibox = wikibox .. '| '
		end
		if anyBenefits then
			wikibox = wikibox .. '| '
			if skillTable.benefitsLevel3 ~= nil then
				wikibox = wikibox .. p.benefits( skillTable.benefitsLevel3 )
			end
			wikibox = wikibox .. '\n'
		end
		
		wikibox = wikibox .. '|- \n'	
		wikibox = wikibox .. '| 4\n'
		wikibox = wikibox .. '| '
		if skillTable.level4Unlocks ~= nil then	
			if skillTable.level4Unlocks.recipeUnlocks ~= nil then
				for i,v in pairs(skillTable.level4Unlocks.recipeUnlocks) do
					wikibox = wikibox .. skillTable.level4Unlocks.recipeUnlocks[i] .. '<br />'
				end
			wikibox = wikibox .. '\n'
			wikibox = wikibox .. '| '
			end
		else
			wikibox = wikibox .. '\n'
			wikibox = wikibox .. '| '
		end
		if anyBenefits then
			wikibox = wikibox .. '| '
			if skillTable.benefitsLevel4 ~= nil then
				wikibox = wikibox .. p.benefits( skillTable.benefitsLevel4 )
			end
			wikibox = wikibox .. '\n'
		end
		
		wikibox = wikibox .. '|- \n'	
		wikibox = wikibox .. '| 5\n'
		wikibox = wikibox .. '| '
		if skillTable.level5Unlocks ~= nil then	
			if skillTable.level5Unlocks.recipeUnlocks ~= nil then
				for i,v in pairs(skillTable.level5Unlocks.recipeUnlocks) do
					wikibox = wikibox .. skillTable.level5Unlocks.recipeUnlocks[i] .. '<br />'
				end
			wikibox = wikibox .. '\n'
			wikibox = wikibox .. '| '
			end
		else
			wikibox = wikibox .. '\n'
			wikibox = wikibox .. '| '
		end
		if anyBenefits then
			wikibox = wikibox .. '| '
			if skillTable.benefitsLevel5 ~= nil then
				wikibox = wikibox .. p.benefits( skillTable.benefitsLevel5 )
			end
			wikibox = wikibox .. '\n'
		end
		
		
		wikibox = wikibox .. '|- \n'	
		wikibox = wikibox .. '| 6\n'
		wikibox = wikibox .. '| '
		if skillTable.level6Unlocks ~= nil then	
			if skillTable.level6Unlocks.recipeUnlocks ~= nil then
				for i,v in pairs(skillTable.level6Unlocks.recipeUnlocks) do
					wikibox = wikibox .. skillTable.level6Unlocks.recipeUnlocks[i] .. '<br />'
				end
			wikibox = wikibox .. '\n'
			wikibox = wikibox .. '| '
			end
		else
			wikibox = wikibox .. '\n'
			wikibox = wikibox .. '| '
		end
		if anyBenefits then
			wikibox = wikibox .. '| '
			if skillTable.benefitsLevel6 ~= nil then
				wikibox = wikibox .. p.benefits( skillTable.benefitsLevel6 )
			end
			wikibox = wikibox .. '\n'
		end
		
		wikibox = wikibox .. '|- \n'	
		wikibox = wikibox .. '| 7\n'
		wikibox = wikibox .. '| '
		if skillTable.level7Unlocks ~= nil then	
			if skillTable.level7Unlocks.recipeUnlocks ~= nil then
				for i,v in pairs(skillTable.level7Unlocks.recipeUnlocks) do
					wikibox = wikibox .. skillTable.level7Unlocks.recipeUnlocks[i] .. '<br />'
				end
			wikibox = wikibox .. '\n'
			wikibox = wikibox .. '| '
			end
		else
			wikibox = wikibox .. '\n'
			wikibox = wikibox .. '| '
		end
		if anyBenefits then
			wikibox = wikibox .. '| '
			if skillTable.benefitsLevel7 ~= nil then
				wikibox = wikibox .. p.benefits( skillTable.benefitsLevel7 )
			end
			wikibox = wikibox .. '\n'
		end	
		
		
		wikibox = wikibox .. '|}\n\n'
	end
	
return wikibox
	
end

return p