m (Load crafting recipes asynchronously) |
mNo edit summary |
||
Line 4: | Line 4: | ||
local data = mw.loadData( 'module:bag of crafting recipes/data' ) |
local data = mw.loadData( 'module:bag of crafting recipes/data' ) |
||
− | function p.recipe(f) |
+ | function p.recipe( f ) |
− | + | return recipe( w_frame.args( f ) ) |
|
end |
end |
||
− | function recipe(r |
+ | function recipe( r ) |
⚫ | |||
− | if |
+ | if r[2] then |
− | return '<div class="crafting-recipe crafting-recipe-async" data-crafting-recipe="' .. r .. '"></div>' |
||
+ | intro = intro .. ' data-next-crafting-recipe="' .. r[2] |
||
⚫ | |||
⚫ | |||
+ | intro = intro .. '|' .. v |
||
⚫ | |||
+ | intro = intro .. '"' |
||
end |
end |
||
+ | r = r[1] |
||
⚫ | |||
+ | return intro .. '>' .. |
||
⚫ | |||
− | data.components[r:byte( |
+ | data.components[r:byte( 1 ) - 0x61] .. |
− | data.components[r:byte( |
+ | data.components[r:byte( 2 ) - 0x61] .. |
− | data.components[r:byte( |
+ | data.components[r:byte( 3 ) - 0x61] .. |
− | data.components[r:byte( |
+ | data.components[r:byte( 4 ) - 0x61] .. |
− | data.components[r:byte( |
+ | data.components[r:byte( 5 ) - 0x61] .. |
− | data.components[r:byte( |
+ | data.components[r:byte( 6 ) - 0x61] .. |
− | data.components[r:byte( |
+ | data.components[r:byte( 7 ) - 0x61] .. |
⚫ | |||
'</div>' |
'</div>' |
||
end |
end |
||
− | function p.tableOfRecipes(f) |
+ | function p.tableOfRecipes( f ) |
+ | return '|-\n| Recipes unavailable at this time' |
||
⚫ | |||
+ | end |
||
⚫ | |||
+ | |||
⚫ | |||
+ | p['table'] = function ( f ) |
||
⚫ | |||
⚫ | |||
− | where = 'id >= ' .. args[2] .. ' AND id < ' .. args[3] .. ' AND is_activated=' .. args[1], |
||
⚫ | |||
⚫ | |||
+ | local where = 'id >= ' .. ( args[1] or '1' ) |
||
+ | if args[2] then |
||
+ | where = where .. ' and id < ' .. args[2] |
||
+ | end |
||
+ | if args.type == 'passive' then |
||
+ | where = where .. ' and is_activated' |
||
+ | elseif args.type == 'active' then |
||
+ | where = where .. ' and not is_activated' |
||
+ | end |
||
+ | |||
⚫ | |||
+ | where = where, |
||
orderBy = 'id', |
orderBy = 'id', |
||
limit = 800 |
limit = 800 |
||
− | }) |
+ | } ) |
+ | |||
⚫ | |||
-- Expand the row templates once per item |
-- Expand the row templates once per item |
||
⚫ | |||
⚫ | |||
⚫ | |||
− | local recipes = data.recipes[tonumber(v.id)] |
+ | local recipes = data.recipes[tonumber( v.id )] |
if recipes ~= nil then |
if recipes ~= nil then |
||
− | table.insert(lines, '|-') |
+ | table.insert( lines, '|-' ) |
− | table.insert(lines, '| ' .. frame:expandTemplate{title='i/query', args=v}) |
+ | table.insert( lines, '| ' .. frame:expandTemplate{ title = 'i/query', args = v } ) |
− | table.insert(lines, '| ' .. tostring(v.id)) |
+ | table.insert( lines, '| ' .. tostring( v.id ) ) |
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | sync = sync - 1 |
||
⚫ | |||
end |
end |
||
end |
end |
||
− | return table.concat(lines, '\n') |
+ | return table.concat( lines, '\n' ) |
end |
end |
||
Revision as of 14:06, 16 October 2021
Documentation for this module may be created at Module:Bag of crafting recipes/doc
local p = {}
local cargo = mw.ext.cargo
local w_frame = require( 'module:frame' )
local data = mw.loadData( 'module:bag of crafting recipes/data' )
function p.recipe( f )
return recipe( w_frame.args( f ) )
end
function recipe( r )
local intro = '<div class="crafting-recipe"'
if r[2] then
intro = intro .. ' data-next-crafting-recipe="' .. r[2]
local n = ipairs( r )
for _, v in n, r, 2 do
intro = intro .. '|' .. v
end
intro = intro .. '"'
end
r = r[1]
return intro .. '>' ..
data.components[r:byte( 1 ) - 0x61] ..
data.components[r:byte( 2 ) - 0x61] ..
data.components[r:byte( 3 ) - 0x61] ..
data.components[r:byte( 4 ) - 0x61] ..
data.components[r:byte( 5 ) - 0x61] ..
data.components[r:byte( 6 ) - 0x61] ..
data.components[r:byte( 7 ) - 0x61] ..
data.components[r:byte( 8 ) - 0x61] ..
'</div>'
end
function p.tableOfRecipes( f )
return '|-\n| Recipes unavailable at this time'
end
p['table'] = function ( f )
local args = w_frame.args( f )
local frame = mw.getCurrentFrame()
local where = 'id >= ' .. ( args[1] or '1' )
if args[2] then
where = where .. ' and id < ' .. args[2]
end
if args.type == 'passive' then
where = where .. ' and is_activated'
elseif args.type == 'active' then
where = where .. ' and not is_activated'
end
local qres = cargo.query( 'collectible', '_pageName = page, dlc, alias, name, image, id', {
where = where,
orderBy = 'id',
limit = 800
} )
-- Expand the row templates once per item
local lines = {}
for _, v in ipairs( qres ) do
local recipes = data.recipes[tonumber( v.id )]
if recipes ~= nil then
table.insert( lines, '|-' )
table.insert( lines, '| ' .. frame:expandTemplate{ title = 'i/query', args = v } )
table.insert( lines, '| ' .. tostring( v.id ) )
table.insert( lines, '| ' .. recipe( recipes ) )
end
end
return table.concat( lines, '\n' )
end
return p