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 = ' | local card = '{|class=\"card mb-3\" style=\"background: #d1ecf1; border: 5px solid #7BC2CE; width: fit-content;\"\n' | ||
-- Name of card | -- Name of card | ||
card = card .. ' | card = card .. '|- style=\"color: white; background-color: #1165AF; text-align: center;\"\n| colspan=\"2\" | \'\'\'<big>' .. variantName .. '</big>\'\'\'\n' | ||
-- Variant: Icon Image | -- Variant: Icon Image | ||
Line 32: | Line 61: | ||
-- create image cell | -- 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>' | card = card .. '|-\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 | |||
card = card .. '|- style=\"background-color: #4688C0; text-align: center;\"\n| colspan=\"2\" | \'\'\'Housing\'\'\'\n' | |||
--roomCategory | |||
card = card .. '|-\n| Room Category:\n| style=\"text-align: right; padding: 3px;\" | ' .. variant.roomCategory .. '\n' | |||
if variant.roomCategory ~= 'Industrial' then | |||
if variant.furnitureType ~= nil then | |||
--furnitureType | |||
card = card .. '|-\n| Furniture Type:\n| style=\"text-align: right; padding: 3px;\" | ' .. variant.furnitureType .. '\n' | |||
--Value of the object | |||
card = card .. '|-\n| Value:\n| style=\"text-align: right; padding: 3px;\" | ' .. variant.skillValue .. '\n' | |||
--Dim. Return % of Object | |||
card = card .. '|-\n| Dim. Return %:\n| style=\"text-align: right; padding: 3px;\" | ' .. variant.repeatsDepreciation .. '\n' | |||
end | |||
end | |||
-- check for industrial | |||
if variant.roomCategory == 'Industrial' then | |||
card = card .. '|- 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 41: | Line 97: | ||
image = itemimagename .. '_Placed.jpg' | image = itemimagename .. '_Placed.jpg' | ||
end | end | ||
card = card .. ' | card = card .. '|-\n| colspan=\"2\" style=\"padding: 10px;\" | [[File:' .. image .. '|center|border|240px]]\n' | ||
card = card .. '|}' | |||
return card | return card | ||
Line 47: | Line 105: | ||
-- 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 117: | ||
-- 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 74: | Line 132: | ||
-- get the variants for the recipe | -- get the variants for the recipe | ||
local variants = defaultRecipe.variants | local variants = defaultRecipe.variants | ||
-- break if no variants. return blank to not break page flow. | -- break if no variants. return blank to not break page flow. | ||
if (variants == nil or | if (variants == nil or #variants <= 1) then | ||
return "No Variants to find" | return "No Variants to find" | ||
end -- if variants don't exist | end -- if variants don't exist | ||
Line 82: | Line 140: | ||
-- create variable to store returned text | -- create variable to store returned text | ||
local text = "" | local text = "" | ||
for i=1, #variants do | |||
--skip the default variant | --skip the default variant | ||
if ( | if (variants[i] ~= defaultName) then | ||
-- build the text for each variant | -- build the text for each variant | ||
text = text .. buildVariant( | text = text .. buildVariant(variants[i]) .. " " | ||
end -- if variant is not default | end -- if variant is not default | ||
end -- for each variant | end -- for each variant | ||
return text | return text |