--Author: ADDRMeridan
local p = {}
--IMPORT
local AvionicsData = mw.loadData( 'Module:Avionics/data' )
local Shared = require( "Module:Shared" )
local Icon = require( "Module:Icon" )
local Tooltip = require('Module:Tooltip')
local Version = require('Module:Version')
--CONSTANT
local cellColor_Boost = "background-color:#bedfe8; color:black;"
local cellColor_Unavailable = "background-color:#f6dddd; color:black;"
function p.getAvionic(avioName)
if(avioName ~= nil) then
local avionic = AvionicsData[avioName]
if(avionic ~= nil) then
return avionic
end
end
return nil
end
local function checkAvionic(avio, avioName)
if(avio == nil or type(avio) ~= 'table') then
return p.getAvionic(avioName)
elseif(type(avio) == 'table') then
return avio
end
end
local function getAvionicLink(avionic, avioName, newName, namespace)
local ret = nil
local avio = checkAvionic(avionic, avioName)
if(namespace == nil) then
namespace = ''
end
if(avio ~= nil) then
if(avio.Link and newName ~= nil) then
ret = "[["..namespace..avio.Link.."|"..newName.."]]"
elseif(avionic.Link ~= nil) then
ret = "[["..namespace..avio.Link.."|"..avio.Name.."]]"
elseif(newName ~= nil) then
ret = "[["..namespace..avio.Name.."|"..newName.."]]"
else
ret = "[["..namespace..avio.Name.."|"..avio.Name.."]]"
end
end
return ret
end
local function _getAvionicsListPerType(typeName)
local ret = nil
local first = true
for key, Avionic in Shared.skpairs(AvionicsData[typeName]) do
if(first) then
ret = Tooltip._tooltipText(Avionic.Name, 'Avionic')
first = false
else
ret = ret.." • "..Tooltip._tooltipText(Avionic.Name, 'Avionic')
end
end
return ret
end
function p.getAvionicsListPerType(frame)
local typeName = frame.args ~= nil and frame.args[1] or nil
if(typeName ~= nil) then
return _getAvionicsListPerType(typeName)
else
return 'Error: Please enter a type name.'
end
end
local function _getIntegratedListPerTarget(target)
local ret = nil
local first = true
for key, Avionic in Shared.skpairs(AvionicsData) do
if(Avionic.Type == "Integrated" and Avionic.Target == target) then
if(first) then
ret = Tooltip._tooltipText(Avionic.Name, 'Avionic')
first = false
else
ret = ret.." • "..Tooltip._tooltipText(Avionic.Name, 'Avionic')
end
end
end
return ret
end
function p.getIntegratedListPerTarget(frame)
local target = frame.args ~= nil and frame.args[1] or nil
if(target ~= nil) then
return _getIntegratedListPerTarget(target)
else
return 'Error: Please enter a target name.'
end
end
local function _getTacticalListPerTarget(target)
local ret = nil
local first = true
for key, Avionic in Shared.skpairs(AvionicsData) do
if(Avionic.Type == "Tactical" and Avionic.Target == target) then
if(first) then
ret = Tooltip._tooltipText(Avionic.Name, 'Avionic')
first = false
else
ret = ret.." • "..Tooltip._tooltipText(Avionic.Name, 'Avionic')
end
end
end
return ret
end
function p.getTacticalListPerTarget(frame)
local target = frame.args ~= nil and frame.args[1] or nil
if(target ~= nil) then
return _getTacticalListPerTarget(target)
else
return 'Error: Please enter a target name.'
end
end
local function _getBattleListPerSlot(slot)
local ret = nil
local first = true
for key, Avionic in Shared.skpairs(AvionicsData) do
if(Avionic.Type == "Battle" and Avionic.Slot == slot) then
if(first) then
ret = Tooltip._tooltipText(Avionic.Name, 'Avionic')
first = false
else
ret = ret.." • "..Tooltip._tooltipText(Avionic.Name, 'Avionic')
end
end
end
return ret
end
function p.getBattleListPerSlot(frame)
local slot = frame.args ~= nil and frame.args[1] or nil
slot = tonumber(slot)
if(slot ~= nil) then
return _getBattleListPerSlot(slot)
else
return 'Error: Please enter a slot number.'
end
end
local function _getValue(avioName, fieldName, frame)
local ret = nil
local avio = p.getAvionic(avioName)
if(avio == nil) then
ret = "Avionic '"..avioName.."' not found"
else
fieldName = string.upper(fieldName)
if(fieldName == "COOLDOWN") then
ret = avio.Cooldown
elseif(fieldName == "DESCRIPTION") then
if(frame ~= nil) then
ret = frame:preprocess(avio.Description)
else
ret = avio.Description
end
elseif(fieldName == "IMAGE") then
if(avio.Image == nil or avio.Image == "") then
ret = "Panel.png"
else
ret = avio.Image
end
elseif(fieldName == "INTRODUCED") then
if(avio.Introduced ~= nil) then
ret = Version._getVersionLink(avio.Introduced)
else
ret = nil
end
elseif(fieldName == "LINK") then
if(avio.Link ~= nil) then
ret = avio.Link
else
ret = avio.Name
end
elseif(fieldName == "MANUFACTURER") then
ret = Icon._Manuf(avio.Manufacturer, nil, "text")
elseif(fieldName == "NAMEEN") then
ret = avio.NameEN:gsub(" ", "_")
elseif(fieldName == "RARITY") then
ret = avio.Rarity
elseif(fieldName == "SLOT") then
slot = {"Defense","Offense","Super"}
if(Avionic.Slot ~= nil) then
if slot[Avionic.Slot] ~= nil then
return slot[Avionic.Slot]
else
if Avionic.Slot==slot[1]
or Avionic.Slot==slot[2]
or Avionic.Slot==slot[3] then
return Avionic.Slot
--ret = avio.Slot
else
return nil
end
end
else
return nil
end
elseif(fieldName == "FLUX") then
if Avionic.Flux == nil then
return ({Defense=25,Offense=50,Super=100})[ValueOf(Avionic, "slot")]
else
return Avionic.Flux
end
elseif(fieldName == "TYPE") then
local avioFamily = avio.Type
if(avioFamily == "Battle") then
ret = "De Combat"
elseif(avioFamily == "Integrated") then
ret = "Intégrée"
elseif(avioFamily) then
ret = "Stratégique"
else
ret = "Inconnu"
end
else
ret = "Field '"..fieldName.."' not found"
end
end
return ret
end
function p.tooltip(frame)
local avioName = frame.args ~= nil and frame.args[1] or nil
local avio = p.getAvionic(avioName)
if(avio == nil) then
return "Data not found"
end
local result = '{| class="Tooltip" \n|-\n| style="padding:0px;"|\n{| class="Sub"\n|-\n| class="Image"| [[File:'.._getValue(avio.Name, "IMAGE")..'|160px]]\n|-\n| class="Spacer"|'
result = result..'\n|-\n| class="Title"|'..avioName..'\n|-\n| class="Spacer"|'
result = result..'\n|-\n| style="background-color:#0D1B1C; color:#eeeeee; padding:10px; font-size:13px; line-height:16px;"|<span style="font-weight:bold;font-size:14px;">'..avio.Rarity..'</span><br/>'..avio.Description..'\n|}\n|}'
return result
end
function p.getValue(frame)
local avioName = frame.args ~= nil and frame.args[1] or nil
local fieldName = frame.args ~= nil and frame.args[2] or nil
return _getValue(avioName, fieldName, frame)
end
function p.tooltipImage(frame)
local Name = frame.args ~= nil and frame.args[1]
if(Name == nil) then
return '<span style="color:red;">Error:</span> Unknowed avionic name. [[Category:'..'Tooltip Error]]'
end
local Avionic = p.getAvionic(Name)
if(Avionic == nil) then
return '<span style="color:red;">Error:</span> Unknowed avionic name. [[Category:'..'Tooltip Error]]'
end
local ret = {}
table.insert(ret, '<span class="avionic-tooltip" data-param="'..Name..'" data-name="imageonly">')
table.insert(ret, '[[File:'.._getValue(Name, "IMAGE")..'|114px|link='.._getValue(Name, "LINK")..']]</span>')
return table.concat(ret)
end
function p.buildAvionicTableByType(frame)
local searchedType = frame.args ~= nil and frame.args[1] or nil
if(searchedType == nil) then
return "Error: Unknowed type."
end
local ret = {}
for key, Avionic in Shared.skpairs(AvionicsData) do
if(Avionic.Type == searchedType) then
local newFrame = {args = {Avionic.Name}}
table.insert(ret, p.tooltipImage(newFrame))
end
end
return '{| border="1" cellpadding="1" cellspacing="1" class="article-table"\n|'..table.concat(ret)..'\n|}'
end
--[===[
Unused functions
--Returns the max natural rank and the first corresponding manufacturer
local function getIntegratedMaxNaturalRank(avio)
local maxNatural = nil
local corrManuf = nil
for manufName, manufData in Shared.skpairs(avio.Manufacturer, true) do
if(maxNatural == nil) then
maxNatural = manufData.MaxNaturalRank
corrManuf = manufName
elseif(manufData.MaxNaturalRank ~= nil) then
if(maxNatural < manufData.MaxNaturalRank) then
maxNatural = manufData.MaxNaturalRank
corrManuf = manufName
end
end
end
return maxNatural, corrManuf
end
local function getIntegratedStats(avio, maxRank)
local ret = ""
for manufName, manufData in Shared.skpairs(avio.Manufacturer) do
ret = ret..'\n|-'
ret = ret..'\n| '..Icon._Manuf(manufName, nil, nil, 30)
ret = ret..'\n| style="font-weight:bold;" | Maison '..manufName..'<br/>Rangs: '..manufData.MaxNaturalRank
ret = ret..'\n| '..Shared.asPercent(manufData.InitialBonus, 1, true)..'<br/>Drain: '..manufData.InitialDrain
--Print Manuf stats
local manufMaxRank = manufData.MaxNaturalRank + 3
for j = 1, maxRank, 1 do
if(j > manufMaxRank) then
ret = ret..'\n| style="text-align:center;'..cellColor_Unavailable..'" | —'
else
local bonus = Shared.asPercent(manufData.InitialBonus * (j + 1), 1, true)
local minDrain = manufData.InitialDrain + math.max(j - 3, 0)
local maxDrain = math.min(manufData.InitialDrain + j, manufData.InitialDrain + manufData.MaxNaturalRank)
if(j <= manufData.MaxNaturalRank) then
ret = ret..'\n| '
else
ret = ret..'\n| style="'..cellColor_Boost..'" | '
end
ret = ret..bonus..'<br/>Drain: '
if(minDrain ~= maxDrain) then
ret = ret..minDrain..'-'..maxDrain
else
ret = ret..maxDrain
end
end
end
end
return ret
end
local function getDrainRow(avio, maxRank)
ret = '\n|-'
ret = ret..'\n| colspan="2" style="font-weight:bold;" | Drain || '..avio.InitialDrain
for i = 1, maxRank, 1 do
local minDrain = avio.InitialDrain + math.max(i - 3, 0)
local maxDrain = math.min(avio.InitialDrain + i, avio.InitialDrain + avio.MaxNaturalRank)
if(i <= avio.MaxNaturalRank) then
ret = ret..'\n| '
else
ret = ret..'\n| style="'..cellColor_Boost..'" | '
end
if(minDrain ~= maxDrain) then
ret = ret..minDrain..'-'..maxDrain
else
ret = ret..maxDrain
end
end
return ret
end
local function getTacticalStats(avio, maxRank)
local ret = "\n|-"
--Bonus Row
if(avio.BonusTitle ~= nil) then
ret = ret..'\n| colspan="2" style="font-weight:bold;" |'..avio.BonusTitle..' || '..avio.InitialBonus
for i = 1, maxRank, 1 do
if(i <= avio.MaxNaturalRank) then
ret = ret..'\n| '
else
ret = ret..'\n| style="'..cellColor_Boost..'" | '
end
local tmp = nil
if(avio.BonusScale ~= nil) then
tmp = avio.InitialBonus + (avio.BonusScale * i)
else
tmp = avio.BonusValues[i]
if(tmp == nil) then
tmp = "Error: Couldn't find value."
end
end
ret = ret..tmp
end
end
--Duration Row
if(avio.InitialDuration ~= nil) then
ret = ret..'\n|-'
ret = ret..'\n| colspan="2" style="font-weight:bold;" | Durée || '..avio.InitialDuration
for i = 1, maxRank, 1 do
if(i <= avio.MaxNaturalRank) then
ret = ret..'\n| '
else
ret = ret..'\n| style="'..cellColor_Boost..'" | '
end
local tmp = nil
if(avio.DurationScale ~= nil) then
tmp = avio.InitialDuration + (avio.DurationScale * i)
else
tmp = avio.DurationValues[i]
end
ret = ret..tmp
end
end
--Drain Row
ret = ret..getDrainRow(avio, maxRank)
return ret
end
local function writeBonusWithUnit(bonus, unit)
local ret = bonus
if(unit ~= nil) then
if(unit == "+%" or unit == "-%") then
ret = string.sub(unit, 1, 1)..ret..string.sub(unit, 2, 2)
else
ret = ret..unit
end
end
return ret
end
local function getBattleStats(avio, maxRank)
local ret = ""
for key, bonusData in Shared.skpairs(avio.Bonus, true) do
ret = ret..'\n|-'
ret = ret..'\n| colspan="2" style="font-weight:bold;" |'..bonusData.Name..' || '..writeBonusWithUnit(bonusData.InitialBonus, bonusData.Unit)
for i = 1, maxRank, 1 do
if(i <= avio.MaxNaturalRank) then
ret = ret..'\n| '
else
ret = ret..'\n| style="'..cellColor_Boost..'" | '
end
local tmp = nil
if(bonusData.BonusScale ~= nil) then
tmp = bonusData.InitialBonus + (bonusData.BonusScale * i)
else
tmp = bonusData.BonusValues[i]
end
if(tmp ~= nil) then
ret = ret..writeBonusWithUnit(tmp, bonusData.Unit)
else
ret = ret.."Error: Couldn't find value."
end
end
end
--Drain Row
ret = ret..getDrainRow(avio, maxRank)
return ret
end
local function _getStatsTable(avioName, tableWidth)
local ret = nil
local avio, family = p.getAvionic(avioName)
if(avio ~= nil) then
--Determine maxRank of table
local maxRank = nil
if(family == "Integrated") then
maxRank = getIntegratedMaxNaturalRank(avio) + 3
else
maxRank = avio.MaxNaturalRank + 3
end
--Add Header Row
ret = '{| class="emodtable" width="'..tableWidth..'" style="font-size:85%;"'
ret = ret..'\n! style="font-weight:bold;" colspan="2" | '
if(family == "Integrated") then
ret = ret..'Fabricants'
end
ret = ret..'\n! style="font-weight:bold;" | Rang 0'
for i = 1, maxRank, 1 do
ret = ret..'\n! style="font-weight:bold;" | Rang '..i
end
--Add body depending on family
if(family == "Integrated") then
ret = ret..getIntegratedStats(avio, maxRank)
elseif(family == "Tactical") then
ret = ret..getTacticalStats(avio, maxRank)
elseif(family == "Battle") then
ret = ret..getBattleStats(avio, maxRank)
else
ret = ret..'\n| colspan="'..(maxRank + 3)..'" | Famille/Type d\'Avionique inconnue.'
end
--Add footer row
ret = ret..'\n|-'
ret = ret..'\n| colspan="'..(maxRank + 3)..'" | [[File:CyanBlock.png]] = Atteignable avec boost de la grille\t[[File:SaumonBlock.png]] = Rang Indiponible'
ret = ret..'\n|}'
end
return ret
end
function p.getStatsTable(frame)
local avioName = frame.args ~= nil and frame.args[1] or nil
local tableWidth = frame.args ~= nil and frame.args[2] or "100%"
return _getStatsTable(avioName, tableWidth)
end
--]===]
return p