Feed The Beast Wiki

Follow the Feed The Beast Wiki on Discord or Mastodon!

READ MORE

Feed The Beast Wiki
m (Taking is giving the in the world of Lua)
m (Protected "Module:NIA" ([Edit=Editors and administrators] (indefinite) [Move=Editors and administrators] (indefinite)))
 
(11 intermediate revisions by 2 users not shown)
Line 9: Line 9:
 
end
 
end
 
local text = ""
 
local text = ""
for item in mw.text.gsplit(args[1], '%s*,%s*') do
+
local escaped = string.gsub(args[1], '\\,', '|')
  +
for item in mw.text.gsplit(escaped, '%s*,%s*') do
text = text .. f:callParserFunction('#icon', {item = item, size = 16, mod = args.mod})
 
  +
local deescaped = string.gsub(item, '|', ',')
 
text = text .. f:callParserFunction('#icon', {"", item = deescaped, size = 16, mod = args.mod})
 
end
 
end
 
return text
 
return text
Line 16: Line 18:
   
 
function shuffle(list)
 
function shuffle(list)
math.randomseed(os.time())
+
math.randomseed(os.time() + math.random(100))
 
local indices = {}
 
local indices = {}
 
for i = 1, #list do
 
for i = 1, #list do
Line 45: Line 47:
 
if string.find(item, " '''·''' %[%[") then
 
if string.find(item, " '''·''' %[%[") then
 
silly = item
 
silly = item
for subitem in mw.text.gsplit(item, "%[%[") do
+
for subitem in mw.text.gsplit(item, " '''·''' %[%[") do
if string.find(subitem, "%]%]") then
+
if string.find(subitem, "</span>") then
table.insert(section, "[[" .. subitem)
+
table.insert(section, (subitem:gsub("-item\">", "", 1):gsub("</span>", "")))
 
else
 
else
subitem = subitem:gsub("&nbsp;'''·'''&#32;", "")
+
if string.find(subitem, "%[%[") then
if subitem ~= "" then
+
table.insert(section, (subitem:gsub("&nbsp;'''·'''&#32;", "")))
  +
else
table.insert(section, "<span class=\"nowrap navbox-item\">" .. subitem)
 
  +
table.insert(section, "[[" .. subitem:gsub("&nbsp;'''·'''&#32;", ""))
 
end
 
end
 
end
 
end

Latest revision as of 03:17, 24 August 2020

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 = ""
        local escaped = string.gsub(args[1], '\\,', '|')
        for item in mw.text.gsplit(escaped, '%s*,%s*') do
                local deescaped = string.gsub(item, '|', ',')
                text = text .. f:callParserFunction('#icon', {"", item = deescaped, size = 16, mod = args.mod})
        end
        return text
end

function shuffle(list)
	math.randomseed(os.time() + math.random(100))
	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 = {}
	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, "&nbsp;'''·'''&#32;%[%[") do
				if string.find(subitem, "</span>") then
					table.insert(section, (subitem:gsub("-item\">", "", 1):gsub("</span>", "")))
				else
					if string.find(subitem, "%[%[") then
						table.insert(section, (subitem:gsub("&nbsp;'''·'''&#32;", "")))
					else
						table.insert(section, "[[" .. subitem:gsub("&nbsp;'''·'''&#32;", ""))
					end
				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;")
end

return p