Module:Sandbox: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 10: | Line 10: | ||
trim = false | trim = false | ||
}) | }) | ||
return p._main(args | return p._main(args) | ||
end | end | ||
function p._main(args | function p._main(args) | ||
local container = mw.html.create('div') | local container = mw.html.create('div') | ||
local group | local group | ||
local function | local function newGroup() | ||
return mw.html.create('span') | return mw.html.create('span') | ||
:attr('class', 'itemboxstatsgroup') | |||
end | end | ||
local function | local function newLine(extraClasses) | ||
return mw.html.create('span') | |||
:attr('class', 'itemboxstatsgroupline ' .. extraClasses) | |||
end | |||
local function newColor(label, text) | |||
if text == nil or text == '' then | if text == nil or text == '' then | ||
return nil | return nil | ||
Line 28: | Line 32: | ||
:wikitext(text) | :wikitext(text) | ||
end | end | ||
group = | args.type = string.lower(args.type) | ||
:wikitext(' | if args.type == 'weapon' then | ||
: | group = newGroup() | ||
: | :node( newLine() | ||
group | :wikitext(args.subtype) | ||
) | |||
:node( | if args.physical then | ||
: | group | ||
: | :node( newLine() | ||
container:node(group) | :wikitext('Physical Damage: ') | ||
group = | :node( newColor('value', args.physical) ) | ||
) | |||
: | end | ||
: | if args.fire or args.cold or args.lightning then | ||
group | if not doConcat then | ||
:wikitext(' | doConcat = require('Module:Concat')._main | ||
: | end | ||
: | group | ||
container:node(group) | :node( newLine() | ||
:wikitext('Elemental Damage: ') | |||
:wikitext( | |||
doConcat({ | |||
tostring( newColor('fire', args.fire) ), | |||
tostring( newColor('cold', args.cold) ), | |||
tostring( newColor('lightning', args.lightning) ) | |||
}) | |||
) | |||
) | |||
end | |||
if args.chaos then | |||
group | |||
:node( newLine() | |||
:wikitext('Chaos Damage: ') | |||
:node( newColor('chaos', args.chaos) ) | |||
) | |||
end | |||
group | |||
:node( newLine() | |||
:wikitext('Critical Strike Chance: ') | |||
:node( newColor('value', args.critChance) ) | |||
) | |||
:node( newLine() | |||
:wikitext('Attacks per Second: ') | |||
:node( 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 | |||
:node( newLine() | |||
:wikitext('Chance to Block: ') | |||
:node( newColor('value', args.blockChance) ) | |||
) | |||
end | |||
if args.armour then | |||
group | |||
:node( newLine() | |||
:wikitext('Armour: ') | |||
:node( newColor('value', args.armour) ) | |||
) | |||
end | |||
if args.evasion then | |||
group | |||
:node( newLine() | |||
:wikitext('Evasion: ') | |||
:node( newColor('value', args.evasion) ) | |||
) | |||
end | |||
if args.energyShield then | |||
group | |||
:node( newLine() | |||
:wikitext('Energy Shield: ') | |||
:node( newColor('value', args.energyShield) ) | |||
) | |||
end | |||
container:node(group) | |||
end | |||
elseif args.type == 'map' then | |||
if args.mapLevel then | |||
group = newGroup() | |||
:node( newLine() | |||
:wikitext('Map Level: ') | |||
:node( newColor('value', args.mapLevel) ) | |||
) | |||
if args.itemQuantity then | |||
group | |||
:node( newLine() | |||
:wikitext('Item Quantity: ') | |||
:node( newColor('value', args.itemQuantity) ) | |||
) | |||
end | |||
container:node(group) | |||
end | |||
elseif args.type == 'jewel' then | |||
if args.radius then | |||
group = newGroup() | |||
:node( newLine() | |||
:wikitext('Radius: ') | |||
:node( newColor('value', args.radius) ) | |||
) | |||
container:node(group) | |||
end | |||
elseif args.type == 'currency' then | |||
group = newGroup() | |||
:node( newLine() | |||
:wikitext('Stack Size: ') | |||
:node( newColor('value', args.stackSize) ) | |||
) | |||
container:node(group) | |||
if args.effect then | |||
group = newGroup('textwrap') | |||
:node( newLine() | |||
:node( newColor('mod', args.effect) ) | |||
) | |||
container:node(group) | |||
end | |||
elseif args.type == 'flask' then | |||
group = newGroup() | |||
if args.life then | |||
group | |||
:node( newLine() | |||
:wikitext('Recovers ') | |||
:node( newColor('value', args.life) ) | |||
:wikitext(' Life over ') | |||
:node( newColor('value', args.duration) ) | |||
:wikitext(' Seconds') | |||
) | |||
end | |||
if args.mana then | |||
group | |||
:node( newLine() | |||
:wikitext('Recovers ') | |||
:node( newColor('value', args.mana) ) | |||
:wikitext(' Mana over ') | |||
:node( newColor('value', args.duration) ) | |||
:wikitext(' Seconds') | |||
) | |||
end | |||
if args.effect then | |||
group | |||
:node( newLine() | |||
:wikitext('Lasts ') | |||
:node( newColor('value', args.duration) ) | |||
:wikitext(' Seconds') | |||
) | |||
end | |||
group | |||
:node( newLine() | |||
:wikitext('Consumes ') | |||
:node( newColor('value', args.chargeUse) ) | |||
:wikitext(' of ') | |||
:node( newColor('value', args.chargeCap) ) | |||
:wikitext(' Charges on use') | |||
) | |||
if args.effect then | |||
group = newGroup('textwrap') | |||
:node( newLine() | |||
:node( newColor('mod', args.effect) ) | |||
) | |||
end | |||
container:node(group) | |||
elseif args.type == 'microtrans' then | |||
group = newGroup() | |||
if args.subtype or args.stackSize then | |||
group | |||
:node( newLine() | |||
:wikitext(args.subtype) | |||
) | |||
if args.stackSize then | |||
group | |||
:node( newLine() | |||
:wikitext('Stack Size: ') | |||
:node( newColor('value', args.stackSize) ) | |||
) | |||
end | |||
end | |||
group = newGroup('textwrap') | |||
:node( newLine() | |||
:node( newColor('mod', args.effect) ) | |||
) | |||
container:node(group) | |||
end | |||
return tostring(container) | return tostring(container) | ||
end | end | ||
return p | return p |
Revision as of 03:14, 22 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 getArgs
function p.main(frame)
if not getArgs then
getArgs = require('Module:Arguments').getArgs
end
local args = getArgs(frame, {
wrappers = 'Template:Sandbox',
trim = false
})
return p._main(args)
end
function p._main(args)
local container = mw.html.create('div')
local group
local function newGroup()
return mw.html.create('span')
:attr('class', 'itemboxstatsgroup')
end
local function newLine(extraClasses)
return mw.html.create('span')
:attr('class', 'itemboxstatsgroupline ' .. extraClasses)
end
local function newColor(label, text)
if text == nil or text == '' then
return nil
end
return mw.html.create('span')
:attr('class', 'text-' .. label)
:wikitext(text)
end
args.type = string.lower(args.type)
if args.type == 'weapon' then
group = newGroup()
:node( newLine()
:wikitext(args.subtype)
)
if args.physical then
group
:node( newLine()
:wikitext('Physical Damage: ')
:node( newColor('value', args.physical) )
)
end
if args.fire or args.cold or args.lightning then
if not doConcat then
doConcat = require('Module:Concat')._main
end
group
:node( newLine()
:wikitext('Elemental Damage: ')
:wikitext(
doConcat({
tostring( newColor('fire', args.fire) ),
tostring( newColor('cold', args.cold) ),
tostring( newColor('lightning', args.lightning) )
})
)
)
end
if args.chaos then
group
:node( newLine()
:wikitext('Chaos Damage: ')
:node( newColor('chaos', args.chaos) )
)
end
group
:node( newLine()
:wikitext('Critical Strike Chance: ')
:node( newColor('value', args.critChance) )
)
:node( newLine()
:wikitext('Attacks per Second: ')
:node( 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
:node( newLine()
:wikitext('Chance to Block: ')
:node( newColor('value', args.blockChance) )
)
end
if args.armour then
group
:node( newLine()
:wikitext('Armour: ')
:node( newColor('value', args.armour) )
)
end
if args.evasion then
group
:node( newLine()
:wikitext('Evasion: ')
:node( newColor('value', args.evasion) )
)
end
if args.energyShield then
group
:node( newLine()
:wikitext('Energy Shield: ')
:node( newColor('value', args.energyShield) )
)
end
container:node(group)
end
elseif args.type == 'map' then
if args.mapLevel then
group = newGroup()
:node( newLine()
:wikitext('Map Level: ')
:node( newColor('value', args.mapLevel) )
)
if args.itemQuantity then
group
:node( newLine()
:wikitext('Item Quantity: ')
:node( newColor('value', args.itemQuantity) )
)
end
container:node(group)
end
elseif args.type == 'jewel' then
if args.radius then
group = newGroup()
:node( newLine()
:wikitext('Radius: ')
:node( newColor('value', args.radius) )
)
container:node(group)
end
elseif args.type == 'currency' then
group = newGroup()
:node( newLine()
:wikitext('Stack Size: ')
:node( newColor('value', args.stackSize) )
)
container:node(group)
if args.effect then
group = newGroup('textwrap')
:node( newLine()
:node( newColor('mod', args.effect) )
)
container:node(group)
end
elseif args.type == 'flask' then
group = newGroup()
if args.life then
group
:node( newLine()
:wikitext('Recovers ')
:node( newColor('value', args.life) )
:wikitext(' Life over ')
:node( newColor('value', args.duration) )
:wikitext(' Seconds')
)
end
if args.mana then
group
:node( newLine()
:wikitext('Recovers ')
:node( newColor('value', args.mana) )
:wikitext(' Mana over ')
:node( newColor('value', args.duration) )
:wikitext(' Seconds')
)
end
if args.effect then
group
:node( newLine()
:wikitext('Lasts ')
:node( newColor('value', args.duration) )
:wikitext(' Seconds')
)
end
group
:node( newLine()
:wikitext('Consumes ')
:node( newColor('value', args.chargeUse) )
:wikitext(' of ')
:node( newColor('value', args.chargeCap) )
:wikitext(' Charges on use')
)
if args.effect then
group = newGroup('textwrap')
:node( newLine()
:node( newColor('mod', args.effect) )
)
end
container:node(group)
elseif args.type == 'microtrans' then
group = newGroup()
if args.subtype or args.stackSize then
group
:node( newLine()
:wikitext(args.subtype)
)
if args.stackSize then
group
:node( newLine()
:wikitext('Stack Size: ')
:node( newColor('value', args.stackSize) )
)
end
end
group = newGroup('textwrap')
:node( newLine()
:node( newColor('mod', args.effect) )
)
container:node(group)
end
return tostring(container)
end
return p