Editing Module:Infobox Item
Jump to navigation
Jump to search
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 save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 3: | Line 3: | ||
local data_module_names = { | local data_module_names = { | ||
item = 'Module:Items/data', | item = 'Module:Items/data', | ||
− | enchantment = 'Module:Enchantment | + | enchantment = 'Module:Enchantment/data' |
− | |||
} | } | ||
− | |||
local loaded_data_modules = {} | local loaded_data_modules = {} | ||
− | + | function p.loadData (data_type) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | function p.loadData(data_type) | ||
local module_name = data_module_names[data_type] | local module_name = data_module_names[data_type] | ||
if loaded_data_modules[module_name] == nil then | if loaded_data_modules[module_name] == nil then | ||
Line 64: | Line 16: | ||
end | end | ||
− | + | function p.findItem (name) | |
− | |||
− | |||
− | |||
− | |||
for key, item in pairs(p.loadData("item")) do | for key, item in pairs(p.loadData("item")) do | ||
− | if | + | if name == item['name'] then |
return item | return item | ||
end | end | ||
Line 77: | Line 25: | ||
end | end | ||
− | + | function p.getEnchantmentName (id) | |
− | return p.loadData(" | + | return p.loadData("enchantment")[tostring(id)]['name'] |
end | end | ||
− | + | function p.getItemName (id) | |
− | return p.loadData(" | + | return p.loadData("item")[tostring(id)]['name'] |
end | end | ||
− | + | function p.addSeparator(num) | |
− | return | + | return tostring(tonumber(num)):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse() |
end | end | ||
− | + | function p.fullUrl(url) | |
− | local newUrl = | + | local newUrl = "" |
− | if url:sub(1,5) | + | if url:sub(1,5) ~= "https" then |
− | return | + | return url |
end | end | ||
if url:sub(1,1) ~= "/" then | if url:sub(1,1) ~= "/" then | ||
− | newUrl = "/" .. | + | newUrl = "/" .. url |
end | end | ||
Line 103: | Line 51: | ||
end | end | ||
− | + | function p.item(frame) | |
− | local | + | local args = frame:getParent().args |
− | + | return p._item(args) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | + | function p._item(args) | |
− | + | local name = args[1] | |
− | local | + | local item = 0 |
− | + | local infobox = "" | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | local | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | local | ||
− | + | item = p.findItem (name) | |
− | + | infobox = p.createInfobox(item) | |
− | + | return infobox | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | return | ||
end | end | ||
− | + | function p.createInfobox(item) | |
− | local | + | local s = "{{Infobox Item\n" |
local url = "" | local url = "" | ||
− | + | s = s .. "|title=" .. item['name'] .. "\n" | |
− | |||
− | |||
− | |||
− | |||
if item['itemIcon'] then | if item['itemIcon'] then | ||
Line 256: | Line 76: | ||
url = item['itemImage'] | url = item['itemImage'] | ||
end | end | ||
− | + | s = s .. "|image=" .. p.fullUrl(url) .. "\n" | |
if item['value'] then | if item['value'] then | ||
− | + | s = s .. "|gold=" .. p.addSeparator(item['value']) .. "\n" | |
− | |||
end | end | ||
− | if item[' | + | if item['craftable'] then |
− | + | s = s .. "|source=[[Crafting]]\n" | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
if item['requiredLevel'] then | if item['requiredLevel'] then | ||
− | s = "" | + | s = s .. "|level-req =" |
for skill, level in pairs(item['requiredLevel']) do | for skill, level in pairs(item['requiredLevel']) do | ||
s = s .. level .. " " .. skill .. "<br>" | s = s .. level .. " " .. skill .. "<br>" | ||
end | end | ||
− | s = s:sub(1,s:len()-4) | + | s = s:sub(1,s:len()-4) .. "\n" |
− | |||
− | |||
end | end | ||
− | |||
− | |||
− | |||
if item['heat'] then | if item['heat'] then | ||
− | + | s = s .. "|heat=" .. p.addSeparator(item['heat']) .. "\n" | |
− | |||
end | end | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
if item['augmentationCost'] then | if item['augmentationCost'] then | ||
− | s = "" | + | s = s .. "|aug-bonus=" |
for key, bonus in pairs(item['equipmentStats']['augmentationBonus']) do | for key, bonus in pairs(item['equipmentStats']['augmentationBonus']) do | ||
s = s .. "+" .. bonus.value .. " " | s = s .. "+" .. bonus.value .. " " | ||
s = s .. bonus.stat:sub(bonus.stat:find('%.')+1,bonus.stat:len()) .. "<br>" | s = s .. bonus.stat:sub(bonus.stat:find('%.')+1,bonus.stat:len()) .. "<br>" | ||
end | end | ||
− | |||
− | |||
− | |||
− | s = "" | + | s = s .. "|aug-cost=" |
for key, cost in pairs(item['augmentationCost']) do | for key, cost in pairs(item['augmentationCost']) do | ||
s = s .. cost .. " " | s = s .. cost .. " " | ||
− | s = s .. | + | s = s .. "{{img|" .. p.getItemName(key) .."}}" .. "<br>" |
end | end | ||
− | s = s:sub(1,s:len()-4) | + | s = s:sub(1,s:len()-4) .. "\n" |
− | |||
− | |||
end | end | ||
− | |||
− | |||
if item['size'] then | if item['size'] then | ||
− | + | s = s .. "|food-size=" .. item['size'] .. "\n" | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
if item['ingredientTags'] then | if item['ingredientTags'] then | ||
− | s = "" | + | s = s .. "|food-cat=" |
for key, tag in pairs(item['ingredientTags']) do | for key, tag in pairs(item['ingredientTags']) do | ||
s = s .. tag .. "<br>" | s = s .. tag .. "<br>" | ||
end | end | ||
− | s = s:sub(1,s:len()-4) | + | s = s:sub(1,s:len()-4) .. "\n" |
− | |||
− | |||
end | end | ||
if item['cookingEnchantment'] then | if item['cookingEnchantment'] then | ||
− | + | s = s .. "|food-buff =" .. p.getEnchantmentName(item['cookingEnchantment']) .. "\n" | |
− | |||
end | end | ||
− | |||
− | |||
local farming = item['farmingStats'] | local farming = item['farmingStats'] | ||
if farming then | if farming then | ||
− | s = "" | + | s = s .. "|plot-size=" .. farming['height'] .. "x" .. farming['width'] .. "\n" |
+ | s = s .. "|seed-exp=" .. farming['experience'] .. "\n" | ||
+ | s = s .. "|harvest-time=" .. farming['time'] .. " minutes\n" | ||
+ | s = s .. "|yield=" | ||
for key, yield in pairs(farming['yield']) do | for key, yield in pairs(farming['yield']) do | ||
s = s .. yield['min'] .. "-" .. yield['max'] .. " " | s = s .. yield['min'] .. "-" .. yield['max'] .. " " | ||
− | s = s .. | + | s = s .. p.getItemName(yield['id']) |
if yield['chance'] ~= 1 then | if yield['chance'] ~= 1 then | ||
s = s .. " " .. tonumber(string.format('%.2f', yield['chance'] * 100)) .. "%" | s = s .. " " .. tonumber(string.format('%.2f', yield['chance'] * 100)) .. "%" | ||
Line 517: | Line 143: | ||
s = s .. "<br>" | s = s .. "<br>" | ||
end | end | ||
− | s = s:sub(1,s:len()-4) | + | s = s:sub(1,s:len()-4) .. "\n" |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | + | if item['extraTooltipInfo'] then | |
− | + | s = s .. "|tooltip=" .. item['extraTooltipInfo'] .. "\n" | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | + | s = s .. "}}" | |
− | + | return s | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | return | ||
end | end | ||
return p | return p |