Module:CosmeticCrates: Difference between revisions
From MCC Island Wiki
More actions
since it seems to expand the wikitext |
oh yeah, i need to use expandTemplate |
||
Line 52: | Line 52: | ||
local cell | local cell | ||
if isAnimated(frame, filename) then | if isAnimated(frame, filename) then | ||
cell = string.format(' | local afix = frame:expandTemplate{ title = 'AFix', args = { filename, link = name } } | ||
cell = string.format('|%s [[%s]]<br /> %.2f%%\n', afix, name, chance) | |||
else | else | ||
cell = string.format('|[[File:%s|150px|center|link=%s]] <br /> [[%s]] <br /> %.2f%%\n', filename, name, name, chance) | cell = string.format('|[[File:%s|150px|center|link=%s]] <br /> [[%s]] <br /> %.2f%%\n', filename, name, name, chance) |
Revision as of 23:02, 12 July 2025
Documentation for this module may be created at Module:CosmeticCrates/doc
local getArgs = require('Module:Arguments').getArgs
local errorModule = require('Module:Error')
local data = require("Module:CosmeticCrates/Data")
if not data then
return "Error: Unable to load data"
end
local p = {}
local function isAnimated(frame, filename)
if not frame.preprocess then
return true
end
local content = frame:preprocess('{{:File:' .. filename .. '}}')
return content:find('Category:Animated images') ~= nil
end
function p.getChance(frame)
local args = getArgs(frame)
local name = args.name
for _, crate in pairs(data) do
local chance = crate[name]
if chance then
return chance .. '%'
end
end
return errorModule.error{
message = 'Cosmetic "' .. name .. '" not found in any crate.',
tag = 'span'
}
end
function p.makeTable(frame)
local args = getArgs(frame)
local crate = args.crate
local crateData = data[crate]
if not crateData then return 'No data found for crate: ' .. crate end
local result = '{| class="wikitable"\n|-\n'
local count = 0
for _, entry in ipairs(crateData) do
if count % 5 == 0 and count > 0 then
result = result .. '|-\n'
end
local name, chance = entry[1], entry[2]
local filename = name .. '.png'
local cell
if isAnimated(frame, filename) then
local afix = frame:expandTemplate{ title = 'AFix', args = { filename, link = name } }
cell = string.format('|%s [[%s]]<br /> %.2f%%\n', afix, name, chance)
else
cell = string.format('|[[File:%s|150px|center|link=%s]] <br /> [[%s]] <br /> %.2f%%\n', filename, name, name, chance)
end
result = result .. cell
count = count + 1
end
result = result .. '|}'
return result
end
return p