Module:Heat
Jump to navigation
Jump to search
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 = "" local s2 = "" s = s .. "{| class=\"wikitable sortable \"\n" s = s .. "!Image\n" s = s .. "!Name\n" s = s .. "!Heat\n" s = s .. "!Vendor\n" s2 = s s = s .. "!Market\n" s = s .. "!Gold(Market)/Heat\n" s = s .. "|-\n" s2 = s2 .. "|-\n" if item ~= 0 then else for key, item in pairs(p.loadData("item")) do local s3 = "" if item['heat'] then s3 = s3 .. "|<img src=\"" .. fullUrl(item['itemImage']) .. "\" width=\"40\">\n" s3 = s3 .. "|" .. item['name'] .. "\n" s3 = s3 .. "|" .. addSeparator(item['heat']) .. "\n" s3 = s3 .. "|" .. addSeparator(item['value']) .. "\n" if item['tradeable'] == false or item['relatedAbility'] then s3 = s3 .. "|-\n" s2 = s2 .. s3 else local market = require("Module:Market")["_price"]({item['name'], 1, 1}) if market then s3 = s3 .. "|" .. addSeparator(market) .. "\n" s3 = s3 .. "|" .. addSeparator(math.floor(market/item['heat']*100)/100) .. "\n" s3 = s3 .. "|-\n" else s3 = s3 .. "|Yes\n" s3 = s3 .. "|\n" s3 = s3 .. "|-\n" end s = s .. s3 end end end end s = s .. "|}" s2 = s2 .. "|}" return s .. "\n" .. s2 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