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/data',
+
enchantment = 'Module:Enchantment/data'
location = 'Module:Location/data'
 
 
}
 
}
  
 
local loaded_data_modules = {}
 
local loaded_data_modules = {}
 
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
 
  
 
function p.loadData(data_type)  
 
function p.loadData(data_type)  
Line 65: Line 18:
  
 
local function findItem(name)
 
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
 
for key, item in pairs(p.loadData("item")) do
if lname == item['name']:lower() then
+
if name == item['name'] then
 
return item
 
return item
 
end
 
end
 
end
 
end
 
return 0
 
return 0
end
 
 
local function getItem(id)
 
return p.loadData("item")[tostring(id)]
 
 
end
 
end
  
Line 105: Line 50:
 
local function icon(name, url, word)
 
local function icon(name, url, word)
 
local s = fullUrl(url)
 
local s = fullUrl(url)
s = "[[" .. name .. "|<img src=\"" .. s
+
s = "<a href=/p/\"" .. name .. "\" title=\"" .. name .. "\"><img src=\"" .. s
 
s = s .. "\" alt=\""  .. name .. "\" width=\"20\">"
 
s = s .. "\" alt=\""  .. name .. "\" width=\"20\">"
 
if word then
 
if word then
 
s = s .. name
 
s = s .. name
 
end
 
end
s = s .. "]]"
+
s = s .. "</a>"
 
return s
 
return s
 
end
 
end
  
local function itemImage(id, word)
+
local function itemImage(id)
 
local item = p.loadData("item")[tostring(id)]
 
local item = p.loadData("item")[tostring(id)]
 
local url = ""
 
local url = ""
Line 122: Line 67:
 
url = item['itemImage']
 
url = item['itemImage']
 
end
 
end
return icon(item['name'], url, word)
+
return icon(item['name'], url)
 
end
 
end
  
local function locationImage(id, word)
+
local function link(name)
local loc = p.loadData("location")[tostring(id)]
+
local s = ""
local url = ""
+
s = "<a href=/p/\"" .. name .. "\" title=\"" .. name .. "\">" .. name .. "</a>"
if loc['locationImage'] then
+
return s
url = loc['locationImage']
 
else
 
return "[[" .. loc['name'] .. "]]"
 
end
 
return icon(loc['name'], url, word)
 
 
end
 
end
  
Line 148: Line 88:
 
local function addSeparator(num)
 
local function addSeparator(num)
 
return tostring(tonumber(num)):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse()
 
return tostring(tonumber(num)):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse()
end
 
 
local function gatheringSource(id)
 
local s = ""
 
for key, loc in pairs(p.loadData('location')) do
 
if loc['loot'] then
 
for key2, loot in pairs(loc['loot']) do
 
if id == loot['id'] then
 
s = s .. locationImage(loc['locID'], true)
 
s = s .. "<br>"
 
end
 
end
 
end
 
end
 
return s
 
end
 
 
local function farmingSource(id)
 
local s = ""
 
 
for key, item in pairs(p.loadData('item')) do
 
if item['farmingStats'] then
 
for key2, yield in pairs(item['farmingStats']['yield']) do
 
if id == yield['id'] then
 
s = s .. itemImage(item['id'], true)
 
s = s .. "<br>"
 
end
 
end
 
end
 
end
 
return s
 
end
 
 
local function smithingSource(id)
 
local s = ""
 
local item = getItem(id)
 
if item['skill'] == "smithing" and item['name'] ~= 'Ichor' then
 
s = '[[Smithing]]<br>'
 
end
 
return s
 
end
 
 
local function cookingSource(id)
 
local s = ""
 
local item = getItem(id)
 
if (item['class'] == "cooking-ingredient" and not item['ingredientTags']) or item['class'] == 'cookedFish' or item['name']=='Ashes' then
 
s = '[[Cooking]]<br>'
 
end
 
return s
 
end
 
 
local function runecraftingSource(id)
 
local s = ""
 
local item = getItem(id)
 
if item['class'] == "cloth" or (item['class'] == 'rune' and item['requiredResources']) then
 
