Difference between revisions of "Module:Heat"
Jump to navigation
Jump to search
m |
m |
||
(6 intermediate revisions by the same user not shown) | |||
Line 89: | Line 89: | ||
local function createTable(item) | local function createTable(item) | ||
local s = "" | local s = "" | ||
− | s = "{| class=\"wikitable sortable \"\n" | + | local s2 = "" |
− | s = s .. " | + | s = s .. "{| class=\"wikitable sortable \"\n" |
− | s = s .. "! | + | s = s .. "|+Tradeable\n" |
+ | s = s .. "|-\n" | ||
+ | s = s .. "!Item\n" | ||
s = s .. "!Heat\n" | s = s .. "!Heat\n" | ||
s = s .. "!Vendor\n" | s = s .. "!Vendor\n" | ||
s = s .. "!Market\n" | s = s .. "!Market\n" | ||
s = s .. "!Gold(Market)/Heat\n" | s = s .. "!Gold(Market)/Heat\n" | ||
− | s = s .. "|-" | + | s = s .. "|-\n" |
+ | |||
+ | s2 = s2 .. "{| class=\"wikitable sortable \"\n" | ||
+ | s2 = s2 .. "|+Untradeable\n" | ||
+ | s2 = s2 .. "|-\n" | ||
+ | s2 = s2 .. "!Item\n" | ||
+ | s2 = s2 .. "!Heat\n" | ||
+ | s2 = s2 .. "!Vendor\n" | ||
+ | s2 = s2 .. "|-\n" | ||
if item ~= 0 then | if item ~= 0 then | ||
− | + | ||
else | else | ||
for key, item in pairs(p.loadData("item")) do | for key, item in pairs(p.loadData("item")) do | ||
+ | local s3 = "" | ||
if item['heat'] then | if item['heat'] then | ||
− | + | s3 = s3 .. "|" .. icon(item['name'], item['itemImage'], 1) .. "\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 | 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 | ||
− | |||
end | end | ||
end | end | ||
s = s .. "|}" | s = s .. "|}" | ||
− | return s | + | s2 = s2 .. "|}" |
+ | return s .. "\n" .. s2 | ||
end | end | ||
Latest revision as of 02:40, 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 = "" local s2 = "" s = s .. "{| class=\"wikitable sortable \"\n" s = s .. "|+Tradeable\n" s = s .. "|-\n" s = s .. "!Item\n" s = s .. "!Heat\n" s = s .. "!Vendor\n" s = s .. "!Market\n" s = s .. "!Gold(Market)/Heat\n" s = s .. "|-\n" s2 = s2 .. "{| class=\"wikitable sortable \"\n" s2 = s2 .. "|+Untradeable\n" s2 = s2 .. "|-\n" s2 = s2 .. "!Item\n" s2 = s2 .. "!Heat\n" s2 = s2 .. "!Vendor\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 .. "|" .. icon(item['name'], item['itemImage'], 1) .. "\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