Jump to content

Module:MaterialInfobox: Difference between revisions

From Elite Dangerous Wiki
Content deleted Content added
A bit of a hack so we don't have to rewrite functions for Infobox Splits
Corrected Rare and Very Rare icons
 
(25 intermediate revisions by 3 users not shown)
Line 23: Line 23:
if not HF.isempty(field.Grade) then
if not HF.isempty(field.Grade) then
if field.Grade == 'Rare' or field.Grade == 'rare' then
if field.Grade == 'Rare' or field.Grade == 'rare' then
output = '[[File:placeholder.png|35px|link=]] ' .. output
output = '[[File:Rare_material.svg|35px|link=]] ' .. output
elseif field.Grade == 'Very common' or field.Grade == 'Very Common' or field.Grade == 'very common' then
elseif field.Grade == 'Very common' or field.Grade == 'Very Common' or field.Grade == 'very common' then
output = '[[File:placeholder.png|35px|link=]] ' .. output
output = '[[File:Very common material.svg|35px|link=]] ' .. output
elseif field.Grade == 'Very rare' or field.Grade == 'Very Rare' or field.Grade == 'very rare' then
output = '[[File:Very_Rare_material.svg|35px|link=]] ' .. output
elseif field.Grade == 'Common' or field.Grade == 'common' then
elseif field.Grade == 'Common' or field.Grade == 'common' then
output = '[[File:placeholder.png|35px|link=]] ' .. output
output = '[[File:Common material.svg|35px|link=]] ' .. output
elseif field.Grade == 'Standard' or field.Grade == 'standard' then
output = '[[File:Standard_material.svg|35px|link=]] ' .. output
else
else
output = output
output = output
Line 35: Line 39:
end
end


function SplitRunFunction(func_name, field, vars)
function Infobox.TableSplitRows( field, vars )
local output = ''
if type( func_name ) == "string" then
if not HF.isempty( func_name ) then
if not HF.isempty(field.Value) then
local ships = HF.explode(';', field.Value)
if type( Infobox[func_name] ) == "function" then
table.sort(ships)
return Infobox[func_name]( field, vars )
end
output = '<tr class="eInfobox-infobox-custom custom-listitem"><td colspan="2">' ..
end
table.concat(ships, '</td></tr><tr class="eInfobox-infobox-custom custom-listitem"><td colspan="2">') ..
'</td></tr>'
⚫
return output
end
end
⚫
return value
end
end


function Infobox.SplitLabelMethod( field, vars )
return {
SplitRunFunction( field.LabelLeftMethod, field, vars ),
SplitRunFunction( field.LabelRightMethod, field, vars )
}
end
function Infobox.SplitValueMethod( field, vars )
field.Value = ValueLeft --[[ A bit hacky, but it's about to be replaced by this function's output anyways, and if it works, then we don't need special functions for Splits ]]--
local ValueLeft = SplitRunFunction( field.ValueLeftMethod, field, vars )
field.Value = ValueRight
local ValueRight = SplitRunFunction( field.ValueRightMethod, field, vars )
return {
ValueLeft,
ValueRight
}
end


return Infobox
return Infobox

Latest revision as of 10:31, 2 August 2017

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

local Infobox = {}
local HF = require('Module:HF')

function Infobox.Newline( field, vars )
    local output = ''
    if not HF.isempty(field.Value) then
        local ships = HF.explode(';', field.Value)
        table.sort(ships)
        for i, ship in ipairs(ships) do
            output = output .. HF.trim(ship) .. '<br />'
        end
 
        if string.sub(output, -6) == '<br />' then
            output = string.sub( output, 1, -7 )
        end
 
        return output
    end
end

function Infobox.PreTitleIcon( field, vars )
    output = field.Value
    if not HF.isempty(field.Grade) then
        if field.Grade == 'Rare' or field.Grade == 'rare' then
            output = '[[File:Rare_material.svg|35px|link=]] ' .. output
        elseif field.Grade == 'Very common' or field.Grade == 'Very Common' or field.Grade == 'very common' then
            output = '[[File:Very common material.svg|35px|link=]] ' .. output
        elseif field.Grade == 'Very rare' or field.Grade == 'Very Rare' or field.Grade == 'very rare' then
            output = '[[File:Very_Rare_material.svg|35px|link=]] ' .. output
        elseif field.Grade == 'Common' or field.Grade == 'common' then
            output = '[[File:Common material.svg|35px|link=]] ' .. output
        elseif field.Grade == 'Standard' or field.Grade == 'standard' then
            output = '[[File:Standard_material.svg|35px|link=]] ' .. output
        else
            output = output
        end
    end
    return output
end

function Infobox.TableSplitRows( field, vars )
    local output = ''
    if not HF.isempty(field.Value) then
        local ships = HF.explode(';', field.Value)
        table.sort(ships)
        
        output =  '<tr class="eInfobox-infobox-custom custom-listitem"><td colspan="2">' ..
                table.concat(ships, '</td></tr><tr class="eInfobox-infobox-custom custom-listitem"><td colspan="2">') ..
                '</td></tr>'
 
        return output
    end
end


return Infobox