Mercurial > wow > lfg-premade-filter
comparison LFGFilter.lua @ 3:041bc456db50 v2
v2 - complete rework to use filtering expressions in search string
author | ovolkov |
---|---|
date | Wed, 21 Jan 2015 19:19:02 +0300 |
parents | df29f8179b76 |
children | 5a89e06534ac |
comparison
equal
deleted
inserted
replaced
2:db862491a577 | 3:041bc456db50 |
---|---|
1 local aName, aEnv = ... | 1 LFGListFrame.SearchPanel.SearchBox:SetMaxLetters(2048) |
2 aEnv.LFGFilter_Allow_Activity = {} | |
3 aEnv.LFGFilter_Allow_Activity.count = 0 | |
4 local LFGFilter_Allow_Activity = aEnv.LFGFilter_Allow_Activity | |
5 | 2 |
3 local filter_expression_functions = setmetatable({}, { | |
4 __mode = "k", | |
5 __index = function(t, key) | |
6 local func, error = loadstring("return " .. key) | |
7 if error then print("Error in LFG filter expression:\n", error) end | |
8 t[key] = func | |
9 return func | |
10 end | |
11 }) | |
12 | |
13 function LFGListSearchPanel_DoSearch(self) | |
14 local searchText = self.SearchBox:GetText(); | |
15 local real_search, filter_expression = searchText:match("^([^=]-)=(.+)$") | |
16 if filter_expression then | |
17 filter_expression = filter_expression:lower() | |
18 self.filter_func = filter_expression_functions[filter_expression] | |
19 end | |
20 self.filter_expression = filter_expression | |
21 | |
22 -- print("lfgsearch", real_search, filter_expression) | |
23 C_LFGList.Search(self.categoryID, real_search or searchText, self.filters, self.preferredFilters); | |
24 self.searching = true; | |
25 self.searchFailed = false; | |
26 self.selectedResult = nil; | |
27 LFGListSearchPanel_UpdateResultList(self); | |
28 LFGListSearchPanel_UpdateResults(self); | |
29 end | |
30 | |
31 local result_env = {} | |
32 -- =highmaul and ((normal and (name:match("imp") or defeated == 6)) or (heroic and defeated == 2)) | |
6 function LFGListUtil_SortSearchResults(results) | 33 function LFGListUtil_SortSearchResults(results) |
7 if LFGFilter_Allow_Activity.count > 0 then | 34 local self = LFGListFrame.SearchPanel |
35 if self.filter_expression then | |
36 local check = self.filter_func | |
8 local shift_down = 0 | 37 local shift_down = 0 |
9 local original_size = #results | 38 local original_size = #results |
10 for idx = 1, original_size do | 39 for idx = 1, original_size do |
11 local result = results[idx] | 40 local id = results[idx] |
12 local _, activityID = C_LFGList.GetSearchResultInfo(result) | 41 local _, activityID, name, comment, voiceChat, iLvl, age, numBNetFriends, numCharFriends, numGuildMates, isDelisted, leaderName, numMembers = C_LFGList.GetSearchResultInfo(id) |
13 if LFGFilter_Allow_Activity[activityID] then | 42 local completedEncounters = C_LFGList.GetSearchResultEncounterInfo(id) |
43 local memberCounts = C_LFGList.GetSearchResultMemberCounts(id) | |
44 | |
45 wipe(result_env) | |
46 result_env.name = name:lower() | |
47 result_env.comment = comment:lower() | |
48 result_env.ilvl = iLvl | |
49 -- TODO: should be calculated in meta | |
50 result_env.defeated = completedEncounters and #completedEncounters or 0 | |
51 result_env.members = numMembers | |
52 result_env.tanks = memberCounts.TANK | |
53 result_env.healers = memberCounts.HEALER | |
54 result_env.damagers = memberCounts.DAMAGER + memberCounts.NOROLE | |
55 result_env.my_server = leaderName and not leaderName:find('-') | |
56 | |
57 if activityID == 37 then | |
58 result_env.highmaul = true | |
59 result_env.normal = true | |
60 elseif activityID == 38 then | |
61 result_env.highmaul = true | |
62 result_env.heroic = true | |
63 end | |
64 | |
65 local pass | |
66 if check then | |
67 setfenv(check, result_env) | |
68 pass = check() | |
69 end | |
70 | |
71 if pass then | |
14 if shift_down > 0 then | 72 if shift_down > 0 then |
15 results[idx - shift_down] = result | 73 results[idx - shift_down] = id |
16 end | 74 end |
17 else | 75 else |
18 shift_down = shift_down + 1 | 76 shift_down = shift_down + 1 |
19 end | 77 end |
78 | |
20 end | 79 end |
21 for idx = original_size - shift_down + 1, original_size do | 80 for idx = original_size - shift_down + 1, original_size do |
22 results[idx] = nil | 81 results[idx] = nil |
23 end | 82 end |
24 end | 83 end |
25 table.sort(results, LFGListUtil_SortSearchResultsCB); | 84 table.sort(results, LFGListUtil_SortSearchResultsCB); |
26 end | 85 end |
27 | 86 |
28 function LFGListUtil_SortSearchResultsCB(id1, id2) | 87 function LFGListUtil_SortSearchResultsCB(id1, id2) |
29 local id1, activityID1, name1, comment1, voiceChat1, iLvl1, age1, numBNetFriends1, numCharFriends1, numGuildMates1, isDelisted1 = C_LFGList.GetSearchResultInfo(id1); | 88 local id1, activityID1, name1, comment1, voiceChat1, iLvl1, age1, numBNetFriends1, numCharFriends1, numGuildMates1, isDelisted1 = C_LFGList.GetSearchResultInfo(id1); |
30 local id2, activityID2, name2, comment2, voiceChat2, iLvl2, age2, numBNetFriends2, numCharFriends2, numGuildMates2, isDelisted2 = C_LFGList.GetSearchResultInfo(id2); | 89 local id2, activityID2, name2, comment2, voiceChat2, iLvl2, age2, numBNetFriends2, numCharFriends2, numGuildMates2, isDelisted2 = C_LFGList.GetSearchResultInfo(id2); |
55 for idx = 1, totalResults do | 114 for idx = 1, totalResults do |
56 local id1, activityID1, name1, comment1, voiceChat1, iLvl1, age1, numBNetFriends1, numCharFriends1, numGuildMates1, isDelisted1 = C_LFGList.GetSearchResultInfo(results[idx]) | 115 local id1, activityID1, name1, comment1, voiceChat1, iLvl1, age1, numBNetFriends1, numCharFriends1, numGuildMates1, isDelisted1 = C_LFGList.GetSearchResultInfo(results[idx]) |
57 print(id1, activityID1, C_LFGList.GetActivityInfo(activityID1), '*', name1) | 116 print(id1, activityID1, C_LFGList.GetActivityInfo(activityID1), '*', name1) |
58 end | 117 end |
59 end | 118 end |
60 | |
61 -- SoO (Normal): 4 | |
62 -- SoO (Heroic): 41 | |
63 -- SoO (Mythic): 42 | |
64 -- /run LFGFilter_Allow_Activity = { [42] = true } |