Module:Inventory: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
Tag: Reverted
No edit summary
 
(12 intermediate revisions by the same user not shown)
Line 26: Line 26:
         local amt_x = 1
         local amt_x = 1
         local note_x = false
         local note_x = false
        local clickable_x = false -- Added line
         if hasc(v) then
         if hasc(v) then
             v = v:gsub('[][]','')
             v = v:gsub('[][]','')
             amt_x = tonumber(v:match('\\(%d+)')) or 1
             amt_x = tonumber(v:match('\\(%d+)')) or 1
             note_x = v:match(';n') == ';n'
             note_x = v:match(';n') == ';n'
            clickable_x = v:match(';c=yes') == ';c=yes' or v:match(';c=true') == ';c=true' -- Modified line
             local v2 = mw.text.split(v,'[;\\]')
             local v2 = mw.text.split(v,'[;\\]')
             item_x = v2[1]
             item_x = v2[1]
         end
         end
         table.insert(items,{item=item_x,amt=amt_x,isnoted=note_x,clickable=clickable_x}) -- Modified line
         table.insert(items,{item=item_x,amt=amt_x,isnoted=note_x})
     end
     end
     local align = args.align
     local align = args.align
Line 49: Line 47:
         end
         end
     end
     end
     return p._main(items,align,bgType)
      
  local clickableItems = {
    ["Infernal max cape"] = "Max cape",
    ["Ardougne max cape"] = "Max cape",
    ["Accumulator max cape"] = "Max cape",
    ["Assembler max cape"] = "Max cape",
    ["Fire max cape"] = "Max cape",
    ["Imbued guthix max cape"] = "Max cape",
    ["Imbued saradomin max cape"] = "Max cape",
    ["Imbued zamorak max cape"] = "Max cape",
    ["Masori assembler max cape"] = "Max cape",   
    ["Mythical max cape"] = "Max cape",   
    ["Guthix max cape"] = "Max cape", 
    ["Saradomin max cape"] = "Max cape", 
    ["Zamorak max cape"] = "Max cape", 
    ["Imbued zamorak cape"] = "Imbued god capes", 
    ["Imbued saradomin cape"] = "Imbued god capes", 
    ["Imbued guthix cape"] = "Imbued god capes", 
    ["Royal seed pod"] = "Bounty Hunter shop", 
   
    -- Add more items and URLs as needed
}
return p._main(items, align, bgType, clickableItems)
 
end
end


function p._main(items,align,bgType)
function p._main(items, align, bgType, clickableItems)
     local className = bgType .. "table"
     local className = bgType .. "table"
     local ret = mw.html.create('table')
     local ret = mw.html.create('table')
Line 58: Line 79:
         :addClass(align)
         :addClass(align)
     local item = 0
     local item = 0
     for i=1,7 do
     for i = 1, 7 do
         local ret_row = ret:tag('tr')
         local ret_row = ret:tag('tr')
         for j=1,4 do
         for j = 1, 4 do
             item = item + 1
             item = item + 1
             local itemx = items[item].item
             local itemx = items[item].item
Line 66: Line 87:
             local amtx_f, amtx_c = formatAmount(amtx)
             local amtx_f, amtx_c = formatAmount(amtx)
             local notex = items[item].isnoted
             local notex = items[item].isnoted
            local clickable_x = items[item].clickable
             local td = ret_row:tag('td')
             local td = ret_row:tag('td')
             if hasc(itemx) then
             if hasc(itemx) then
                 if clickable_x then
                 if clickableItems[itemx] then
                     td:wikitext(string.format("[[File:%s.%s|%s|link=]]", itemx, itemx))
                    -- If the item is clickable, add a link to the image tag
                     td:wikitext(string.format('[[File:%s.png|%s|link=%s|32x32px|frameless]]', itemx, itemx, clickableItems[itemx]))
                 else
                 else
                     td:wikitext(string.format('[[File:%s.png|link=|32x32px|frameless]]', itemx, itemx, itemx))
                    -- If the item is not clickable, just add the image tag without a link
                     td:wikitext(string.format('[[File:%s.png|%s|link=|32x32px|frameless]]', itemx, itemx))
                 end
                 end
                 if notex then
                 if notex then
