Difference between revisions of "Module:Infobox Item"
Jump to navigation
Jump to search
m |
m |
||
Line 2: | Line 2: | ||
local data_module_names = { | local data_module_names = { | ||
− | + | item = 'Module:Items/data', | |
+ | enchantment = 'Module:Enchantment/data' | ||
} | } | ||
local loaded_data_modules = {} | local loaded_data_modules = {} | ||
− | function p. | + | 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 | ||
loaded_data_modules[module_name] = mw.loadData(module_name) | loaded_data_modules[module_name] = mw.loadData(module_name) | ||
end | end | ||
− | + | ||
− | for key, item in pairs( | + | return loaded_data_modules[module_name] |
− | if name == item[ | + | end |
+ | |||
+ | function p.findItem (name) | ||
+ | for key, item in pairs(p.loadData("item")) do | ||
+ | if name == item['name'] then | ||
return item | return item | ||
end | end | ||
end | end | ||
− | |||
return 0 | return 0 | ||
+ | end | ||
+ | |||
+ | function p.getEnchantmentName (id) | ||
+ | return p.loadData("enchantment")[tostring(id)]['name'] | ||
+ | end | ||
+ | |||
+ | function p.getItemName (id) | ||
+ | return p.loadData("item")[tostring(id)]['name'] | ||
end | end | ||
function p.addSeparator(num) | function p.addSeparator(num) | ||
− | return tostring(num):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse() | + | return tostring(tonumber(num)):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse() |
end | end | ||
Line 49: | Line 61: | ||
local infobox = "" | local infobox = "" | ||
− | item = p. | + | item = p.findItem (name) |
infobox = p.createInfobox(item) | infobox = p.createInfobox(item) | ||
return infobox | return infobox | ||
Line 57: | Line 69: | ||
local s = "{{Infobox Item\n" | local s = "{{Infobox Item\n" | ||
local url = "" | local url = "" | ||
− | s = s .. "|title = | + | s = s .. "|title=" .. item['name'] .. "\n" |
− | if item[ | + | if item['itemIcon'] then |
− | url = item[ | + | url = item['itemIcon'] |
else | else | ||
− | url = item[ | + | url = item['itemImage'] |
end | end | ||
− | s = s .. "|image =" .. p.fullUrl(url) .. "\n" | + | s = s .. "|image=" .. p.fullUrl(url) .. "\n" |
− | if item[ | + | if item['value'] then |
− | s = s .. "|gold =" .. p.addSeparator | + | s = s .. "|gold=" .. p.addSeparator(item['value']) .. "\n" |
end | end | ||
− | if item[ | + | if item['craftable'] then |
− | s = s .. "|source = [[Crafting]]\n" | + | s = s .. "|source=[[Crafting]]\n" |
end | end | ||
− | if item[ | + | if item['requiredLevel'] then |
s = s .. "|level-req =" | s = s .. "|level-req =" | ||
− | for skill, level in pairs(item[ | + | for skill, level in pairs(item['requiredLevel']) do |
− | s = s .. level .. " " .. skill .. " | + | s = s .. level .. " " .. skill .. "<br>" |
end | end | ||
+ | s = s:sub(1,s:len()-4) .. "\n" | ||
end | end | ||
− | if item[ | + | if item['heat'] then |
− | s = s .. "|heat =" .. p.addSeparator | + | s = s .. "|heat=" .. p.addSeparator(item['heat']) .. "\n" |
end | end | ||
− | if item[ | + | if item['augmentationCost'] then |
− | s = s .. "| | + | s = s .. "|aug-bonus=" |
+ | for key, bonus in pairs(item['equipmentStats']['augmentationBonus']) do | ||
+ | s = s .. "+" .. bonus.value .. " " | ||
+ | s = s .. bonus.stat:sub(bonus.stat:find('%.')+1,bonus.stat:len()) .. "<br>" | ||
+ | end | ||
+ | |||
+ | s = s .. "|aug-cost=" | ||
+ | for key, cost in pairs(item['augmentationCost']) do | ||
+ | s = s .. cost .. " " | ||
+ | s = s .. "{{img|" .. p.getItemName(key) .."}}" .. "<br>" | ||
+ | end | ||
+ | s = s:sub(1,s:len()-4) .. "\n" | ||
end | end | ||
− | if item["ingredientTags | + | if item['size'] then |
− | s = s .. "|food-cat =" | + | s = s .. "|food-size=" .. item['size'] .. "\n" |
− | for key, tag in pairs(item[ | + | end |
− | s = s .. tag .. " | + | |
+ | if item['ingredientTags'] then | ||
+ | s = s .. "|food-cat=" | ||
+ | for key, tag in pairs(item['ingredientTags']) do | ||
+ | s = s .. tag .. "<br>" | ||
end | end | ||
+ | s = s:sub(1,s:len()-4) .. "\n" | ||
end | end | ||
+ | if item['cookingEnchantment'] then | ||
+ | s = s .. "|food-buff =" .. p.getEnchantmentName(item['cookingEnchantment']) .. "\n" | ||
+ | end | ||
+ | |||
+ | local farming = item['farmingStats'] | ||
+ | if farming then | ||
+ | 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 | ||
+ | s = s .. yield['min'] .. "-" .. yield['max'] .. " " | ||
+ | s = s .. p.getItemName(yield['id']) | ||
+ | if yield['chance'] ~= 1 then | ||
+ | s = s .. " " .. tonumber(string.format('%.2f', yield['chance'] * 100)) .. "%" | ||
+ | end | ||
+ | s = s .. "<br>" | ||
+ | end | ||
+ | s = s:sub(1,s:len()-4) .. "\n" | ||
+ | end | ||
+ | |||
+ | if item['extraTooltipInfo'] then | ||
+ | s = s .. "|tooltip=" .. item['extraTooltipInfo'] .. "\n" | ||
+ | end | ||
+ | |||
+ | s = s .. "}}" | ||
return s | return s | ||
end | end | ||
return p | return p |
Revision as of 12:49, 11 September 2023
local p = {} local data_module_names = { item = 'Module:Items/data', enchantment = 'Module:Enchantment/data' } local loaded_data_modules = {} function p.loadData (data_type) local module_name = data_module_names[data_type] if loaded_data_modules[module_name] == nil then loaded_data_modules[module_name] = mw.loadData(module_name) end return loaded_data_modules[module_name] end function p.findItem (name) for key, item in pairs(p.loadData("item")) do if name == item['name'] then return item end end return 0 end function p.getEnchantmentName (id) return p.loadData("enchantment")[tostring(id)]['name'] end function p.getItemName (id) return p.loadData("item")[tostring(id)]['name'] end function p.addSeparator(num) return tostring(tonumber(num)):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse() end function p.fullUrl(url) local newUrl = "" if url:sub(1,5) ~= "https" then return url end if url:sub(1,1) ~= "/" then newUrl = "/" .. url end newUrl = "https://www.play.idlescape.com" .. newUrl return newUrl end function p.item(frame) local args = frame:getParent().args return p._item(args) end function p._item(args) local name = args[1] local item = 0 local infobox = "" item = p.findItem (name) infobox = p.createInfobox(item) return infobox end function p.createInfobox(item) local s = "{{Infobox Item\n" local url = "" s = s .. "|title=" .. item['name'] .. "\n" if item['itemIcon'] then url = item['itemIcon'] else url = item['itemImage'] end s = s .. "|image=" .. p.fullUrl(url) .. "\n" if item['value'] then s = s .. "|gold=" .. p.addSeparator(item['value']) .. "\n" end if item['craftable'] then s = s .. "|source=[[Crafting]]\n" end if item['requiredLevel'] then s = s .. "|level-req =" for skill, level in pairs(item['requiredLevel']) do s = s .. level .. " " .. skill .. "<br>" end s = s:sub(1,s:len()-4) .. "\n" end if item['heat'] then s = s .. "|heat=" .. p.addSeparator(item['heat']) .. "\n" end if item['augmentationCost'] then s = s .. "|aug-bonus=" for key, bonus in pairs(item['equipmentStats']['augmentationBonus']) do s = s .. "+" .. bonus.value .. " " s = s .. bonus.stat:sub(bonus.stat:find('%.')+1,bonus.stat:len()) .. "<br>" end s = s .. "|aug-cost=" for key, cost in pairs(item['augmentationCost']) do s = s .. cost .. " " s = s .. "{{img|" .. p.getItemName(key) .."}}" .. "<br>" end s = s:sub(1,s:len()-4) .. "\n" end if item['size'] then s = s .. "|food-size=" .. item['size'] .. "\n" end if item['ingredientTags'] then s = s .. "|food-cat=" for key, tag in pairs(item['ingredientTags']) do s = s .. tag .. "<br>" end s = s:sub(1,s:len()-4) .. "\n" end if item['cookingEnchantment'] then s = s .. "|food-buff =" .. p.getEnchantmentName(item['cookingEnchantment']) .. "\n" end local farming = item['farmingStats'] if farming then 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 s = s .. yield['min'] .. "-" .. yield['max'] .. " " s = s .. p.getItemName(yield['id']) if yield['chance'] ~= 1 then s = s .. " " .. tonumber(string.format('%.2f', yield['chance'] * 100)) .. "%" end s = s .. "<br>" end s = s:sub(1,s:len()-4) .. "\n" end if item['extraTooltipInfo'] then s = s .. "|tooltip=" .. item['extraTooltipInfo'] .. "\n" end s = s .. "}}" return s end return p