Module:VariantDetails: Difference between revisions

From Eco - English Wiki
[unchecked revision][unchecked revision]
No edit summary
No edit summary
Line 1: Line 1:
-- Credit:  
-- Credit:


local p = {}
local p = {}
Line 19: Line 19:
end
end


-- Build an Varient Card
-- build all variant cards
function variantBox( args, itemData )
function main( args )
    -- check that all necessary arguments are passed correctly
local args = norm()
-- check that all necessary arguments are passed correctly
     if args.name == nil or args.name == '' then
     if args.name == nil or args.name == '' then
         return '\'name\' must be specified.'
         return '\'name\' must be specified.'
     end
     end
      
      
local varientName = args.name
-- name passed in will be the default recipe variant
local itemTable = itemData.items[varientName]
local defaultName = args.name
-- need both crafting recipes to find variants
local recipeData = require( "Module:CraftingRecipes" )
-- get the tables from the modules
local recipeList = recipeData.recipes
-- get the main recipe
local defaultRecipe = recipeList[defaultName]
-- break if defaultName not found
if (defaultRecipe == nil) then
return defaultName .. " could not be found in the recipe data"
end -- if default is nil
-- get the variants for the recipe
local variants = defaultRecipe.variants
-- break if no variants. return blank to not break page flow.
if (variant == nil or #variants < 1) then
return ""
end -- if variants don't exist
-- create variable to store returned text
local text = ""
for i=1, #variants do
if (variants[i] ~= defaultName) then
-- build the text for each variant
text = buildVariant(variants[i])
end -- if variant is not default
end -- for each variant
return text
end


if itemTable == nil then
-- build a variant card
return varientName .. ' could not be found in Module:ItemData.'
function variantCard( variantName)
-- variant cards require itemData
local itemData = require( "Module:ItemData" )
-- get the item data tables
local itemList = itemData.items
-- get the variant from the list
local variant = itemList[variantName]
-- variant does not exist as an item then just return
if variant == nil then
return  
end
end
 
     local itemType = itemTable.type
     local itemType = variant.type
local itemEN = string.sub (itemType, 1, -5)
local itemEN = string.sub (itemType, 1, -5)
local itemimagename = string.gsub(itemEN, ' ', '')
local itemimagename = string.gsub(itemEN, ' ', '')
      
      
     -- string used to build the varientCard
     -- string used to build the variantCard
     local varientCard = '{|class=\"card mb-3\" style=\"background: #d1ecf1; border: 5px solid #7BC2CE; width: fit-content;\"\n'
     local variantCard = '{|class=\"card mb-3\" style=\"background: #d1ecf1; border: 5px solid #7BC2CE; width: fit-content;\"\n'
      
      
-- Name of variantCard
variantCard = variantCard .. '|- style=\"color: white; background-color: #1165AF; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. variantName .. '</big>\'\'\'\n'


-- Name of VarientCard
-- Variant: Icon Image
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]]'
local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Icon.png|[[Category:Pages_with_missing_icon]]'
-- find the image file if it exists
if mw.title.makeTitle('File', itemimagename .. '_Icon.png').file.exists then
if mw.title.makeTitle('File', itemimagename .. '_Icon.png').file.exists then
image = itemimagename .. '_Icon.png'
image = itemimagename .. '_Icon.png'
elseif mw.title.makeTitle('File', itemimagename .. '_Icon.jpg').file.exists then
elseif mw.title.makeTitle('File', itemimagename .. '_Icon.jpg').file.exists then
image = itemimagename .. '_Icon.jpg'
image = itemimagename .. '_Icon.jpg'
end
end -- if image file found
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'
-- create image cell
variantCard = variantCard .. '|-\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)
-- 'Housing' section (if there is a Room Category)
if itemTable.roomCategory ~= nil then   
if variant.roomCategory ~= nil then   
-- Housing Header
-- Housing Header
varientCard = varientCard .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Housing\'\'\'\n'
variantCard = variantCard .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Housing\'\'\'\n'
      
      
--roomCategory
--roomCategory
varientCard = varientCard .. '|-\n| Room Category:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomCategory .. '\n'
variantCard = variantCard .. '|-\n| Room Category:\n| style=\"text-align: right; padding: 3px;\" | ' .. variant.roomCategory .. '\n'


if itemTable.roomCategory ~= 'Industrial' then
if variant.roomCategory ~= 'Industrial' then
if itemTable.furnitureType ~= nil then  
if variant.furnitureType ~= nil then  
--furnitureType
--furnitureType
varientCard = varientCard .. '|-\n| Furniture Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.furnitureType .. '\n'
variantCard = variantCard .. '|-\n| Furniture Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. variant.furnitureType .. '\n'
              
              
--Value of the object
--Value of the object
varientCard = varientCard .. '|-\n| Value:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.skillValue .. '\n'
variantCard = variantCard .. '|-\n| Value:\n| style=\"text-align: right; padding: 3px;\" | ' .. variant.skillValue .. '\n'
              
              
--Dim. Return % of Object   
--Dim. Return % of Object   
varientCard = varientCard .. '|-\n| Dim. Return %:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.repeatsDepreciation .. '\n'     
variantCard = variantCard .. '|-\n| Dim. Return %:\n| style=\"text-align: right; padding: 3px;\" | ' .. variant.repeatsDepreciation .. '\n'     
end
end
end
end
if itemTable.roomCategory == 'Industrial' then
-- check for industrial
varientCard = varientCard .. '|- style=\"background-color: red; text-align: center;\"\n| colspan=\"2\" | \'\'\'ALL ROOM VALUE LOST\'\'\'\n'
if variant.roomCategory == 'Industrial' then
variantCard = variantCard .. '|- style=\"background-color: red; text-align: center;\"\n| colspan=\"2\" | \'\'\'ALL ROOM VALUE LOST\'\'\'\n'
end
end
end
end
Line 88: Line 140:
image = itemimagename .. '_Placed.jpg'
image = itemimagename .. '_Placed.jpg'
end
end
varientCard = varientCard .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
variantCard = variantCard .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
varientCard = varientCard .. '|}'
variantCard = variantCard .. '|}'
return varientCard
return variantCard
end
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
return p

Revision as of 11:48, 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 all variant cards
function main( args )  
	local args = norm()
	
	-- check that all necessary arguments are passed correctly
    if args.name == nil or args.name == '' then
        return '\'name\' must be specified.'
    end
    
	-- name passed in will be the default recipe variant
	local defaultName = args.name
	
	-- need both crafting recipes to find variants
	local recipeData =  require( "Module:CraftingRecipes" )
	
	-- get the tables from the modules
	local recipeList = recipeData.recipes
	
	-- get the main recipe
	local defaultRecipe = recipeList[defaultName]
	
	-- break if defaultName not found
	if (defaultRecipe == nil) then
		return defaultName .. " could not be found in the recipe data"
	end -- if default is nil
	
	-- get the variants for the recipe
	local variants = defaultRecipe.variants
	
	-- break if no variants. return blank to not break page flow.
	if (variant == nil or #variants < 1) then
		return ""
	end -- if variants don't exist
	
	-- create variable to store returned text
	local text = ""
	
	for i=1, #variants do
		
		if (variants[i] ~= defaultName) then
			-- build the text for each variant
			text = buildVariant(variants[i])
		end -- if variant is not default
	end -- for each variant
	
	return text
end	

-- build a variant card
function variantCard( variantName)
	-- variant cards require itemData
	local itemData = require( "Module:ItemData" )
	
	-- get the item data tables
	local itemList = itemData.items
	
	-- get the variant from the list
	local variant = itemList[variantName]
	
	-- variant does not exist as an item then just return
	if variant == nil then
		return 
	end
	
    local itemType = variant.type
	local itemEN = string.sub (itemType, 1, -5)
	local itemimagename = string.gsub(itemEN, ' ', '')
    
    -- string used to build the variantCard
    local variantCard = '{|class=\"card mb-3\" style=\"background: #d1ecf1; border: 5px solid #7BC2CE; width: fit-content;\"\n'
    
	-- Name of variantCard
	variantCard = variantCard .. '|- style=\"color: white; background-color: #1165AF; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. variantName .. '</big>\'\'\'\n'

	-- Variant: 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]]'
	
-- find the image file if it exists	
	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 -- if image file found
	
	-- create image cell	
	variantCard = variantCard .. '|-\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 variant.roomCategory ~= nil then  
		-- Housing Header
		variantCard = variantCard .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Housing\'\'\'\n'
    
		--roomCategory
		variantCard = variantCard .. '|-\n| Room Category:\n| style=\"text-align: right; padding: 3px;\" | ' .. variant.roomCategory .. '\n'

		if variant.roomCategory ~= 'Industrial' then
			if variant.furnitureType ~= nil then 
			--furnitureType
			variantCard = variantCard .. '|-\n| Furniture Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. variant.furnitureType .. '\n'
            
			--Value of the object
			variantCard = variantCard .. '|-\n| Value:\n| style=\"text-align: right; padding: 3px;\" | ' .. variant.skillValue .. '\n'
            
			--Dim. Return % of Object  
			variantCard = variantCard .. '|-\n| Dim. Return %:\n| style=\"text-align: right; padding: 3px;\" | ' .. variant.repeatsDepreciation .. '\n'    
			end
		end
		
		-- check for industrial
		if variant.roomCategory == 'Industrial' then
			variantCard = variantCard .. '|- 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
	variantCard = variantCard .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
		
	variantCard = variantCard .. '|}'
	
	
	return variantCard
	
end
	
return p