improved tooltip filter parser

This commit is contained in:
Manuel Simon Hirsig
2016-02-02 22:34:29 +01:00
parent 3cf3f8ccea
commit 710b36f3f0
3 changed files with 38 additions and 15 deletions
+26 -15
View File
@@ -88,87 +88,98 @@ function m.filter_from_string(filter_term)
local parts = Aux.util.split(filter_term, '/') local parts = Aux.util.split(filter_term, '/')
local filter = {} local filter = {}
local tooltip_counter = 0
for i, str in ipairs(parts) do for i, str in ipairs(parts) do
str = Aux.util.trim(str) str = Aux.util.trim(str)
if strupper(str) == 'AND' or strupper(str) == 'OR' or strupper(str) == 'NOT' or strupper(str) == 'TT' then if tooltip_counter > 0 or strupper(str) == 'AND' or strupper(str) == 'OR' or strupper(str) == 'NOT' or strupper(str) == 'TT' then
filter.tooltip = {} filter.tooltip = filter.tooltip or {}
tinsert(filter.tooltip, str)
tooltip_counter = tooltip_counter == 0 and tooltip_counter + 1 or tooltip_counter
for j=i,getn(parts) do for j=i,getn(parts) do
tinsert(filter.tooltip, parts[j]) tinsert(filter.tooltip, parts[j])
end end
break if strupper(str) == 'AND' or strupper(str) == 'OR' then
tooltip_counter = tooltip_counter + 1
elseif not (strupper(str) == 'NOT' or strupper(str) == 'TT' or str == '') then
tooltip_counter = tooltip_counter - 1
end
elseif tonumber(str) then elseif tonumber(str) then
if not filter.min_level then if not filter.min_level then
filter.min_level = tonumber(str) filter.min_level = tonumber(str)
elseif not filter.max_level and tonumber(str) >= filter.min_level then elseif not filter.max_level and tonumber(str) >= filter.min_level then
filter.max_level = tonumber(str) filter.max_level = tonumber(str)
else else
return false, 'Invalid Level Range' return false, 'Erroneous Level Range Modifier'
end end
elseif Aux.item_class_index(str) then elseif Aux.item_class_index(str) then
if not filter.class then if not filter.class then
filter.class = Aux.item_class_index(str) filter.class = Aux.item_class_index(str)
else else
return false, 'Invalid Item Class' return false, 'Erroneous Item Class Modifier'
end end
elseif filter.class and Aux.item_subclass_index(filter.class, str) then elseif filter.class and Aux.item_subclass_index(filter.class, str) then
if not filter.subclass then if not filter.subclass then
filter.subclass = Aux.item_subclass_index(filter.class, str) filter.subclass = Aux.item_subclass_index(filter.class, str)
else else
return false, 'Invalid Item Subclass' return false, 'Erroneous Item Subclass Modifier'
end end
elseif filter.subclass and Aux.item_slot_index(filter.class, filter.subclass, str) then elseif filter.subclass and Aux.item_slot_index(filter.class, filter.subclass, str) then
if not filter.slot then if not filter.slot then
filter.slot = Aux.item_slot_index(filter.class, filter.subclass, str) filter.slot = Aux.item_slot_index(filter.class, filter.subclass, str)
else else
return false, 'Invalid Item Slot' return false, 'Erroneous Item Slot Modifier'
end end
elseif Aux.item_quality_index(str) then elseif Aux.item_quality_index(str) then
if not filter.quality then if not filter.quality then
filter.quality = Aux.item_quality_index(str) filter.quality = Aux.item_quality_index(str)
else else
return false, 'Invalid Item Rarity' return false, 'Erroneous Rarity Modifier'
end end
elseif strlower(str) == 'usable' then elseif strlower(str) == 'usable' then
if not filter.usable then if not filter.usable then
filter.usable = true filter.usable = true
else else
return false, 'Invalid Usable Only Filter' return false, 'Erroneous Usable Only Modifier'
end end
elseif strlower(str) == 'exact' then elseif strlower(str) == 'exact' then
if not filter.exact then if not filter.exact then
filter.exact = true filter.exact = true
else else
return false, 'Invalid Exact Only Filter' return false, 'Erroneous Exact Only Modifier'
end end
elseif strlower(str) == 'discard' then elseif strlower(str) == 'discard' then
if not filter.discard then if not filter.discard then
filter.discard = true filter.discard = true
else else
return false, 'Invalid Discard Filter' return false, 'Erroneous Discard Modifier'
end end
elseif Aux.money.from_string(str) > 0 then elseif Aux.money.from_string(str) > 0 then
if not filter.max_price then if not filter.max_price then
filter.max_price = Aux.money.from_string(str) filter.max_price = Aux.money.from_string(str)
else else
return false, 'Invalid Max Price Filter' return false, 'Erroneous Max Price Modifier'
end end
elseif strfind(str, '^%d+%%$') then elseif strfind(str, '^%d+%%$') then
if not filter.max_percent then if not filter.max_percent then
filter.max_percent = tonumber(({strfind(str, '(%d+)%%')})[3]) filter.max_percent = tonumber(({strfind(str, '(%d+)%%')})[3])
else else
return false, 'Invalid Max Percent Filter' return false, 'Erroneous Max Percent Modifier'
end end
elseif i == 1 then elseif i == 1 then
filter.name = str filter.name = str
else else
return false, 'Unknown Filter' return false, 'Unknown Modifier'
end end
end end
if tooltip_counter > 0 then
return false, 'Erroneous Tooltip Modifier'
end
if filter.exact then if filter.exact then
if filter.min_level or filter.max_level or filter.class or filter.subclass or filter.slot or filter.quality or filter.usable or not Aux.static.auctionable_items[strupper(filter.name)] then if filter.min_level or filter.max_level or filter.class or filter.subclass or filter.slot or filter.quality or filter.usable or not Aux.static.auctionable_items[strupper(filter.name)] then
return false, 'Invalid Exact Only Filter' return false, 'Erroneous Exact Only Modifier'
end end
end end
+1
View File
@@ -188,6 +188,7 @@ function public.on_load()
end end
do do
local editbox = Aux.gui.editbox(AuxFilterSearchFrame) local editbox = Aux.gui.editbox(AuxFilterSearchFrame)
editbox:SetMaxLetters(Aux.huge)
editbox:EnableMouse(1) editbox:EnableMouse(1)
editbox.complete = Aux.test.complete editbox.complete = Aux.test.complete
editbox:SetPoint('TOPLEFT', 5, -8) editbox:SetPoint('TOPLEFT', 5, -8)
+11
View File
@@ -19,6 +19,9 @@ function m.display_name(item_id)
end end
function m:complete() function m:complete()
if IsControlKeyDown() then -- TODO problem is ctrl-v, maybe find a better solution
return
end
local filter_string = this:GetText() local filter_string = this:GetText()
@@ -30,6 +33,11 @@ function m:complete()
if current_filter or not completed_filter_string then if current_filter or not completed_filter_string then
current_filter = current_filter or {} current_filter = current_filter or {}
tinsert(options, 'and')
tinsert(options, 'or')
tinsert(options, 'not')
tinsert(options, 'tt')
if current_filter.name if current_filter.name
and Aux.static.auctionable_items[strupper(current_filter.name)] and Aux.static.auctionable_items[strupper(current_filter.name)]
and not current_filter.min_level and not current_filter.min_level
@@ -110,6 +118,9 @@ function m:complete()
end end
function m:complete_item() function m:complete_item()
if IsControlKeyDown() then -- TODO problem is ctrl-v, maybe find a better solution
return
end
local text = this:GetText() local text = this:GetText()