Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Stores a blank array to add the instructions to later, and stores that array in a global variable.
- --Returns both the index of that variable and the created filter.
- CW_Filter_ClearFilter = function()
- return {{CW_Globals_Store({})}, ClearFilter()}
- --[[
- ...Verbose version...
- local aNewArray = {}
- local iGlobalIndex = CW_Globals_Store(NewArray)
- local aiIndices = {iGlobalIndex}
- local oFilter = ClearFilter()
- local aoFilter = {aiIndices, oFilter}
- return aoFilter
- ]]
- end
- --Simply gets the global index of the filter. When passed into CW_Globals_Retrieve(), you'll get the instruction table.
- CW_Filter_GetGlobalIndex = function(aoFilter)
- return aoFilter[1][1]
- end
- --Calls oFilter:Add() with the parameters given and stores "Add" and the parameters in the instruction table.
- CW_Filter_Add = function(aoFilter, aParameters)
- local aoFilterTable = CW_Filter_GetFilterTable(aoFilter)
- aoFilterTable[#aoFilterTable+1] = {"Add", aParameters}
- --Because Lua's tables are references, the changes above exist in the actual global table. They do not need to be stored.
- local oFilter = aoFilter[2]
- if #aParameters == 2 then
- oFilter:Add(aParameters[1], aParameters[2])
- else
- oFilter:Add(aParameters[1], aParameters[2], aParameters[3])
- end
- end
- --Calls oFilter:AddSubFilter_Or() and stores "AddSubFilter_Or" and a new empty array in the instruction table.
- --Adds the index at which this new array is found to the indices list.
- --Returns the indices and the subfilter.
- CW_Filter_AddSubFilter_Or = function(aoFilter)
- local aoFilterTable = CW_Filter_GetFilterTable(aoFilter)
- local aiIndices = aoFilter[1]
- aiIndices[#aiIndices+1] = #aoFilterTable+1
- aoFilterTable[#aoFilterTable+1] = {"AddSubFilter_Or", {}}
- local oFilter = aoFilter[2]
- local oSubfilter = oFilter:AddSubFilter_Or()
- return {aiIndices, oSubfilter}
- end
- --Calls oFilter:AddSubFilter_And() and stores "AddSubFilter_And" and a new empty array in the instruction table.
- --Adds the index at which this new array is found to the indices list.
- --Returns the indices and the subfilter.
- CW_Filter_AddSubFilter_And = function(aoFilter)
- local aoFilterTable = CW_Filter_GetFilterTable(aoFilter)
- local aiIndices = aoFilter[1]
- aiIndices[#aiIndices+1] = #aoFilterTable+1
- aoFilterTable[#aoFilterTable+1] = {"AddSubFilter_And", {}}
- local oFilter = aoFilter[2]
- local oSubfilter = oFilter:AddSubFilter_And()
- return {aiIndices, oSubfilter}
- end
- --Calls oFilter:SetZone() with the parameters given and stores "SetZone" and the parameters in the instruction table.
- CW_Filter_SetZone = function(aoFilter, aParameters)
- local aoFilterTable = CW_Filter_GetFilterTable(aoFilter)
- aoFilterTable[#aoFilterTable+1] = {"SetZone", aParameters}
- local oFilter = aoFilter[2]
- if #aParameters == 1 then
- oFilter:SetZone(aParameters[1])
- else
- oFilter:SetZone(aParameters[1], aParameters[2])
- end
- end
- --Calls oFilter:SetFilterType() with the parameters given and stores "SetFilterType" and the parameters in the instruction table.
- CW_Filter_SetFilterType = function(aoFilter, aParameters)
- local aoFilterTable = CW_Filter_GetFilterTable(aoFilter)
- aoFilterTable[#aoFilterTable+1] = {"SetFilterType", aParameters}
- local oFilter = aoFilter[2]
- oFilter:SetFilterType(aParameters[1])
- end
- --Calls oFilter:SetPortion() with the parameters given and stores "SetPortion" and the parameters in the instruction table.
- CW_Filter_SetPortion = function(aoFilter, aParameters)
- local aoFilterTable = CW_Filter_GetFilterTable(aoFilter)
- aoFilterTable[#aoFilterTable+1] = {"SetPortion", aParameters}
- local oFilter = aoFilter[2]
- oFilter:SetPortion(aParameters[1])
- end
- --Calls oFilter:SetReversePortion() with the parameters given and stores "SetReversePortion" and the parameters in the instruction table.
- CW_Filter_SetReversePortion = function(aoFilter, aParameters)
- local aoFilterTable = CW_Filter_GetFilterTable(aoFilter)
- aoFilterTable[#aoFilterTable+1] = {"SetReversePortion", aParameters}
- local oFilter = aoFilter[2]
- oFilter:SetReversePortion(aParameters[1])
- end
- --Calls oFilter:SetUnique() with the parameters given and stores "SetUnique" and the parameters in the instruction table.
- CW_Filter_SetUnique = function(aoFilter)
- local aoFilterTable = CW_Filter_GetFilterTable(aoFilter)
- aoFilterTable[#aoFilterTable+1] = {"SetUnique"}
- local oFilter = aoFilter[2]
- oFilter:SetUnique()
- end
- --Calls oFilter:SetMarkedObjectsOnly() with the parameters given and stores "SetMarkedObjectsOnly" and the parameters in the instruction table.
- CW_Filter_SetMarkedObjectsOnly = function(aoFilter)
- local aoFilterTable = CW_Filter_GetFilterTable(aoFilter)
- aoFilterTable[#aoFilterTable+1] = {"SetMarkedObjectsOnly"}
- local oFilter = aoFilter[2]
- oFilter:SetMarkedObjectsOnly()
- end
- --Calls oFilter:SetUnmarkedObjectsOnly() with the parameters given and stores "SetUnmarkedObjectsOnly" and the parameters in the instruction table.
- CW_Filter_SetUnmarkedObjectsOnly = function(aoFilter)
- local aoFilterTable = CW_Filter_GetFilterTable(aoFilter)
- aoFilterTable[#aoFilterTable+1] = {"SetUnmarkedObjectsOnly"}
- local oFilter = aoFilter[2]
- oFilter:SetUnmarkedObjectsOnly()
- end
- --Gets the instruction table based on the GlobalIndex provided.
- --Iterates through the instructions and calls the functions as they're found.
- --Recursively reconstructs subfilters, which, except for their local rather than global index, are treated as their own filter.
- --Returns the resulting filter.
- CW_Filter_GetStoredFilter = function(iIndex)
- local aoFilterTable = CW_Globals_Retrieve(iIndex)
- local oFilter = ClearFilter()
- for _, aEntry in pairs(aoFilterTable) do
- local sCall = aEntry[1]
- local aParameters = aEntry[2]
- if sCall == "Add" then
- if #aParameters == 2 then
- oFilter:Add(aParameters[1], aParameters[2])
- else
- oFilter:Add(aParameters[1], aParameters[2], aParameters[3])
- end
- elseif sCall == "SetFilterType" then
- oFilter:SetFilterType(aParameters[1])
- elseif sCall == "SetZone" then
- if #aParameters == 1 then
- oFilter:SetZone(aParameters[1])
- else
- oFilter:SetZone(aParameters[1], aParameters[2])
- end
- elseif sCall == "AddSubFilter_Or" then
- CW_Filter_ReconstructSubfilter(oFilter:AddSubFilter_Or(), aParameters)
- elseif sCall == "AddSubFilter_And" then
- CW_Filter_ReconstructSubfilter(oFilter:AddSubFilter_And(), aParameters)
- else
- CW_General_Error("CW_Filter_Reconstruct: Unknown call ("..sCall..")")
- end
- end
- return oFilter
- end
- --A recursive function for constructing subfilters.
- --Returns the subfilter, even though it is unlikely to be used.
- CW_Filter_ReconstructSubfilter = function(oFilter, aoFilterTable)
- for _, aEntry in pairs(aoFilterTable) do
- local sCall = aEntry[1]
- local aParameters = aEntry[2]
- if sCall == "Add" then
- if #aParameters == 2 then
- oFilter:Add(aParameters[1], aParameters[2])
- else
- oFilter:Add(aParameters[1], aParameters[2], aParameters[3])
- end
- elseif sCall == "SetFilterType" then
- oFilter:SetFilterType(aParameters[1])
- elseif sCall == "SetZone" then
- if #aParameters == 1 then
- oFilter:SetZone(aParameters[1])
- else
- oFilter:SetZone(aParameters[1], aParameters[2])
- end
- elseif sCall == "AddSubFilter_Or" then
- CW_Filter_ReconstructSubfilter(oFilter:AddSubFilter_Or(), aParameters)
- elseif sCall == "AddSubFilter_And" then
- CW_Filter_ReconstructSubfilter(oFilter:AddSubFilter_And(), aParameters)
- else
- CW_General_Error("CW_Filter_Reconstruct: Unknown call ("..sCall..")")
- end
- end
- return oFilter
- end
- --Sort of an analogue to CW_Filter_GetGlobalIndex(), this will take any index array given to it (starting at the global index) and retrieve the specific filter those indices point to.
- --Works for both the main filter and any subfilters.
- CW_Filter_GetFilterTable = function(aoFilter)
- local aiIndices = aoFilter[1]
- local aoFilterTable = CW_Globals_Retrieve(aiIndices[1])
- for i=2,#aiIndices do
- aoFilterTable = aoFilterTable[i]
- end
- return aoFilterTable
- end
- --A set of quick functions set up to match the naming convention of the above functions.
- CW_Filter_Count = function(aoFilter)
- return aoFilter[2]:Count()
- end
- CW_Filter_CountStopAt = function(aoFilter, iInt)
- return aoFilter[2]:CountStopAt(iInt)
- end
- CW_Filter_EvaluateObjects = function(aoFilter)
- return aoFilter[2]:EvaluateObjects()
- end
- CW_Filter_GetNthEvaluatedObject = function(aoFilter, iIndex)
- return aoFilter[2]:GetNthEvaluatedObject(iIndex)
- end
- CW_Filter_GetRandomEvaluatedObject = function(aoFilter)
- return aoFilter[2]:GetRandomEvaluatedObject()
- end
- CW_Filter_EvaluatePlayers = function(aoFilter)
- return aoFilter[2]:EvaluatePlayers()
- end
- CW_Filter_GetNthEvaluatedPlayer = function(aoFilter, iIndex)
- return aoFilter[2]:GetNthEvaluatedPlayer(iIndex)
- end
- CW_Filter_ChromaCount = function(aoFilter)
- return aoFilter[2]:ChromaCount()
- end
- CW_Filter_Invalidate = function(aoFilter)
- return aoFilter[2]:Invalidate()
- end
Add Comment
Please, Sign In to add comment