Editing Module:VariantDetails
From Eco - English Wiki
Your changes will be displayed to readers once an authorized user accepts them. (help)
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 3: | Line 3: | ||
local p = {} | local p = {} | ||
local | -- Grabs args from the parent frame | ||
local | -- 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 a variant card | -- build a variant card | ||
function buildVariant(variantName | function buildVariant( variantName ) | ||
-- variant cards require itemData | |||
local itemData = require( "Module:ItemData" ) | |||
-- check to see if module loaded | |||
if (itemData == nil) then | |||
return "Item Data not loaded" | |||
end -- if itemData does not exist | |||
-- 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 | -- variant does not exist as an item then just return | ||
if variant == nil then | if variant == nil then | ||
Line 13: | Line 40: | ||
end | end | ||
local itemimagename = string.gsub( | local itemType = variant.type | ||
local itemEN = string.sub (itemType, 1, -5) | |||
local itemimagename = string.gsub(itemEN, ' ', '') | |||
-- string used to build the card | -- string used to build the card | ||
local card = '<div class="col mb-4"><div class="card h-100" style=" | local card = '<div class="col mb-4"><div class="card h-100" style="background: #d1ecf1; border: 5px solid #7BC2CE;">' | ||
-- Name of card | -- Name of card | ||
Line 41: | Line 70: | ||
image = itemimagename .. '_Placed.jpg' | image = itemimagename .. '_Placed.jpg' | ||
end | end | ||
card = card .. ' <p class="card-img-bottom" style="text-align-last: center;"> [[File:' .. image .. '| | card = card .. ' <p class="card-img-bottom" style="text-align-last: center;"> [[File:' .. image .. '|100px]] </p> </div></div>' | ||
return card | return card | ||
Line 47: | Line 76: | ||
-- build all variant cards | -- build all variant cards | ||
function p.main( | function p.main( args ) | ||
local args = | local args = norm() | ||
-- check that all necessary arguments are passed correctly | -- check that all necessary arguments are passed correctly | ||
Line 59: | Line 88: | ||
-- need both crafting recipes to find variants | -- need both crafting recipes to find variants | ||
local recipeData = | local recipeData = require( "Module:CraftingRecipes" ) | ||
-- get the tables from the modules | -- get the tables from the modules | ||
Line 83: | Line 112: | ||
local text = "" | local text = "" | ||
text = text .. '<div class="card-deck">' | text = text .. '<div class="card-deck">' | ||
text = text .. '<h2> | text = text .. '<h2>Variants</h2>\n' | ||
text = text .. | text = text .. '\'\'\'Note:\'\'\'\'\'The Infobox displays information for all Variants as they have the same stats. World Object Items 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 | text = text .. '<div class="row row-cols-1 row-cols-md-3">' | ||
for k,v in pairs(variants) do | for k,v in pairs(variants) do | ||
--skip the default variant | --skip the default variant | ||
if (k ~= defaultName) then | if (k ~= defaultName) then | ||
-- build the text for each variant | -- build the text for each variant | ||
text = text .. buildVariant(k | text = text .. buildVariant(k) .. '' | ||
end -- if variant is not default | end -- if variant is not default | ||
end -- for each variant | end -- for each variant |