Module:SmwTables

From SWGoH Wiki
Jump to navigationJump to search

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

local p = {}

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 p.fixLinks(a)
  list = split(a.args[1],",")
 
  result = ""
  for i, link in ipairs(list) do
    if(table.maxn(list) > 0) then
      if(table.maxn(list) > 1) then
        if(i == table.maxn(list)) then
          if(link == "Category:Character") then
             result = result.."[[:Category:Character|All]]"
          else
            result = result..'[[:'..link..']]'
          end
        else
          if(link == "Category:Character") then
             result = result.."[[:Category:Character|All]] • "
          else
            result = result..'[[:'..link..']] • '
          end
        end
      else
        if(link == "Category:Character") then
          result = result.."[[:Category:Character|All]]"
        else
          result = result..'[[:'..link..']]'
        end
      end
    end
  end
  return result
end  

function p.splitList(a)
  list = split(a.args[1],",")
 
  result = ""
  for i, word in ipairs(list) do
    if(table.maxn(list) > 0) then
      if(table.maxn(list) > 1) then
        if(i == table.maxn(list)) then
           result = result..word
        else
          result = result..word.." • "
        end
      else
        result = word
      end
    end
  end
  
  return result
end


function p.effectImage(a)
  list = split(a.args[1],",")
  result = ""
  for i, effect in ipairs(list) do
    if(string.find(effect, "Protection Up"))then
      effect = "Protection Up"
    end
    result = result.."<div class='tooltip' style='float:left;margin:0 5px 5px 0;'>[[File:Status Effect-"..effect..".png|35px|link="..effect.."]]<span class='tooltiptext'>"..effect.."</span></div>"
  end
  return result
end


function p.crewImage(a)
  list = split(a.args[1],",")

  result = ""
  for i, unit in ipairs(list) do
    result = result.."<div class='tooltip' style='float:left;margin:0 5px 5px 0;'><div style='overflow:hidden;border:2px solid gold;border-radius:50%;'>[[File:Unit-Character-"..unit.."-portrait.png|40px|link="..unit.."]]</div><span class='tooltiptext'>"..unit.."</span></div>"
  end

  return result

end

return p