m (Undo revision 2113850 by Giga Martin (talk)) |
mNo edit summary |
||
Line 262: | Line 262: | ||
for key, _part in pairs(tablePart[Parameter]) do |
for key, _part in pairs(tablePart[Parameter]) do |
||
if imgOnly then |
if imgOnly then |
||
− | buildTable = buildTable..'|-\n! '..(Parameter=='House' and ('[[File:'..HouseIcon(key)..'| |
+ | buildTable = buildTable..'|-\n! '..(Parameter=='House' and ('[[File:'..HouseIcon(key)..'|60px|link=House '..key..']]') or key)..'\n|\n'.._part |
else |
else |
||
buildTable = buildTable..'\n|-\n! rowspan = '..(indexes[Parameter][key]+1)..' |'..key..'\n'.._part |
buildTable = buildTable..'\n|-\n! rowspan = '..(indexes[Parameter][key]+1)..' |'..key..'\n'.._part |
Revision as of 21:45, 9 July 2020
- Description
- This template will make a link to the Avionic with a tooltip showing the avionic. It will only accept the exact name of the avionic.
- Note: Some avionic articles have an "(Avionic)" suffix which shouldn't be included.
- Uses Module:Avionics and its database
- Tooltip is Template:Tooltip/Avionic
- See also {{Avi/GetValue}}
- Syntax
- Type {{Avi|<Avionic>|<Custom Name>|<image=Image only?>|<size=(size?)px>|<icon=Icon type: none, icon>}} as a replacement for avionic link.
- Input examples
{{Avi|Hyperstrike}}
{{Avi|Seeker Volley|Super Avionic}}
{{Avi|Seeker Volley|Super Avionic|image=qwe|size=30px}}
{{Avi||Hyperstrike}}
<span class="avionic-tooltip" data-param="Hyperstrike">Hyperstrike</span>
- Hyperstrike
{{Avi|Hyperstrike}} {{Avi|Hyperstrike|icon=none}} {{Avi|Hyperstrike|icon=qwe}} {{Avi|Hyperstrike|icon=icon}}
Hyperstrike Hyperstrike Hyperstrike Hyperstrike
{{Avi|The One Ring}}
Incorrect avionic name gives an error.
- {{Avionic}} "The One Ring" not found
You should always use the avionic's name without (Avionic) suffix.
-
{{Avi|Warhead}}
=> Warhead {{Avi|Warhead (Avionic)}}
=> Warhead (Avionic)
Other Templates
{{#invoke:Avionics|AvionicTable|SortBy|Find|Image?}}
{{#invoke:Avionics|AvionicTable|Type|Integrated}}
Lua error at line 208: attempt to call field 'skpairs' (a nil value).
{{#invoke:Avionics|AvionicTable|Type}}
Lua error at line 208: attempt to call field 'skpairs' (a nil value).
{{#invoke:Avionics|AvionicTable}}
Lua error at line 208: attempt to call field 'skpairs' (a nil value).
{{#invoke:Avionics|AvionicTable|Type|Integrated|img}}
Lua error at line 208: attempt to call field 'skpairs' (a nil value).
{{#invoke:Avionics|AvionicTable|Type||img}}
Lua error at line 208: attempt to call field 'skpairs' (a nil value).
{{#invoke:Avionics|AvionicTable|||img}}
Lua error at line 208: attempt to call field 'skpairs' (a nil value).
Codebase
Copied:
Mostly the same as in the text below, but now the work is done by Module:Mods.
Old notes below:
The template checks if first argument matches the name of the mod in Module:Mods/data. This is to check if a mod with that name actually exists. Another possibility would've been to check if an article with that name exists but it's limited to 250 calls per article and is not ideal as it would break on Mods 2.0.
- If the mod exists, class="mod-tooltip" data-param="{{#var:Name}}" tells javascript that this text wants a tooltip, which is made by {{Tooltip/Mod}}.
- If the mod doesn't exist, the error is shown instead of a redlink along with Category:Mod Tooltip error added on that page.
If second argument is used -> Category:Mod Tooltip rename is added on the page as to list pages with second argument, as they are harder to edit automatically if there's a need for that. Note: commented out until needed
--Module:Mods or Arcanes for Avionics
local p = {}
local AvionicData = mw.loadData( 'Module:Avionics/data' )
local Shared = require( "Module:Shared" )-- contains
local Icon = require( "Module:Icon" )
local Version = require( "Module:Version" )
local function getAvionic(name)
local _av = AvionicData["Avionics"][name]
if _av ~= nil then
if _av.Name then
return _av
else
local av_ = {Name = name}
for k,v in pairs(_av) do
av_[k]=v
end
return av_
end
else
for avionicName, Avionic in pairs(AvionicData["Avionics"]) do
if avionicName == name or Avionic.Link == name then
if Avionic.Name then
return Avionic
else
local _av = {Name = name}
for k,v in pairs(Avionic) do
_av[k]=v
end
return _av
end
end
end
end
end
local function AvionicExists(name, _av)
if type(_av) ~= table then
_av = AvionicData["Avionics"][name]
elseif _av.Name == name then
return true
end
if _av ~= nil and _av.Name == name then
return true
else
for avionicName, Avionic in pairs(AvionicData["Avionics"]) do
if avionicName == name or Avionic.Name == name or Avionic.Link == name then
return true
end
end
end
return false
end
function p.RawValueFromFrame(frame)
local AvionicName = frame.args[1]
local ValName = frame.args[2]
return RawValueFromName(AvionicName, ValName)
end
function RawValueFromName(AvionicName, ValName)
return RawValue(getAvionic(AvionicName), ValName)
end
function RawValue(Avionic, ValName)
if Avionic ~= nil then
return Avionic[Shared.titleCase(ValName)]
end
end
function p.ValueFromFrame(frame)
local AvionicName = frame.args[1]
local ValName = frame.args[2]
return ValueFromName(AvionicName, ValName)
end
function ValueFromName(AvionicName, ValName)
if(AvionicName == nil) then
return "ERROR: No avionic specified"
elseif AvionicExists (AvionicName, AvionicName) == false then
return "ERROR: No such avionic "..AvionicName.." found"
end
return ValueOf(getAvionic(AvionicName), ValName)
end
function ValueOf(Avionic, ValName)
if(Avionic == nil) then
return "ERROR: No avionic"
elseif(ValName == nil) then
return "ERROR: No value specified"
end
local UpName = string.upper(ValName)
if(UpName == "NAME") then
return Avionic.Name
elseif(UpName == "IMAGE") then
if(Avionic.Image ~= nil) then
return Avionic.Image
else
return "Avionic.png"
end
elseif(UpName == "LINK") then
if(Avionic.Link ~= nil) then
return Avionic.Link
else
return Avionic.Name
end
elseif(UpName == "HOUSE") then
if(Avionic.House ~= nil) then
return Avionic.House
else
return "None"
end
elseif(UpName == "HOUSEICON") then
return HouseIcon(Avionic.House)
elseif(UpName == "RARITY") then
if(Avionic.Rarity ~= nil) then
return Avionic.Rarity
else
return "Unknown"
end
elseif(UpName == "DESC" or UpName == "DESCRIPTION") then
if(Avionic.Desc ~= nil) then
return Avionic.Desc
else
return ""
end
elseif(UpName == "TYPE") then
if(Avionic.Type ~= nil) then
return Avionic.Type
else
return "Integrated"
end
elseif(UpName == "INTRO" or UpName == "INTRODUCTION") then
if(Avionic.Intro ~= nil) then
return Version.getVersionLink({args={Avionic.Intro}})
else
return Version.getVersionLink({args={'27'}})
end
elseif(UpName == "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
else
return nil
end
end
else
return nil
end
elseif(UpName == "FLUX") then
if Avionic.Flux == nil then
return ({Defense=25,Offense=50,Super=100})[ValueOf(Avionic, "slot")]
else
return Avionic.Flux
end
elseif(UpName == "TRADETAX") then
if(Avionic.Rarity ~= nil) then
return Icon._Item("Credits")..({Common=" 2,000",Uncommon=" 4,000",Rare=" 8,000"})[ValueOf(Avionic, "Rarity")]
end
else
return Avionic[Shared.titleCase(ValName)]--AvionicData["Avionics"][Avionic.Name][ValName]
end
end
function HouseIcon(House)
if House == "Sigma"
or House == "Vidar"
or House == "Lavan"
or House == "Zetki" then
return 'House'..House..'.png'
else
return 'Avionics_dark.png'
end
end
function p.AvionicTable(frame)----------------------------------------------------------------------
local Parameter,searchParameter,imgOnly = frame.args[1],frame.args[2],frame.args[3]
if Parameter == '' then Parameter = nil end
if searchParameter == '' then searchParameter = nil end
if imgOnly == nil or imgOnly == '' then imgOnly = false end
local buildTable = '{| border="1" cellpadding="1" cellspacing="1" class="article-table"\n'
local tablePart, indexes = {House={None}},{}
if not imgOnly then
if searchParameter or not Parameter then
buildTable = buildTable..'|-\n! Icon !! Name !! Description\n'
else
buildTable = buildTable..'|-\n!'..Parameter..' !! Icon !! Name !! Description\n|-'
end
else
if searchParameter or not Parameter then
buildTable = buildTable .. '|'
else
buildTable = buildTable .. '|-\n!'..Parameter..' !! Avionic\n'
end
end--header
--local isFirst = true
for Name, Avionic in Shared.skpairs(AvionicData["Avionics"]) do
local avpart
if imgOnly then
avpart =
p.tooltipImage({ args = {Avionic.Name or Name,'135px'} })
else
avpart =
'| ' .. p.tooltipImage({ args = {Avionic.Name or Name,'40px'} }) ..'\n'..
'| ' .. p.tooltipText({ args={Avionic.Name or Name} }) ..'\n'..
'| ' .. ValueOf(Avionic, 'desc') ..'\n'
end--make part
if searchParameter then
--one param
if ValueOf(Avionic, Parameter) == searchParameter then
if imgOnly then
buildTable = buildTable .. avpart
else
buildTable = buildTable ..'|-\n'.. avpart .. ''
end
end
elseif not Parameter then
if imgOnly then
buildTable = buildTable .. avpart
else
buildTable = buildTable ..'|-\n'.. avpart .. ''
end
else
--multiple params
local param = ValueOf(Avionic, Parameter)
if param then
if not tablePart[Parameter] then tablePart[Parameter]={} end
if imgOnly then
tablePart[Parameter][param] = (tablePart[Parameter][param] or '') .. avpart .. '\n'
else
tablePart[Parameter][param] = (tablePart[Parameter][param] or '') .. '|-\n' .. avpart
end
if not indexes[Parameter] then indexes[Parameter]={} end
indexes[Parameter][param] = (indexes[Parameter][param] or 0) + 1
end
end--join part
--if isFirst then isFirst = false end
end
if searchParameter then
if imgOnly then
buildTable = buildTable .. '\n'
end
elseif not Parameter then
if imgOnly then
buildTable = buildTable .. '\n'
end
else
for key, _part in pairs(tablePart[Parameter]) do
if imgOnly then
buildTable = buildTable..'|-\n! '..(Parameter=='House' and ('[[File:'..HouseIcon(key)..'|60px|link=House '..key..']]') or key)..'\n|\n'.._part
else
buildTable = buildTable..'\n|-\n! rowspan = '..(indexes[Parameter][key]+1)..' |'..key..'\n'.._part
end
end
end
return buildTable.."|}"
end
function p.getHouseList()
local hses = {}
for name, Avionic in pairs(AvionicData["Avionics"]) do
local House = ValueOf(Avionic,'House')
if(hses[House] == nil) then
hses[House] = 1
else
hses[House] = hses[House] + 1
end
end
local result = "HOUSES:"
for key, trash in pairs(hses) do
result = result.."\n"..key.." ("..trash..")"
end
return result
end
function p.getRarityList()
local hses = {}
for name, Avionic in pairs(AvionicData["Avionics"]) do
if(hses[Avionic.Rarity] == nil) then
hses[Avionic.Rarity] = 1
else
hses[Avionic.Rarity] = hses[Avionic.Rarity] + 1
end
end
local result = "RARITIES:"
for key, trash in pairs(hses) do
result = result.."\n"..key.." ("..trash..")"
end
return result
end
function p.getTypeList()
local hses = {}
for name, Avionic in pairs(AvionicData["Avionics"]) do
local Type = ValueOf(Avionic,'Type')
if(hses[Type] == nil) then
hses[Type] = 1
else
hses[Type] = hses[Type] + 1
end
end
local result = "TYPES:"
for key, trash in pairs(hses) do
result = result.."\n"..key.." ("..trash..")"
end
return result
end
function p.getAvionicCount(frame)
local total = 0
local rarity = frame.args[1]
local house = frame.args[2]
if (rarity == '' or rarity == nil) then
rarity = 'All'
end
--if (house == '' or house == nil) then
-- house = 'All'
--end
for name, Avionic in pairs(AvionicData['Avionics']) do
if ((Avionic['Rarity'] == rarity or rarity == 'All') and
(Avionic['House'] == house or house == 'All') and
not Shared.contains(AvionicData['IgnoreInCount'], name)) then
total = total + 1
end
end
return total
end
function p.tooltipText(frame)-----------------------------------------------------------------------
local Name = frame.args ~= nil and frame.args[1] or nil
if Name == nil then
return '<span style="color:red;">{{[[Template:Avi]]}}</span> Insert an avionic name.[[Category:'..'Avionic Tooltip error]]'
end
local Avionic = getAvionic(Name)
if Avionic == nil then
return '<span style="color:red;">{{[[Template:Avi|Avionic]]}}</span> "'..Name..'" not found[[Category:'..'Avionic Tooltip error]]'
end
local newName = frame.args ~= nil and frame.args[2]
if newName == '' then newName = nil end
local Link = Avionic.Link
local linkText = ''
if Link == nil then
Link = Name
end
local showIcon = ((frame.args[3] ~= '') and frame.args[3]) or nil
local dataname
if newName ~= nil then
linkText = Link..'|'..newName
dataname = newName
else
if Name == Link then
linkText = Link
else
linkText = Link..'|'..Name
end
dataname = ''
end--link
local tAvionic ={}
table.insert(tAvionic,'<span class="avionic-tooltip" data-param="'..Name..'" data-name="'..dataname..'">')
--20px thumb, 200px hover
if Avionic.House ~= nil then
if showIcon == nil then
table.insert(tAvionic,'[[File:'..ValueOf(Avionic, 'HouseIcon')..'|20px|link='..ValueOf(Avionic,'LINK')..']] ')
elseif showIcon == "none" then
--table.insert(tAvionic, '')
elseif showIcon == "icon" then
table.insert(tAvionic, '[[File:'..ValueOf(Avionic, 'Image')..'|20px|link='..ValueOf(Avionic,'LINK')..']] ')
else
table.insert(tAvionic, '[[File:Avionics_dark.png|20px|link='..ValueOf(Avionic,'LINK')..']] ')
end
else
table.insert(tAvionic, '[[File:Avionics_dark.png|20px|link='..ValueOf(Avionic,'LINK')..']] ')
end
table.insert(tAvionic,'[['..linkText..']]</span>')--link
return table.concat(tAvionic)
end
function p.tooltipImage(frame)----------------------------------------------------------------------
local Name = frame.args ~= nil and frame.args[1]
if Name == nil then
return '<span style="color:red;">{{[[Template:Avi]]}}</span> Insert an avionic name. [[Category:'..'Avionic Tooltip error]]'
end
local Avionic = getAvionic(Name)
local size = frame.args[2]
if size == nil then size = '130px' end
if Avionic == nil then
return '<span style="color:red;">{{[[Template:Avi|Avionic]]}}</span> "'..Name..'" not found [[Category:'..'Avionic Tooltip error]]'
end
local tAvionic ={}
table.insert(tAvionic,'<span class="avionic-tooltip" data-param="'..Name..'" data-name="imageonly">')--hover
-- if Avionic.House ~= nil then
-- table.insert(tAvionic,'[[File:House'..ValueOf(Avionic, 'House')..'.png|20px|link='..ValueOf(Avionic,'LINK')..']] ')
-- else
-- table.insert(tAvionic, '[[File:Avionics_dark.png|20px|link='..ValueOf(Avionic,'LINK')..']] ')
-- end--20px thumb
table.insert(tAvionic,'[[file:'..ValueOf(Avionic, 'Image')..'|'..size..'|link='..ValueOf(Avionic, 'Link')..']]</span>')--text, end hover
return table.concat(tAvionic)
end
function p.tooltip(frame)--------------------------------------------------------------------------
local AvionicName = frame.args ~= nil and frame.args[1] or nil;
local renamed = frame.args ~= nil and frame.args[2] or nil;
if renamed == '' then
renamed = nil;
end
local Avionic = getAvionic(AvionicName, "Name");
if Avionic ~= nil then
result = {'{| class="Tooltip"\n|-\n| style="padding:0px;"|\n{| class="Sub"\n|-\n| class="Image"| [[File:'..ValueOf(Avionic, "Image")..'|180px]]\n|-\n| class="Spacer"|'};--Main image
if renamed ~= nil then
table.insert(result,('\n|-\n! class="Title"|'..AvionicName..'\n|-\n| class="Spacer"|'));
end--Name
if false then
local desc = ValueOf(Avionic, "Desc");
local house = ValueOf(Avionic, "House");
local rarity = ValueOf(Avionic, "Rarity");
local Type = ValueOf(Avionic, "Type");
local trade = ValueOf(Avionic, "TradeTax");
table.insert(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;">House:</span> '..house..'<br /><span style="font-weight: bold;font-size: 14px;">Rarity:</span> '..rarity..'<br /><span style="font-weight: bold;font-size: 14px;">Type:</span> '..Type..'<br /><span style="font-weight: bold;font-size: 14px;">Trade Tax:</span> '..trade..'<br />'..desc..'\n|}\n|-\n|}'));--old version
elseif renamed == 'imageonly' then
table.insert(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;">'..ValueOf(Avionic, 'House')..' '..ValueOf(Avionic, "Rarity")..'</span><br />'..ValueOf(Avionic, "Desc")..'\n|}\n|-\n|}'));--as image
else
table.insert(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;">'..ValueOf(Avionic, "Rarity")..'</span><br />'..ValueOf(Avionic, "Desc")..'\n|}\n|-\n|}'));--default
end
else
return "Something went wrong with Module:Avionics (p.tooltip: name is nil)";
end
return table.concat(result);
end
return p