Module:VariantDetails: Difference between revisions

From Eco - English Wiki
[unchecked revision][unchecked revision]
No edit summary
No edit summary
Line 19: Line 19:
end
end


-- Build an Item wikibox
-- Build an Item varientBox
function variantBox( args, itemData )
function variantBox( args, itemData )
     -- check that all necessary arguments are passed correctly
     -- check that all necessary arguments are passed correctly
Line 37: Line 37:
local itemimagename = string.gsub(itemEN, ' ', '')
local itemimagename = string.gsub(itemEN, ' ', '')
      
      
     -- string used to build the wikibox
     -- string used to build the varientBox
     local wikibox = '{| class=\"wikitable\"\n'
     local varientBox = '{| class=\"wikitable\"\n'
      
      
-- 'Name and Image' section
-- 'Name and Image' section
-- name of the item
-- name of the item
wikibox = wikibox .. '|- style=\"color: white; background-color: #1165AF; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. item .. '</big>\'\'\'\n'
varientBox = varientBox .. '|- style=\"color: white; background-color: #1165AF; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. item .. '</big>\'\'\'\n'
      
      
-- the item's type (ItemData - group)
-- the item's type (ItemData - group)
wikibox = wikibox .. '|- style=\"text-align: center; color: white; background-color: '
varientBox = varientBox .. '|- style=\"text-align: center; color: white; background-color: '
if itemTable.group == 'Food' then
if itemTable.group == 'Food' then
wikibox = wikibox .. '#85D66B;\"\n| colspan=\"2\" | \'\'\'Food\'\'\'\n'
varientBox = varientBox .. '#85D66B;\"\n| colspan=\"2\" | \'\'\'Food\'\'\'\n'
-- Items:Food Icon Image
-- Items:Food 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]]'
local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Icon.png|[[Category:Pages_with_missing_icon]]'
Line 57: Line 57:
end
end
     wikibox = wikibox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | <div class="iconContainer"><div class="iconStack">[[File:' .. image .. '|frameless|class=iconGreen]]</div><div class=iconBorder style=\"position:absolute;\"></div></div> \n'
     varientBox = varientBox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | <div class="iconContainer"><div class="iconStack">[[File:' .. image .. '|frameless|class=iconGreen]]</div><div class=iconBorder style=\"position:absolute;\"></div></div> \n'
