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 - local p = {}

local getArgs = require('Module:Arguments').getArgs local mergeArgsSyntax = require('Module:Arguments').mergeArgsSyntax local setColor = require('Module:Color')._colorTemplates local string = require('Module:String') local table = require('Module:Table') local addThousandSep = string._formatNum local yesno = require('Module:Yesno') 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 = mergeArgsSyntax(args) for i, v in ipairs(list) do		list[i] = string.parseDualArg(v) end return table.concat(list, " • ") 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"]) return string.pcall(p._resourceList, text, listType, img, nolink, noerror, args) end function p._resourceList(text, listType, img, nolink, noerror, args) 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), '', { 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"]) return string.pcall(p._imageList, text, listType, img, nolink, noerror, args) end function p._imageList(text, listType, img, nolink, noerror, args) 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), '', { 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"] return string.pcall(p._mobList, text, listType) end

function p._mobList(text, listType, args) local makeSprite = require('Module:Sprite')._mobSprite 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{ makeSprite(mob, alt, true), '', { 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"] return frame:preprocess(p._npcList(text, listType)) end function p._npcList(text, listType, args) local makeSprite = require('Module:Sprite')._npcSprite 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{ makeSprite(npc, alt, true), '', { 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: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 makeSprite = require('Module:Sprite')._locationSprite local addPlainlist = p._plainlist listType = listType or "none" local ret = table.tableUtil mw.logObject(text) for i, v in ipairs(text) do		-- get alterante text to display local alt if v:match(";") then location, alt = v:match("(.+);(.*)") else location = v		end if not location:match('catacombs') then local success, result = pcall(makeSprite, location, alt, true) if not success then result = noError and '' or string.error(result) end -- 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

return p