Binding of Isaac: Rebirth Wiki
Binding of Isaac: Rebirth Wiki
m
m
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
local p = {}
 
local p = {}
   
local bit32 = require( 'bit32' )
+
local w_bit = require( 'module:bit' )
 
 
local w_frame = require( 'module:frame' )
 
local w_frame = require( 'module:frame' )
   
Line 16: Line 15:
 
local args = w_frame.args( f )
 
local args = w_frame.args( f )
 
return ( data.test[tonumber( args[1] )] or {} )[tonumber( args[2] ) or 15] or 0
 
return ( data.test[tonumber( args[1] )] or {} )[tonumber( args[2] ) or 15] or 0
end
 
 
 
p['context push'] = function ( f )
 
local args = w_frame.args( f )
 
local filter = args.parsed or data.values[args[1]]
 
if not filter then
 
return
 
end
 
local frame = mw.getCurrentFrame()
 
local context = frame:callParserFunction( '#var:context' )
 
filter = bit32.band( filter, tonumber( context ~= '' and mw.text.split( context, ' ' )[1] or 15 ) )
 
if not filter then
 
return
 
end
 
frame:callParserFunction( '#vardefine:context', filter .. ' ' .. context )
 
end
 
 
 
p['context test'] = function ( f )
 
local args = w_frame.args( f )
 
local filter = tonumber( args.parsed or data.values[args[1]] )
 
if not filter or not data.test[filter] then
 
return 0
 
end
 
local context = mw.getCurrentFrame():callParserFunction( '#var:context' )
 
return data.test[filter][tonumber( context ~= '' and mw.text.split( context, ' ' )[1] ) or 15] or 0
 
 
end
 
end
   
Line 48: Line 20:
 
function p.find( f )
 
function p.find( f )
 
local args = w_frame.args( f )
 
local args = w_frame.args( f )
local filter = args[2] == 'last' and 8 or args[2] or mw.getCurrentFrame():callParserFunction( '#var:context' )
+
local filter = args[2] == 'last' and 8 or args[2] or tonumber( mw.getCurrentFrame():callParserFunction( '#var:context' ) ) or 15
 
local parts
 
local parts
 
for str in mw.text.gsplit( args[1], '▼' ) do
 
for str in mw.text.gsplit( args[1], '▼' ) do
 
parts = mw.text.split( str, '►' )
 
parts = mw.text.split( str, '►' )
if bit32.band( tonumber( parts[1] ), filter ) > 0 then
+
if w_bit['and']{ parts[1], filter } > 0 then
 
return parts[2]
 
return parts[2]
 
end
 
end

Latest revision as of 10:07, 3 May 2021


local p = {}

local w_bit = require( 'module:bit' )
local w_frame = require( 'module:frame' )

local data = mw.loadData( 'module:dlc/data' )


function p.parse( f )
	return data.values[w_frame.args( f )[1] or ''] or 0
end


function p.test( f )
	local args = w_frame.args( f )
	return ( data.test[tonumber( args[1] )] or {} )[tonumber( args[2] ) or 15] or 0
end


function p.find( f )
	local args   = w_frame.args( f )
	local filter = args[2] == 'last' and 8 or args[2] or tonumber( mw.getCurrentFrame():callParserFunction( '#var:context' ) ) or 15
	local parts
	for str in mw.text.gsplit( args[1], '▼' ) do
		parts = mw.text.split( str, '►' )
		if w_bit['and']{ parts[1], filter } > 0 then
			return parts[2]
		end
	end
end


return p