Difference between revisions of "Module:EnchantmentList"
Jump to navigation
Jump to search
(Convert arguments to lowercase) |
(Order scrolls by level) |
||
| Line 164: | Line 164: | ||
s = s .. "</th>" | s = s .. "</th>" | ||
s = s .. "</tr>" | s = s .. "</tr>" | ||
| − | + | local items = p.loadData('item') | |
| + | local scrollIds = {} | ||
| + | for key, item in pairs(items) do | ||
if item.class == "enchanted-scroll" then | if item.class == "enchanted-scroll" then | ||
if slot and item.categories then | if slot and item.categories then | ||
if contains(item.categories, slot) then | if contains(item.categories, slot) then | ||
if (item.name ~= "Scroll of the Soul Wisdom") then | if (item.name ~= "Scroll of the Soul Wisdom") then | ||
| − | s = s .. createRow(item) | + | table.insert(scrollIds, {key = key, level = item.level}) |
| + | -- s = s .. createRow(item) | ||
end | end | ||
end | end | ||
| Line 175: | Line 178: | ||
if contains(item.tags, skill) then | if contains(item.tags, skill) then | ||
if (item.name ~= "Scroll of the Soul Wisdom") then | if (item.name ~= "Scroll of the Soul Wisdom") then | ||
| − | s = s .. createRow(item) | + | table.insert(scrollIds, {key = key, level = item.level}) |
| + | -- s = s .. createRow(item) | ||
end | end | ||
end | end | ||
end | end | ||
end | end | ||
| + | end | ||
| + | table.sort(scrollIds, function(a, b) return a.level < b.level end) | ||
| + | for _, scroll in ipairs(scrollIds) do | ||
| + | s = s .. createRow(items[scroll.key]) | ||
end | end | ||
s = s .. "</table>" | s = s .. "</table>" | ||
Revision as of 10:01, 29 April 2025
local p = {}
local data_module_names = {
item = 'Module:Items/data',
enchantment = 'Module:Enchantment/data',
craftaug = 'Module:CraftingAugmenting/data',
}
local loaded_data_modules = {}
function p.loadData(data_type)
local module_name = data_module_names[data_type]
if loaded_data_modules[module_name] == nil then
loaded_data_modules[module_name] = mw.loadData(module_name)
end
return loaded_data_modules[module_name]
end
local function getItem(id)
return p.loadData("item")[tostring(id)]
end
local function getEnchantment(id)
return p.loadData("enchantment")[tostring(id)]
end
local function getCraftAug(id)
return p.loadData("craftaug")[tostring(id)]
end
local function fullUrl(url)
local newUrl = url
if url:sub(1,5) == "https" then
return newUrl
end
if url:sub(1,1) ~= "/" then
newUrl = "/" .. newUrl
end
newUrl = "https://www.play.idlescape.com" .. newUrl
return newUrl
end
local function icon(name, url, word)
local s = fullUrl(url)
s = "[[" .. name .. "|<img src=\"" .. s
s = s .. "\" alt=\"" .. name .. "\" width=\"20\">"
if word then
s = s .. name
end
s = s .. "]]"
return s
end
local function addSeparator(num)
return tostring(tonumber(num)):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse()
end
local function contains (tab, val)
for index, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
local function createRow(item)
local s = ""
s = s .. "<tr>"
s = s .. "<td>"
-- Image and Name
s = s .. icon(item.name, item.itemImage, 1)
s = s .. "</td>"
s = s .. "<td>"
-- Slot
if item.categories then
for index, val in pairs(item.categories) do
s = s .. val .. ", "
end
s = s:sub(1, -3)
end
s = s .. "</td>"
s = s .. "<td>"
-- Level
if item.level then
s = s .. item.level
end
s = s .. "</td>"
s = s .. "<td>"
-- Silver Amount
local craft = getCraftAug(item.id)
if craft and craft.scrollcrafting and craft.scrollcrafting["111"] then
s = s .. craft.scrollcrafting["111"]
end
s = s .. "</td>"
s = s .. "<td>"
-- Rune Amount
if craft and craft.scrollcrafting then
local skip = false
for index, val in pairs(craft.scrollcrafting) do
if skip == false and index >= "510" and index <= "519" then
s = s .. val
skip = true
end
end
end
s = s .. "</td>"
s = s .. "<td>"
-- Rune Type
if craft and craft.scrollcrafting then
local remove = false
for index, val in pairs(craft.scrollcrafting) do
if index >= "510" and index <= "519" then
local ing = getItem(index)
s = s .. ing.name
s = s:sub(1, -6) .. ", "
remove = true
end
end
if remove then
s = s:sub(1, -3)
end
end
s = s .. "</td>"
s = s .. "<td>"
if item.enchantmentID then
local enchant = getEnchantment(item.enchantmentID)
s = s .. enchant.desc
end
s = s .. "</td>"
s = s .. "</tr>"
return s
end
local function createTable(slot, skill)
local s = ""
s = s .. "<table class=\"wikitable sortable hover-highlight jqery-tablesorter mw-collapsible -mw-made-collapsible\">"
s = s .. "<tr>"
s = s .. "<th class=\"headerSort\">"
s = s .. "<img src=\"https://play.idlescape.com/images/enchanting/enchanted_scroll.png\" alt=\"Scrollcrafting\" width=\"40px\" height=\"40px\">"
s = s .. "Scroll"
s = s .. "</th>"
s = s .. "<th class=\"headerSort\">"
s = s .. "Slot"
s = s .. "</th>"
s = s .. "<th class=\"headerSort\">"
s = s .. "Level"
s = s .. "</th>"
s = s .. "<th class=\"headerSort\">"
s = s .. "Silver Amount"
s = s .. "</th>"
s = s .. "<th class=\"headerSort\">"
s = s .. "Rune Amount"
s = s .. "</th>"
s = s .. "<th class=\"headerSort\">"
s = s .. "Runes"
s = s .. "</th>"
s = s .. "<th class=\"headerSort\">"
s = s .. "Effect per scroll"
s = s .. "</th>"
s = s .. "</tr>"
local items = p.loadData('item')
local scrollIds = {}
for key, item in pairs(items) do
if item.class == "enchanted-scroll" then
if slot and item.categories then
if contains(item.categories, slot) then
if (item.name ~= "Scroll of the Soul Wisdom") then
table.insert(scrollIds, {key = key, level = item.level})
-- s = s .. createRow(item)
end
end
elseif skill and item.tags then
if contains(item.tags, skill) then
if (item.name ~= "Scroll of the Soul Wisdom") then
table.insert(scrollIds, {key = key, level = item.level})
-- s = s .. createRow(item)
end
end
end
end
end
table.sort(scrollIds, function(a, b) return a.level < b.level end)
for _, scroll in ipairs(scrollIds) do
s = s .. createRow(items[scroll.key])
end
s = s .. "</table>"
return s
end
function p.list(frame)
local args = frame:getParent().args
return p._list(args)
end
function p._list(args)
local slot
local skill
if args.slot then
slot = args.slot:lower()
elseif args.skill then
skill = args.skill:lower()
else
slot = args[1]:lower()
end
return createTable(slot, skill)
end
return p