FANDOM


local p = {}
 
local data = mw.loadData("Module:Asset/data")
local fNum = require( 'Module:FormatNum' ).formatNum
 
function p.listAsset(frame)
    local rawname = tostring(frame.args[1])
    local price = data[rawname]['price']
    local listAssetPrice
    listAssetPrice = frame:expandTemplate{ title = 'mb', args = { price } } or "Unknown"
    return listAssetPrice
end
 
function p.res(frame)
    local rawname = tostring(frame.args[1])
    local name = data[rawname]['name']
    local link = '[[:Category:' .. name .. '|' .. name .. ']]'
    local category = '[[Category:' .. name .. ']]'
    local link2
    local price
    local fullcost
    local img
    local amount = tonumber(frame.args[2]) or 0
    local version = frame.args['version']
    local cat = data[rawname]['type'] or "" or nil
 
    if rawname == 'tarpaulin' then
        link2 = link .. "<br/><small>(''a.k.a '''Tarpaulin''''')</small>"
    elseif rawname == 'field_columns' then
        link2 = link .. "<br/><small>(''a.k.a '''Aerodrome Floodlights''''')</small>"
    elseif rawname == 'socket' then
        link2 = link .. "<br/><small>(''a.k.a '''Power Outlet''''')</small>"
    else
        link2 = link
    end
 
    if cat == 'Unique' then
        img = 'Unique Asset ' .. name .. '.png'
    elseif cat == 'Special' then
        img = name .. '.png'
    else
        img = 'Asset ' .. name .. '.png'
    end
 
    if cat == 'Diagram' then
        price = frame:expandTemplate{ title = 'coin', args = { data[rawname]['cost'] } }
        fullcost = tonumber(data[rawname]['cost']) * amount
        fullcost = frame:expandTemplate{ title = 'coin', args = { fullcost } }
    elseif cat == 'Special' then
        price = ""
        fullcost = ""
    elseif cat == 'SpecialAsset' then
        price = ""
        fullcost = ""
    else
        price = frame:expandTemplate{ title = 'mb', args = { data[rawname]['price'] } }
        fullcost = tonumber(data[rawname]['price']) * amount
        fullcost = frame:expandTemplate{ title = 'mb', args = { fullcost } }
    end
 
    if version == '2' then
        return p.v2(link2,img,amount,price,fullcost,category)
    else
        return p.v1(name,link,img,amount)
    end
end
 
function p.v1(name,link,img,amount)
    if amount == 0 then
        amount = ""
    elseif tonumber(amount) < 10 then
        amount = "<span class=\"hidden\" style=\"font-family: 'Ubuntu Mono', monospace;\">0" .. tostring(amount) .. "</span><span style=\"display:none\">'''0" .. tostring(amount) .. "'''</span>&nbsp;x&nbsp;"
    else
        amount = "<span class=\"hidden\" style=\"font-family: 'Ubuntu Mono', monospace;\">" .. fNum(amount) .. "</span><span style=\"display:none\">'''" .. fNum(amount) .. "'''</span>&nbsp;x&nbsp;"
    end
    return amount .. link .. ' [[File:' .. img .. '|25px]]'
end
 
function p.v2(link2,img,amount,price,fullcost,category)
    local final
    if amount == 0 then
        final = '|-\n| colspan="4" | Invalid Asset Amount'
    else
        final = '|- style="text-align: center; vertical-align:middle"\n|' .. category .. link2 .. '||' .. '[[File:' .. img .. '|60px]] ||' .. fNum(amount) .. 'x||' .. price .. '||' .. fullcost
    end
    return final
end
 
function p.price(frame)
    local rawname = tostring(frame.args[1])
    local price = data[rawname]['price']
    return price
end
 
return p