Module:VariantDetails

From Eco - English Wiki
Revision as of 08:13, 4 February 2021 by ZeelNightwolf (talk | contribs)

Documentation

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

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


-- Credit: 

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

-- Build an Varient Card
function variantBox( args, itemData )
    -- check that all necessary arguments are passed correctly
    if args.name == nil or args.name == '' then
        return '\'name\' must be specified.'
    end
    
	local varientName = args.name
	local itemTable = itemData.items[varientName]

	if itemTable == nil then
		return varientName .. ' could not be found in Module:ItemData.'
	end

    local itemType = itemTable.type
	local itemEN = string.sub (itemType, 1, -5)
	local itemimagename = string.gsub(itemEN, ' ', '')
    
    -- string used to build the varientCa
    local varientCard = '{| class=\"card mb-3\" style=\"background: #d1ecf1; border: 5px solid #7BC2CE; width: fit-content;\"\n'
    

	-- Name of Varient
	varientCard = varientCard .. '|- style=\"color: white; background-color: #1165AF; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. varientName .. '</big>\'\'\'\n'

	-- Varient: Icon Image
	local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Icon.png|[[Category:Pages_with_missing_icon]]'
		
	if mw.title.makeTitle('File', itemimagename .. '_Icon.png').file.exists then
		image = itemimagename .. '_Icon.png'
	elseif mw.title.makeTitle('File', itemimagename .. '_Icon.jpg').file.exists then
		image = itemimagename .. '_Icon.jpg'
	end
		
	varientCard = varientCard .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | <div class="iconContainer"><div class="iconStack">[[File:' .. image .. '|frameless|class=iconBlue]]</div><div class=iconBorder style=\"position:absolute;\"></div></div> \n'
			
	-- 'Housing' section (if there is a Room Category)
	if itemTable.roomCategory ~= nil then  
		-- Housing Header
		varientCard = varientCard .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Housing\'\'\'\n'
    
		--roomCategory
		varientCard = varientCard .. '|-\n| Room Category:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomCategory .. '\n'

		if itemTable.roomCategory ~= 'Industrial' then
			if itemTable.furnitureType ~= nil then 
			--furnitureType
			varientCard = varientCard .. '|-\n| Furniture Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.furnitureType .. '\n'
            
			--Value of the object
			varientCard = varientCard .. '|-\n| Value:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.skillValue .. '\n'
            
			--Dim. Return % of Object  
			varientCard = varientCard .. '|-\n| Dim. Return %:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.repeatsDepreciation .. '\n'    
			end
		end
		
		if itemTable.roomCategory == 'Industrial' then
			varientCard = varientCard .. '|- style=\"background-color: red; text-align: center;\"\n| colspan=\"2\" | \'\'\'ALL ROOM VALUE LOST\'\'\'\n'
		end
	end
			
	-- Object Placed Image
	local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Placed.png|[[Category:Pages_with_missing_placed]]'
	if mw.title.makeTitle('File', itemimagename .. '_Placed.png').file.exists then
		image = itemimagename .. '_Placed.png'
	elseif mw.title.makeTitle('File', itemimagename .. '_Placed.jpg').file.exists then
		image = itemimagename .. '_Placed.jpg'
	end
	varientCard = varientCard .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
		
	varientCard = varientCard .. '|}'
	return varientCard
	
	end
	
-- Main entry point for the Module
function p.main()
    -- get args from the Template
    local args = norm()
    
    -- get item data
    local itemData = require( "Module:ItemData" )
    return variantBox( args, itemData )
end

return p