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 loader = require('Module:Loader') local string, table, yesno, statname, sprite, item = loader.require('String', 'Table', 'Yesno', 'Statname', 'Sprite', 'Item')

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

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

local function generateList(list_, type_) return string.wrapHtml{ list_, '', { style={ ['list-style-type'] = listTypes[type_] or 'none'; ['margin'] = '0'; ['line-height'] = 'inherit'; }		}	} end

local function generateListItem(res, liststyle) local styles = table.concat{ 'margin-bottom: 0;', 'margin: 0;', 'padding-bottom: 0;', liststyle or '', }	return string.wrapHtml{ res, '', { style = styles }	} end

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

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['type'] or args['ls'] or args['t'] 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) local liststyle = args['list_style'] or args['liststyle'] or args['style'] local noImgPad = yesno(args['noimgpad'], false) return string.pcall(p._resourceList, text, listType, img, nolink, noerror, args, ignoreOdds, noImgPad, liststyle) end

function p._resourceList(text, listType, img, nolink, noerror, args, ignoreOdds, noImgPad, liststyle) if text[1] == "none" then return "none" end for i = 1,#text,1 do		--function stored in Module:Item._resourceDisplay text[i] = generateListItem(processResource(text[i], img, nolink, noerror, ignoreOdds, noImgPad), liststyle) end return generateList(text, listType) 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['type'] or args['ls'] or args['t'] 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) local liststyle = args['list_style'] or args['liststyle'] or args['style'] local noImgPad = yesno(args['noimgpad'], false)

return string.pcall(p._imageList, text, listType, img, nolink, noerror, args, ignoreOdds, noImgPad, liststyle) end function p._imageList(text, listType, img, nolink, noerror, args, ignoreOdds, noImgPad, liststyle)

if text[1] == "none" then return "none" end

for i = 1,#text,1 do		--function stored in Module:Item._itemDisplay text[i] = generateListItem(processItem(text[i], img, nolink, noerror, ignoreOdds, noImgPad), liststyle) end

return generateList(text, listType) 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['listtype'] or args['type'] or args['ls'] or args['t'] local noError = args['noerror'] or args['ne'] or args['noerr'] local liststyle = args['list_style'] or args['liststyle'] or args['style'] local noImgPad = args['noimgpad'] return p._mobList(text, listType, noError, noImgPad, liststyle) end

function p._mobList(text, listType, noError, noImgPad, liststyle) 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] = generateListItem(sprite.spriteGenerator('mob', mob, alt, true, noError, noImgPad), liststyle) end return generateList(text, listType) 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['listtype'] or args['type'] or args['ls'] or args['t'] local noError = args['noerror'] or args['ne'] or args['noerr'] local liststyle = args['list_style'] or args['liststyle'] or args['style'] local noImgPad = args['noimgpad'] return p._npcList(text, listType, noError, noImgPad, liststyle) end

function p._npcList(text, listType, noError, noImgPad, liststyle) 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] = generateListItem(sprite.spriteGenerator('npc', npc, alt, true, noError, noImgPad), liststyle) end

return generateList(text, listType) 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['listtype'] or args['type'] or args['ls'] or args['t'] local noError = args['noerror'] or args['ne'] or args['noerr'] local liststyle = args['list_style'] or args['liststyle'] or args['style'] local noImgPad = args['noimgpad'] return p._locationList(text, listType, noError, noImgPad, liststyle) end

function p._locationList(text, listType, noError, noImgPad, liststyle) local addPlainlist = p._plainlist listType = listType or "none" local ret = {} 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, noImgPad) -- add images if result ~= '' then table.push(ret, generateListItem(result or v), liststyle) end else table.push(ret, string.makeLink(alt or location, location)) end end return generateList(ret, listType) 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" local liststyle = args['list_style'] or args['liststyle'] or args['style'] return p._statsList(text, short, superShort, liststyle) end

function p._statsList(text, short, superShort) local addPlainlist = p._plainlist local listType = "none" local noError = false local ret = {} 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 table.push(ret, generateListItem(result or v), liststyle) end end return generateList(ret, listType) end

- -- Template:Gemstone slots -- -- Produces a list of gemstone slots - function p.gemstoneSlots(frame) local args = getArgs(frame) local list = mergeArgsSyntax(args, 1) return p._gemstoneSlots(list) end

function p._gemstoneSlots(list) local noError = false, num, slotName, slotPrice -- nil string check needed for DPL if not list or not list[1] or list[1] == 'nil' then return "" end local statData = { hp = statname._getstatdata("hp"), def = statname._getstatdata("def"), mf = statname._getstatdata("mf"), int = statname._getstatdata("int"), ms = statname._getstatdata("ms"), pristine = statname._getstatdata("pristine"), str = statname._getstatdata("str"), }	local slots = { -- Normal Slots ruby = { icon=statData.hp.character, color=statData.hp.color, text="Ruby Slot" }, amethyst = { icon=statData.def.character, color=statData.def.color, text="Amethyst Slot" }, jade = { icon=statData.mf.character, color=statData.mf.color, text="Jade Slot" }, sapphire = { icon=statData.int.character, color=statData.int.color, text="Sapphire Slot" }, amber = { icon=statData.ms.character, color=statData.ms.color, text="Amber Slot" }, topaz = { icon=statData.pristine.character, color=statData.pristine.color, text="Topaz Slot" }, jasper = { icon=statData.str.character, color=statData.str.color, text="Jasper Slot" }, -- Special Slots combat = { icon="⚔", color="#A00", text="Combat Slot - Accepts: Ruby, Amethyst, Sapphire, Jasper" }, offensive = { icon="☠", color="#55F", text="Offensive Slot - Accepts: Sapphire, Jasper" }, defensive = { icon="☤", color="#5F5", text="Defensive Slot - Accepts: Ruby, Amethyst" }, mining = { icon="✦", color="#A0A", text="Mining Slot - Accepts: Jade, Amber, Topaz" }, universal = { icon="❂", color="white", text="Universal Slot - Accepts: Any" }, }	local ret = {} for i, str in ipairs(list) do		-- seperate out the number if str:match('^([%d,%-%?]+%.?[%d,%-]*x?) (.*)') then num, slotName = str:match('^([%d,%-%?]+%.?[%d,%-]*x?) (.*)') else num = 1 slotName = str end if slotName:match('^(.*) &(.*)&') then slotName, slotPrice = slotName:match('^(.*) &(.*)&') end local slot = slots[slotName:lower] -- add stats if result ~= '' then -- If we have multiple of same slot specified by a number in front, duplicate it that many times for i = 1,num do				ret[#ret+1] = string.wrapHtml{ slot.icon, ' ', {						class='minetip', style={ ['display'] = 'inline-flex'; ['width'] = '25px'; ['height'] = '25px'; ['line-height'] = '25px'; ['color'] = slot.color; ['border'] = '1px solid currentColor'; ['border-radius'] = '3px'; ['justify-content'] = 'center'; ['align-items'] = 'center'; },						['data-minetip-title']=slot.text, ['data-minetip-text']=slotPrice or '', }				}			end end end return string.wrapHtml{ table.concat(ret, ""), "div", {			style={ ['display'] = 'flex'; ['gap'] = '3px'; ['justify-content'] = 'center'; }		}	} end

return p