Feed The Beast Wiki

Follow the Feed The Beast Wiki on Discord or Mastodon!

READ MORE

Feed The Beast Wiki
m (Only with Lua could it get confused what to do first)
m (Woop woop it's the sound of the bullshit alarm)
Line 42: Line 42:
 
end
 
end
 
section = {}
 
section = {}
  +
bs = "false"
 
for item in mw.text.gsplit(args[1], "<span class=\"nowrap navbox") do
 
for item in mw.text.gsplit(args[1], "<span class=\"nowrap navbox") do
 
if string.find(item, "&nbsp;'''·'''&#32;%[%[") then
 
if string.find(item, "&nbsp;'''·'''&#32;%[%[") then
Line 49: Line 50:
 
table.insert(section, "[[" .. subitem:gsub("&nbsp;'''·'''&#32;", ""))
 
table.insert(section, "[[" .. subitem:gsub("&nbsp;'''·'''&#32;", ""))
 
else
 
else
--subitem = subitem:gsub("-item\">", "", 1):gsub("&nbsp;'''·'''&#32;", "")
+
table.insert(section, --[["<span class=\"nowrap navbox-item\">" ..--]] (subitem:gsub("&nbsp;'''·'''&#32;", ""):gsub("</span>", "")))
 
end
--if subitem ~= "" then
 
  +
end
table.insert(section, --[["<span class=\"nowrap navbox-item\">" ..--]] (subitem:gsub("&nbsp;'''·'''&#32;", "")))
 
  +
for i, thing in ipairs(section) do
--end
 
 
if thing == "-item\">" then
  +
--bullshit detected
  +
table.remove(section, i)
  +
bs = "true"
 
end
 
end
 
end
 
end
Line 62: Line 67:
 
end
 
end
 
end
 
end
return table.concat(shuffle(section), "&nbsp;'''·'''&#32;")
+
return table.concat(shuffle(section), "&nbsp;'''·'''&#32;") .. "BS Alarm: " .. bs
 
end
 
end
   

Revision as of 01:34, 5 March 2016

Documentation for this module may be created at Module:NIA/doc

local p = {}

p.items = function( f )
        local args = f.args or f
        if f == mw.getCurrentFrame() and args[1] == nil then
                args = f:getParent().args
        else
                f = mw.getCurrentFrame()
        end
        local text = ""
        for item in mw.text.gsplit(args[1], '%s*,%s*') do
                text = text .. f:callParserFunction('#icon', {item = item, size = 16, mod = args.mod})
        end
        return text
end

function shuffle(list)
	math.randomseed(os.time())
	local indices = {}
	for i = 1, #list do
		indices[#indices+1] = i
	end
	local shuffled = {}
	for i = 1, #list do
		local index = math.random(#indices)
		local value = list[indices[index]]
		table.remove(indices, index)
		shuffled[#shuffled+1] = value
	end
	return shuffled
end

p.rand = function(f)
	local args = f.args or f
	if f == mw.getCurrentFrame() and args[1] == nil then
		args = f:getParent().args
	else
		f = mw.getCurrentFrame()
	end
	if args[1] == "" then
		return ""
	end
	section = {}
	bs = "false"
	for item in mw.text.gsplit(args[1], "<span class=\"nowrap navbox") do
		if string.find(item, "&nbsp;'''·'''&#32;%[%[") then
			silly = item
			for subitem in mw.text.gsplit(item, "%[%[") do
				if string.find(subitem, "%]%]") then
					table.insert(section, "[[" .. subitem:gsub("&nbsp;'''·'''&#32;", ""))
				else
					table.insert(section, --[["<span class=\"nowrap navbox-item\">" ..--]] (subitem:gsub("&nbsp;'''·'''&#32;", ""):gsub("</span>", "")))
				end
			end
			for i, thing in ipairs(section) do
				if thing == "-item\">" then
					--bullshit detected
					table.remove(section, i)
					bs = "true"
				end
			end
		else
			item = item:gsub("-item\">", "", 1):gsub("&nbsp;'''·'''&#32;", "")
			if item ~= "" then
				table.insert(section, "<span class=\"nowrap navbox-item\">" .. item)
			end
		end
	end
	return table.concat(shuffle(section), "&nbsp;'''·'''&#32;") .. "BS Alarm: " .. bs
end

return p