Module:Inventory: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
Tag: Reverted
No edit summary
 
(14 intermediate revisions by the same user not shown)
Line 2: Line 2:


local hasc = require('Module:Paramtest').has_content
local hasc = require('Module:Paramtest').has_content
local itemstats = require('Module:FetchItemStats')
local yesno = require('Module:Yesno')
local lang = mw.language.getContentLanguage()
local GEPrice = require('Module:Exchange')._price


-- Parse item string and check if GIF icons are allowed
function formatAmount(_x)
local function parseItem(ret, itemString, equipSlot, stats, quantity, clickable)
     local x = tonumber(_x) or 1
     local itemString = itemString
     if x < 100000 then
     local allowGif = false -- Set default to not allow GIF icons
        return x, 'qty-1'
    local itemName = ""
     elseif x < 10000000 then
 
         return tostring(math.floor(x/1000))..'K', 'qty-100k'
    -- Look for a ;g at the end of the string and separate them
    else
     if hasc(itemString) then
         return tostring(math.floor(x/1000000))..'M', 'qty-10m'
         allowGif = itemString:sub(-2) == ";g"
        if allowGif then
            itemName = itemString:sub(0, -3)
        else
            itemName = itemString or ""
         end
     end
     end
   
    return ret, itemName, allowGif, equipSlot, stats, quantity, clickable
end
end


-- Formats a <div> element for items
function p.main(frame)
local function makeDiv(ret, itemName, allowGif, equipSlot, stats, quantity, clickable)
     local bgType = frame.args.bgType
     local itemName = itemName
     if bgType == nil then
     local allowGif = allowGif
        bgType = "inventory"
     local topDivClass = "equipment-" .. equipSlot
    end
 
     local args = frame:getParent().args
     local names = mw.text.split(itemName, ";")
    local items = {}
    if #names <= 1 or names[2] == 'g' then
     for i=1,28 do
        names[2] = itemstats.defaultVersion(names[1]) or names[1]
        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
     end
 
     local align = args.align
     local imgType = allowGif == true and "gif" or "png"
     local acss
 
     if hasc(align) then
     local equipSlotText = ""
        align = align:lower()
      
        if align == 'right' then
    -- Check if the item name is not empty
            align = "storage-right"
    if itemName ~= '' then
         elseif align == 'left' then
         if clickable then
             align = "storage-left"
             -- Construct a clickable link
            equipSlotText = string.format("[[File:%s.%s|%s|link=]]", names[1], imgType, names[2])
         else
         else
             -- Construct a plain image without a link
             align = "storage-center"
            equipSlotText = string.format("[[File:%s.%s|link=%s]]", names[1], imgType, names[2])
         end
         end
     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)


    -- Create the divs
    local topDiv = ret
        :tag("div")
        :addClass(topDivClass)
    local nestedDiv = topDiv
        :tag("div")
        :addClass("equipment-plinkp")
        :wikitext(equipSlotText)
    if quantity then
        local amt, quantclass = formatAmount(quantity)
        nestedDiv:tag('span')
            :addClass('inv-quantity-text')
            :addClass(quantclass)
            :wikitext(amt)
    end
    if stats and itemName ~= '' then
        -- Add stat-related code here if needed
    end
    if itemName ~= '' then
        topDiv:addClass("equipment-blank")
    end
end
end


function p.main(frame)
function p._main(items, align, bgType, clickableItems)
    local args = frame:getParent().args
     local className = bgType .. "table"
    local buttons = yesno(args.buttons, false)
     local ret = mw.html.create('table')
     local stats = yesno(args.stats, false)
        :addClass(className)
 
        :addClass(align)
    local align
     local item = 0
    if args.align == "right" then
    for i = 1, 7 do
        align = "equipment-right"
        local ret_row = ret:tag('tr')
    elseif args.align == "center" then
         for j = 1, 4 do
        align = "equipment-center"
             item = item + 1
    else
             local itemx = items[item].item
        align = "equipment-left"
             local amtx = items[item].amt
    end
             local amtx_f, amtx_c = formatAmount(amtx)
    -- general 'equipment' class for the whole thing
             local notex = items[item].isnoted
    align = "equipment " .. align
             local td = ret_row:tag('td')
 
             if hasc(itemx) then
     local tbl = mw.html.create("table"):addClass(align):tag("tr")
                if clickableItems[itemx] then
     local ret = tbl:tag("td"):tag("div")
                    -- If the item is clickable, add a link to the image tag
    if stats then
                    td:wikitext(string.format('[[File:%s.png|%s|link=%s|32x32px|frameless]]', itemx, itemx, clickableItems[itemx]))
         stats = {
                else
             astab = 0,
                    -- If the item is not clickable, just add the image tag without a link
             aslash = 0,
                    td:wikitext(string.format('[[File:%s.png|%s|link=|32x32px|frameless]]', itemx, itemx))
             acrush = 0,
                end
             amagic = 0,
                if notex then
             arange = 0,
                    td:addClass('noted-item')
             dstab = 0,
                end
             dslash = 0,
                if amtx > 1 or notex then
            dcrush = 0,
                    td:tag('span')
            dmagic = 0,
                      :addClass('inv-quantity-text')
            drange = 0,
                      :addClass(amtx_c)
            str = 0,
                      :wikitext(amtx_f)
            rstr = 0,
                end
            mdmg = 0,
             end
            prayer = 0,
         end
            weight = 0,
             ikods = {},
         }
     end
     end
 
     return ret
     if buttons then
        ret:addClass("equipment-div-buttons")
    else
        ret:addClass("equipment-div")
    end
 
    -- Fetch equipment and create divs
    makeDiv(parseItem(ret, args.head, "head", stats, nil, yesno(args.headClickable, false)))
    makeDiv(parseItem(ret, args.cape, "cape", stats, nil, yesno(args.capeClickable, false)))
    makeDiv(parseItem(ret, args.neck, "neck", stats, nil, yesno(args.neckClickable, false)))
    makeDiv(parseItem(ret, args.ammo, "ammo", stats, args.ammoquantity, yesno(args.ammoClickable, false)))
    makeDiv(parseItem(ret, args.weapon, "weapon", stats, args.weaponquantity, yesno(args.weaponClickable, false)))
    makeDiv(parseItem(ret, args.torso, "torso", stats, nil, yesno(args.torsoClickable, false)))
    makeDiv(parseItem(ret, args.shield, "shield", stats, nil, yesno(args.shieldClickable, false)))
    makeDiv(parseItem(ret, args.legs, "legs", stats, nil, yesno(args.legsClickable, false)))
    makeDiv(parseItem(ret, args.gloves, "gloves", stats, nil, yesno(args.glovesClickable, false)))
    makeDiv(parseItem(ret, args.hands, "gloves", stats, nil, yesno(args.handsClickable, false)))
    makeDiv(parseItem(ret, args.boots, "boots", stats, nil, yesno(args.bootsClickable, false)))
    makeDiv(parseItem(ret, args.ring, "ring", stats, nil, yesno(args.ringClickable, false)))
   
    if stats then
        -- Add stat-related code here if needed
    end
 
    return tbl:done()
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