FANDOM


--Module de centralisation des tooltipText, les tooltip en eux meme sont dans leur module respectif
 
local p = {}
 
local Shared = require('Module:Shared')
 
--local function to build an object link
local function getObjLink(obj, newName, namespace)
 
  local ret = '[['
  if(namespace ~= nil) then
    ret = ret..namespace..':'
  end
  if(obj.Link ~= nil) then
    ret = ret..obj.Link..'|'
  else
    ret = ret..obj.Name..'|'
  end
  if(newName ~= nil) then
    ret = ret..newName
  else
    ret = ret..obj.Name
  end
  ret = ret..']]'
 
  return ret
end
 
--Returns the table containing the asked type of objects, the module name, the tooltip class and the image size
local function getObjDB(objType, conclave)
 
  local retTable = nil
  local retDBName = nil
  local retTooltipClass = nil
 
  local objDB = nil
  if(objType == 'Ability') then
    if(conclave) then
      retDBName = 'Module:Ability/Conclave/data'
    else
      retDBName = 'Module:Ability/data'
    end
    objDB = mw.loadData(retDBName)
    retTable = objDB['Ability']
    retTooltipClass = 'ability-tooltip'
  elseif(objType == 'Arcane') then
    retDBName = 'Module:Arcane/data'
    objDB = mw.loadData(retDBName)
    retTable = objDB['Arcanes']
    retTooltipClass = 'arcane-tooltip'
  elseif(objType == 'Avionic') then
    retDBName = 'Module:Avionics/data'
    objDB = mw.loadData(retDBName)
    retTable = {}
    --Merge tables
    for k, v in Shared.skpairs(objDB['Battle']) do
      retTable[k] = v
    end
    for k, v in Shared.skpairs(objDB['Integrated']) do
      retTable[k] = v
    end
    for k, v in Shared.skpairs(objDB['Tactical']) do
      retTable[k] = v
    end
    retTooltipClass = 'avionic-tooltip'
  elseif(objType == 'Mod') then
    retDBName = 'Module:Mods/data'
    objDB = mw.loadData(retDBName)
    retTable = objDB['Mods']
    retTooltipClass = 'mod-tooltip'
  elseif(objType == 'Warframe') then
    if(conclave) then
      retDBName = 'Module:Warframes/Conclave/data'
    else
      retDBName = 'Module:Warframes/data'
    end
    objDB = mw.loadData(retDBName)
    retTable = objDB['Warframes']
    retTooltipClass = 'warframe-tooltip'
  elseif(objType == 'Weapon') then
    if(conclave) then
      retDBName = 'Module:Weapons/Conclave/data'
    else
      retDBName = 'Module:Weapons/data'
    end
    objDB = mw.loadData(retDBName)
    retTable = objDB['Weapons']
    retTooltipClass = 'weapon-tooltip'
  end
  --Add the other object database
 
  return retTable, retDBName, retTooltipClass
end
 
--For Template calls
function p.tooltipText(frame)
 
  local objName = frame.args[1]
  local objType = frame.args[2]
  local newName = frame.args[3]
  local conclave = frame.args[4]
  local iconless = frame.args[5]
 
  return p._tooltipText(objName, objType, newName, conclave, iconless)
end
 
--For Module calls
function p._tooltipText(objName, objType, newName, conclave, iconless)
 
  --Check input parameters
  if(objName == nil or objName == '') then
    --Print Error message
    return '<span style="color:red;">Error:</span> Please enter an object name.[[Category:Tooltip Error]]'
  end
  if(objType == nil or objType == '') then
    --Print Error message
    return '<span style="color:red;">Error:</span> Please enter an object type.[[Category:Tooltip Error]]'
  end
  --Format input parameters
  if(newName == '') then
    newName = nil
  end
  if(conclave == '') then
    conclave = false
  end
  if(iconless == '') then
    iconless = false
  end
  --Load corresponding data
  local objDB, objDBName, objTooltipClass = getObjDB(objType, conclave)
  --Check if data has been found
  if(objDB == nil) then
    return '<span style="color:red;">Error:</span> Unknow object type.[[Category:Tooltip Error]]'
  end
 
  --Search object by key
  local obj = objDB[objName]
  --If object wasn't found, try again with the object.Name
  if(obj == nil) then
    local keySet = Shared.getKeySet(objDB)
    local nbObjects= #keySet
    local i = 1
    while(i <= nbObjects and obj == nil) do
      local tmp = objDB[keySet[i]]
      if(tmp.Name == objName) then
        obj = tmp
      end
      i = i + 1
    end
  end
  --Check if a weapon was found
  if(obj == nil) then
    --Print Error message
    return '<span style="color:red;">Error:</span> The object named "'..objName..'" couldn\'t be found in [['..objDBName..']].[[Category:Tooltip Error]]'
  end
  --Build link text
  local textLink = nil
  if(conclave) then
    textLink = getObjLink(obj, newName, 'Conclave')
  else
    textLink = getObjLink(obj, newName, nil)
  end
  --Build tooltip span caller
  local ret = '<span class="'..objTooltipClass..'" data-param="'..objName..'"'
  if(conclave) then
    ret = ret..' data-param2="true"'
  end
 
  ret = ret..' style="white-space:pre;">'..textLink
  --Add image
  if(not iconless) then
    --Recover image
    local image = nil
    if(objType == 'Ability') then
      image = obj.WhiteIcon
    elseif(objType == 'Mod') then
      image = 'Icon Mods.png'
    elseif(objType == 'Warframe') then
      image = obj.Portrait
    else
      image = obj.Image
    end
    --Set a default image if nul
    if(image == nil) then
      image = 'Panel.png'
    end
    ret = ret..' [[File:'..image..'|x19px|link='
    if(conclave) then
      ret = ret..'Conclave:'
    end
    if(obj.Link ~= nil) then
      ret = ret..obj.Link
    else
      ret = ret..obj.Name
    end
    ret = ret..']]'
  end
  ret = ret..'</span>'
 
  return ret
end
 
 
return p
* DIVULGATION : Certains des liens ci-dessus sont des liens d'affiliation, ce qui signifie que, sans frais supplémentaires pour vous, Fandom percevra une commission si vous cliquez et effectuez un achat.Sauf mention contraire, le contenu de la communauté est disponible sous licence CC-BY-SA .