Module:DropsLineRoatz: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
local p = {}
local params = require('Module:Paramtest')
local lang = mw.language.getContentLanguage()
local lang = mw.language.getContentLanguage()
local coins_image = require('Module:Coins image')
local curr_image = require('Module:Currency Image')
local yesno = require('Module:Yesno')
-- Load JSON data
local droppeditem_data = mw.loadData('Module:DropsLine/itemData.json')
local geprices_data = mw.loadData('Module:GEPrices/data.json')
local highalch_data = mw.loadData('Module:GEHighAlchs/data.json')
local _noted = '&nbsp;<span class="dropsline-noted">(noted)</span>'
local coins_priceString = "%s Pkp"
local other_priceString = "%s Pkp"
-- Rarity definitions
local rarities = {
    always = { 'table-bg-blue', 1 },
    common = { 'table-bg-green', 16 },
    uncommon = { 'table-bg-yellow', 64 },
    rare = { 'table-bg-orange', 128 },
    ['very rare'] = { 'table-bg-red', 1024 },
    random = { 'table-bg-pink', 4096 },
    varies = { 'table-bg-pink', 4096 },
    once = { 'table-bg-pink', 65536 },
    conditional = { 'table-bg-pink', 65536 },
    _default = { 'table-bg-grey', 65536 }
}
-- Colour-code rarities
local rarities_class = {
    { 1, 'table-bg-blue' },
    { 1/25, 'table-bg-green' },
    { 1/99.99, 'table-bg-yellow' },
    { 1/999.99, 'table-bg-orange' },
    { 1/9999999, 'table-bg-red' }
}


-- Function to get rarity class based on value
-- Function to get rarity class based on value
local function get_rarity_class(val)
local function get_rarity_class(val)
    local rarities_class = {
        { 1, 'table-bg-blue' },
        { 1/25, 'table-bg-green' },
        { 1/99.99, 'table-bg-yellow' },
        { 1/999.99, 'table-bg-orange' },
        { 1/9999999, 'table-bg-red' }
    }
     for i, v in ipairs(rarities_class) do
     for i, v in ipairs(rarities_class) do
         if val >= v[1] then
         if val >= v[1] then
Line 57: Line 26:
         return n
         return n
     end
     end
end
-- Function to handle expression evaluation
local function expr(t)
    local noerr, val = pcall(mw.ext.ParserFunctions.expr, t)
    if noerr then
        return tonumber(val)
    else
        return false
    end
end
-- Function to round to significant figures
local function sigfig(n, f)
    f = math.floor(f - 1)
    if n == 0 then return 0 end
    local m = math.floor(math.log10(n))
    f = math.max(m, f)
    local v = n / (10^(m - f))
    v = math.floor(v + 0.5) * 10^(m - f)
    return v
end
end


Line 84: Line 32:
     local args = frame:getParent().args
     local args = frame:getParent().args


    -- Extract parameters
     local name = args.name or args.Name or 'Item'
     local name = args.name or args.Name or 'Item'
     local quantity = args.quantity or args.Quantity or 'Unknown'
     local quantity = args.quantity or args.Quantity or 'Unknown'
     local rarity = args.rarity or args.Rarity or 'Unknown'
     local rarity = args.rarity or args.Rarity or 'Unknown'


    -- Call the categories function with appropriate arguments
     local output = string.format('|-\n| style="text-align:center" | %s\n| style="text-align:center" | %s\n| style="text-align:center" | %s\n', name, quantity, rarity)
     local cats = categories(name, quantity, rarity)
 
    return cats
end
 
-- Define the categories function
function categories(name, quantity, rarity)
    local ret = ''
    name = name:lower()
    quantity = quantity:lower()
    rarity = rarity:lower()
 
    if name:find('clue scroll') then
        ret = ret .. ''
    end
 
    if rarity == 'unknown' then
        ret = ret .. ''
    end
 
    if quantity == 'unknown' then
        ret = ret .. ''
    end


     return ret
     return mw.text.tag('tr', output)
end
end


return p
return p

Latest revision as of 11:01, 4 April 2024

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

local p = {}
local lang = mw.language.getContentLanguage()

-- Function to get rarity class based on value
local function get_rarity_class(val)
    local rarities_class = {
        { 1, 'table-bg-blue' },
        { 1/25, 'table-bg-green' },
        { 1/99.99, 'table-bg-yellow' },
        { 1/999.99, 'table-bg-orange' },
        { 1/9999999, 'table-bg-red' }
    }
    for i, v in ipairs(rarities_class) do
        if val >= v[1] then
            return v[2]
        end
    end
    return rarities_class[#rarities_class][2] -- default to the last rarity class
end

-- Function to format numbers with commas
local function commas(n)
    if tonumber(n) then
        return lang:formatNum(tonumber(n))
    else
        return n
    end
end

-- Main function
function p.main(frame)
    local args = frame:getParent().args

    local name = args.name or args.Name or 'Item'
    local quantity = args.quantity or args.Quantity or 'Unknown'
    local rarity = args.rarity or args.Rarity or 'Unknown'

    local output = string.format('|-\n| style="text-align:center" | %s\n| style="text-align:center" | %s\n| style="text-align:center" | %s\n', name, quantity, rarity)

    return mw.text.tag('tr', output)
end

return p