BitSpawn Lv 1
About filters, one thing I do on recipes is disable them with structure functions (wiggle, shake…) and enable them for getting score.
I have written a code for overload the lua classes, so we can set/unset filters for all the functions in a class, and easily modify the old recipes.
The idea is:
MutClass(structure, false): set filters disabled on all the functions in 'structure'
MutClass(band, false): set filters disabled for band functions
MutClass(current, true): set filters enabled on all the functions in 'current' (for example GetEnergyScore
On that way if you are cutting, wiggling, and so on, you change filters only one time, avoiding disable_filters/cut/enable/disable/cut/enable/disable… For example, a sequence of actions:
getScore: filter on
Wiggle: filters off
Shake: nothing
Wiggle: nothing
Shake: nothing
getScore: filters on
For this, the functions:
-- function to copy class/table
function CopyTable(orig)
local copy = {}
for orig_key, orig_value in pairs(orig) do
copy[orig_key] = orig_value
end
return copy
end
-- functions for filters
function FiltersOn()
if behavior.GetSlowFiltersDisabled() then
behavior.SetSlowFiltersDisabled(false)
end
end
function FiltersOff()
if behavior.GetSlowFiltersDisabled()==false then
behavior.SetSlowFiltersDisabled(true)
end
end
-- function to overload a funtion
function mutFunction(func)
local currentfunc = func
local function mutate(func, newfunc)
local lastfunc = currentfunc
currentfunc = function(...) return newfunc(lastfunc, ...) end
end
local wrapper = function(...) return currentfunc(...) end
return wrapper, mutate
end
-- function to overload a class
-- to do: set the name of function
classes_copied = 0
myclcp = {}
function MutClass(cl, filters)
classes_copied = classes_copied+1
myclcp[classes_copied] = CopyTable(cl)
local mycl =myclcp[classes_copied]
for orig_key, orig_value in pairs(cl) do
myfunc, mutate = mutFunction(mycl[orig_key])
if filters==true then
mutate(myfunc, function(...)
print("Mutated function called: filter on")
FiltersOn()
if table.getn(arg)>1 then
-- first arg is self (function pointer), we pack from second argument
local arguments = {}
for i=2,table.getn(arg) do
arguments[i-1]=arg[i]
end
return mycl[orig_key](unpack(arguments))
else
--print("No arguments")
return mycl[orig_key]()
end
end)
cl[orig_key] = myfunc
else
mutate(myfunc, function(...)
print("mutated funcion called: filter off")
FiltersOff()
if table.getn(arg)>1 then
local arguments = {}
for i=2, table.getn(arg) do
arguments[i-1]=arg[i]
end
return mycl[orig_key](unpack(arguments))
else
return mycl[orig_key]()
end
end)
cl[orig_key] = myfunc
end
end
end
-- how to use:
MutClass(structure, false)
MutClass(band, false)
MutClass(current, true)
</pre>
On this way class structure and class band will be with no filters, and class current will use filters. Write this code at the start of your recipe.