SHOW:
|
|
- or go back to the newest paste.
| 1 | --Stores a blank array to add the instructions to later, and stores that array in a global variable. | |
| 2 | --Returns both the index of that variable and the created filter. | |
| 3 | CW_Filter_ClearFilter = function() | |
| 4 | return {{CW_Globals_Store({})}, ClearFilter()}
| |
| 5 | ||
| 6 | --[[ | |
| 7 | ...Verbose version... | |
| 8 | local aNewArray = {}
| |
| 9 | local iGlobalIndex = CW_Globals_Store(NewArray) | |
| 10 | local aiIndices = {iGlobalIndex}
| |
| 11 | local oFilter = ClearFilter() | |
| 12 | local aoFilter = {aiIndices, oFilter}
| |
| 13 | return aoFilter | |
| 14 | ]] | |
| 15 | end | |
| 16 | ||
| 17 | --Simply gets the global index of the filter. When passed into CW_Globals_Retrieve(), you'll get the instruction table. | |
| 18 | CW_Filter_GetGlobalIndex = function(aoFilter) | |
| 19 | return aoFilter[1][1] | |
| 20 | end | |
| 21 | ||
| 22 | --Calls oFilter:Add() with the parameters given and stores "Add" and the parameters in the instruction table. | |
| 23 | CW_Filter_Add = function(aoFilter, aParameters) | |
| 24 | local aoFilterTable = CW_Filter_GetFilterTable(aoFilter) | |
| 25 | aoFilterTable[#aoFilterTable+1] = {"Add", aParameters}
| |
| 26 | --Because Lua's tables are references, the changes above exist in the actual global table. They do not need to be stored. | |
| 27 | ||
| 28 | local oFilter = aoFilter[2] | |
| 29 | if #aParameters == 2 then | |
| 30 | oFilter:Add(aParameters[1], aParameters[2]) | |
| 31 | else | |
| 32 | oFilter:Add(aParameters[1], aParameters[2], aParameters[3]) | |
| 33 | end | |
| 34 | end | |
| 35 | ||
| 36 | --Calls oFilter:AddSubFilter_Or() and stores "AddSubFilter_Or" and a new empty array in the instruction table. | |
| 37 | --Adds the index at which this new array is found to the indices list. | |
| 38 | --Returns the indices and the subfilter. | |
| 39 | CW_Filter_AddSubFilter_Or = function(aoFilter) | |
| 40 | local aoFilterTable = CW_Filter_GetFilterTable(aoFilter) | |
| 41 | local aiIndices = aoFilter[1] | |
| 42 | aiIndices[#aiIndices+1] = #aoFilterTable+1 | |
| 43 | aoFilterTable[#aoFilterTable+1] = {"AddSubFilter_Or", {}}
| |
| 44 | ||
| 45 | local oFilter = aoFilter[2] | |
| 46 | local oSubfilter = oFilter:AddSubFilter_Or() | |
| 47 | ||
| 48 | return {aiIndices, oSubfilter}
| |
| 49 | end | |
| 50 | ||
| 51 | --Calls oFilter:AddSubFilter_And() and stores "AddSubFilter_And" and a new empty array in the instruction table. | |
| 52 | --Adds the index at which this new array is found to the indices list. | |
| 53 | --Returns the indices and the subfilter. | |
| 54 | CW_Filter_AddSubFilter_And = function(aoFilter) | |
| 55 | local aoFilterTable = CW_Filter_GetFilterTable(aoFilter) | |
| 56 | local aiIndices = aoFilter[1] | |
| 57 | aiIndices[#aiIndices+1] = #aoFilterTable+1 | |
| 58 | aoFilterTable[#aoFilterTable+1] = {"AddSubFilter_And", {}}
| |
| 59 | ||
| 60 | local oFilter = aoFilter[2] | |
| 61 | local oSubfilter = oFilter:AddSubFilter_And() | |
| 62 | ||
| 63 | return {aiIndices, oSubfilter}
| |
| 64 | end | |
| 65 | ||
| 66 | --Calls oFilter:SetZone() with the parameters given and stores "SetZone" and the parameters in the instruction table. | |
| 67 | CW_Filter_SetZone = function(aoFilter, aParameters) | |
| 68 | local aoFilterTable = CW_Filter_GetFilterTable(aoFilter) | |
| 69 | aoFilterTable[#aoFilterTable+1] = {"SetZone", aParameters}
| |
| 70 | ||
| 71 | local oFilter = aoFilter[2] | |
| 72 | if #aParameters == 1 then | |
| 73 | oFilter:SetZone(aParameters[1]) | |
| 74 | else | |
| 75 | oFilter:SetZone(aParameters[1], aParameters[2]) | |
| 76 | end | |
| 77 | end | |
| 78 | ||
| 79 | --Calls oFilter:SetFilterType() with the parameters given and stores "SetFilterType" and the parameters in the instruction table. | |
| 80 | CW_Filter_SetFilterType = function(aoFilter, aParameters) | |
| 81 | local aoFilterTable = CW_Filter_GetFilterTable(aoFilter) | |
| 82 | aoFilterTable[#aoFilterTable+1] = {"SetFilterType", aParameters}
| |
| 83 | ||
| 84 | local oFilter = aoFilter[2] | |
| 85 | oFilter:SetFilterType(aParameters[1]) | |
| 86 | end | |
| 87 | ||
| 88 | --Calls oFilter:SetPortion() with the parameters given and stores "SetPortion" and the parameters in the instruction table. | |
| 89 | CW_Filter_SetPortion = function(aoFilter, aParameters) | |
| 90 | local aoFilterTable = CW_Filter_GetFilterTable(aoFilter) | |
| 91 | aoFilterTable[#aoFilterTable+1] = {"SetPortion", aParameters}
| |
| 92 | ||
| 93 | local oFilter = aoFilter[2] | |
| 94 | oFilter:SetPortion(aParameters[1]) | |
| 95 | end | |
| 96 | ||
| 97 | --Calls oFilter:SetReversePortion() with the parameters given and stores "SetReversePortion" and the parameters in the instruction table. | |
| 98 | CW_Filter_SetReversePortion = function(aoFilter, aParameters) | |
| 99 | local aoFilterTable = CW_Filter_GetFilterTable(aoFilter) | |
| 100 | aoFilterTable[#aoFilterTable+1] = {"SetReversePortion", aParameters}
| |
| 101 | ||
| 102 | local oFilter = aoFilter[2] | |
| 103 | oFilter:SetReversePortion(aParameters[1]) | |
| 104 | end | |
| 105 | ||
| 106 | --Calls oFilter:SetUnique() with the parameters given and stores "SetUnique" and the parameters in the instruction table. | |
| 107 | CW_Filter_SetUnique = function(aoFilter) | |
| 108 | local aoFilterTable = CW_Filter_GetFilterTable(aoFilter) | |
| 109 | aoFilterTable[#aoFilterTable+1] = {"SetUnique"}
| |
| 110 | ||
| 111 | local oFilter = aoFilter[2] | |
| 112 | oFilter:SetUnique() | |
| 113 | end | |
| 114 | ||
| 115 | --Calls oFilter:SetMarkedObjectsOnly() with the parameters given and stores "SetMarkedObjectsOnly" and the parameters in the instruction table. | |
| 116 | CW_Filter_SetMarkedObjectsOnly = function(aoFilter) | |
| 117 | local aoFilterTable = CW_Filter_GetFilterTable(aoFilter) | |
| 118 | aoFilterTable[#aoFilterTable+1] = {"SetMarkedObjectsOnly"}
| |
| 119 | ||
| 120 | local oFilter = aoFilter[2] | |
| 121 | oFilter:SetMarkedObjectsOnly() | |
| 122 | end | |
| 123 | ||
| 124 | --Calls oFilter:SetUnmarkedObjectsOnly() with the parameters given and stores "SetUnmarkedObjectsOnly" and the parameters in the instruction table. | |
| 125 | CW_Filter_SetUnmarkedObjectsOnly = function(aoFilter) | |
| 126 | local aoFilterTable = CW_Filter_GetFilterTable(aoFilter) | |
| 127 | aoFilterTable[#aoFilterTable+1] = {"SetUnmarkedObjectsOnly"}
| |
| 128 | ||
| 129 | local oFilter = aoFilter[2] | |
| 130 | oFilter:SetUnmarkedObjectsOnly() | |
| 131 | end | |
| 132 | ||
| 133 | --Gets the instruction table based on the GlobalIndex provided. | |
| 134 | --Iterates through the instructions and calls the functions as they're found. | |
| 135 | --Recursively reconstructs subfilters, which, except for their local rather than global index, are treated as their own filter. | |
| 136 | --Returns the resulting filter. | |
| 137 | CW_Filter_GetStoredFilter = function(iIndex) | |
| 138 | local aoFilterTable = CW_Globals_Retrieve(iIndex) | |
| 139 | local oFilter = ClearFilter() | |
| 140 | for _, aEntry in pairs(aoFilterTable) do | |
| 141 | local sCall = aEntry[1] | |
| 142 | local aParameters = aEntry[2] | |
| 143 | if sCall == "Add" then | |
| 144 | if #aParameters == 2 then | |
| 145 | oFilter:Add(aParameters[1], aParameters[2]) | |
| 146 | else | |
| 147 | oFilter:Add(aParameters[1], aParameters[2], aParameters[3]) | |
| 148 | end | |
| 149 | elseif sCall == "SetFilterType" then | |
| 150 | oFilter:SetFilterType(aParameters[1]) | |
| 151 | elseif sCall == "SetZone" then | |
| 152 | if #aParameters == 1 then | |
| 153 | oFilter:SetZone(aParameters[1]) | |
| 154 | else | |
| 155 | oFilter:SetZone(aParameters[1], aParameters[2]) | |
| 156 | end | |
| 157 | elseif sCall == "AddSubFilter_Or" then | |
| 158 | CW_Filter_ReconstructSubfilter(oFilter:AddSubFilter_Or(), aParameters) | |
| 159 | elseif sCall == "AddSubFilter_And" then | |
| 160 | CW_Filter_ReconstructSubfilter(oFilter:AddSubFilter_And(), aParameters) | |
| 161 | else | |
| 162 | CW_General_Error("CW_Filter_Reconstruct: Unknown call ("..sCall..")")
| |
| 163 | end | |
| 164 | end | |
| 165 | return oFilter | |
| 166 | end | |
| 167 | ||
| 168 | --A recursive function for constructing subfilters. | |
| 169 | --Returns the subfilter, even though it is unlikely to be used. | |
| 170 | CW_Filter_ReconstructSubfilter = function(oFilter, aoFilterTable) | |
| 171 | for _, aEntry in pairs(aoFilterTable) do | |
| 172 | local sCall = aEntry[1] | |
| 173 | local aParameters = aEntry[2] | |
| 174 | if sCall == "Add" then | |
| 175 | if #aParameters == 2 then | |
| 176 | oFilter:Add(aParameters[1], aParameters[2]) | |
| 177 | else | |
| 178 | oFilter:Add(aParameters[1], aParameters[2], aParameters[3]) | |
| 179 | end | |
| 180 | elseif sCall == "SetFilterType" then | |
| 181 | oFilter:SetFilterType(aParameters[1]) | |
| 182 | elseif sCall == "SetZone" then | |
| 183 | if #aParameters == 1 then | |
| 184 | oFilter:SetZone(aParameters[1]) | |
| 185 | else | |
| 186 | oFilter:SetZone(aParameters[1], aParameters[2]) | |
| 187 | end | |
| 188 | elseif sCall == "AddSubFilter_Or" then | |
| 189 | CW_Filter_ReconstructSubfilter(oFilter:AddSubFilter_Or(), aParameters) | |
| 190 | elseif sCall == "AddSubFilter_And" then | |
| 191 | CW_Filter_ReconstructSubfilter(oFilter:AddSubFilter_And(), aParameters) | |
| 192 | else | |
| 193 | CW_General_Error("CW_Filter_Reconstruct: Unknown call ("..sCall..")")
| |
| 194 | end | |
| 195 | end | |
| 196 | return oFilter | |
| 197 | end | |
| 198 | ||
| 199 | --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. | |
| 200 | --Works for both the main filter and any subfilters. | |
| 201 | CW_Filter_GetFilterTable = function(aoFilter) | |
| 202 | local aiIndices = aoFilter[1] | |
| 203 | local aoFilterTable = CW_Globals_Retrieve(aiIndices[1]) | |
| 204 | for i=2,#aiIndices do | |
| 205 | aoFilterTable = aoFilterTable[i] | |
| 206 | end | |
| 207 | return aoFilterTable | |
| 208 | end | |
| 209 | ||
| 210 | --A set of quick functions set up to match the naming convention of the above functions. | |
| 211 | CW_Filter_Count = function(aoFilter) | |
| 212 | return aoFilter[2]:Count() | |
| 213 | ||
| 214 | end | |
| 215 | CW_Filter_CountStopAt = function(aoFilter, iInt) | |
| 216 | return aoFilter[2]:CountStopAt(iInt) | |
| 217 | end | |
| 218 | ||
| 219 | CW_Filter_EvaluateObjects = function(aoFilter) | |
| 220 | return aoFilter[2]:EvaluateObjects() | |
| 221 | end | |
| 222 | ||
| 223 | CW_Filter_GetNthEvaluatedObject = function(aoFilter, iIndex) | |
| 224 | return aoFilter[2]:GetNthEvaluatedObject(iIndex) | |
| 225 | end | |
| 226 | ||
| 227 | CW_Filter_GetRandomEvaluatedObject = function(aoFilter) | |
| 228 | return aoFilter[2]:GetRandomEvaluatedObject() | |
| 229 | end | |
| 230 | ||
| 231 | CW_Filter_EvaluatePlayers = function(aoFilter) | |
| 232 | return aoFilter[2]:EvaluatePlayers() | |
| 233 | end | |
| 234 | ||
| 235 | CW_Filter_GetNthEvaluatedPlayer = function(aoFilter, iIndex) | |
| 236 | return aoFilter[2]:GetNthEvaluatedPlayer(iIndex) | |
| 237 | end | |
| 238 | ||
| 239 | CW_Filter_ChromaCount = function(aoFilter) | |
| 240 | return aoFilter[2]:ChromaCount() | |
| 241 | end | |
| 242 | ||
| 243 | CW_Filter_Invalidate = function(aoFilter) | |
| 244 | return aoFilter[2]:Invalidate() | |
| 245 | end |