Difference between revisions of "Module:Infobox Item"
Jump to navigation
Jump to search
m |
m |
||
| Line 6: | Line 6: | ||
local function h() | local function h() | ||
local s = "header" .. headerCount | local s = "header" .. headerCount | ||
| + | headerCount = headerCount + 1 | ||
| + | labelCount = headerCount | ||
| + | dataCount = headerCount | ||
| + | return s | ||
| + | end | ||
| + | |||
| + | local function sbreak() | ||
| + | local s = "sbreak" .. headerCount | ||
headerCount = headerCount + 1 | headerCount = headerCount + 1 | ||
labelCount = headerCount | labelCount = headerCount | ||
| Line 25: | Line 33: | ||
headerCount = dataCount | headerCount = dataCount | ||
labelCount = dataCount | labelCount = dataCount | ||
| + | return s | ||
| + | end | ||
| + | |||
| + | local function sl() | ||
| + | local s = "s" .. l{} | ||
| + | return s | ||
| + | end | ||
| + | |||
| + | local function sd() | ||
| + | local s = "s" .. d{} | ||
return s | return s | ||
end | end | ||
| Line 136: | Line 154: | ||
end | end | ||
| − | + | if item['tradeable'] then | |
| − | |||
args[l()] = icon('Market', "/images/ui/marketplace_icon.png") | args[l()] = icon('Market', "/images/ui/marketplace_icon.png") | ||
| − | args[d()] = addSeparator(market) | + | local market = require("Module:Market")["_price"]({item['name'], 1, 1}) |
| + | if market then | ||
| + | args[d()] = addSeparator(market) | ||
| + | else | ||
| + | args[d()] = "Yes" | ||
| + | end | ||
end | end | ||
| Line 156: | Line 178: | ||
args[d()] = "[[Crafting]]" | args[d()] = "[[Crafting]]" | ||
end | end | ||
| − | |||
if item['heat'] then | if item['heat'] then | ||
| Line 163: | Line 184: | ||
end | end | ||
| − | + | local stats = item['equipmentStats'] | |
| − | args[l()] = " | + | if stats then |
| − | args[d()] = | + | args[l()] = "Slot" |
| − | if | + | args[d()] = stats['slot'] |
| + | if stats['toolBoost'] then | ||
s = "" | s = "" | ||
| − | for key, stat in pairs( | + | for key, stat in pairs(stats['toolBoost']) do |
s = s .. stat.boost .. " " | s = s .. stat.boost .. " " | ||
s = s .. stat.skill .. "<br>" | s = s .. stat.skill .. "<br>" | ||
| Line 175: | Line 197: | ||
args[l()] = "Stats" | args[l()] = "Stats" | ||
args[d()] = s | args[d()] = s | ||
| + | end | ||
| + | |||
| + | if stats['oneHanded'] == false then | ||
| + | args[l()] = "Two-handed" | ||
| + | args[d()] = "Yes" | ||
| + | end | ||
| + | |||
| + | if stats['attackSpeed'] then | ||
| + | args[l()] = "Attack Speed" | ||
| + | args[d()] = stats['attackSpeed'] | ||
| + | end | ||
| + | |||
| + | args[h()] = "Offensive Stats" | ||
| + | |||
| + | local stat = stats['offensiveCritical'] | ||
| + | if stat then | ||
| + | args[l()] = "Crit Chance" | ||
| + | args[d()] = stat['chance'] | ||
| + | args[l()] = "Crit Multiplier" | ||
| + | args[d()] = stats['damageMultiplier'] | ||
| + | end | ||
| + | |||
| + | stat = stats['weaponBonus'] | ||
| + | if stat then | ||
| + | args[sl()] = "Str" | ||
| + | args[sd()] = stat['strength'] | ||
| + | args[sl()] = "Int" | ||
| + | args[sd()] = stat['intellect'] | ||
| + | args[sl()] = "Dex" | ||
| + | args[sd()] = stat['dexterity'] | ||
| + | end | ||
| + | |||
| + | args[h()] = "Offensive Affinity" | ||
| + | stat = stats['weaponBonus'] | ||
| + | if stat then | ||
| + | args[sl()] = "Melee" | ||
| + | args[sd()] = stat['Melee'] | ||
| + | args[sl()] = "Magic" | ||
| + | args[sd()] = stat['Magic'] | ||
| + | args[sl()] = "Range" | ||
| + | args[sd()] = stat['Range'] | ||
| + | args[sbreak()] = "yes" | ||
| + | |||
| + | args[sl()] = "Piercing" | ||
| + | args[sd()] = stat['Piercing'] | ||
| + | args[sl()] = "Blunt" | ||
| + | args[sd()] = stat['Blunt'] | ||
| + | args[sl()] = "Slashing" | ||
| + | args[sd()] = stat['Slashing'] | ||
| + | args[sbreak()] = "yes" | ||
| + | |||
| + | args[sl()] = "Fire" | ||
| + | args[sd()] = stat['Fire'] | ||
| + | args[sl()] = "Ice" | ||
| + | args[sd()] = stat['Ice'] | ||
| + | args[sl()] = "Nature" | ||
| + | args[sd()] = stat['Nature'] | ||
| + | args[sl()] = "Chaos" | ||
| + | args[sd()] = stat['Chaos'] | ||
| + | args[sbreak()] = "yes" | ||
end | end | ||
end | end | ||
| Line 202: | Line 284: | ||
if item['size'] then | if item['size'] then | ||
args[l()] = "Size" | args[l()] = "Size" | ||
| − | args[d()] = | + | args[d()] = item['size'] |
end | end | ||
if item['difficulty'] then | if item['difficulty'] then | ||
args[l()] = "Difficulty" | args[l()] = "Difficulty" | ||
| − | args[d()] = | + | args[d()] = item['difficulty'] |
end | end | ||
| Line 258: | Line 340: | ||
args[h()] = "Tooltip" | args[h()] = "Tooltip" | ||
args[d()] = require('Module:Infobox')['infobox'](args2) | args[d()] = require('Module:Infobox')['infobox'](args2) | ||
| + | |||
| + | for key, data in pairs(args) do | ||
| + | if string.find(key, "data") then | ||
| + | args[key] = tostring(data) | ||
| + | end | ||
| + | end | ||
return require('Module:Infobox')['infobox'](args) | return require('Module:Infobox')['infobox'](args) | ||
| Line 281: | Line 369: | ||
if item == 0 then | if item == 0 then | ||
| − | return "<div style=\"color:red\"> No item named '" .. name .. "'</div> | + | return "<div style=\"color:red\"> No item named '" .. name .. "'</div>. The Module:Items/data maybe outdated." |
end | end | ||
Revision as of 03:16, 12 September 2023
local p = {}
local headerCount = 1
local labelCount = 1
local dataCount = 1
local function h()
local s = "header" .. headerCount
headerCount = headerCount + 1
labelCount = headerCount
dataCount = headerCount
return s
end
local function sbreak()
local s = "sbreak" .. headerCount
headerCount = headerCount + 1
labelCount = headerCount
dataCount = headerCount
return s
end
local function l()
local s = "label" .. labelCount
dataCount = labelCount
labelCount = labelCount + 1
headerCount = labelCount
return s
end
local function d()
local s = "data" .. dataCount
dataCount = dataCount + 1
headerCount = dataCount
labelCount = dataCount
return s
end
local function sl()
local s = "s" .. l{}
return s
end
local function sd()
local s = "s" .. d{}
return s
end
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
local function findItem(name)
local lname = name:lower()
--Remove leading and trailing spaces.
lname = lname:gsub('^%s*(.-)%s*$', '%1')
for key, item in pairs(p.loadData("item")) do
if lname == item['name']:lower() then
return item
end
end
return 0
end
local function getEnchantmentName(id)
return p.loadData("enchantment")[tostring(id)]['name']
end
local function getItemName(id)
return p.loadData("item")[tostring(id)]['name']
end
local function fullUrl(url)
local newUrl = url
if url:sub(1,5) == "https" then
return newUrl
end
if url:sub(1,1) ~= "/" then
newUrl = "/" .. newUrl
end
newUrl = "https://www.play.idlescape.com" .. newUrl
return newUrl
end
local function icon(name, url, word)
local s = fullUrl(url)
s = "[[" .. name .. "|<img src=\"" .. s
s = s .. "\" alt=\"" .. name .. "\" width=\"20\">"
if word then
s = s .. name
end
s = s .. "]]"
return s
end
local function itemImage(id, word)
local item = p.loadData("item")[tostring(id)]
local url = ""
if item['itemIcon'] then
url = item['itemIcon']
else
url = item['itemImage']
end
return icon(item['name'], url, word)
end
local function img(id)
local url = ""
if item['itemIcon'] then
url = item['itemIcon']
else
url = item['itemImage']
end
return fullUrl(url)
end
local function addSeparator(num)
return tostring(tonumber(num)):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse()
end
local function createInfobox(item)
local args = {}
local url = ""
local s = ""
args['autoheaders'] = "y"
args['subbox'] = "no"
args['bodystyle'] = " "
args['title'] = item['name']
if item['itemIcon'] then
url = item['itemIcon']
else
url = item['itemImage']
end
args['image'] = "<img src=\"" .. fullUrl(url) .. "\" width=\"150\">"
if item['value'] then
args[l()] = icon('Gold', "/images/gold_coin.png")
args[d()] = addSeparator(item['value'])
end
if item['tradeable'] then
args[l()] = icon('Market', "/images/ui/marketplace_icon.png")
local market = require("Module:Market")["_price"]({item['name'], 1, 1})
if market then
args[d()] = addSeparator(market)
else
args[d()] = "Yes"
end
end
if item['requiredLevel'] then
s = ""
for skill, level in pairs(item['requiredLevel']) do
s = s .. level .. " " .. skill .. "<br>"
end
s = s:sub(1,s:len()-4)
args[l()] = "Level Required"
args[d()] = s
end
if item['craftable'] then
args[l()] = "Source"
args[d()] = "[[Crafting]]"
end
if item['heat'] then
args[l()] = itemImage(2)
args[d()] = addSeparator(item['heat'])
end
local stats = item['equipmentStats']
if stats then
args[l()] = "Slot"
args[d()] = stats['slot']
if stats['toolBoost'] then
s = ""
for key, stat in pairs(stats['toolBoost']) do
s = s .. stat.boost .. " "
s = s .. stat.skill .. "<br>"
end
s = s:sub(1,s:len()-4)
args[l()] = "Stats"
args[d()] = s
end
if stats['oneHanded'] == false then
args[l()] = "Two-handed"
args[d()] = "Yes"
end
if stats['attackSpeed'] then
args[l()] = "Attack Speed"
args[d()] = stats['attackSpeed']
end
args[h()] = "Offensive Stats"
local stat = stats['offensiveCritical']
if stat then
args[l()] = "Crit Chance"
args[d()] = stat['chance']
args[l()] = "Crit Multiplier"
args[d()] = stats['damageMultiplier']
end
stat = stats['weaponBonus']
if stat then
args[sl()] = "Str"
args[sd()] = stat['strength']
args[sl()] = "Int"
args[sd()] = stat['intellect']
args[sl()] = "Dex"
args[sd()] = stat['dexterity']
end
args[h()] = "Offensive Affinity"
stat = stats['weaponBonus']
if stat then
args[sl()] = "Melee"
args[sd()] = stat['Melee']
args[sl()] = "Magic"
args[sd()] = stat['Magic']
args[sl()] = "Range"
args[sd()] = stat['Range']
args[sbreak()] = "yes"
args[sl()] = "Piercing"
args[sd()] = stat['Piercing']
args[sl()] = "Blunt"
args[sd()] = stat['Blunt']
args[sl()] = "Slashing"
args[sd()] = stat['Slashing']
args[sbreak()] = "yes"
args[sl()] = "Fire"
args[sd()] = stat['Fire']
args[sl()] = "Ice"
args[sd()] = stat['Ice']
args[sl()] = "Nature"
args[sd()] = stat['Nature']
args[sl()] = "Chaos"
args[sd()] = stat['Chaos']
args[sbreak()] = "yes"
end
end
if item['augmentationCost'] then
s = ""
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:sub(1,s:len()-4)
args[l()] = "Aug Bonus"
args[d()] = s
s = ""
for key, cost in pairs(item['augmentationCost']) do
s = s .. cost .. " "
s = s .. itemImage(key, true) .. "<br>"
end
s = s:sub(1,s:len()-4)
args[l()] = "Aug Cost"
args[d()] = s
end
args[h()] = "Cooking"
if item['size'] then
args[l()] = "Size"
args[d()] = item['size']
end
if item['difficulty'] then
args[l()] = "Difficulty"
args[d()] = item['difficulty']
end
if item['ingredientTags'] then
s = ""
for key, tag in pairs(item['ingredientTags']) do
s = s .. tag .. "<br>"
end
s = s:sub(1,s:len()-4)
args[l()] = "Category"
args[d()] = s
end
if item['cookingEnchantment'] then
args[l()] = "Buff"
args[d()] = getEnchantmentName(item['cookingEnchantment'])
end
args[h()] = "Seeds"
local farming = item['farmingStats']
if farming then
s = ""
for key, yield in pairs(farming['yield']) do
s = s .. yield['min'] .. "-" .. yield['max'] .. " "
s = s .. 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)
args[l()] = "Level Required"
args[d()] = farming['requiredLevel']
args[l()] = "Experience"
args[d()] = farming['experience']
args[l()] = "Plot Size"
args[d()] = farming['height'] .. "x" .. farming['width']
args[l()] = "Harvest Time"
args[d()] = farming['time'] .. " minutes"
args[l()] = "Yield"
args[d()] = s
end
local args2 = {}
args2['subbox'] = "yes"
args2['bodystyle'] = "padding: 0.5em; margin:auto; font-style:italic; font-size:110%; text-align: center"
args2['data1'] = item['extraTooltipInfo']
args[h()] = "Tooltip"
args[d()] = require('Module:Infobox')['infobox'](args2)
for key, data in pairs(args) do
if string.find(key, "data") then
args[key] = tostring(data)
end
end
return require('Module:Infobox')['infobox'](args)
end
function p.item(frame)
local args = frame:getParent().args
return p._item(args)
end
function p._item(args)
local name = ""
local item = 0
local infobox = ""
if args[1] then
name = args[1]
else
name = mw.title.getCurrentTitle().text
end
item = findItem(name)
if item == 0 then
return "<div style=\"color:red\"> No item named '" .. name .. "'</div>. The Module:Items/data maybe outdated."
end
infobox = createInfobox(item)
return infobox
end
return p