Module:Loops: Difference between revisions

From IdleOn MMO Wiki
mNo edit summary
mNo edit summary
 
(28 intermediate revisions by the same user not shown)
Line 1: Line 1:
local loops = {}
local loops = {}
 
local NumberFormater = require('Module:NumberFormater')
local function explode(list, delimiter)
local Utility = require("Module:Utility")
    if delimiter == nil then
local VariablesLua = mw.ext.VariablesLua
delimiter = "%s"
end
t = {}
for str in string.gmatch(list, "([^" .. delimiter .. "]+)") do
table.insert(t, str)
end
return t
end


function loops.slabOrderList(frame)  
function loops.slabOrderList(frame)  
Line 19: Line 11:
for i = 1, #tableList do
for i = 1, #tableList do
if tableList[i] == orderItem then
if tableList[i] == orderItem then
mw.ext.VariablesLua.vardefine('Slaborder', i - 1)
VariablesLua.vardefine('Slaborder', i - 1)
return i - 1
return i - 1
end
end
end
end
mw.ext.VariablesLua.vardefine('Slaborder', -1)
VariablesLua.vardefine('Slaborder', -1)
return -1
return -1 .. "[[Category:Using Loops Module - SlabOrderList]]"
end
end


local function numFormater(arg)
if arg == "Lots" then
return n
end
local n = tonumber(arg)
    if n >= 10^18 then
        return string.format("%.2fQQ", n / 10^18)
    elseif n >= 10^15 then
        return string.format("%.2fQ", n / 10^15)
    elseif n >= 10^12 then
        return string.format("%.2fT", n / 10^12)
    elseif n >= 10^9 then
        return string.format("%.2fB", n / 10^9)
    elseif n >= 10^6 then
        return string.format("%.2fM", n / 10^6)
    elseif n >= 10^4 then
        return string.format("%.1fK", n / 10^3)
    else
        return tostring(n)
    end
end
function loops.bitsFormater(frame)
function loops.bitsFormater(frame)
local bitTotal = tonumber(frame.args.Bits)
local bitTotal = tonumber(frame.args.Bits)
Line 70: Line 41:
     ret = ret .. 'Total: ' .. bitTotal .. ', Part: ' .. bitPart .. ', Color: White.'
     ret = ret .. 'Total: ' .. bitTotal .. ', Part: ' .. bitPart .. ', Color: White.'
     end
     end
     return string.format("%d", frame.args.Bits)
     return string.format("%d", frame.args.Bits) .. "[[Category:Using Loops Module - BitsFormater]]"
end
end


function numGreaterThanStrings(numStr, compStr)
end


function loops.formatCDC(frame)
function loops.formatCDC(frame)
Line 82: Line 50:
     local ret = "<span style='display: none;'>" .. 1/val .. "</span>" ..
     local ret = "<span style='display: none;'>" .. 1/val .. "</span>" ..
           "{{#tip-text:1 in " .. string.format("3,3d", n) .. "|<span class='text-only'>" .. (tonumber(val) * 100) .. "%</span>}}"
           "{{#tip-text:1 in " .. string.format("3,3d", n) .. "|<span class='text-only'>" .. (tonumber(val) * 100) .. "%</span>}}"
     return ret
     return ret .. "[[Category:Using Loops Module - FormatCDC]]"
end
end


function loops.coinDisplay(frame)
local n = "20000" --frame.args.coins
local ret = {}
local coins = {"Copper", "Silver", "Gold", "Platinum", "Dementia", "Void", "Lustre", "Starfire", "Dreadlo", "Godshard", "Sunder", "Tydal", "Marbiglass", "Orberal", "Eclipse"}
local coininc = 1
local stringpiece = [=[[[File:%s Coin.png|link=]] %s]=]
repeat
-- Set denomVStr to remaining n if on last type, or get last 2 for current denom.
local denomVStr = coininc >= #coins and n or n:sub(-2)
--denomVStr = denomVStr:gsub("%s+", "")
if tonumber(denomVStr) > 0 then
ret[#ret+1] = string.format(stringpiece, "coins[coininc]", "denomVStr")
n = n:sub(1, -1-#denomVStr)
end
coininc = coininc + 1
until(n == "")
return ret:concat(" ")
end


function loops.bossAttacks(frame)
function loops.bossAttacks(frame)
local frameArgs = frame.args
local frameArgs = frame.args
local attackList = explode(frameArgs.attackList,",")
local attackList = Utility.explode(frameArgs.attackList,",")
local damageList = explode(frameArgs.damageList,",")
local damageList = Utility.explode(frameArgs.damageList,",")
local ret = ""
local ret = ""
Line 121: Line 70:
end
end


return ret
return ret .. "[[Category:Using Loops Module - BossAttacks]]"
end
end


Line 127: Line 76:
local defenseCalc = require("Module:DefenseCalc")
local defenseCalc = require("Module:DefenseCalc")
local frameArgs = frame.args
local frameArgs = frame.args
local attackList = explode(frameArgs.attackList,",")
local attackList = Utility.explode(frameArgs.attackList,",")
local damageList = explode(frameArgs.damageList,",")
local damageList = Utility.explode(frameArgs.damageList,",")
local ret = ""
local ret = ""
Line 143: Line 92:
end
end


return ret
return ret .. "[[Category:Using Loops Module - BossAttacksInfobox]]"
end
end


Line 151: Line 100:
local delimiter, list1, list2, list3, list4, returnDelim
local delimiter, list1, list2, list3, list4, returnDelim
if(frameArgs.delimiter) then delimiter = frameArgs.delimiter else delimiter = "," end
if(frameArgs.delimiter) then delimiter = frameArgs.delimiter else delimiter = "," end
if(frameArgs.list1) then list1 = explode(frameArgs.list1, delimiter) end
if(frameArgs.list1) then list1 = Utility.explode(frameArgs.list1, delimiter) end
if(frameArgs.list2) then list2 = explode(frameArgs.list2, delimiter) end
if(frameArgs.list2) then list2 = Utility.explode(frameArgs.list2, delimiter) end
if(frameArgs.list3) then list3 = explode(frameArgs.list3, delimiter) end
if(frameArgs.list3) then list3 = Utility.explode(frameArgs.list3, delimiter) end
if(frameArgs.list4) then list4 = explode(frameArgs.list4, delimiter) end
if(frameArgs.list4) then list4 = Utility.explode(frameArgs.list4, delimiter) end
if(frameArgs.returnDelimiter) then returnDelim = frameArgs.returnDelimiter end
if(frameArgs.returnDelimiter) then returnDelim = frameArgs.returnDelimiter end
local replaceString = frameArgs.replaceString
local replaceString = frameArgs.replaceString
Line 168: Line 117:
ret = ret .. tStr
ret = ret .. tStr
end
end
return ret
return ret .. "[[Category:Using Loops Module - ParseLoop]]"
end
end


Line 174: Line 123:
local ret = ""
local ret = ""
local frameArgs = frame.args
local frameArgs = frame.args
local reqs = explode(frameArgs.reqs, ",")
local reqs = Utility.explode(frameArgs.reqs, ",")
local areas = explode(frameArgs.areas, ",")
local areas = Utility.explode(frameArgs.areas, ",")
local reqsString = frameArgs.reqsString
local icon = frameArgs.icon == "Boss" and "Boss Skull" or string.format("%s Skill Icon", frameArgs.icon)
local reqsString = [=[<td>[[File:%s.png|30px|link=]] %s</td>]=]
local numFormString = [[<span class="simple-tooltip simple-tooltip-inline tooltipstered" data-simple-tooltip="&ltp&&gt&ltspan class='text-only'&gt%s&lt/span&gt&lt/p&gt">%s</span>]]
for i = 1, #reqs do
for i = 1, #reqs do
if(i > 1 ) then ret = ret .. "</tr><tr>" end
if(i > 1 ) then ret = ret .. "</tr><tr>" end
local tStr = reqsString
local fullformat = NumberFormater.formatwithseperator(reqs[i])
tStr = tStr:gsub("%(1%)", reqs[i])
local shortformat = NumberFormater.formatnumber(reqs[i])
local numform = reqs[i]:len() > 4 and string.format(numFormString, fullformat, shortformat) or reqs[i]
local tStr = string.format(reqsString, icon, numform)
if(areas[i] == "NULL") then  
if(areas[i] == "NULL") then  
tStr = tStr .. "<td>This portal connects to nothing, or returns to a random default location.</td>"
tStr = tStr .. "<td>This portal connects to nothing, or returns to a random default location.</td>"
Line 187: Line 141:
tStr = tStr .. "<td>[[Worlds#" .. areas[i] .. "|" .. areas[i] .. "]]</td>"
tStr = tStr .. "<td>[[Worlds#" .. areas[i] .. "|" .. areas[i] .. "]]</td>"
end
end
ret = ret .. tStr
ret = ret .. tStr
end
end
ret = ret .. "</tr>"
ret = ret .. "</tr>[[Category:Using Loops Module - PortalRowLoop]]"
return ret
return ret
end
end


VariablesLua = mw.ext.VariablesLua
 
function loops.numberNabber(frame)
function loops.numberNabber(frame)
local ret = ""
return "[[Category:Using Loops Module - NumberNabber]]"
local frameArgs = frame.args
local searchText = frameArgs.searchText
local temp = frameArgs.list
-- Remove image size and tooltip data
local list = explode(temp:gsub("%d+px","px"):gsub('data\-simple\-tooltip.+\>"\>', ''), ",")
local n
for i = 1, #list do
if(list[i]:find(searchText, 1, true)) then
-- These are for testing and should be disabled when not in use.
--local varValue = list[i]:sub(1, 2)
--VariablesLua.vardefine( "nabberTest", varValue )
if (list[i]:sub(1, 2):match("%d")) then
n = tonumber(list[i]:match('%d[%d.,]*'))
elseif(list[i]:find(": ", 1, true)) then
n = tonumber(list[i]:match('.*%f[%d.](%d*%.?%d+)'))
end
if (n >= 10^4) then
ret = "<div class='tooltip'>" .. numFormater(n) .. "<span>" .. n .. "</span></div>"
else
ret = n
end
if(list[i]:match("[Cc]raft")) then ret = ret .. " (Crafted)" end
if(list[i]:match("[Bb]uy")) then ret = ret .. " (Bought)" end
return ret
end
end
return ret
end
end


Line 232: Line 158:
local frameArgs = frame.args
local frameArgs = frame.args
local delimiter = frameArgs.delimiter
local delimiter = frameArgs.delimiter
local list = explode(frameArgs.list, delimiter)
local list = Utility.explode(frameArgs.list, delimiter)
local cols
local cols
local template = frameArgs.template
local template = frameArgs.template
Line 240: Line 166:
ret = ret .. frame:expandTemplate{title = template, args = { list[i] } };
ret = ret .. frame:expandTemplate{title = template, args = { list[i] } };
end
end
ret = ret .. '</div>'
ret = ret .. '</div>[[Category:Using Loops Module - OneVariableTemplateParser]]'
return ret
return ret
end
end


return loops
return loops

Latest revision as of 02:26, 15 March 2024

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

local loops = {}
local NumberFormater = require('Module:NumberFormater')
local Utility = require("Module:Utility")
local VariablesLua = mw.ext.VariablesLua

function loops.slabOrderList(frame) 
	local orderItem = frame.args.Item
	local bigList = frame.args.OrderList
	local tableList = explode(bigList, ',')
	
	for i = 1, #tableList do
		if tableList[i] == orderItem then
			VariablesLua.vardefine('Slaborder', i - 1)
			return i - 1
		end
	end
	
	VariablesLua.vardefine('Slaborder', -1)
	return -1 .. "[[Category:Using Loops Module - SlabOrderList]]"
end

function loops.bitsFormater(frame)
	local bitTotal = tonumber(frame.args.Bits)
	local bitPart = 0
	local ret = ''
	-- {{#tip-text:{{formatnum:{{#expr:{{#expr:({{{1}}}) / 1E+15}} round 1}}}} Q| <span class="text-only">{{formatnum:{{{1}}}}}</span> }}
    if bitTotal > 1e72 then
    	bitPart = math.floor(bitTotal / 1e72)
    	ret = ret .. 'Total: ' .. bitTotal .. ', Part: ' .. bitPart .. ', Color: Blue.'
    elseif bitTotal > 1e54 then
    	bitPart = math.floor(bitTotal / 1e54)
    	ret = ret .. 'Total: ' .. bitTotal .. ', Part: ' .. bitPart .. ', Color: Purple.'
    elseif bitTotal > 1e36 then
    	bitPart = math.floor(bitTotal / 1e36)
    	ret = ret .. 'Total: ' .. bitTotal .. ', Part: ' .. bitPart .. ', Color: Red.'
    elseif bitTotal > 1e18 then
    	bitPart = math.floor(bitTotal / 1e18)
    	ret = ret .. 'Total: ' .. bitTotal .. ', Part: ' .. bitPart .. ', Color: Green.'
    else
    	bitPart = bitTotal
    	ret = ret .. 'Total: ' .. bitTotal .. ', Part: ' .. bitPart .. ', Color: White.'
    end
    return string.format("%d", frame.args.Bits) .. "[[Category:Using Loops Module - BitsFormater]]"
end


function loops.formatCDC(frame)
    local val = frame.args.value
    local n = 1/tonumber(val)
    local ret = "<span style='display: none;'>" .. 1/val .. "</span>" ..
          "{{#tip-text:1 in " .. string.format("3,3d", n) .. "|<span class='text-only'>" .. (tonumber(val) * 100) .. "%</span>}}"
    return ret .. "[[Category:Using Loops Module - FormatCDC]]"
end


function loops.bossAttacks(frame)
	local frameArgs = frame.args
	local attackList = Utility.explode(frameArgs.attackList,",")
	local damageList = Utility.explode(frameArgs.damageList,",")
	
	local ret = ""
	for i = 1, #attackList do
		ret = ret .. "<dt>" .. attackList[i]
		if(damageList[i])
    	then
			ret = ret .. "</dt><dd><span class='simple-tooltip simple-tooltip-inline tooltipstered' data-simple-tooltip='&lt;span class=&apos;text-only&apos;&gt;"..damageList[i] .. "&lt;/span&gt;'>" .. numFormater(damageList[i]) .. "</span></dd>"
		else
			ret = ret .. "</dt><dd>N.A.</dd>"
		end
	end

	return ret .. "[[Category:Using Loops Module - BossAttacks]]"
end

function loops.bossAttacksInfoBox(frame)
	local defenseCalc = require("Module:DefenseCalc")
	local frameArgs = frame.args
	local attackList = Utility.explode(frameArgs.attackList,",")
	local damageList = Utility.explode(frameArgs.damageList,",")
	
	local ret = ""
	for i = 1, #attackList do
		ret = ret .. "<div class='pi-item pi-data pi-item-spacing pi-border-color' data-source=''><h3 class='pi-data-label pi-secondary-font' style='width: 80px;'>" .. attackList[i] .. "</h3><div class='pi-data-value pi-font'>"
		if(damageList[i]) 
        then 
        	local atkDamage = tonumber(damageList[i])
			local defZero = defenseCalc.calc({ args = { Attack = atkDamage } })
            ret = ret .. "<span class='simple-tooltip simple-tooltip-inline tooltipstered' data-simple-tooltip='&lt;span class=&apos;text-only&apos;&gt;" .. damageList[i] .. "&lt;/span&gt;'>" .. numFormater(damageList[i]) .. "</span>" .. "<span class='simple-tooltip simple-tooltip-inline tooltipstered' data-simple-tooltip='&lt;span class=&apos;text-only&apos;&gt;Required defense for zero damage: " .. defZero .. "&lt;/span&gt;'> (" .. numFormater(defZero) .. ")</span></div></div>"
        else 
            ret = ret .. "N/A</div></div>"
        end
	end

	return ret .. "[[Category:Using Loops Module - BossAttacksInfobox]]"
end

function loops.parseLoop(frame)
	local ret = ""
	local frameArgs = frame.args
	local delimiter, list1, list2, list3, list4, returnDelim
	if(frameArgs.delimiter) then delimiter = frameArgs.delimiter else delimiter = "," end
	if(frameArgs.list1) then list1 = Utility.explode(frameArgs.list1, delimiter) end
	if(frameArgs.list2) then list2 = Utility.explode(frameArgs.list2, delimiter) end
	if(frameArgs.list3) then list3 = Utility.explode(frameArgs.list3, delimiter) end
	if(frameArgs.list4) then list4 = Utility.explode(frameArgs.list4, delimiter) end
	if(frameArgs.returnDelimiter) then returnDelim = frameArgs.returnDelimiter end
	local replaceString = frameArgs.replaceString
	
	for i = 1, #list1 do
		if(i > 1 and returnDelim) then ret = ret .. returnDelim end
		local tStr = replaceString
		if(list1) then tStr = tStr:gsub("%(1%)", list1[i]) end
		if(list2) then tStr = tStr:gsub("%(2%)", list2[i]) end
		if(list3) then tStr = tStr:gsub("%(3%)", list3[i]) end
		if(list4) then tStr = tStr:gsub("%(4%)", list4[i]) end
		
		ret = ret .. tStr
	end
	return ret .. "[[Category:Using Loops Module - ParseLoop]]"
end

function loops.portalRowLoop(frame)
	local ret = ""
	local frameArgs = frame.args
	local reqs = Utility.explode(frameArgs.reqs, ",")
	local areas = Utility.explode(frameArgs.areas, ",")
	local icon = frameArgs.icon == "Boss" and "Boss Skull" or string.format("%s Skill Icon", frameArgs.icon)
	local reqsString = [=[<td>[[File:%s.png|30px|link=]] %s</td>]=]
	local numFormString = [[<span class="simple-tooltip simple-tooltip-inline tooltipstered" data-simple-tooltip="&ltp&&gt&ltspan class='text-only'&gt%s&lt/span&gt&lt/p&gt">%s</span>]]
	
	for i = 1, #reqs do
		if(i > 1 ) then ret = ret .. "</tr><tr>" end
		local fullformat = NumberFormater.formatwithseperator(reqs[i])
		local shortformat = NumberFormater.formatnumber(reqs[i])
		local numform = reqs[i]:len() > 4 and string.format(numFormString, fullformat, shortformat) or reqs[i]
		local tStr = string.format(reqsString, icon, numform)
		
		if(areas[i] == "NULL") then 
			tStr = tStr .. "<td>This portal connects to nothing, or returns to a random default location.</td>"
		else
			tStr = tStr .. "<td>[[Worlds#" .. areas[i] .. "|" .. areas[i] .. "]]</td>"
		end
		
		ret = ret .. tStr
	end
	ret = ret .. "</tr>[[Category:Using Loops Module - PortalRowLoop]]"
	
	return ret
end


function loops.numberNabber(frame)
	return "[[Category:Using Loops Module - NumberNabber]]"
end

function loops.oneVariableTemplateParser(frame)
	local ret = ""
	local frameArgs = frame.args
	local delimiter = frameArgs.delimiter
	local list = Utility.explode(frameArgs.list, delimiter)
	local cols
	local template = frameArgs.template
	if(frameArgs.colCount) then cols = frameArgs.colCount else cols = 3 end
	if(frameArgs.divClass) then ret = '<div class="' .. frameArgs.divClass .. '">' else ret = '<div class="DetailboxGrid">' end
	for i = 1, #list do
		ret = ret .. frame:expandTemplate{title = template, args = { list[i] } };
	end
	ret = ret .. '</div>[[Category:Using Loops Module - OneVariableTemplateParser]]'
	return ret
end

return loops