Module:Func
From SWGoH Wiki
Jump to navigationJump to searchDocumentation for this module may be created at Module:Func/doc
local str = require( "Module:String" )
local call = {}
function split(inputstr, sep)
if sep == nil then
sep = ","
end
local t={}
for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
table.insert(t, trim(str))
end
return t
end
function trim(s)
return s:match( "^%s*(.-)%s*$" )
end
function replace(source_str,pattern,replace,count)
if source_str == '' or pattern == '' then
return source_str
end
pattern = mw.ustring.gsub( pattern, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" )
replace = mw.ustring.gsub( replace, "%%", "%%%%" ); --Only need to escape replacement sequences.
local result
if count ~= nil then
result = mw.ustring.gsub( source_str, pattern, replace, count )
else
result = mw.ustring.gsub( source_str, pattern, replace )
end
return result
end
function call.getEnergy(p)
battle = p.args[1]
if(string.find(battle,"Cantina") == nil) then
if(string.find(battle,"Fleet")== nil) then
if(string.find(battle,"Dark Side") == nil) then
if(string.find(battle,"Light Side")==nil) then
if(string.find(battle,"Mod")==nil) then
return ""
else
return "Mod Energy"
end
else
return "Energy"
end
else
return "Energy"
end
else
return "Ship Energy"
end
else
return "Cantina Energy"
end
end
function call.splitRewards(a)
list = split(a.args[1],",")
if(a.args.line == nil) then
line = "single"
else
line = a.args.line
end
if(a.args.type == nil) then
type = "item"
else
type = a.args.type
end
result = ""
for i, item in ipairs(list) do
if(type == "item") then
if(line == "single") then
result = result.."<div class='tooltip' style='float:left;margin-left:5px;'>[[File:Game-Icon-"..item..".png|30px|link="..item.."]]<span class='tooltiptext'>"..item.."</span></div>"
else
result = result.."<div class='tooltip' style='margin-left:5px;'>[[File:Game-Icon-"..item..".png|30px|link="..item.."]]<span class='tooltiptext'>"..item.."</span></div><br />"
end
elseif(type == "shard") then
if(line == "single") then
result = result.."<div style='float:left;margin-left:5px;'>[[File:Shard-Character-"..item..".png|30px|"..item.."|link="..item.."]] [["..item.."]]</div>"
else
result = result.."<div style='margin-left:5px;'>[[File:Shard-Character-"..item..".png|30px|"..item.."|link="..item.."]] [["..item.."]]</div>"
end
elseif(type == "blueprint") then
if(line == "single") then
result = result.."<div style='float:left;margin-left:5px;'>[[File:Shard-Ship-"..item..".png|35px|"..item.."|link="..item.."]] [["..item.."]]</div>"
else
result = result.."<div style='margin-left:5px;'>[[File:Shard-Ship-"..item..".png|35px|"..item.."|link="..item.."]] [["..item.."]]</div>"
end
elseif(type == "gear") then
if(line == "single") then
result = result.."<div class='tooltip' style='float:left;margin-left:5px;'>[[File:Gear-"..item..".png|40px|link="..item.."]]<span class='tooltiptext'>"..item.."</span></div>"
else
result = result.."<div class='tooltip' style='margin-left:5px;'>[[File:Gear-"..item..".png|40px|link="..item.."]]<span class='tooltiptext'>"..item.."</span></div><br />"
end
elseif(type == "mod") then
modArr = split(item," ")
if(#modArr == 6) then
tier = split(modArr[6],"-")
if(modArr[5] == "Mystery") then
img = modArr[5].."-"..modArr[3].." "..modArr[4].."-"..tier[1]
else
img = modArr[3].." "..modArr[4].."-"..modArr[5].."-"..tier[1]
end
else
tier = split(modArr[5],"-")
if(modArr[4] == "Mystery") then
img = modArr[4].."-"..modArr[3].."-"..tier[1]
else
img = modArr[3].."-"..modArr[4].."-"..tier[1]
end
end
link = modArr[1].." "..modArr[2].." "..modArr[3].." "..modArr[4]
rarity = modArr[2]
if(line == "single") then
result = result.."<div class='tooltip' style='float:left;margin-left:5px;'><div>[[File:Indicator-Mod Dots-"..rarity..".png|30px|link=]]</div><div style='margin-top:-3px;'>[[File:Mod-"..img..".png|30px|link=]]</div><span class='tooltiptext'>"..item.."</span></div>"
else
result = result.."<div class='tooltip' style='margin-left:5px;'><div>[[File:Indicator-Mod Dots-"..rarity..".png|30px|link=]]</div><div style='margin-top:-3px;'>[[File:Mod-"..img..".png|30px|link=]]</div><span class='tooltiptext'>"..item.."</span></div><br />"
end
end
end
return result
end
function call.splitGear(a)
list = split(a.args[1],",")
result=""
for i, gear in ipairs(list) do
result = result.."<div class='tooltip' style='float:left;margin-left:5px;'>[[File:Gear-"..gear..".png|40px|link="..gear.."]]<span class='tooltiptext'>"..gear.."</span></div>"
end
return result
end
function call.getSeason(a)
list = split(a.args[1],"-")
if(string.find(list[1],"Season") == nil) then
if(table.maxn(list) > 1) then
return list[1].." - "..list[2]
else
return list[1]
end
end
if(a.args.week == "Yes") then
if(table.maxn(list) > 2) then
return list[2].." - "..list[3]
else
return list[2]
end
else
return list[1]
end
end
function call.getTB(a)
list = split(a.args[1],"&")
if(table.maxn(list) > 1) then
return "[["..list[2].."]] or [["..list[1].."]]"
else
return "[["..list[1].."]]"
end
end
function call.eventNames(n)
name = n.args[1]
link = n.args.link
if(string.find(name,"vs") ~= nil) then
if(string.find(name,"TBD") ~= nil) then
name = "Galactic Challenge-TBD"
elseif(string.find(name,"Bespin") ~= nil) then
name = "Bespin Galactic Challenge"
elseif(string.find(name,"Coruscant") ~= nil) then
name = "Coruscant Galactic Challenge"
elseif(string.find(name,"Dathomir") ~= nil) then
name = "Dathomir Galactic Challenge"
elseif(string.find(name,"Death Star") ~= nil) then
name = "Death Star Galactic Challenge"
elseif(string.find(name,"Endor") ~= nil) then
name = "Endor Galactic Challenge"
elseif(string.find(name,"Geonosis") ~= nil) then
name = "Geonosis Galactic Challenge"
elseif(string.find(name,"Hoth") ~= nil) then
name = "Hoth Galactic Challenge"
elseif(string.find(name,"Ilum") ~= nil) then
name = "Ilum Galactic Challenge"
elseif(string.find(name,"Jakku") ~= nil) then
name = "Jakku Galactic Challenge"
elseif(string.find(name,"Kamino") ~= nil) then
name = "Kamino Galactic Challenge"
elseif(string.find(name,"Kashyyyk") ~= nil) then
name = "Kashyyyk Galactic Challenge"
elseif(string.find(name,"Lothal") ~= nil) then
name = "Lothal Galactic Challenge"
elseif(string.find(name,"Malachor") ~= nil) then
name = "Malachor Galactic Challenge"
elseif(string.find(name,"Nevarro") ~= nil) then
name = "Nevarro Galactic Challenge"
elseif(string.find(name,"Takodana") ~= nil) then
name = "Takodana Galactic Challenge"
elseif(string.find(name,"Tatooine") ~= nil) then
name = "Tatooine Galactic Challenge"
end
end
if(string.find(name,"&") ~= nil) then
name = replace(name,"&","and")
elseif(string.find(name,": ") ~= nil) then
if(link == nil) then
name = replace(name,": ","-")
else
nameArr = split(name,":")
name = nameArr[1].." Galactic Challenge"
end
elseif(name == "Endurance" or name == "Home One" or name == "Executrix") then
name = name.." Fleet Mastery"
elseif(name == "Bespin" or name == "Coruscant" or name == "Dathomir" or name == "Death Star" or name == "Endor" or name == "Hoth" or name == "Ilum" or name == "Jakku" or name == "Kamino" or name == "Kashyyyk" or name == "Lothal" or name == "Malachor" or name == "Nevarro" or name == "Takodana" or name == "Tatooine" or name == "Geonosis") then
name = name.." Galactic Challenge"
end
return name
end
function call.accelDate(n)
rDate = n.args[1]
aDate = ""
if(string.find(rDate,"Jan") ~= nil) then
aDate = "January "
elseif(string.find(rDate,"Feb") ~= nil) then
aDate = "February "
elseif(string.find(rDate,"Mar") ~= nil) then
aDate = "March "
elseif(string.find(rDate,"Apr") ~= nil) then
aDate = "April "
elseif(string.find(rDate,"May") ~= nil) then
aDate = "May "
elseif(string.find(rDate,"Jun") ~= nil) then
aDate = "June "
elseif(string.find(rDate,"Jul") ~= nil) then
aDate = "July "
elseif(string.find(rDate,"Aug") ~= nil) then
aDate = "August "
elseif(string.find(rDate,"Sep") ~= nil) then
aDate = "September "
elseif(string.find(rDate,"Oct") ~= nil) then
aDate = "October "
elseif(string.find(rDate,"Nov") ~= nil) then
aDate = "November "
elseif(string.find(rDate,"Dec") ~= nil) then
aDate = "December "
end
return aDate
end
return call