Line 86: Line 108:
         end
         end
     end
     end
     return ret
     return ret
end
end


return p
return p

Latest revision as of 11:38, 15 May 2024

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

local p = {}

local hasc = require('Module:Paramtest').has_content

function formatAmount(_x)
    local x = tonumber(_x) or 1
    if x < 100000 then
        return x, 'qty-1'
    elseif x < 10000000 then
        return tostring(math.floor(x/1000))..'K', 'qty-100k'
    else
        return tostring(math.floor(x/1000000))..'M', 'qty-10m'
    end
end

function p.main(frame)
    local bgType = frame.args.bgType
    if bgType == nil then
        bgType = "inventory"
    end
    local args = frame:getParent().args
    local items = {}
    for i=1,28 do
        local v = mw.text.trim(args[i] or '')
        local item_x
        local amt_x = 1
        local note_x = false
        if hasc(v) then
            v = v:gsub('[][]','')
            amt_x = tonumber(v:match('\\(%d+)')) or 1
            note_x = v:match(';n') == ';n'
            local v2 = mw.text.split(v,'[;\\]')
            item_x = v2[1]
        end
        table.insert(items,{item=item_x,amt=amt_x,isnoted=note_x})
    end
    local align = args.align
    local acss
    if hasc(align) then
        align = align:lower()
        if align == 'right' then
            align = "storage-right"
        elseif align == 'left' then
            align = "storage-left"
        else
            align = "storage-center"
        end
    end
    
   local clickableItems = {
    ["Infernal max cape"] = "Max cape",
    ["Ardougne max cape"] = "Max cape",
    ["Accumulator max cape"] = "Max cape",
    ["Assembler max cape"] = "Max cape",
    ["Fire max cape"] = "Max cape",
    ["Imbued guthix max cape"] = "Max cape",
    ["Imbued saradomin max cape"] = "Max cape",
    ["Imbued zamorak max cape"] = "Max cape",
    ["Masori assembler max cape"] = "Max cape",    
    ["Mythical max cape"] = "Max cape",    
    ["Guthix max cape"] = "Max cape",   
    ["Saradomin max cape"] = "Max cape",   
    ["Zamorak max cape"] = "Max cape",   
    ["Imbued zamorak cape"] = "Imbued god capes",   
    ["Imbued saradomin cape"] = "Imbued god capes",   
    ["Imbued guthix cape"] = "Imbued god capes",   
    ["Royal seed pod"] = "Bounty Hunter shop",  
    
    -- Add more items and URLs as needed
}
return p._main(items, align, bgType, clickableItems)

end

function p._main(items, align, bgType, clickableItems)
    local className = bgType .. "table"
    local ret = mw.html.create('table')
        :addClass(className)
        :addClass(align)
    local item = 0
    for i = 1, 7 do
        local ret_row = ret:tag('tr')
        for j = 1, 4 do
            item = item + 1
            local itemx = items[item].item
            local amtx = items[item].amt
            local amtx_f, amtx_c = formatAmount(amtx)
            local notex = items[item].isnoted
            local td = ret_row:tag('td')
            if hasc(itemx) then
                if clickableItems[itemx] then
                    -- If the item is clickable, add a link to the image tag
                    td:wikitext(string.format('[[File:%s.png|%s|link=%s|32x32px|frameless]]', itemx, itemx, clickableItems[itemx]))
                else
                    -- If the item is not clickable, just add the image tag without a link
                    td:wikitext(string.format('[[File:%s.png|%s|link=|32x32px|frameless]]', itemx, itemx))
                end
                if notex then
                    td:addClass('noted-item')
                end
                if amtx > 1 or notex then
                    td:tag('span')
                      :addClass('inv-quantity-text')
                      :addClass(amtx_c)
                      :wikitext(amtx_f)
                end
            end
        end
    end
    return ret
end

return p