Editing Module:VariantDetails

From Eco - English Wiki

Your changes will be displayed to readers once an authorized user accepts them. (help)

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
-- Credit:
-- Credit:  


local p = {}
local p = {}


local Utils = require('Module:Utils')
-- Grabs args from the parent frame
local L = require('Module:Localization')
-- Trims and parses the args into a table, then returns the table
 
function norm()
-- build a variant card
    local origArgs = mw.getCurrentFrame():getParent().args
function buildVariant(variantName, variant)
    local args = {}
-- variant does not exist as an item then just return
   
if variant == nil then
    for k, v in pairs( origArgs ) do
return "No variant here"
        v = mw.text.trim( tostring( v ) )
end
        if v ~= '' then
            args[k] = v
local itemimagename = string.gsub(variant.untranslated, ' ', '')
        end
    end
      
      
     -- string used to build the card
     return args
    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
end


-- build all variant cards
-- Build an Item varientBox
function p.main(frame) 
function variantBox( args, itemData )
local args = Utils.normaliseArgs(frame)
    -- check that all necessary arguments are passed correctly
-- 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
      
      
-- name passed in will be the default recipe variant
local item = args.name
local defaultName = 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: '
-- need both crafting recipes to find variants
if itemTable.group == 'Food' then
local recipeData = mw.loadData( "Module:CraftingRecipes" )
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'
-- get the tables from the modules
elseif itemTable.group == 'Skill Scrolls' then
local recipeList = recipeData.recipes
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'
-- get the main recipe
else
local defaultRecipe = recipeList[defaultName]
varientBox = varientBox .. '#78B1FF;\"\n| colspan=\"2\" | \'\'\'' .. itemTable.group .. '\'\'\'\n'
-- Items: Other Icon Image
-- break if defaultName not found
local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Icon.png|[[Category:Pages_with_missing_icon]]'
if (defaultRecipe == nil) then
if mw.title.makeTitle('File', itemimagename .. '_Icon.png').file.exists then
return defaultName .. " could not be found in the recipe data"
image = itemimagename .. '_Icon.png'
end -- if default is nil
elseif mw.title.makeTitle('File', itemimagename .. '_Icon.jpg').file.exists then
image = itemimagename .. '_Icon.jpg'
-- get the variants for the recipe
end
local variants = defaultRecipe.variants
    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'
local numVariants = tonumber(defaultRecipe.numberOfVariants)
end
-- break if no variants. return blank to not break page flow.
 
if (variants == nil or numVariants <= 1) then
-- Object Placed Image
return "No Variants to find"
local image = 'NoImage.png|link=https://wiki.play.eco/index.php?title=Special:Upload&wpDestFile=' .. itemimagename .. '_Placed.png|[[Category:Pages_with_missing_placed]]'
end -- if variants don't exist
if mw.title.makeTitle('File', itemimagename .. '_Placed.png').file.exists then
image = itemimagename .. '_Placed.png'
-- create variable to store returned text
elseif mw.title.makeTitle('File', itemimagename .. '_Placed.jpg').file.exists then
local text = ""
image = itemimagename .. '_Placed.jpg'
text = text .. '<div class="card-deck">'
end
text = text .. '<h2>' .. L.t('Variants') .. '</h2>\n'
varientBox = varientBox .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\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;">'
-- 'Housing' section (if there is a Room Category)
for k,v in pairs(variants) do
if itemTable.roomCategory ~= nil then 
--skip the default variant
-- Housing Header
if (k ~= defaultName) then
varientBox = varientBox .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Housing\'\'\'\n'
-- build the text for each variant
   
text = text .. buildVariant(k, v) .. ''
--roomCategory
end -- if variant is not default
varientBox = varientBox .. '|-\n| Room Category:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.roomCategory .. '\n'
end -- for each variant
 
if itemTable.roomCategory ~= 'Industrial' then
text = text ..'</div></div>'
if itemTable.furnitureType ~= nil then
--furnitureType
return text
varientBox = varientBox .. '|-\n| Furniture Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. itemTable.furnitureType .. '\n'
end
           
--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
return p
Please note that all contributions to Eco - English Wiki are considered to be released under the CC BY-NC-SA 4.0 (see Eco:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following hCaptcha:

Cancel Editing help (opens in new window)

Template used on this page: