Module:List

-- - -- Module:List -- This Module is used to store list templates of all kinds. -- -- TABLE OF CONTENTS --  *Unordered List (Unused as of now) --  *Template: Plainlist --  *Template: Resource list --  *Template: Image List --  *Template: Horizontal List - local p = {}

local getArgs = require('Module:Arguments').getArgs local string = require('Module:String') local table = require('Module:Table') local yesno = require('Module:Yesno')

local statname = require('Module:Statname') local sprite = require('Module:Sprite')

local mergeArgsSyntax = require('Module:Arguments').mergeArgsSyntax local item = require('Module:Item') local processResource = require('Module:Item')._resourceDisplay local processItem = require('Module:Item')._itemDisplay

--List Type Table local listTypes = { ['circle']='circle', ['square']='square', ['disc']='disc', ['none']='none', ['n']='none', ['d']='disc', ['sq']='square', ['s']='square', ['c']='circle', }

- -- Unordered List (not a template) -- -- - function p.list(frame) local args = getArgs(frame) local text = args[1] local color = args["color"] local listType = args["type"]

return p._list(text, color, listType) end

function p._list(text, color, listType) local split = mw.text.split(string.gsub(text, '\*', ''), "%s*\*%s*"); if not color then color = '' end if not listType then listType = 'square' end return string.wrapHtml{ split, '', { style={ ["list-style-type"]=listType; color=color; }		}	} end

- --Template:Plainlist -- --makes a list without any spacing in the lines, indistinguishable from a ' list' - function p.plainlist(frame) args = getArgs(frame) text = args[1] class = args["class"] style = args["style"] indent = args["indent"] return p._plainlist(text, class, style, indent) end

function p._plainlist(text, class, style, indent) local styleObj = {} local div = mw.html.create("div"):addClass("plainlist") if class then div:addClass(class) end if style then div:cssText(style) end if indent then indent = tonumber(indent) * 1.6 div:css("margin-left", indent.."em") end -- Don't mess with the s! they're needed to force a new line before the wiki list syntax div:wikitext(	..text) return div end

-- For making a horizontal list (seperated by •)

function p.horizontal(frame) local args = getArgs(frame) local list = args[1] local bracket = yesno(args["bracket"] or args["brackets"],false) local hlist = mw.html.create('div'):addClass('hlist'):css("margin-left", "2em") if list:sub(1,1) == '*' then -- Add newlines to support lists properly hlist :newline :wikitext( list ) :newline else hlist:wikitext( list ) end return '\n' .. tostring(hlist) end

-- Template: Resource List -- -- For making a formatted list of items, mostly used in infoboxes ("Raw Materials" section)

function p.resourceList(frame) local args = getArgs(frame) local text = mergeArgsSyntax(args) local listType = args["list_type"] or args["listtype"] or args["ls"] local img = yesno(args["image"] or args["img"] or args["i"], true) local nolink = yesno(args["nl"] or args["nolink"], false) local noerror = yesno(args["ne"] or args["noerror"] or args["error"] or args["e"] or args["no_error"]) local ignoreOdds = yesno(args["ignoreodds"], false) return string.pcall(p._resourceList, text, listType, img, nolink, noerror, args, ignoreOdds) end function p._resourceList(text, listType, img, nolink, noerror, args, ignoreOdds) if text[1] == "none" then return "none" end for i = 1,#text,1 do		text[i] = string.wrapHtml{ --function stored in Module:Item._resourceDisplay processResource(text[i], img, nolink, noerror, ignoreOdds), '', { style={ ["margin-bottom"]="0px"; ["margin"]="0px"; ["padding-bottom"]="0px"; }			}		}	end --List Type Table local listTypes = { ['circle']='circle', ['square']='square', ['disc']='disc', ['none']='none', ['n']='none', ['d']='disc', ['sq']='square', ['s']='square', ['c']='circle', }

return string.wrapHtml{ text, '', { style={ ["list-style-type"]=listTypes[listType] and listTypes[listType] or "none"; ["margin"]="0px"; ["line-height"]="inherit"; }		}	} end

- -- Template:Image List -- -- Produces a list of items alongside their images - function p.imageList(frame) local args = getArgs(frame) local text = mergeArgsSyntax(args) local listType = args["list_type"] or args["listtype"] or args["ls"] local img = yesno(args["image"] or args["img"] or args["i"], true) local nolink = yesno(args["nl"] or args["nolink"], false) local noerror = yesno(args["ne"] or args["noerror"] or args["error"] or args["e"] or args["no_error"]) local ignoreOdds = yesno(args["ignoreodds"], false) return string.pcall(p._imageList, text, listType, img, nolink, noerror, args, ignoreOdds) end function p._imageList(text, listType, img, nolink, noerror, args, ignoreOdds) if text[1] == "none" then return "none" end for i = 1,#text,1 do		text[i] = string.wrapHtml{ --function stored in Module:Item._itemDisplay processItem(text[i], img, nolink, noerror, ignoreOdds), '', { style={ ["margin-bottom"]="0px"; ["margin"]="0px"; ["padding-bottom"]="0px"; }			}		}	end --List Type Table local listTypes = { ['circle']='circle', ['square']='square', ['disc']='disc', ['none']='none', ['n']='none', ['d']='disc', ['sq']='square', ['s']='square', ['c']='circle', }

return string.wrapHtml{ text, '', { style={ ["list-style-type"]=listTypes[listType] and listTypes[listType] or "none"; ["margin"]="0px"; ["line-height"]="inherit"; }		}	} end

- -- Template:Mob List -- -- Produces a list of mobs alongsite their sprites. - function p.mobList(frame) local args = getArgs(frame) local text = mergeArgsSyntax(args, 1) local listType = args["list_type"] or args["type"] or args["t"] local noError = args['noerror'] or args['ne'] or args['noerr'] return p._mobList(text, listType, noError) end

function p._mobList(text, listType, noError) local addPlainlist = p._plainlist for i=1,#text,1 do		-- get alterante text to display local alt if text[i]:match(";") then mob, alt = text[i]:match("(.+);(.+)") else mob = text[i] end -- add images text[i] = string.wrapHtml{ sprite.spriteGenerator('mob', mob, alt, true, noError), '', { style={ ["margin-bottom"]="0px"; ["margin"]="0px"; ["padding-bottom"]="0px"; }			}		}	end --List Type Table local listTypes = { ['circle']='circle', ['square']='square', ['disc']='disc', ['none']='none', ['n']='none', ['d']='disc', ['sq']='square', ['s']='square', ['c']='circle', }

return string.wrapHtml{ text, '', { style={ ["list-style-type"]=listTypes[listType] and listTypes[listType] or "none"; ["margin"]="0px"; ["line-height"]="inherit"; }		}	} end

- -- Template:NPC List -- -- Produces a list of NPCs alongsite their sprites. - function p.npcList(frame) local args = getArgs(frame) local text = mergeArgsSyntax(args, 1) local listType = args["list_type"] or args["type"] or args["t"] local noErr = yesno(args['noerr'] or args['noe'], false) return p._npcList(text, listType, noErr) end

function p._npcList(text, listType, noErr) local addPlainlist = p._plainlist listType = listType or "none" for i=1,#text,1 do		-- get alterante text to display local alt if text[i]:match(";") then npc, alt = text[i]:match("(.+);(.+)") else npc = text[i] end -- add images text[i] = string.wrapHtml{ sprite.spriteGenerator('npc', npc, alt, true, noError), '', { style={ ["margin-bottom"]="0px"; ["margin"]="0px"; ["padding-bottom"]="0px"; }			}		}	end

return string.wrapHtml{ text, '', { style={ ["list-style-type"]=listTypes[listType] and listTypes[listType] or "none"; ["margin"]="0px"; ["line-height"]="inherit"; }		}	} end

- -- Template:Location List -- -- Produces a list of locations alongsite their sprites. - function p.locationList(frame) local args = getArgs(frame) local text = mergeArgsSyntax(args, 1) local listType = args["list_type"] or args["type"] or args["t"] local noError = args['noerror'] or args['ne'] or args['noerr'] return p._locationList(text, listType, noError) end

function p._locationList(text, listType, noError) local addPlainlist = p._plainlist listType = listType or "none" local ret = table.tableUtil for i, v in ipairs(text) do		-- get alterante text to display local alt if v:match("[^%%];") then location, alt = v:match("(.+)%s*;%s*(.*)") else location = v		end v = v:gsub('%%;', ';') if not location:match('catacombs') then local result = sprite.spriteGenerator('location', location, alt, true, noError) -- add images if result ~= '' then ret:push(string.wrapHtml{					result or v,					'', {						style={							["margin-bottom"]="0px";							["margin"]="0px";							["padding-bottom"]="0px";						}					}				}) end else ret:push(string.makeLink(alt or location, location)) end end --List Type Table local listTypes = { ['circle']='circle', ['square']='square', ['disc']='disc', ['none']='none', ['n']='none', ['d']='disc', ['sq']='square', ['s']='square', ['c']='circle', }	return string.wrapHtml{ ret, '', { style={ ["list-style-type"]=listTypes[listType] and listTypes[listType] or "none"; ["margin"]="0px"; ["line-height"]="inherit"; }		}	} end

- -- Template:Stats List -- -- Produces a list of stats alongsite the amounts. - function p.statsList(frame) local args = getArgs(frame) local text = mergeArgsSyntax(args, 1) local short = yesno(args["short"], false) local superShort = args["short"] == "ss" return p._statsList(text, short, superShort) end function p._statsList(...) local text, short, superShort = checkArgs({ 'table', { 'boolean', nilOk=true }, { 'boolean', nilOk=true } }, ...) local addPlainlist = p._plainlist local listType = "none" local noError = false local ret = table.tableUtil for i, v in ipairs(text) do		local success, result = pcall(statname._getStatName, v, nil, short, superShort) if not success then result = noError and '' or string.error(result) end -- add stats if result ~= '' then ret:push(string.wrapHtml{				result or v,				'', {					style={						["margin-bottom"]="0px";						["margin"]="0px";						["padding-bottom"]="0px";					}				}			}) end end return string.wrapHtml{ ret, '', { style={ ["list-style-type"]=listTypes[listType] and listTypes[listType] or "none"; ["margin"]="0px"; ["line-height"]="inherit"; }		}	} end

return p