From dba5dcdf8dc7cd70cf00a8a59cd5def9f65a7bc0 Mon Sep 17 00:00:00 2001 From: Manuel Simon Hirsig Date: Thu, 11 Aug 2016 19:14:17 +0200 Subject: [PATCH] filter bugfix --- control.lua | 4 +-- core.lua | 2 +- init.lua | 4 +-- module.lua | 60 +++++++++++++----------------------------- tabs/search/core.lua | 9 +------ tabs/search/filter.lua | 20 ++++++++------ tabs/search/frames.lua | 16 +++++++++++ util/core.lua | 8 ++---- 8 files changed, 55 insertions(+), 68 deletions(-) diff --git a/control.lua b/control.lua index 3a796c2..1905083 100644 --- a/control.lua +++ b/control.lua @@ -64,7 +64,7 @@ end function public.event_listener(event, cb) local listener_id = m.id() - m.listeners[listener_id] = { event=event, cb=cb, kill=function(...) if arg.n == 0 or arg[1] then m.kill_listener(listener_id) end end } + m.listeners[listener_id] = {event=event, cb=cb, kill=function(...) if arg.n == 0 or arg[1] then m.kill_listener(listener_id) end end} m.event_frame:RegisterEvent(event) return listener_id end @@ -78,7 +78,7 @@ end function public.thread(k, ...) local thread_id = m.id() - m.threads[thread_id] = { k = aux._(k, unpack(arg)) } + m.threads[thread_id] = {k = aux._(k, unpack(arg))} return thread_id end diff --git a/core.lua b/core.lua index 19b2ce2..08aeb3e 100644 --- a/core.lua +++ b/core.lua @@ -398,7 +398,7 @@ function public.index(t, ...) return t end -public.huge = 2^100000 +public.huge = 1.8*10^308 function public.log(...) local msg = '[aux]' diff --git a/init.lua b/init.lua index 7d014c1..4e60571 100644 --- a/init.lua +++ b/init.lua @@ -1,4 +1,4 @@ -local addon = aux_module() +local addon = {aux_module()} aux = tremove(addon, 1) local m, public, private = unpack(addon) @@ -16,7 +16,7 @@ function public.module(path) local qualified_name = prefix and prefix..'.'..name or name module = m.modules[qualified_name] if not module then - module = aux_module() + module = {aux_module()} module[4].LOAD = nil (prefix and m.modules[prefix] or addon)[2][name] = tremove(module, 1) m.modules[qualified_name] = module diff --git a/module.lua b/module.lua index 518f442..0a65529 100644 --- a/module.lua +++ b/module.lua @@ -1,62 +1,40 @@ +local PUBLIC, PRIVATE = 1, 2 local state = {} - -local public_interface_mt = { - __newindex = function() - error('Unsupported operation.', 2) - end, +local interface_mt = { __index = function(self, key) - if state[self].public[key] then - return state[self].data[key] - else - error('Read of undeclared "'..key..'".', 2) - end - end, -} -local private_interface_mt = { - __newindex = function(self, key, value) - if not state[self].declared[key] then - error('Write of undeclared "'..key..'".', 2) - end - state[self].data[key] = value - end, - __index = function(self, key) - if not state[self].declared[key] then + if not state[self].access[state[self].type][key] then error('Read of undeclared "'..key..'".', 2) end return state[self].data[key] end, -} -local public_declarator_mt = { __newindex = function(self, key, value) - if state[self].declared[key] then - error('Multiple declarations of "'..key..'".', 2) + if state[self].type == PUBLIC then + error('Unsupported operation.', 2) + elseif not state[self].access[PRIVATE][key] then + error('Write of undeclared "'..key..'".', 2) end state[self].data[key] = value - state[self].public[key] = true - state[self].declared[key] = true end, +} +local declarator_mt = { __index = function() error('Unsupported operation.', 2) end, -} -local private_declarator_mt = { __newindex = function(self, key, value) - if state[self].declared[key] then + if state[self].access[PRIVATE][key] then error('Multiple declarations of "'..key..'".', 2) end state[self].data[key] = value - state[self].declared[key] = true - end, - __index = function() - error('Unsupported operation.', 2) + state[self].access[PRIVATE][key] = true + state[self].access[state[self].type][key] = true end, } - function aux_module() - local new_state = {data={}, public={}, declared={}} - local module = {setmetatable({}, public_interface_mt), setmetatable({}, private_interface_mt), setmetatable({}, public_declarator_mt), setmetatable({}, private_declarator_mt)} - for _, component in module do - state[component] = new_state - end - return module + local data, access = {}, {{}, {}} + local public_state, private_state = {type=PUBLIC, data=data, access=access}, {type=PRIVATE, data=data, access=access} + local public_interface, private_interface = setmetatable({}, interface_mt), setmetatable({}, interface_mt) + local public_declarator, private_declarator = setmetatable({}, declarator_mt), setmetatable({}, declarator_mt) + state[public_interface], state[private_interface] = public_state, private_state + state[public_declarator], state[private_declarator] = public_state, private_state + return public_interface, private_interface, public_declarator, private_declarator end \ No newline at end of file diff --git a/tabs/search/core.lua b/tabs/search/core.lua index a9b02a7..7222f34 100644 --- a/tabs/search/core.lua +++ b/tabs/search/core.lua @@ -116,14 +116,7 @@ end function private.blizzard_page_index(str) if tonumber(str) then - return aux.util.round(max(0, tonumber(str) - 1)) + return max(0, tonumber(str) - 1) end end -function private.blizzard_level(str) - if tonumber(str) then - return aux.util.round(aux.util.bound(1, 60, tonumber(str))) - end -end - - diff --git a/tabs/search/filter.lua b/tabs/search/filter.lua index 75f47ee..f4e11b9 100644 --- a/tabs/search/filter.lua +++ b/tabs/search/filter.lua @@ -54,13 +54,17 @@ private.blizzard_query = setmetatable({}, { elseif key == 'usable' then return m.usable_checkbox:GetChecked() elseif key == 'class' then - return UIDropDownMenu_GetSelectedValue(m.class_dropdown) + local class_index = UIDropDownMenu_GetSelectedValue(m.class_dropdown) + return (class_index or 0) > 0 and class_index or nil elseif key == 'subclass' then - return UIDropDownMenu_GetSelectedValue(m.subclass_dropdown) + local subclass_index = UIDropDownMenu_GetSelectedValue(m.subclass_dropdown) + return (subclass_index or 0) > 0 and subclass_index or nil elseif key == 'slot' then - return UIDropDownMenu_GetSelectedValue(m.slot_dropdown) + local slot_index = UIDropDownMenu_GetSelectedValue(m.slot_dropdown) + return (slot_index or 0) > 0 and slot_index or nil elseif key == 'quality' then - return UIDropDownMenu_GetSelectedValue(m.quality_dropdown) + local quality_code = UIDropDownMenu_GetSelectedValue(m.quality_dropdown) + return (quality_code or -1) >= 0 and quality_code or nil end end, }) @@ -126,13 +130,13 @@ function private.get_form_query() add(m.blizzard_query.max_level) add(m.blizzard_query.usable and 'usable') - for _, class in {m.blizzard_query.class ~= 0 and m.blizzard_query.class} do + for _, class in {m.blizzard_query.class} do local classes = {GetAuctionItemClasses()} add(strlower(classes[class])) - for _, subclass in {m.blizzard_query.subclass ~= 0 and m.blizzard_query.subclass} do + for _, subclass in {m.blizzard_query.subclass} do local subclasses = {GetAuctionItemSubClasses(class)} add(strlower(subclasses[subclass])) - add(m.blizzard_query.slot ~= 0 and m.blizzard_query.slot and strlower(getglobal(m.blizzard_query.slot))) + add(m.blizzard_query.slot and strlower(getglobal(m.blizzard_query.slot))) end end @@ -141,7 +145,7 @@ function private.get_form_query() add(strlower(getglobal('ITEM_QUALITY'..quality..'_DESC'))) end - return query_string + return query_string or '' end function private.set_form(components) diff --git a/tabs/search/frames.lua b/tabs/search/frames.lua index b63c032..9304574 100644 --- a/tabs/search/frames.lua +++ b/tabs/search/frames.lua @@ -80,6 +80,14 @@ function private.create_frames() m.execute() end) editbox:SetScript('OnTextChanged', function() + local page = tonumber(this:GetText()) + local valid_input = page and tostring(max(1, page)) or '' + if this:GetText() ~= valid_input then + this:SetText(valid_input) + end + if (tonumber(m.last_page_input:GetText()) or aux.huge) < (tonumber(this:GetText()) or 1) then + m.last_page_input:SetText(tonumber(this:GetText())) + end if m.blizzard_page_index(this:GetText()) and not m.real_time_button:GetChecked() then this:SetBackdropColor(unpack(aux.gui.color.state.enabled)) else @@ -106,6 +114,14 @@ function private.create_frames() m.execute() end) editbox:SetScript('OnTextChanged', function() + local page = tonumber(this:GetText()) + local valid_input = page and tostring(max(1, page)) or '' + if this:GetText() ~= valid_input then + this:SetText(valid_input) + end + if (tonumber(m.first_page_input:GetText()) or 1) > (tonumber(this:GetText()) or aux.huge) then + m.first_page_input:SetText(tonumber(this:GetText())) + end if m.blizzard_page_index(this:GetText()) and not m.real_time_button:GetChecked() then this:SetBackdropColor(unpack(aux.gui.color.state.enabled)) else diff --git a/util/core.lua b/util/core.lua index 5410758..31c41f6 100644 --- a/util/core.lua +++ b/util/core.lua @@ -1,11 +1,7 @@ local m, public, private = aux.module'util' -function public.either(p, a, b) - if p then - return a - else - return b - end +function public.present(value) + return value ~= nil and {[value]=true} or {} end function public.unpack(array, ...)