s = '[[Runecrafting]]<br>'
 
end
 
return s
 
end
 
 
local function scrollcraftingSource(id)
 
local s = ""
 
local item = getItem(id)
 
if item['class'] == "enchanted-scroll" and item['level'] < 100 then
 
s = '[[Scrollcrafting]]<br>'
 
end
 
return s
 
end
 
 
 
local function craftingSource(id)
 
local s = ""
 
local item = getItem(id)
 
if item['craftable'] then
 
s = '[[Crafting]]<br>'
 
end
 
return s
 
end
 
 
local function findSource(id)
 
local s = ""
 
s = s .. gatheringSource(id)
 
s = s .. farmingSource(id)
 
s = s .. scrollcraftingSource(id)
 
s = s .. runecraftingSource(id)
 
s = s .. smithingSource(id)
 
s = s .. craftingSource(id)
 
s = s .. cookingSource(id)
 
if s:len() > 4 then
 
s = s:sub(1,s:len()-4)
 
end
 
return s
 
 
end
 
end
  
Line 247: Line 95:
 
local s = ""
 
local s = ""
 
args['autoheaders'] = "y"
 
args['autoheaders'] = "y"
args['subbox'] = "no"
 
args['bodystyle'] = " "
 
 
args['title'] = item['name']
 
args['title'] = item['name']
 
 
Line 256: Line 102:
 
url = item['itemImage']
 
url = item['itemImage']
 
end
 
end
args['image'] = "<img src=\"" .. fullUrl(url) .. "\" width=\"150\">"
+
args['image'] = fullUrl(url)
 
 
 
if item['value'] then
 
if item['value'] then
args[l()] = icon('Gold', "/images/gold_coin.png")
+
args['label1'] = itemImage(1)
args[d()] = addSeparator(item['value'])
+
args['data1'] = addSeparator(item['value'])
 
end
 
end
 
 
if item['tradeable'] then
+
local market = require("Module:Market")["_price"]({item['name'], 1, 1})
args[l()] = icon('Market', "/images/ui/marketplace_icon.png")
+
if market then
local market = require("Module:Market")["_price"]({item['name'], 1, 1})
+
args['label2'] = icon('Market', "/images/ui/marketplace_icon.png")
if market then
+
args['data2'] = addSeparator(item['value'])
args[d()] = addSeparator(market)
 
else
 
args[d()] = "Yes"
 
end
 
 
end
 
end
 
 
Line 279: Line 121:
 
end
 
end
 
s = s:sub(1,s:len()-4)
 
s = s:sub(1,s:len()-4)
args[l()] = "Level Required"
+
args['label3'] = "Level Required"
args[d()] = s
+
args['data3'] = s
 +
end
 +
 +
if item['craftable'] then
 +
args['label4'] = Source
 +
args['data4'] = link("Crafting")
 
end
 
end
 
 
args[l()] = "Source"
 
args[d()] = findSource(item['id'])
 
 
 
 
if item['heat'] then
 
if item['heat'] then
args[l()] = itemImage(2)
+
args['label5'] = itemImage(2)
args[d()] = addSeparator(item['heat'])
+
args['data5'] = addSeparator(item['heat'])
 
end
 
end
 
 
local stats = item['equipmentStats']
 
if stats then
 
args[l()] = "Slot"
 
args[d()] = stats['slot']
 
 
if item['enchantmentTier'] then
 
args[l()] = "Enchantment Slots"
 
args[d()] = item['enchantmentTier']
 
end
 
 
if item['forcedEnchant'] then
 
args[l()] = "Enchantments"
 
args[d()] = "[[" .. getEnchantmentName(item['forcedEnchant']) .. "]]"
 