elseif itemTable.group == 'Skill Books' then
elseif itemTable.group == 'Skill Books' then
wikibox = wikibox .. '#FFCF4D;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
varientBox = varientBox .. '#FFCF4D;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
-- Items:Skill Book Icon Image
-- Items:Skill Book Icon Image
wikibox = wikibox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | <div class="iconContainer"><div class="iconStack">[[File:SkillBook.png|link=https://wiki.play.eco/File:SkillBook.png|frameless|class=iconGold]]</div><div class=iconBorder style=\"position:absolute;\"></div></div> \n'
varientBox = varientBox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | <div class="iconContainer"><div class="iconStack">[[File:SkillBook.png|link=https://wiki.play.eco/File:SkillBook.png|frameless|class=iconGold]]</div><div class=iconBorder style=\"position:absolute;\"></div></div> \n'
elseif itemTable.group == 'Skill Scrolls' then
elseif itemTable.group == 'Skill Scrolls' then
wikibox = wikibox .. '#FFCF4D;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
varientBox = varientBox .. '#FFCF4D;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
-- Items:Skill Scrolls Icon Image
-- Items:Skill Scrolls Icon Image
wikibox = wikibox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | <div class="iconContainer"><div class="iconStack">[[File:SkillScroll.png|link=https://wiki.play.eco/File:SkillScroll.png|frameless|class=iconGold]]</div><div class=iconBorder style=\"position:absolute;\"></div></div> \n'
varientBox = varientBox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | <div class="iconContainer"><div class="iconStack">[[File:SkillScroll.png|link=https://wiki.play.eco/File:SkillScroll.png|frameless|class=iconGold]]</div><div class=iconBorder style=\"position:absolute;\"></div></div> \n'
else
else
wikibox = wikibox .. '#78B1FF;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
varientBox = varientBox .. '#78B1FF;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
-- Items: Other Icon Image
-- Items: Other 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]]'
local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Icon.png|[[Category:Pages_with_missing_icon]]'
Line 78: Line 78:
image = itemimagename .. '_Icon.jpg'
image = itemimagename .. '_Icon.jpg'
end
end
     wikibox = wikibox .. '|-\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'
     varientBox = varientBox .. '|-\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'
end
end


    -- 'Item' World Object header (if itemTable.group = Placeable or Blocks)
if itemTable.group == 'Block Items' or itemTable.group == 'World Object Items' then
wikibox = wikibox .. '|- style=\"text-align: center; background-color: #517ab2;\"\n| colspan=\"2\" | \'\'\'World Object\'\'\'\n'
-- Object Placed Image
-- 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]]'
local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Placed.png|[[Category:Pages_with_missing_placed]]'
Line 92: Line 88:
image = itemimagename .. '_Placed.jpg'
image = itemimagename .. '_Placed.jpg'
end
end
wikibox = wikibox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
varientBox = varientBox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
 
--Material Tier
if itemTable.materialTier ~= nil or itemTable.materialTier == 0 then
wikibox = wikibox .. '|-\n| Room Material:\n| style=\"text-align: right; padding: 3px;\" | Tier ' .. itemTable.materialTier .. '\n'
end
--Room Req.
if itemTable.roomContainReq ~= nil then
wikibox = wikibox .. '|-\n| Room Required:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomContainReq .. '\n'
end
--Room Size. Req.
if itemTable.roomSizeReq ~= nil then
wikibox = wikibox .. '|-\n| Room Size:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomSizeReq .. ' m³\n'
end
--Room Mat. Req.
if itemTable.roomMatReq ~= nil then
wikibox = wikibox .. '|-\n| Room Materials:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomMatReq .. '\n'
end
end
-- 'Housing' section (if there is a Room Category)
-- 'Housing' section (if there is a Room Category)
if itemTable.roomCategory ~= nil then   
if itemTable.roomCategory ~= nil then   
-- Housing Header
-- Housing Header
wikibox = wikibox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Housing\'\'\'\n'
varientBox = varientBox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Housing\'\'\'\n'
      
      
--roomCategory
--roomCategory
wikibox = wikibox .. '|-\n| Room Category:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomCategory .. '\n'
varientBox = varientBox .. '|-\n| Room Category:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomCategory .. '\n'


if itemTable.roomCategory ~= 'Industrial' then
if itemTable.roomCategory ~= 'Industrial' then
if itemTable.furnitureType ~= nil then  
if itemTable.furnitureType ~= nil then  
--furnitureType
--furnitureType
wikibox = wikibox .. '|-\n| Furniture Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.furnitureType .. '\n'
varientBox = varientBox .. '|-\n| Furniture Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.furnitureType .. '\n'
              
              
--Value of the object
--Value of the object
wikibox = wikibox .. '|-\n| Value:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.skillValue .. '\n'
varientBox = varientBox .. '|-\n| Value:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.skillValue .. '\n'
              
              
--Dim. Return % of Object   
--Dim. Return % of Object   
wikibox = wikibox .. '|-\n| Dim. Return %:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.repeatsDepreciation .. '\n'     
varientBox = varientBox .. '|-\n| Dim. Return %:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.repeatsDepreciation .. '\n'     
end
end
end
end
if itemTable.roomCategory == 'Industrial' then
if itemTable.roomCategory == 'Industrial' then
wikibox = wikibox .. '|- style=\"background-color: red; text-align: center;\"\n| colspan=\"2\" | \'\'\'ALL ROOM VALUE LOST\'\'\'\n'
varientBox = varientBox .. '|- style=\"background-color: red; text-align: center;\"\n| colspan=\"2\" | \'\'\'ALL ROOM VALUE LOST\'\'\'\n'
end
end
end
end
wikibox = wikibox .. '|}'
varientBox = varientBox .. '|}'
return wikibox
return varientBox
end
end


-- Main entry point for the Module
-- Main entry point for the Module
function p.ItemMain()
function p.main()
     -- get args from the Template
     -- get args from the Template
     local args = norm()
     local args = norm()

Revision as of 06:57, 4 February 2021

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 Item varientBox
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 item = args.name
	local itemTable = itemData.items[item]

	if itemTable == nil then
		return item .. ' 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 varientBox
    local varientBox = '{| class=\"wikitable\"\n'
    
	-- 'Name and Image' section
		-- name of the item
		varientBox = varientBox .. '|- style=\"color: white; background-color: #1165AF; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. item .. '</big>\'\'\'\n'
    
		-- the item's type (ItemData - group)
		varientBox = varientBox .. '|- style=\"text-align: center; color: white; background-color: '
	
		if itemTable.group == 'Food' then
			varientBox = varientBox .. '#85D66B;\"\n| colspan=\"2\" | \'\'\'Food\'\'\'\n'
			-- Items:Food 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
			
    		varientBox = varientBox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | <div class="iconContainer"><div class="iconStack">[[File:' .. image .. '|frameless|class=iconGreen]]</div><div class=iconBorder style=\"position:absolute;\"></div></div> \n'
		
		elseif itemTable.group == 'Skill Books' then
			varientBox = varientBox .. '#FFCF4D;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
			-- Items:Skill Book Icon Image
			varientBox = varientBox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | <div class="iconContainer"><div class="iconStack">[[File:SkillBook.png|link=https://wiki.play.eco/File:SkillBook.png|frameless|class=iconGold]]</div><div class=iconBorder style=\"position:absolute;\"></div></div> \n'
	
		elseif itemTable.group == 'Skill Scrolls' then
			varientBox = varientBox .. '#FFCF4D;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
			-- Items:Skill Scrolls Icon Image
			varientBox = varientBox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | <div class="iconContainer"><div class="iconStack">[[File:SkillScroll.png|link=https://wiki.play.eco/File:SkillScroll.png|frameless|class=iconGold]]</div><div class=iconBorder style=\"position:absolute;\"></div></div> \n'
	
		else
			varientBox = varientBox .. '#78B1FF;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
			-- Items: Other 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
    		varientBox = varientBox .. '|-\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'
		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
			varientBox = varientBox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
			
		-- 'Housing' section (if there is a Room Category)
			if itemTable.roomCategory ~= nil then  
				-- Housing Header
				varientBox = varientBox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Housing\'\'\'\n'
    
				--roomCategory
				varientBox = varientBox .. '|-\n| Room Category:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomCategory .. '\n'

				if itemTable.roomCategory ~= 'Industrial' then
					if itemTable.furnitureType ~= nil then 
					--furnitureType
						varientBox = varientBox .. '|-\n| Furniture Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.furnitureType .. '\n'
            
					--Value of the object
						varientBox = varientBox .. '|-\n| Value:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.skillValue .. '\n'
            
					--Dim. Return % of Object  
						varientBox = varientBox .. '|-\n| Dim. Return %:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.repeatsDepreciation .. '\n'    
					end
				end
		
				if itemTable.roomCategory == 'Industrial' then
					varientBox = varientBox .. '|- style=\"background-color: red; text-align: center;\"\n| colspan=\"2\" | \'\'\'ALL ROOM VALUE LOST\'\'\'\n'
				end
			end
		
	varientBox = varientBox .. '|}'
	return varientBox
	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