Module:Sandbox: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
local h = {} | local h = {} | ||
local views = {} | local views = {} | ||
local getArgs, | local getArgs, roundAndPad | ||
--------------------------------------------------------------------- | --------------------------------------------------------------------- | ||
Line 27: | Line 27: | ||
parentFirst = true | parentFirst = true | ||
}) | }) | ||
args.view = args.view or args.View or 'full' | |||
if not views[args.view] then | |||
if not views[ | error('The requested view "' .. args.view .. '" does not exist') | ||
error('The requested view "' .. | |||
end | end | ||
args.format = args.format or args.Format | |||
args.name = args.name or args.Name | |||
args.sortKey = args.sortKey or args.SortKey or args.name | |||
args.pageName = args.pageName or args.PageName or args.name | |||
args.image = args.image or args.Image or args.pageName .. '.png' | |||
args.size = args.size or args.Size or '2x_' | |||
args.rarity = args.rarity or args.Rarity or 'Normal' | |||
args.type = args.type or args.Type | |||
args.subtype = args.subtype or args.Subtype | |||
args.baseItem = args.baseItem or args.BaseItem | |||
args.baseItemPage = args.baseItemPage or args.BaseItemPage or args.baseItem | |||
args.level = args.level or args.RequiredLevel | |||
args.strength = args.strength or args.RequiredStrength | |||
args.dexterity = args.dexterity or args.RequiredDexterity | |||
args.intelligence = args.intelligence or args.RequiredIntelligence | |||
args.physical = args.physicalDamage or args.PhysicalDamage | |||
args.fire = args.fire or args.FireDamage | |||
args.cold = args.cold or args.ColdDamage | |||
args.lightning = args.lightning or args.LightningDamage | |||
args.chaos = args.chaos or args.ChaosDamage | |||
args.averageDamage = args.averageDamage or args.AverageDamage | |||
args.critChance = args.critChance or args.CriticalStrikeChance | |||
args.attacksPerSecond = args.attacksPerSecond or args.AttacksPerSecond | |||
args.blockChance = args.blockChance or args.Block | |||
args.armour = args.armour or args.Armour | |||
args.evasion = args.evasion or args.Evasion | |||
args.energyShield = args.energyShield or args.EnergyShield | |||
args.mapLevel = args.mapLevel or args.MapLevel | |||
args.itemQuantity = args.itemQuantity or args.itemQuantity | |||
args.radius = args.radius or args.Radius | |||
args.stackSize = args.stackSize or args.StackSize | |||
args.effect = args.effect or args.Effect | |||
args.life = args.life or args.FlaskLife | |||
args.mana = args.mana or args.FlaskMana | |||
args.duration = args.duration or args.FlaskDuration | |||
args.chargeCap = args.chargeCap or args.FlaskCharges | |||
args.chargeUse = args.chargeUse or args.FlaskChargesUsed | |||
args.implicitMods = args.implicitMods or args.ImplicitMods | |||
args.randomMods = args.randomMods or args.RandomMods | |||
args.cosmeticMods = args.cosmeticMods or args.CosmeticMods | |||
args.helpText = args.helpText or args.HelpText | |||
args.flavourText = args.flavourText or args.FlavourText | |||
return views[ | return views[args.view](args) | ||
end | end | ||
Line 85: | Line 84: | ||
args.name = '[[' .. args.pageName .. '|' .. args.name .. ']]' | args.name = '[[' .. args.pageName .. '|' .. args.name .. ']]' | ||
args.baseItem = args.baseItem and ('[[' .. args.baseItemPage .. '|' .. args.baseItem .. ']]') or nil | args.baseItem = args.baseItem and ('[[' .. args.baseItemPage .. '|' .. args.baseItem .. ']]') or nil | ||
local types = { | local types = { | ||
['Weapon'] = { | ['Weapon'] = { | ||
Line 132: | Line 127: | ||
['Microtrans'] = 'Microtransaction features' | ['Microtrans'] = 'Microtransaction features' | ||
} | } | ||
category = types[args.type] | local category = types[args.type] | ||
if type(category) == 'table' then | if type(category) == 'table' then | ||
category = types[args.type][args.subtype or '_default'] | category = types[args.type][args.subtype or '_default'] | ||
Line 143: | Line 138: | ||
category = 'Items with invalid types' | category = 'Items with invalid types' | ||
end | end | ||
args.belowStats = mw.html.create('div') | |||
:attr('class', 'itemboximage') | |||
:wikitext( '[[File:' .. args.image .. '|' .. p._itemsize({args.size}) .. '|]]' ) | |||
:wikitext( '[[Category:' .. category .. ']]' ) | |||
return tostring( p._itembox(args) ) | |||
end | end | ||
Line 157: | Line 156: | ||
args.class = 'itemboxhover itemboxhoverhide itemboxhovernojs' | args.class = 'itemboxhover itemboxhoverhide itemboxhovernojs' | ||
args.isHover = true | args.isHover = true | ||
args.itemLinkText = args.itemLinkText or args.name | |||
args.itemLinkArt = args.itemLinkArt and string.gsub(args.image, '%.(%a+)$', ' ' .. args.itemLinkArt .. '.%1') or args.image | |||
local container = mw.html.create('span') | local container = mw.html.create('span') | ||
:tag('span') | :tag('span') | ||
:attr('class', 'itemhover') | :attr('class', 'itemhover') | ||
:wikitext( | :wikitext( | ||
args.itemLinkLarge | |||
and '[[' .. args.pageName .. '|' .. | and '[[' .. args.pageName .. '|' .. args.itemLinkText .. ']] <br> [[File:' .. args.itemLinkText .. '|' .. p._itemsize({args.size, '39'}) .. '|link=' .. args.pageName .. '|alt=]]' | ||
or '[[File:' .. | or '[[File:' .. args.itemLinkArt .. '|16x16px|link=|alt=]][[' .. args.pageName .. '|' .. args.itemLinkText .. ']]' | ||
) | ) | ||
:done() | :done() | ||
Line 173: | Line 170: | ||
:tag('span') | :tag('span') | ||
:attr('class', 'itemboxhovericon itemboxhoverhide itemboxhovernojs') | :attr('class', 'itemboxhovericon itemboxhoverhide itemboxhovernojs') | ||
:wikitext( '[[File:' .. | :wikitext( '[[File:' .. args.itemLinkArt .. '|' .. p._itemsize({args.size}) .. '|link=|alt=]]' ) | ||
:done() | :done() | ||
return tostring(container) | return tostring(container) | ||
Line 179: | Line 176: | ||
function views.tablerow(args) | function views.tablerow(args) | ||
if not | if not roundAndPad then | ||
roundAndPad = require('Module:Decimals')._main | |||
end | end | ||
local otherPage = mw.title.getCurrentTitle().fullText ~= args.pageName | local otherPage = mw.title.getCurrentTitle().fullText ~= args.pageName | ||
local | local flags = args.flags and mw.text.split(args.flags, ' ', true) or {} | ||
for i=1, # | for i=1, #flags do | ||
flags[ flags[i] ] = true | |||
end | end | ||
local function newNA(val) | local function newNA(val) | ||
Line 202: | Line 199: | ||
:attr('id', args.name) | :attr('id', args.name) | ||
end | end | ||
if | if flags.name then | ||
row | row | ||
:tag('td') | :tag('td') | ||
Line 209: | Line 206: | ||
:done() | :done() | ||
end | end | ||
if | if flags.base then | ||
row | row | ||
:tag('td') | :tag('td') | ||
:wikitext( '[[' .. args.baseItem .. ']]' ) | :wikitext( '[[' .. args.baseItemPage .. '|' .. args.baseItem .. ']]' ) | ||
:done() | :done() | ||
end | end | ||
if | if flags.level then | ||
if args.level then | if args.level then | ||
row | row | ||
Line 227: | Line 224: | ||
end | end | ||
if args.type == 'Weapon' or args.type == 'Armour' then | if args.type == 'Weapon' or args.type == 'Armour' then | ||
if | if flags.str then | ||
if args.strength then | if args.strength then | ||
row | row | ||
Line 238: | Line 235: | ||
end | end | ||
end | end | ||
if | if flags.dex then | ||
if args.dexterity then | if args.dexterity then | ||
row | row | ||
Line 249: | Line 246: | ||
end | end | ||
end | end | ||
if | if flags.int then | ||
if args.intelligence then | if args.intelligence then | ||
row | row | ||
Line 262: | Line 259: | ||
end | end | ||
if args.type == 'Weapon' then | if args.type == 'Weapon' then | ||
if | if flags.weapon then | ||
local avgDmg = tonumber(args.averageDamage) or ( (args.physical and p._itemRangeAverage({args.physical}) or 0) + (args.fire and p._itemRangeAverage({args.fire}) or 0) + (args.cold and p._itemRangeAverage({args.cold}) or 0) + (args.lightning and p._itemRangeAverage({args.lightning}) or 0) + (args.chaos and p._itemRangeAverage({args.chaos}) or 0) ) | local avgDmg = tonumber(args.averageDamage) or ( (args.physical and p._itemRangeAverage({args.physical}) or 0) + (args.fire and p._itemRangeAverage({args.fire}) or 0) + (args.cold and p._itemRangeAverage({args.cold}) or 0) + (args.lightning and p._itemRangeAverage({args.lightning}) or 0) + (args.chaos and p._itemRangeAverage({args.chaos}) or 0) ) | ||
local avgCrt = args.critChance and p._itemRangeAverage({args.critChance}) or 0 | local avgCrt = args.critChance and p._itemRangeAverage({args.critChance}) or 0 | ||
Line 308: | Line 305: | ||
:done() | :done() | ||
:tag('td') | :tag('td') | ||
:wikitext( | :wikitext( roundAndPad( avgDmg * avgAps * (1 - avgCrt / 100) + avgDmg * avgAps * avgCrt / 100 * 1.5, 2 ) ) | ||
:done() | :done() | ||
end | end | ||
elseif args.type == 'Armour' then | elseif args.type == 'Armour' then | ||
if | if flags.block then | ||
if args.blockChance then | if args.blockChance then | ||
row | row | ||
Line 324: | Line 321: | ||
end | end | ||
end | end | ||
if | if flags.armour then | ||
if args.armour then | if args.armour then | ||
row | row | ||
Line 336: | Line 333: | ||
end | end | ||
end | end | ||
if | if flags.evasion then | ||
if args.evasion then | if args.evasion then | ||
row | row | ||
Line 348: | Line 345: | ||
end | end | ||
end | end | ||
if | if flags.energyshield then | ||
if args.energyShield then | if args.energyShield then | ||
row | row | ||
Line 361: | Line 358: | ||
end | end | ||
elseif args.type == 'Flask' then | elseif args.type == 'Flask' then | ||
if | if flags.life then | ||
if args.life then | if args.life then | ||
row | row | ||
Line 373: | Line 370: | ||
end | end | ||
end | end | ||
if | if flags.mana then | ||
if args.mana then | if args.mana then | ||
row | row | ||
Line 385: | Line 382: | ||
end | end | ||
end | end | ||
if | if flags.effect then | ||
if args.effect then | if args.effect then | ||
row | row | ||
Line 415: | Line 412: | ||
:wikitext(args.mapLevel) | :wikitext(args.mapLevel) | ||
:done() | :done() | ||
if | if flags.qty then | ||
if args.itemQuantity then | if args.itemQuantity then | ||
row | row | ||
Line 437: | Line 434: | ||
:wikitext(args.stackSize) | :wikitext(args.stackSize) | ||
:done() | :done() | ||
if | if flags.effect then | ||
if args.effect then | if args.effect then | ||
row | row | ||
Line 450: | Line 447: | ||
end | end | ||
end | end | ||
if | if flags.mods then | ||
if args.implicitMods or args.randomMods or args.cosmeticMods then | if args.implicitMods or args.randomMods or args.cosmeticMods then | ||
local stats = mw.html.create('div') | local stats = mw.html.create('div') | ||
Line 484: | Line 481: | ||
end | end | ||
end | end | ||
if | if flags.flavour then | ||
if args.flavourText then | if args.flavourText then | ||
row | row | ||
Line 496: | Line 493: | ||
end | end | ||
end | end | ||
if | if flags.help then | ||
if args.helpText then | if args.helpText then | ||
row | row | ||
Line 566: | Line 563: | ||
end | end | ||
local args = getArgs(frame, { | local args = getArgs(frame, { | ||
parentOnly = true | |||
}) | }) | ||
local save = 'itemlink__' .. string.gsub(args[1], '%W+', '') .. '_' .. (args.image or '1') .. (args.large and '_large' or '') | local save = 'itemlink__' .. string.gsub(args[1], '%W+', '') .. '_' .. (args.art or args.image or '1') .. (args.large and '_large' or '') | ||
if frame:callParserFunction('#varexists', {save}) == '1' then | if frame:callParserFunction('#varexists', {save}) == '1' then | ||
return frame:callParserFunction('#var', {save}) | return frame:callParserFunction('#var', {save}) | ||
Line 576: | Line 573: | ||
title = ':' .. args[1], | title = ':' .. args[1], | ||
args = { | args = { | ||
view = 'inline', | |||
itemLinkText = args[2], | |||
itemLinkArt = args.art or args.image, | |||
itemLinkLarge = args.large | |||
} | } | ||
} | } | ||
Line 590: | Line 589: | ||
getArgs = require('Module:Arguments').getArgs | getArgs = require('Module:Arguments').getArgs | ||
end | end | ||
local args = getArgs(frame) | local args = getArgs(frame, { | ||
local | parentOnly = true | ||
for i=1, # | }) | ||
args.flags = args.flags | |||
local flags = args.format and mw.text.split(args.format, ' ', true) or {} | |||
for i=1, #flags do | |||
flags[ flags[i] ] = true | |||
end | end | ||
local function newAbbr(text, title) | local function newAbbr(text, title) | ||
Line 608: | Line 610: | ||
:wikitext('Name') | :wikitext('Name') | ||
:done() | :done() | ||
if | if flags.base then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 614: | Line 616: | ||
:done() | :done() | ||
end | end | ||
if | if flags.level then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 621: | Line 623: | ||
:done() | :done() | ||
end | end | ||
if | if flags.str then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 628: | Line 630: | ||
:done() | :done() | ||
end | end | ||
if | if flags.dex then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 635: | Line 637: | ||
:done() | :done() | ||
end | end | ||
if | if flags.int then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 642: | Line 644: | ||
:done() | :done() | ||
end | end | ||
if | if flags.weapon then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 661: | Line 663: | ||
:done() | :done() | ||
end | end | ||
if | if flags.block then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 668: | Line 670: | ||
:done() | :done() | ||
end | end | ||
if | if flags.armour then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 675: | Line 677: | ||
:done() | :done() | ||
end | end | ||
if | if flags.evasion then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 682: | Line 684: | ||
:done() | :done() | ||
end | end | ||
if | if flags.energyshield then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 689: | Line 691: | ||
:done() | :done() | ||
end | end | ||
if | if flags.flask then | ||
if | if flags.life or flags.mana then | ||
if | if flags.life then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 698: | Line 700: | ||
:done() | :done() | ||
end | end | ||
if | if flags.mana then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 710: | Line 712: | ||
:node( newAbbr( | :node( newAbbr( | ||
'Time', | 'Time', | ||
( | (flags.life and 'Life' or '') .. ( (flags.life and flags.mana) and ' and ' or '' ) .. (flags.mana and 'Mana' or '') .. ' Recovery Time in Seconds' | ||
) ) | ) ) | ||
:done() | :done() | ||
end | end | ||
if | if flags.effect then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 735: | Line 737: | ||
:done() | :done() | ||
end | end | ||
if | if flags.map then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 741: | Line 743: | ||
:wikitext('Map Level') | :wikitext('Map Level') | ||
:done() | :done() | ||
if | if flags.qty then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 749: | Line 751: | ||
end | end | ||
end | end | ||
if | if flags.jewel then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 755: | Line 757: | ||
:done() | :done() | ||
end | end | ||
if | if flags.currency then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 761: | Line 763: | ||
:wikitext('Stack Size') | :wikitext('Stack Size') | ||
:done() | :done() | ||
if | if flags.effect then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 769: | Line 771: | ||
end | end | ||
end | end | ||
if | if flags.mods then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 776: | Line 778: | ||
:done() | :done() | ||
end | end | ||
if | if flags.flavour then | ||
hdr | hdr | ||
:tag('th') | :tag('th') | ||
Line 783: | Line 785: | ||
:done() | :done() | ||
end | end | ||
if | if flags.help then | ||
hdr | hdr | ||
:tag('th') | :tag('th') |
Revision as of 00:28, 29 April 2015
This page is not an actual Scribunto module. It exists to provide editors a place to create experimental modules.
Naming your modules
To keep things tidy, please use the following format to name your experimental modules:
Module:Sandbox/Your username/Module name
Cleaning up unused modules
Experimental modules may be deleted by admins upon request or after a long period of inactivity.
List of modules in this area
For a list of the experimental modules under Module:Sandbox, see Special:PrefixIndex/Module:Sandbox/.
The above documentation is transcluded from Module:Sandbox/doc.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
local p = {}
local h = {}
local views = {}
local getArgs, roundAndPad
---------------------------------------------------------------------
-- Argument processing
---------------------------------------------------------------------
local function makeInvokeFunc(funcName)
return function (frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
local args = getArgs(frame)
return p[funcName](args)
end
end
---------------------------------------------------------------------
-- Implements {{item}}
---------------------------------------------------------------------
function p.item(frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
local args = getArgs(frame, {
parentFirst = true
})
args.view = args.view or args.View or 'full'
if not views[args.view] then
error('The requested view "' .. args.view .. '" does not exist')
end
args.format = args.format or args.Format
args.name = args.name or args.Name
args.sortKey = args.sortKey or args.SortKey or args.name
args.pageName = args.pageName or args.PageName or args.name
args.image = args.image or args.Image or args.pageName .. '.png'
args.size = args.size or args.Size or '2x_'
args.rarity = args.rarity or args.Rarity or 'Normal'
args.type = args.type or args.Type
args.subtype = args.subtype or args.Subtype
args.baseItem = args.baseItem or args.BaseItem
args.baseItemPage = args.baseItemPage or args.BaseItemPage or args.baseItem
args.level = args.level or args.RequiredLevel
args.strength = args.strength or args.RequiredStrength
args.dexterity = args.dexterity or args.RequiredDexterity
args.intelligence = args.intelligence or args.RequiredIntelligence
args.physical = args.physicalDamage or args.PhysicalDamage
args.fire = args.fire or args.FireDamage
args.cold = args.cold or args.ColdDamage
args.lightning = args.lightning or args.LightningDamage
args.chaos = args.chaos or args.ChaosDamage
args.averageDamage = args.averageDamage or args.AverageDamage
args.critChance = args.critChance or args.CriticalStrikeChance
args.attacksPerSecond = args.attacksPerSecond or args.AttacksPerSecond
args.blockChance = args.blockChance or args.Block
args.armour = args.armour or args.Armour
args.evasion = args.evasion or args.Evasion
args.energyShield = args.energyShield or args.EnergyShield
args.mapLevel = args.mapLevel or args.MapLevel
args.itemQuantity = args.itemQuantity or args.itemQuantity
args.radius = args.radius or args.Radius
args.stackSize = args.stackSize or args.StackSize
args.effect = args.effect or args.Effect
args.life = args.life or args.FlaskLife
args.mana = args.mana or args.FlaskMana
args.duration = args.duration or args.FlaskDuration
args.chargeCap = args.chargeCap or args.FlaskCharges
args.chargeUse = args.chargeUse or args.FlaskChargesUsed
args.implicitMods = args.implicitMods or args.ImplicitMods
args.randomMods = args.randomMods or args.RandomMods
args.cosmeticMods = args.cosmeticMods or args.CosmeticMods
args.helpText = args.helpText or args.HelpText
args.flavourText = args.flavourText or args.FlavourText
return views[args.view](args)
end
---------------------------------------------------------------------
-- Views
---------------------------------------------------------------------
function views.full(args)
args.stats = h.statsBuilder(args)
args.class = 'itembox-full'
args.name = '[[' .. args.pageName .. '|' .. args.name .. ']]'
args.baseItem = args.baseItem and ('[[' .. args.baseItemPage .. '|' .. args.baseItem .. ']]') or nil
local types = {
['Weapon'] = {
['Bow'] = 'Bows',
['Claw'] = 'Claws',
['Dagger'] = 'Daggers',
['Wand'] = 'Wands',
['Fishing Rod'] = 'Fishing rods',
['Staff'] = 'Staves',
['One Handed Axe'] = 'One-handed axes',
['Two Handed Axe'] = 'Two-handed axes',
['One Handed Mace'] = 'One-handed maces',
['Two Handed Mace'] = 'Two-handed maces',
['One Handed Sword'] = 'One-handed swords',
['Two Handed Sword'] = 'Two-handed swords'
},
['Armour'] = {
['Body Armour'] = 'Body armours',
['Helmet'] = 'Helmets',
['Shield'] = 'Shields',
['Boots'] = 'Boots',
['Gloves'] = 'Gloves'
},
['Accessory'] = {
['Amulet'] = 'Amulets',
['Belt'] = 'Belts',
['Quiver'] = 'Quivers',
['Ring'] = 'Rings'
},
['Flask'] = {
['Life'] = 'Life flasks',
['Mana'] = 'Mana flasks',
['Hybrid'] = 'Hybrid flasks',
['Utility'] = 'Utility flasks'
},
['Map'] = {
['Fragment'] = 'Map fragments',
['_default'] = 'Maps'
},
['Jewel'] = 'Jewels',
['Currency'] = 'Currency items',
['Quest'] = 'Quest items',
['Microtrans'] = 'Microtransaction features'
}
local category = types[args.type]
if type(category) == 'table' then
category = types[args.type][args.subtype or '_default']
end
if category then
if args.rarity == 'Unique' then
category = 'Unique ' .. string.lower(category)
end
else
category = 'Items with invalid types'
end
args.belowStats = mw.html.create('div')
:attr('class', 'itemboximage')
:wikitext( '[[File:' .. args.image .. '|' .. p._itemsize({args.size}) .. '|]]' )
:wikitext( '[[Category:' .. category .. ']]' )
return tostring( p._itembox(args) )
end
function views.standard(args)
args.stats = h.statsBuilder(args)
args.name = '[[' .. args.pageName .. '|' .. args.name .. ']]'
args.baseItem = args.baseItem and ('[[' .. args.baseItemPage .. '|' .. args.baseItem .. ']]') or nil
return tostring( p._itembox(args) )
end
function views.inline(args)
args.stats = h.statsBuilder(args)
args.class = 'itemboxhover itemboxhoverhide itemboxhovernojs'
args.isHover = true
args.itemLinkText = args.itemLinkText or args.name
args.itemLinkArt = args.itemLinkArt and string.gsub(args.image, '%.(%a+)$', ' ' .. args.itemLinkArt .. '.%1') or args.image
local container = mw.html.create('span')
:tag('span')
:attr('class', 'itemhover')
:wikitext(
args.itemLinkLarge
and '[[' .. args.pageName .. '|' .. args.itemLinkText .. ']] <br> [[File:' .. args.itemLinkText .. '|' .. p._itemsize({args.size, '39'}) .. '|link=' .. args.pageName .. '|alt=]]'
or '[[File:' .. args.itemLinkArt .. '|16x16px|link=|alt=]][[' .. args.pageName .. '|' .. args.itemLinkText .. ']]'
)
:done()
:node( p._itembox(args) )
:tag('span')
:attr('class', 'itemboxhovericon itemboxhoverhide itemboxhovernojs')
:wikitext( '[[File:' .. args.itemLinkArt .. '|' .. p._itemsize({args.size}) .. '|link=|alt=]]' )
:done()
return tostring(container)
end
function views.tablerow(args)
if not roundAndPad then
roundAndPad = require('Module:Decimals')._main
end
local otherPage = mw.title.getCurrentTitle().fullText ~= args.pageName
local flags = args.flags and mw.text.split(args.flags, ' ', true) or {}
for i=1, #flags do
flags[ flags[i] ] = true
end
local function newNA(val)
local cell = mw.html.create('td')
:attr('class', 'table-na')
:wikitext('<small>N/A</small>')
if val ~= nil then
cell
:attr('data-sort-value', val)
end
return cell
end
local row = mw.html.create('tr')
if otherPage then
row
:attr('id', args.name)
end
if flags.name then
row
:tag('td')
:attr('data-sort-value', args.sortKey)
:wikitext( (otherPage and '[[' .. args.pageName .. '|' .. args.name .. ']]' or args.name) .. ' <br> [[File:' .. args.image .. '|' .. p._itemsize({args.size, '39'}) .. '|link=' .. (otherPage and args.pageName or '') .. '|alt=]]' )
:done()
end
if flags.base then
row
:tag('td')
:wikitext( '[[' .. args.baseItemPage .. '|' .. args.baseItem .. ']]' )
:done()
end
if flags.level then
if args.level then
row
:tag('td')
:wikitext(args.level)
:done()
else
row
:node( newNA(0) )
end
end
if args.type == 'Weapon' or args.type == 'Armour' then
if flags.str then
if args.strength then
row
:tag('td')
:wikitext(args.strength)
:done()
else
row
:node( newNA(0) )
end
end
if flags.dex then
if args.dexterity then
row
:tag('td')
:wikitext(args.dexterity)
:done()
else
row
:node( newNA(0) )
end
end
if flags.int then
if args.intelligence then
row
:tag('td')
:wikitext(args.intelligence)
:done()
else
row
:node( newNA(0) )
end
end
end
if args.type == 'Weapon' then
if flags.weapon then
local avgDmg = tonumber(args.averageDamage) or ( (args.physical and p._itemRangeAverage({args.physical}) or 0) + (args.fire and p._itemRangeAverage({args.fire}) or 0) + (args.cold and p._itemRangeAverage({args.cold}) or 0) + (args.lightning and p._itemRangeAverage({args.lightning}) or 0) + (args.chaos and p._itemRangeAverage({args.chaos}) or 0) )
local avgCrt = args.critChance and p._itemRangeAverage({args.critChance}) or 0
local avgAps = args.attacksPerSecond and p._itemRangeAverage({args.attacksPerSecond}) or 0
local damage = mw.html.create('td')
:attr('data-sort-value', avgDmg)
if avgDmg == 0 then
damage
:wikitext('0')
else
if args.physical then
damage
:node( h.newColor('physical', args.physical) )
:tag('br'):done()
end
if args.fire then
damage
:node( h.newColor('fire', args.fire) )
:tag('br'):done()
end
if args.cold then
damage
:node( h.newColor('cold', args.cold) )
:tag('br'):done()
end
if args.lightning then
damage
:node( h.newColor('lightning', args.lightning) )
:tag('br'):done()
end
if args.chaos then
damage
:node( h.newColor('chaos', args.chaos) )
end
end
row
:node(damage)
:tag('td')
:attr('data-sort-value', avgCrt)
:wikitext(args.critChance)
:done()
:tag('td')
:attr('data-sort-value', avgAps)
:wikitext(args.attacksPerSecond)
:done()
:tag('td')
:wikitext( roundAndPad( avgDmg * avgAps * (1 - avgCrt / 100) + avgDmg * avgAps * avgCrt / 100 * 1.5, 2 ) )
:done()
end
elseif args.type == 'Armour' then
if flags.block then
if args.blockChance then
row
:tag('td')
:attr( 'data-sort-value', p._itemRangeAverage({args.blockChance}) )
:wikitext(args.blockChance)
:done()
else
row
:node( newNA(0) )
end
end
if flags.armour then
if args.armour then
row
:tag('td')
:attr( 'data-sort-value', p._itemRangeAverage({args.armour}) )
:wikitext(args.armour)
:done()
else
row
:node( newNA(0) )
end
end
if flags.evasion then
if args.evasion then
row
:tag('td')
:attr( 'data-sort-value', p._itemRangeAverage({args.evasion}) )
:wikitext(args.evasion)
:done()
else
row
:node( newNA(0) )
end
end
if flags.energyshield then
if args.energyShield then
row
:tag('td')
:attr( 'data-sort-value', p._itemRangeAverage({args.energyShield}) )
:wikitext(args.energyShield)
:done()
else
row
:node( newNA(0) )
end
end
elseif args.type == 'Flask' then
if flags.life then
if args.life then
row
:tag('td')
:attr( 'data-sort-value', p._itemRangeAverage({args.life}) )
:wikitext(args.life)
:done()
else
row
:node( newNA(0) )
end
end
if flags.mana then
if args.mana then
row
:tag('td')
:attr( 'data-sort-value', p._itemRangeAverage({args.mana}) )
:wikitext(args.mana)
:done()
else
row
:node( newNA(0) )
end
end
if flags.effect then
if args.effect then
row
:tag('td')
:attr('class', 'text-mod')
:node(args.effect)
:done()
else
row
:node( newNA() )
end
end
row
:tag('td')
:attr( 'data-sort-value', p._itemRangeAverage({args.duration}) )
:wikitext(args.duration)
:done()
:tag('td')
:attr( 'data-sort-value', p._itemRangeAverage({args.chargeCap}) )
:wikitext(args.chargeCap)
:done()
:tag('td')
:attr( 'data-sort-value', p._itemRangeAverage({args.chargeUse}) )
:wikitext(args.chargeUse)
:done()
elseif args.type == 'Map' then
row
:tag('td')
:wikitext(args.mapLevel)
:done()
if flags.qty then
if args.itemQuantity then
row
:tag('td')
:attr( 'data-sort-value', p._itemRangeAverage({args.itemQuantity}) )
:wikitext(args.itemQuantity)
:done()
else
row
:node( newNA(0) )
end
end
elseif args.type == 'Jewel' then
row
:tag('td')
:wikitext(args.radius)
:done()
elseif args.type == 'Currency' then
row
:tag('td')
:wikitext(args.stackSize)
:done()
if flags.effect then
if args.effect then
row
:tag('td')
:attr('class', 'text-mod')
:wikitext(args.effect)
:done()
else
row
:node( newNA() )
end
end
end
if flags.mods then
if args.implicitMods or args.randomMods or args.cosmeticMods then
local stats = mw.html.create('div')
:attr('class', 'itemboxstats')
if args.implicitMods then
stats
:tag('div')
:attr('class', 'itemboxstatsgroup text-mod')
:wikitext(args.implicitMods)
:done()
end
if args.randomMods then
stats
:tag('div')
:attr('class', 'itemboxstatsgroup text-mod')
:wikitext(args.randomMods)
:done()
end
if args.cosmeticMods then
stats
:tag('div')
:attr('class', 'itemboxstatsgroup text-cosmetic')
:wikitext(args.cosmeticMods)
:done()
end
row
:tag('td')
:node(stats)
:done()
else
row
:node( newNA() )
end
end
if flags.flavour then
if args.flavourText then
row
:tag('td')
:attr('class', 'text-flavour')
:wikitext(args.flavourText)
:done()
else
row
:node( newNA() )
end
end
if flags.help then
if args.helpText then
row
:tag('td')
:attr('class', 'text-help')
:wikitext(args.helpText)
:done()
else
row
:node( newNA() )
end
end
return row
end
---------------------------------------------------------------------
-- Implements {{itembox}}
---------------------------------------------------------------------
p.itembox = makeInvokeFunc('_itembox')
function p._itembox(args)
local frames = {
['Currency'] = 'currency',
['Microtrans'] = 'currency',
['Gem'] = 'gem',
['Quest'] = 'quest'
}
local container = mw.html.create(args.isHover and 'span' or 'div')
:attr( 'class', 'itembox-' .. ( string.lower(args.frame or frames[args.type] or args.rarity or 'normal') ) .. ' ' .. (args.class or '') )
:tag('span')
:attr( 'class', 'itemboxheader-' .. (args.baseItem and 'double' or 'single') )
:tag('span')
:attr('class', 'itemboxheaderleft')
:done()
:tag('span')
:attr('class', 'itemboxheaderright')
:done()
:tag('span')
:attr('class', 'itemboxheadertext')
:wikitext( args.name .. (args.baseItem and '<br>' .. args.baseItem or '') )
:done()
:done()
if type(args.aboveStats) == 'table' then
container:node(args.aboveStats)
elseif type(args.aboveStats) == 'string' then
container:wikitext(args.aboveStats)
end
local stats = mw.html.create('span')
:attr('class', 'itemboxstats')
if type(args.stats) == 'table' then
stats:node(args.stats)
elseif type(args.stats) == 'string' then
stats:wikitext(args.stats)
end
container:node(stats)
if type(args.belowStats) == 'table' then
container:node(args.belowStats)
elseif type(args.belowStats) == 'string' then
container:wikitext(args.belowStats)
end
return container
end
---------------------------------------------------------------------
-- Implements {{il}}
---------------------------------------------------------------------
function p.itemLink(frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
local args = getArgs(frame, {
parentOnly = true
})
local save = 'itemlink__' .. string.gsub(args[1], '%W+', '') .. '_' .. (args.art or args.image or '1') .. (args.large and '_large' or '')
if frame:callParserFunction('#varexists', {save}) == '1' then
return frame:callParserFunction('#var', {save})
end
return frame:callParserFunction('#vardefineecho', { save,
frame:expandTemplate{
title = ':' .. args[1],
args = {
view = 'inline',
itemLinkText = args[2],
itemLinkArt = args.art or args.image,
itemLinkLarge = args.large
}
}
})
end
---------------------------------------------------------------------
-- Implements {{item table}}
---------------------------------------------------------------------
function p.itemTable(frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
local args = getArgs(frame, {
parentOnly = true
})
args.flags = args.flags
local flags = args.format and mw.text.split(args.format, ' ', true) or {}
for i=1, #flags do
flags[ flags[i] ] = true
end
local function newAbbr(text, title)
return mw.html.create('abbr')
:attr('class', 'nounderline')
:attr('title', title)
:wikitext(text)
end
local tbl = mw.html.create('table')
:attr('class', 'wikitable sortable')
:attr('style', 'text-align:center; ' .. ( args.width and 'width:' .. args.width or '' ) )
local hdr = mw.html.create('tr')
:tag('th')
:wikitext('Name')
:done()
if flags.base then
hdr
:tag('th')
:wikitext('Base Item')
:done()
end
if flags.level then
hdr
:tag('th')
:attr('data-sort-type', 'number')
:node( newAbbr('[[File:Level_up_icon_small.png|link=|Lvl.]]', 'Required Level') )
:done()
end
if flags.str then
hdr
:tag('th')
:attr('data-sort-type', 'number')
:node( newAbbr('[[File:StrengthIcon_small.png|link=|Str.]]', 'Required Strength') )
:done()
end
if flags.dex then
hdr
:tag('th')
:attr('data-sort-type', 'number')
:node( newAbbr('[[File:DexterityIcon_small.png|link=|Dex.]]', 'Required Dexterity') )
:done()
end
if flags.int then
hdr
:tag('th')
:attr('data-sort-type', 'number')
:node( newAbbr('[[File:IntelligenceIcon_small.png|link=|Int.]]', 'Required Intelligence') )
:done()
end
if flags.weapon then
hdr
:tag('th')
:attr('data-sort-type', 'number')
:wikitext('Damage')
:done()
:tag('th')
:attr('data-sort-type', 'number')
:wikitext('Critical Strike Chance')
:done()
:tag('th')
:attr('data-sort-type', 'number')
:wikitext('Attacks per Second')
:done()
:tag('th')
:attr('data-sort-type', 'number')
:wikitext('Damage per Second')
:done()
end
if flags.block then
hdr
:tag('th')
:attr('data-sort-type', 'number')
:wikitext('Chance to Block')
:done()
end
if flags.armour then
hdr
:tag('th')
:attr('data-sort-type', 'number')
:wikitext('Armour Rating')
:done()
end
if flags.evasion then
hdr
:tag('th')
:attr('data-sort-type', 'number')
:wikitext('Evasion Rating')
:done()
end
if flags.energyshield then
hdr
:tag('th')
:attr('data-sort-type', 'number')
:wikitext('Energy Shield')
:done()
end
if flags.flask then
if flags.life or flags.mana then
if flags.life then
hdr
:tag('th')
:attr('data-sort-type', 'number')
:node( newAbbr('Life', 'Life Recovered over Time per Sip') )
:done()
end
if flags.mana then
hdr
:tag('th')
:attr('data-sort-type', 'number')
:node( newAbbr('Mana', 'Mana Recovered over Time per Sip') )
:done()
end
hdr
:tag('th')
:attr('data-sort-type', 'number')
:node( newAbbr(
'Time',
(flags.life and 'Life' or '') .. ( (flags.life and flags.mana) and ' and ' or '' ) .. (flags.mana and 'Mana' or '') .. ' Recovery Time in Seconds'
) )
:done()
end
if flags.effect then
hdr
:tag('th')
:attr('class', 'unsortable')
:wikitext('Effects')
:done()
:tag('th')
:attr('data-sort-type', 'number')
:wikitext('Duration')
:done()
end
hdr
:tag('th')
:attr('data-sort-type', 'number')
:node( newAbbr('Capacity', 'Total Amount of Charges the Flask Can Hold') )
:done()
:tag('th')
:attr('data-sort-type', 'number')
:node( newAbbr('Usage', 'Amount of Charges Used per Sip') )
:done()
end
if flags.map then
hdr
:tag('th')
:attr('data-sort-type', 'number')
:wikitext('Map Level')
:done()
if flags.qty then
hdr
:tag('th')
:attr('data-sort-type', 'number')
:wikitext('Item Quantity')
:done()
end
end
if flags.jewel then
hdr
:tag('th')
:wikitext('Radius')
:done()
end
if flags.currency then
hdr
:tag('th')
:attr('data-sort-type', 'number')
:wikitext('Stack Size')
:done()
if flags.effect then
hdr
:tag('th')
:attr('class', 'unsortable')
:wikitext('Effects')
:done()
end
end
if flags.mods then
hdr
:tag('th')
:attr('class', 'unsortable')
:wikitext('Modifiers')
:done()
end
if flags.flavour then
hdr
:tag('th')
:attr('class', 'unsortable')
:wikitext('Flavour Text')
:done()
end
if flags.help then
hdr
:tag('th')
:attr('class', 'unsortable')
:wikitext('Help Text')
:done()
end
tbl:node(hdr)
local i = 1
while args[i] do
tbl
:node(
frame:expandTemplate{
title = ':' .. args[i],
args = {
['View'] = 'tablerow',
['Format'] = 'name ' .. (args.format or '')
}
}
)
i = i + 1
end
return tostring(tbl)
end
---------------------------------------------------------------------
-- Implements {{item range average}}
---------------------------------------------------------------------
p.itemRangeAverage = makeInvokeFunc('_itemRangeAverage')
function p._itemRangeAverage(args)
if args[1] == nil then
return nil
end
local s = {}
s.mod = string.match(args[1], '>([^><]+)</') or args[1]
s.sign = string.find(s.mod, '−', 0, true) and -1 or 1
s.min = string.match(s.mod, '%((%S+)%s*to') or s.mod
s.max = string.match(s.mod, 'to%s*(%S+)%)') or s.min
s.minLow = tonumber( string.match(s.min, '(%d*%.?%d+)') )
s.minHigh = tonumber( string.match(s.min, '–(%d*%.?%d+)') or s.minLow )
s.maxLow = tonumber( string.match(s.max, '(%d*%.?%d+)') )
s.maxHigh = tonumber( string.match(s.max, '–(%d*%.?%d+)') or s.maxLow )
if #{s.minLow, s.minHigh, s.maxLow, s.maxHigh} == 0 then
return nil
end
return ( ( (s.minLow + s.minHigh) / 2 ) + ( (s.maxLow + s.maxHigh) / 2 ) ) / 2 * s.sign
end
---------------------------------------------------------------------
-- Implements {{itemsize}}
---------------------------------------------------------------------
p.itemsize = makeInvokeFunc('_itemsize')
function p._itemsize(args)
local size = args[1] or '1x_'
local grid = args[2] or 78
local dim = mw.text.split(size, 'x', true)
if dim[1] == '_' then
if dim[2] == '_' then
dim[1] = grid
else
dim[1] = ''
end
else
dim[1] = dim[1] * grid
end
if dim[2] == '_' then
dim[2] = ''
else
dim[2] = 'x' .. dim[2] * grid
end
return dim[1] .. dim[2] .. 'px'
end
---------------------------------------------------------------------
-- Helper functions
---------------------------------------------------------------------
function h.statsBuilder(args)
local container = mw.html.create('span')
local group
local function newGroup(class)
return mw.html.create('span')
:attr( 'class', 'itemboxstatsgroup ' .. (class or '') )
end
if args.type == 'Weapon' then
group = newGroup()
:wikitext(args.subtype)
:tag('br'):done()
if args.physical then
group
:wikitext('Physical Damage: ')
:node( h.newColor('value', args.physical) )
:tag('br'):done()
end
if args.fire or args.cold or args.lightning then
local elementalDamage = {}
if args.fire then
table.insert( elementalDamage, tostring( h.newColor('fire', args.fire) ) )
end
if args.cold then
table.insert( elementalDamage, tostring( h.newColor('cold', args.cold) ) )
end
if args.lightning then
table.insert( elementalDamage, tostring( h.newColor('lightning', args.lightning) ) )
end
group
:wikitext('Elemental Damage: ')
:wikitext( table.concat(elementalDamage, ', ') )
:tag('br'):done()
end
if args.chaos then
group
:wikitext('Chaos Damage: ')
:node( h.newColor('chaos', args.chaos) )
:tag('br'):done()
end
group
:wikitext('Critical Strike Chance: ')
:node( h.newColor('value', args.critChance) )
:tag('br'):done()
:wikitext('Attacks per Second: ')
:node( h.newColor('value', args.attacksPerSecond) )
container:node(group)
elseif args.type == 'Armour' then
if args.blockChance or args.armour or args.evasion or args.energyShield then
group = newGroup()
if args.blockChance then
group
:wikitext('Chance to Block: ')
:node( h.newColor('value', args.blockChance) )
:tag('br'):done()
end
if args.armour then
group
:wikitext('Armour: ')
:node( h.newColor('value', args.armour) )
:tag('br'):done()
end
if args.evasion then
group
:wikitext('Evasion: ')
:node( h.newColor('value', args.evasion) )
:tag('br'):done()
end
if args.energyShield then
group
:wikitext('Energy Shield: ')
:node( h.newColor('value', args.energyShield) )
end
container:node(group)
end
elseif args.type == 'Map' then
if args.mapLevel then
group = newGroup()
:wikitext('Map Level: ')
:node( h.newColor('value', args.mapLevel) )
:tag('br'):done()
if args.itemQuantity then
group
:wikitext('Item Quantity: ')
:node( h.newColor('value', args.itemQuantity) )
end
container:node(group)
end
elseif args.type == 'Jewel' then
if args.radius then
group = newGroup()
:wikitext('Radius: ')
:node( h.newColor('value', args.radius) )
container:node(group)
end
elseif args.type == 'Currency' then
group = newGroup()
:wikitext('Stack Size: ')
:node( h.newColor('value', args.stackSize) )
container:node(group)
if args.effect then
group = newGroup('textwrap text-mod')
:wikitext(args.effect)
container:node(group)
end
elseif args.type == 'Flask' then
group = newGroup()
if args.life then
group
:wikitext('Recovers ')
:node( h.newColor('value', args.life) )
:wikitext(' Life over ')
:node( h.newColor('value', args.duration) )
:wikitext(' Seconds')
:tag('br'):done()
end
if args.mana then
group
:wikitext('Recovers ')
:node( h.newColor('value', args.mana) )
:wikitext(' Mana over ')
:node( h.newColor('value', args.duration) )
:wikitext(' Seconds')
:tag('br'):done()
end
if args.effect then
group
:wikitext('Lasts ')
:node( h.newColor('value', args.duration) )
:wikitext(' Seconds')
:tag('br'):done()
end
group
:wikitext('Consumes ')
:node( h.newColor('value', args.chargeUse) )
:wikitext(' of ')
:node( h.newColor('value', args.chargeCap) )
:wikitext(' Charges on use')
:tag('br'):done()
if args.effect then
group
:wikitext(args.effect)
end
container:node(group)
elseif args.type == 'Microtrans' then
group = newGroup()
if args.subtype or args.stackSize then
group
:wikitext(args.subtype)
:tag('br'):done()
if args.stackSize then
group
:wikitext('Stack Size: ')
:node( h.newColor('value', args.stackSize) )
end
container:node(group)
end
group = newGroup('textwrap text-mod')
:wikitext(args.effect)
container:node(group)
end
if args.level or args.strength or args.dexterity or args.intelligence then
local requirements = {}
local attrLabel
if args.level then
table.insert( requirements, 'Level ' .. tostring( h.newColor('value', args.level) ) )
end
if args.strength then
attrLabel = ' Strength'
if args.level or args.dexterity or args.intelligence then
attrLabel = ' Str'
end
table.insert( requirements, tostring( h.newColor('value', args.strength) ) .. attrLabel )
end
if args.dexterity then
attrLabel = ' Dexterity'
if args.level or args.strength or args.intelligence then
attrLabel = ' Dex'
end
table.insert( requirements, tostring( h.newColor('value', args.dexterity) ) .. attrLabel )
end
if args.intelligence then
attrLabel = ' Intelligence'
if args.level or args.strength or args.dexterity then
attrLabel = ' Int'
end
table.insert( requirements, tostring( h.newColor('value', args.intelligence) ) .. attrLabel )
end
group = newGroup()
:wikitext('Requires ')
:wikitext( table.concat(requirements, ', ') )
container:node(group)
end
if args.implicitMods then
group = newGroup('text-mod')
:wikitext(args.implicitMods)
container:node(group)
end
if args.randomMods then
group = newGroup('text-mod')
:wikitext(args.randomMods)
container:node(group)
end
if args.cosmeticMods then
group = newGroup('text-cosmetic')
:wikitext(args.cosmeticMods)
container:node(group)
end
if args.flavourText then
group = newGroup('textwrap text-flavour')
:wikitext(args.flavourText)
container:node(group)
end
if args.helpText then
group = newGroup('textwrap text-help')
:wikitext(args.helpText)
container:node(group)
end
return container
end
function h.newColor(label, text)
if text == nil or text == '' then
return nil
end
return mw.html.create('span')
:attr('class', 'text-' .. label)
:wikitext(text)
end
return p