end
 
 
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()] = stat['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['offensiveDamageAffinity']
 
if stat then
 
args[sl()] = "Melee"
 
args[sd()] = stat['Melee'] and stat['Melee'] * 100 .. "%"
 
args[sl()] = "Magic"
 
args[sd()] = stat['Magic'] and stat['Magic'] * 100 .. "%"
 
args[sl()] = "Range"
 
args[sd()] = stat['Range'] and stat['Range'] * 100 .. "%"
 
args[sbreak()] = "yes"
 
 
args[sl()] = "Piercing"
 
args[sd()] = stat['Piercing'] and stat['Piercing'] * 100 .. "%"
 
args[sl()] = "Blunt"
 
args[sd()] = stat['Blunt'] and stat['Blunt'] * 100 .. "%"
 
args[sl()] = "Slashing"
 
args[sd()] = stat['Slashing'] and stat['Slashing'] * 100 .. "%"
 
args[sl()] = "Fire"
 
args[sd()] = stat['Fire'] and stat['Fire'] * 100 .. "%"
 
args[sl()] = "Ice"
 
args[sd()] = stat['Ice'] and stat['Ice'] * 100 .. "%"
 
args[sl()] = "Nature"
 
args[sd()] = stat['Nature'] and stat['Nature'] * 100 .. "%"
 
args[sl()] = "Chaos"
 
args[sd()] = stat['Chaos'] and stat['Chaos'] * 100 .. "%"
 
args[sbreak()] = "yes"
 
end
 
 
args[h()] = "Accuracy"
 
stat = stats['offensiveAccuracyAffinityRating']
 
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[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
 
 
args[h()] = "Defensive Stats"
 
 
local stat = stats['defensiveCritical']
 
if stat then
 
args[l()] = "Crit Avoidance"
 
args[d()] = stat['chance']
 
args[l()] = "Crit Reduction"
 
args[d()] = stat['damageMultiplier']
 
end
 
 
stat = stats['armorBonus']
 
if stat then
 
args[sl()] = "Protection"
 
args[sd()] = stat['protection']
 
args[sl()] = "Resistance"
 
args[sd()] = stat['resistance']
 
args[sl()] = "Agility"
 
args[sd()] = stat['agility']
 
args[sl()] = "Stamina"
 
args[sd()] = stat['stamina']
 
end
 
 
args[h()] = "Defensive Affinity"
 
stat = stats['defensiveDamageAffinity']
 
if stat then
 
args[sl()] = "Melee"
 
args[sd()] = stat['Melee'] and stat['Melee'] * 100 .. "%"
 
args[sl()] = "Magic"
 
args[sd()] = stat['Magic'] and stat['Magic'] * 100 .. "%"
 
args[sl()] = "Range"
 
args[sd()] = stat['Range'] and stat['Range'] * 100 .. "%"
 
args[sbreak()] = "yes"
 
 
args[sl()] = "Piercing"
 
args[sd()] = stat['Piercing'] and stat['Piercing'] * 100 .. "%"
 
args[sl()] = "Blunt"
 
args[sd()] = stat['Blunt'] and stat['Blunt'] * 100 .. "%"
 
args[sl()] = "Slashing"
 
args[sd()] = stat['Slashing'] and stat['Slashing'] * 100 .. "%"
 
args[sl()] = "Fire"
 
args[sd()] = stat['Fire'] and stat['Fire'] * 100 .. "%"
 
args[sl()] = "Ice"
 
args[sd()] = stat['Ice'] and stat['Ice'] * 100 .. "%"
 
args[sl()] = "Nature"
 
args[sd()] = stat['Nature'] and stat['Nature'] * 100 .. "%"
 
args[sl()] = "Chaos"
 
args[sd()] = stat['Chaos'] and stat['Chaos'] * 100 .. "%"
 
args[sbreak()] = "yes"
 
end
 
end
 
 
args[h()] = "Augment"
 
 
 
if item['augmentationCost'] then
 
if item['augmentationCost'] then
 
s = ""
 
s = ""
Line 464: Line 143:
 
end
 
end
 
s = s:sub(1,s:len()-4)
 
s = s:sub(1,s:len()-4)
args[sl()] = "Aug Bonus"
+
args['label7'] = "Aug Bonus"
args[sd()] = s
+
args['data7'] = s
 
 
 
s = ""
 
s = ""
 
for key, cost in pairs(item['augmentationCost']) do
 
for key, cost in pairs(item['augmentationCost']) do
 
s = s .. cost .. " "
 
s = s .. cost .. " "
s = s .. itemImage(key, true) .. "<br>"
+
s = s .. "{{img|" .. getItemName(key) .."|word=1}}" .. "<br>"
 
end
 
end
 
s = s:sub(1,s:len()-4)
 
s = s:sub(1,s:len()-4)
args[sl()] = "Aug Cost"
+
args['label9'] = "Aug Cost"
args[sd()] = s
+
args['data9'] = s
 
end
 
end
 
 
args[h()] = "Cooking"
+
args['header20'] = "Cooking"
 
 
 
if item['size'] then
 
if item['size'] then
args[l()] = "Size"
+
args['label21'] = "Size"
args[d()] = item['size']
+
args['data21'] = item['size']
 
end
 
end
 
 
 
if item['difficulty'] then
 
if item['difficulty'] then
args[l()] = "Difficulty"
+
args['label22'] = "Difficulty"
args[d()] = item['difficulty']
+
args['data22'] = item['difficulty']
 
end
 
end
 
 
Line 495: Line 174:
 
end
 
end
 
s = s:sub(1,s:len()-4)
 
s = s:sub(1,s:len()-4)
args[l()] = "Category"
+
args['label23'] = "Category"
args[d()] = s
+
args['data23'] = item['size']
 
end
 
end
 
 
 
if item['cookingEnchantment'] then
 
if item['cookingEnchantment'] then
args[l()] = "Buff"
+
args['label24'] = "Buff"
args[d()] = getEnchantmentName(item['cookingEnchantment'])
+
args['data24'] = getEnchantmentName(item['cookingEnchantment'])
 
end
 
end
 
 
args[h()] = "Seeds"
+
args['header80'] = "Seeds"
 
 
 
local farming = item['farmingStats']
 
local farming = item['farmingStats']
Line 511: Line 190:
 
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 .. itemImage(yield['id'], true)
+
s = s .. 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 518: Line 197:
 
end
 
end
 
s = s:sub(1,s:len()-4)
 
s = s:sub(1,s:len()-4)
args[l()] = "Level Required"
+
args['label81'] = "Level Required"
args[d()] = farming['requiredLevel']
+
args['data81'] = farming['requiredLevel']
args[l()] = "Experience"
+
args['label82'] = "Experience"
args[d()] = addSeparator(farming['experience'])
+
args['data82'] = farming['experience']
args[l()] = "Plot Size"
+
args['label83'] = "Plot Size"
args[d()] = farming['height'] .. "x" .. farming['width']
+
args['data83'] = farming['height'] .. "x" .. farming['width']
args[l()] = "Harvest Time"
+
args['label84'] = "Harvest Time"
args[d()] = farming['time'] .. " minutes"
+
args['data84'] = farming['time'] .. " minutes"
args[l()] = "Yield"
+
args['label85'] = "Yield"
args[d()] = s
+
args['data85'] = s
 
end
 
end
 
 
local args2 = {}
+
args['header100'] = "Tooltip"
 
 
args2['subbox'] = "yes"
+
args['data101'] = "{{Infobox | subbox = yes"
args2['bodystyle'] = "padding: 0.5em; margin:auto; font-style:italic; font-size:110%; text-align: center"
+
args['bodystyle'] = "padding: 0.5em; margin:auto; font-style:italic; font-size:110%; text-align: center"
args2['data1'] = item['extraTooltipInfo']
+
args['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)
 
return require('Module:Infobox')['infobox'](args)
Line 553: Line 224:
  
 
function p._item(args)
 
function p._item(args)
local name = ""
+
local name = args[1]
 
local item = 0
 
local item = 0
 
local infobox = ""
 
local infobox = ""
 
 
if args[1] then
+
item = findItem (name)
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)
 
infobox = createInfobox(item)
 
return infobox
 
return infobox

Please note that all contributions to Idlescape Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see IdleScape Wiki:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)

Template used on this page: