Module:DropsLineRoatz: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local lang = mw.language.getContentLanguage() | local lang = mw.language.getContentLanguage() | ||
local rarities_class = { | local rarities_class = { | ||
{ 1, 'table-bg-blue' }, | { 1, 'table-bg-blue' }, | ||
Line 69: | Line 40: | ||
end | end | ||
-- | -- Load JSON data | ||
local | local droppeditem_data = mw.loadJsonData('Module:DropsLine/itemData.json') | ||
local geprices_data = mw.loadJsonData('Module:GEPrices/data.json') | |||
local highalch_data = mw.loadJsonData('Module:GEHighAlchs/data.json') | |||
-- Main function | -- Main function | ||
Line 84: | Line 49: | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
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' | ||
local cats = categories(name, quantity, rarity) | local cats = categories(name, quantity, rarity) | ||
Revision as of 10:58, 4 April 2024
Documentation for this module may be created at Module:DropsLineRoatz/doc
local p = {}
local lang = mw.language.getContentLanguage()
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
local function get_rarity_class(val)
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
-- 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
-- Load JSON data
local droppeditem_data = mw.loadJsonData('Module:DropsLine/itemData.json')
local geprices_data = mw.loadJsonData('Module:GEPrices/data.json')
local highalch_data = mw.loadJsonData('Module:GEHighAlchs/data.json')
-- 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 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
end
return p