Difference between revisions of "Module:Heat"
Jump to navigation
Jump to search
m |
m |
||
Line 102: | Line 102: | ||
for key, item in pairs(p.loadData("item")) do | for key, item in pairs(p.loadData("item")) do | ||
if item['heat'] then | if item['heat'] then | ||
− | s = s .. "|<img src=\"" .. fullUrl(item['itemImage']) .. "\" width=\" | + | s = s .. "|<img src=\"" .. fullUrl(item['itemImage']) .. "\" width=\"40\">\n" |
s = s .. "|" .. item['name'] .. "\n" | s = s .. "|" .. item['name'] .. "\n" | ||
s = s .. "|" .. addSeparator(item['heat']) .. "\n" | s = s .. "|" .. addSeparator(item['heat']) .. "\n" |
Revision as of 02:01, 10 October 2023
local p = {} local data_module_names = { item = 'Module:Items/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 findItem(name) local lname = name:lower() --Remove leading and trailing spaces. lname = lname:gsub('^%s*(.-)%s*$', '%1') for key, item in pairs(p.loadData("item")) do if lname == item['name']:lower() then return item end end return 0 end local function getItem(id) return p.loadData("item")[tostring(id)] end local function getItemName(id) return p.loadData("item")[tostring(id)]['name'] 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 itemImage(id, word) local item = p.loadData("item")[tostring(id)] local url = "" if item['itemIcon'] then url = item['itemIcon'] else url = item['itemImage'] end return icon(item['name'], url, word) end local function img(id) local url = "" if item['itemIcon'] then url = item['itemIcon'] else url = item['itemImage'] end return fullUrl(url) end local function addSeparator(num) return tostring(tonumber(num)):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse() end local function createTable(item) local s = "" s = "{| class=\"wikitable sortable \"\n" s = s .. "!Image\n" s = s .. "!Name\n" s = s .. "!Heat\n" s = s .. "!Vendor\n" s = s .. "!Market\n" s = s .. "!Gold(Market)/Heat\n" s = s .. "|-" if item ~= 0 then else for key, item in pairs(p.loadData("item")) do if item['heat'] then s = s .. "|<img src=\"" .. fullUrl(item['itemImage']) .. "\" width=\"40\">\n" s = s .. "|" .. item['name'] .. "\n" s = s .. "|" .. addSeparator(item['heat']) .. "\n" s = s .. "|" .. addSeparator(item['value']) .. "\n" local market = require("Module:Market")["_price"]({item['name'], 1, 1}) if market then s = s .. "|" .. addSeparator(market) .. "\n" s = s .. "|" .. addSeparator(math.floor(market/item['heat']*100)/100) .. "\n" else s = s .. "|Yes\n" s = s .. "|\n" end end s = s .. "|-\n" end end s = s .. "|}" return s end function p.heat(frame) local args = frame:getParent().args return p._heat(args) end function p._heat(args) local name = "" local item = 0 local wikitable = "" if args[1] then name = args[1] item = findItem(name) end wikitable = createTable(item) return wikitable end return p