Module:VariantDetails: Difference between revisions

From Eco - English Wiki
[unchecked revision][checked revision]
testing varient
 
No edit summary
 
(48 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
-- build a variant card
    local args = {}
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, ' ', '')
      
      
     for k, v in pairs( origArgs ) do
     -- string used to build the card
        v = mw.text.trim( tostring( v ) )
    local card = '<div class="col mb-4"><div class="card h-100" style="width: 300px; background: #d1ecf1; border: 5px solid #7BC2CE;">'
        if v ~= '' then
   
            args[k] = v
-- Name of card
        end
card = card .. '<div class="card-header" style="color: white; background-color: #1165AF; text-align: center; padding:.1rem;">' .. variantName .. '</div>'
    end
 
   
-- Variant: Icon Image
    return args
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
end


-- Build an Item wikibox
-- build all variant cards
function variantBox( args, itemData )
function p.main(frame) 
    -- check that all necessary arguments are passed correctly
local args = Utils.normaliseArgs(frame)
-- 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 item = args.name
-- name passed in will be the default recipe variant
local itemTable = itemData.items[item]
local defaultName = args.name
 
if itemTable == nil then
-- need both crafting recipes to find variants
return item .. ' could not be found in Module:ItemData.'
local recipeData = mw.loadData( "Module:CraftingRecipesData" )
end
 
-- get the tables from the modules
    local itemType = itemTable.type
local recipeList = recipeData.recipes
local itemEN = string.sub (itemType, 1, -5)
local itemimagename = string.gsub(itemEN, ' ', '')
   
    -- string used to build the wikibox
    local wikibox = '{| class=\"wikitable\"\n'
   
-- 'Name and Image' section
-- name of the item
wikibox = wikibox .. '|- style=\"color: white; background-color: #1165AF; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. item .. '</big>\'\'\'\n'
   
-- the item's type (ItemData - group)
wikibox = wikibox .. '|- style=\"text-align: center; color: white; background-color: '
if itemTable.group == 'Food' then
-- get the main recipe
wikibox = wikibox .. '#85D66B;\"\n| colspan=\"2\" | \'\'\'Food\'\'\'\n'
local defaultRecipe = recipeList[defaultName]
-- 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
    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'
elseif itemTable.group == 'Skill Books' then
wikibox = wikibox .. '#FFCF4D;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
-- 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'
elseif itemTable.group == 'Skill Scrolls' then
-- break if defaultName not found
wikibox = wikibox .. '#FFCF4D;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
if (defaultRecipe == nil) then
-- Items:Skill Scrolls Icon Image
return defaultName .. " could not be found in the recipe data"
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'
end -- if default is nil
else
-- get the variants for the recipe
wikibox = wikibox .. '#78B1FF;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
local variants = defaultRecipe.variants
-- Items: Other Icon Image
local numVariants = tonumber(defaultRecipe.numberOfVariants)
local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Icon.png|[[Category:Pages_with_missing_icon]]'
-- break if no variants. return blank to not break page flow.
if mw.title.makeTitle('File', itemimagename .. '_Icon.png').file.exists then
if (variants == nil or numVariants <= 1) then
image = itemimagename .. '_Icon.png'
return "No Variants to find"
elseif mw.title.makeTitle('File', itemimagename .. '_Icon.jpg').file.exists then
end -- if variants don't exist
image = itemimagename .. '_Icon.jpg'
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'
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
-- create variable to store returned text
local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Placed.png|[[Category:Pages_with_missing_placed]]'
local text = ""
if mw.title.makeTitle('File', itemimagename .. '_Placed.png').file.exists then
text = text .. '<div class="card-deck">'
image = itemimagename .. '_Placed.png'
text = text .. '<h2>' .. L.t('Variants') .. '</h2>\n'
elseif mw.title.makeTitle('File', itemimagename .. '_Placed.jpg').file.exists then
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"
image = itemimagename .. '_Placed.jpg'
text = text .. '<div class="row row-cols-1 row-cols-md-3" style="text-align:-webkit-center;">'
end
for k,v in pairs(variants) do
wikibox = wikibox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
--skip the default variant
 
if (k ~= defaultName) then
--Material Tier
-- build the text for each variant
if itemTable.materialTier ~= nil or itemTable.materialTier == 0 then
text = text .. buildVariant(k, v) .. ''
wikibox = wikibox .. '|-\n| Room Material:\n| style=\"text-align: right; padding: 3px;\" | Tier ' .. itemTable.materialTier .. '\n'
end -- if variant is not default
end
end -- for each variant
--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 .. ' \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
 
-- 'Housing' section (if there is a Room Category)
if itemTable.roomCategory ~= nil then 
-- Housing Header
wikibox = wikibox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Housing\'\'\'\n'
   
--roomCategory
wikibox = wikibox .. '|-\n| Room Category:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomCategory .. '\n'
 
if itemTable.roomCategory ~= 'Industrial' then
if itemTable.furnitureType ~= nil then
--furnitureType
wikibox = wikibox .. '|-\n| Furniture Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.furnitureType .. '\n'
           
--Value of the object
wikibox = wikibox .. '|-\n| Value:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.skillValue .. '\n'
           
--Dim. Return % of Object 
wikibox = wikibox .. '|-\n| Dim. Return %:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.repeatsDepreciation .. '\n'   
end
end
if itemTable.roomCategory == 'Industrial' then
wikibox = wikibox .. '|- style=\"background-color: red; text-align: center;\"\n| colspan=\"2\" | \'\'\'ALL ROOM VALUE LOST\'\'\'\n'
end
end
-- Object Placed Image
text = text ..'</div></div>'
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
wikibox = wikibox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n'
end
wikibox = wikibox .. '|}'
return text
return wikibox
end
end
-- Main entry point for the Module
function p.ItemMain()
    -- 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