Module:VariantDetails: Difference between revisions

From Eco - English Wiki
[unchecked revision][checked revision]
No edit summary
No edit summary
 
(44 intermediate revisions by 2 users not shown)
Line 1: Line 1:
-- Credit:  
-- Credit:


local p = {}
local p = {}


-- Grabs args from the parent frame
local Utils = require('Module:Utils')
-- Trims and parses the args into a table, then returns the table
local L = require('Module:Localization')
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 varientName = args.name
local itemTable = itemData.items[varientName]


if itemTable == nil then
-- build a variant card
return varientName .. ' could not be found in Module:ItemData.'
function buildVariant(variantName, variant)
-- variant does not exist as an item then just return
if variant == nil then
return "No variant here"
end
end
 
    local itemType = itemTable.type
local itemimagename = string.gsub(variant.untranslated, ' ', '')
local itemEN = string.sub (itemType, 1, -5)
local itemimagename = string.gsub(itemEN, ' ', '')
   
    -- string used to build the varientBox
    local varientBox = '{| class=\"card-deck\"\n'
      
      
    -- string used to build the card
    local card = '<div class="col mb-4"><div class="card h-100" style="width: 300px; background: #d1ecf1; border: 5px solid #7BC2CE;">'
   
-- Name of card
card = card .. '<div class="card-header" style="color: white; background-color: #1165AF; text-align: center; padding:.1rem;">' .. variantName .. '</div>'


-- Name of Varient
-- Variant: Icon Image
varientBox = varientBox .. '|- 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
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'
-- create image cell
card = card .. '<div class="iconContainer"><div class="iconStack">[[File:' .. image .. '|frameless|class=iconBlue]]</div><div class=iconBorder style=\"position:absolute;\"></div></div>'
-- '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
-- 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 88: Line 41:
image = itemimagename .. '_Placed.jpg'
image = itemimagename .. '_Placed.jpg'
end
end
varientBox = varientBox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
card = card .. ' <p class="card-img-bottom" style="text-align-last: center;"[[File:' .. image .. '|250px]] </p> </div></div>'
varientBox = varientBox .. '|}'
return card
return varientBox
end
 
-- build all variant cards
function p.main(frame) 
local args = Utils.normaliseArgs(frame)
-- 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
end
-- need both crafting recipes to find variants
local recipeData =  mw.loadData( "Module:CraftingRecipesData" )
-- 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
local numVariants = tonumber(defaultRecipe.numberOfVariants)
-- break if no variants. return blank to not break page flow.
if (variants == nil or numVariants <= 1) then
return "No Variants to find"
end -- if variants don't exist
-- create variable to store returned text
local text = ""
text = text .. '<div class="card-deck">'
text = text .. '<h2>' .. L.t('Variants') .. '</h2>\n'
text = text .. "'''" .. L.t('Note') .. ":'''''" .. L.t("The Infobox displays information for all Variants as they have the same stats. World Object item variants are crafted using different recipe materials which usually means the items come in a variety of different colours depending on the material used.") .. "''\n"
text = text .. '<div class="row row-cols-1 row-cols-md-3" style="text-align:-webkit-center;">'
for k,v in pairs(variants) do
--skip the default variant
if (k ~= defaultName) then
-- build the text for each variant
text = text .. buildVariant(k, v) .. ''
end -- if variant is not default
end -- for each variant
text = text ..'</div></div>'
return text
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

Latest revision as of 15:00, 18 June 2024

Documentation[edit source]

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 = {}

local Utils = require('Module:Utils')
local L = require('Module:Localization')

-- build a variant card
function buildVariant(variantName, variant)
	-- variant does not exist as an item then just return
	if variant == nil then
		return "No variant here"
	end
	
	local itemimagename = string.gsub(variant.untranslated, ' ', '')
    
    -- string used to build the card
    local card = '<div class="col mb-4"><div class="card h-100" style="width: 300px; background: #d1ecf1; border: 5px solid #7BC2CE;">'
	    
	-- Name of card
	card = card .. '<div class="card-header" style="color: white; background-color: #1165AF; text-align: center; padding:.1rem;">' .. variantName .. '</div>'

	-- 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	
	card = card .. '<div class="iconContainer"><div class="iconStack">[[File:' .. image .. '|frameless|class=iconBlue]]</div><div class=iconBorder style=\"position:absolute;\"></div></div>'

	-- 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
	card = card .. ' <p class="card-img-bottom" style="text-align-last: center;">  [[File:' .. image .. '|250px]] </p> </div></div>'
		
	return card	
end

-- build all variant cards
function p.main(frame)  
	local args = Utils.normaliseArgs(frame)
	
	-- 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 =  mw.loadData( "Module:CraftingRecipesData" )
	
	-- 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
	local numVariants = tonumber(defaultRecipe.numberOfVariants)
	-- break if no variants. return blank to not break page flow.
	if (variants == nil or numVariants <= 1) then
		return "No Variants to find"
	end -- if variants don't exist
	
	-- create variable to store returned text
	local text = ""
	text = text .. '<div class="card-deck">'
	text = text .. '<h2>' .. L.t('Variants') .. '</h2>\n'
	text = text .. "'''" .. L.t('Note') .. ":'''''" .. L.t("The Infobox displays information for all Variants as they have the same stats. World Object item variants are crafted using different recipe materials which usually means the items come in a variety of different colours depending on the material used.") .. "''\n"
	text = text .. '<div class="row row-cols-1 row-cols-md-3" style="text-align:-webkit-center;">'
	for k,v in pairs(variants) do		
		--skip the default variant
		if (k ~= defaultName) then
			-- build the text for each variant
			text = text .. buildVariant(k, v) .. ''
		end -- if variant is not default
	end -- for each variant
	
	text = text ..'</div></div>'
	
	return text
end	
	
return p