Cleanup the new lib path

This commit is contained in:
tekkub :bear:  2011-11-20 16:36:14 -07:00
parent c24f75eae3
commit 61a3abe1fb
7 changed files with 444 additions and 507 deletions

View File

@ -15,7 +15,7 @@
tekFunks\gsc.lua tekFunks\gsc.lua
tekKonfig\tekKonfig.xml tekKonfig\tekKonfig.xml
libs\LibItemSearch-1.0\LibItemSearch-1.0.lua LibItemSearch-1.0.lua
KnownScanner.lua KnownScanner.lua
GnomishVendorShrinker.lua GnomishVendorShrinker.lua

View File

@ -1,444 +1,444 @@
--[[ --[[
ItemSearch ItemSearch
An item text search engine of some sort An item text search engine of some sort
Grammar: Grammar:
<search> := <intersect search> <search> := <intersect search>
<intersect search> := <union search> & <union search> ; <union search> <intersect search> := <union search> & <union search> ; <union search>
<union search> := <negatable search> | <negatable search> ; <negatable search> <union search> := <negatable search> | <negatable search> ; <negatable search>
<negatable search> := !<primitive search> ; <primitive search> <negatable search> := !<primitive search> ; <primitive search>
<primitive search> := <tooltip search> ; <quality search> ; <type search> ; <text search> <primitive search> := <tooltip search> ; <quality search> ; <type search> ; <text search>
<tooltip search> := bop ; boa ; bou ; boe ; quest <tooltip search> := bop ; boa ; bou ; boe ; quest
<quality search> := q<op><text> ; q<op><digit> <quality search> := q<op><text> ; q<op><digit>
<ilvl search> := ilvl<op><number> <ilvl search> := ilvl<op><number>
<type search> := t:<text> <type search> := t:<text>
<text search> := <text> <text search> := <text>
<op> := : | = | == | != | ~= | < | > | <= | >= <op> := : | = | == | != | ~= | < | > | <= | >=
I kindof half want to make a full parser for this I kindof half want to make a full parser for this
--]] --]]
local MAJOR, MINOR = "LibItemSearch-1.0", 3 local MAJOR, MINOR = "LibItemSearch-1.0", 3
local ItemSearch = LibStub:NewLibrary(MAJOR, MINOR) local ItemSearch = LibStub:NewLibrary(MAJOR, MINOR)
if not ItemSearch then return end if not ItemSearch then return end
--[[ general search ]]-- --[[ general search ]]--
function ItemSearch:Find(itemLink, search) function ItemSearch:Find(itemLink, search)
if not search then if not search then
return true return true
end end
if not itemLink then if not itemLink then
return false return false
end end
local search = search:lower() local search = search:lower()
if search:match('\124') then if search:match('\124') then
return self:FindUnionSearch(itemLink, strsplit('\124', search)) return self:FindUnionSearch(itemLink, strsplit('\124', search))
end end
return self:FindUnionSearch(itemLink, search) return self:FindUnionSearch(itemLink, search)
end end
--[[ union search: <search>&<search> ]]-- --[[ union search: <search>&<search> ]]--
function ItemSearch:FindUnionSearch(itemLink, ...) function ItemSearch:FindUnionSearch(itemLink, ...)
for i = 1, select('#', ...) do for i = 1, select('#', ...) do
local search = select(i, ...) local search = select(i, ...)
if search and search ~= '' then if search and search ~= '' then
if search:match('\038') then if search:match('\038') then
if self:FindIntersectSearch(itemLink, strsplit('\038', search)) then if self:FindIntersectSearch(itemLink, strsplit('\038', search)) then
return true return true
end end
else else
if self:FindIntersectSearch(itemLink, search) then if self:FindIntersectSearch(itemLink, search) then
return true return true
end end
end end
end end
end end
return false return false
end end
--[[ intersect search: <search>|<search> ]]-- --[[ intersect search: <search>|<search> ]]--
function ItemSearch:FindIntersectSearch(itemLink, ...) function ItemSearch:FindIntersectSearch(itemLink, ...)
for i = 1, select('#', ...) do for i = 1, select('#', ...) do
local search = select(i, ...) local search = select(i, ...)
if search and search ~= '' then if search and search ~= '' then
if not self:FindNegatableSearch(itemLink, search) then if not self:FindNegatableSearch(itemLink, search) then
return false return false
end end
end end
end end
return true return true
end end
--[[ negated search: !<search> ]]-- --[[ negated search: !<search> ]]--
function ItemSearch:FindNegatableSearch(itemLink, search) function ItemSearch:FindNegatableSearch(itemLink, search)
local negatedSearch = search:match('^\033(.+)$') local negatedSearch = search:match('^\033(.+)$')
if negatedSearch then if negatedSearch then
return not self:FindTypedSearch(itemLink, negatedSearch) return not self:FindTypedSearch(itemLink, negatedSearch)
end end
return self:FindTypedSearch(itemLink, search) return self:FindTypedSearch(itemLink, search)
end end
--[[ --[[
typed search: typed search:
user defined search types user defined search types
A typed search object should look like the following: A typed search object should look like the following:
{ {
string id string id
unique identifier for the search type, unique identifier for the search type,
string searchCapture = function isSearch(self, search) string searchCapture = function isSearch(self, search)
returns a capture if the given search matches this typed search returns a capture if the given search matches this typed search
returns nil if the search is not a match for this type returns nil if the search is not a match for this type
bool isMatch = function findItem(self, itemLink, searchCapture) bool isMatch = function findItem(self, itemLink, searchCapture)
returns true if <itemLink> is in the search defined by <searchCapture> returns true if <itemLink> is in the search defined by <searchCapture>
} }
--]] --]]
local typedSearches = {} local typedSearches = {}
function ItemSearch:RegisterTypedSearch(typedSearchObj) function ItemSearch:RegisterTypedSearch(typedSearchObj)
typedSearches[typedSearchObj.id] = typedSearchObj typedSearches[typedSearchObj.id] = typedSearchObj
end end
function ItemSearch:GetTypedSearches() function ItemSearch:GetTypedSearches()
return pairs(typedSearches) return pairs(typedSearches)
end end
function ItemSearch:GetTypedSearch(id) function ItemSearch:GetTypedSearch(id)
return typedSearches[id] return typedSearches[id]
end end
function ItemSearch:FindTypedSearch(itemLink, search) function ItemSearch:FindTypedSearch(itemLink, search)
if not search then if not search then
return false return false
end end
for id, searchInfo in self:GetTypedSearches() do for id, searchInfo in self:GetTypedSearches() do
local capture1, capture2, capture3 = searchInfo:isSearch(search) local capture1, capture2, capture3 = searchInfo:isSearch(search)
if capture1 then if capture1 then
return searchInfo:findItem(itemLink, capture1, capture2, capture3) return searchInfo:findItem(itemLink, capture1, capture2, capture3)
end end
end end
return self:GetTypedSearch('itemTypeGeneric'):findItem(itemLink, search) or self:GetTypedSearch('itemName'):findItem(itemLink, search) return self:GetTypedSearch('itemTypeGeneric'):findItem(itemLink, search) or self:GetTypedSearch('itemName'):findItem(itemLink, search)
end end
--[[ --[[
Basic typed searches Basic typed searches
--]] --]]
function ItemSearch:Compare(op, lhs, rhs) function ItemSearch:Compare(op, lhs, rhs)
--ugly, but it works --ugly, but it works
if op == ':' or op == '=' or op == '==' then if op == ':' or op == '=' or op == '==' then
return lhs == rhs return lhs == rhs
end end
if op == '!=' or op == '~=' then if op == '!=' or op == '~=' then
return lhs ~= rhs return lhs ~= rhs
end end
if op == '<=' then if op == '<=' then
return lhs <= rhs return lhs <= rhs
end end
if op == '<' then if op == '<' then
return lhs < rhs return lhs < rhs
end end
if op == '>' then if op == '>' then
return lhs > rhs return lhs > rhs
end end
if op == '>=' then if op == '>=' then
return lhs >= rhs return lhs >= rhs
end end
return false return false
end end
--[[ basic text search n:(.+) ]]-- --[[ basic text search n:(.+) ]]--
local function search_IsInText(search, ...) local function search_IsInText(search, ...)
for i = 1, select('#', ...) do for i = 1, select('#', ...) do
local text = select(i, ...) local text = select(i, ...)
text = text and tostring(text):lower() text = text and tostring(text):lower()
if text and (text == search or text:match(search)) then if text and (text == search or text:match(search)) then
return true return true
end end
end end
return false return false
end end
ItemSearch:RegisterTypedSearch{ ItemSearch:RegisterTypedSearch{
id = 'itemName', id = 'itemName',
isSearch = function(self, search) isSearch = function(self, search)
return search and search:match('^n:(.+)$') return search and search:match('^n:(.+)$')
end, end,
findItem = function(self, itemLink, search) findItem = function(self, itemLink, search)
local itemName = (GetItemInfo(itemLink)) local itemName = (GetItemInfo(itemLink))
return search_IsInText(search, itemName) return search_IsInText(search, itemName)
end end
} }
--[[ item type,subtype,equip loc search t:(.+) ]]-- --[[ item type,subtype,equip loc search t:(.+) ]]--
ItemSearch:RegisterTypedSearch{ ItemSearch:RegisterTypedSearch{
id = 'itemTypeGeneric', id = 'itemTypeGeneric',
isSearch = function(self, search) isSearch = function(self, search)
return search and search:match('^t:(.+)$') return search and search:match('^t:(.+)$')
end, end,
findItem = function(self, itemLink, search) findItem = function(self, itemLink, search)
local name, link, quality, iLevel, reqLevel, type, subType, maxStack, equipSlot = GetItemInfo(itemLink) local name, link, quality, iLevel, reqLevel, type, subType, maxStack, equipSlot = GetItemInfo(itemLink)
if not name then if not name then
return false return false
end end
return search_IsInText(search, type, subType, _G[equipSlot]) return search_IsInText(search, type, subType, _G[equipSlot])
end end
} }
--[[ item quality search: q(sign)(%d+) | q:(qualityName) ]]-- --[[ item quality search: q(sign)(%d+) | q:(qualityName) ]]--
ItemSearch:RegisterTypedSearch{ ItemSearch:RegisterTypedSearch{
id = 'itemQuality', id = 'itemQuality',
isSearch = function(self, search) isSearch = function(self, search)
if search then if search then
return search:match('^q([%~%:%<%>%=%!]+)(%w+)$') return search:match('^q([%~%:%<%>%=%!]+)(%w+)$')
end end
end, end,
descToQuality = function(self, desc) descToQuality = function(self, desc)
local q = 0 local q = 0
local quality = _G['ITEM_QUALITY' .. q .. '_DESC'] local quality = _G['ITEM_QUALITY' .. q .. '_DESC']
while quality and quality:lower() ~= desc do while quality and quality:lower() ~= desc do
q = q + 1 q = q + 1
quality = _G['ITEM_QUALITY' .. q .. '_DESC'] quality = _G['ITEM_QUALITY' .. q .. '_DESC']
end end
if quality then if quality then
return q return q
end end
end, end,
findItem = function(self, itemLink, op, search) findItem = function(self, itemLink, op, search)
local name, link, quality = GetItemInfo(itemLink) local name, link, quality = GetItemInfo(itemLink)
if not name then if not name then
return false return false
end end
local num = tonumber(search) or self:descToQuality(search) local num = tonumber(search) or self:descToQuality(search)
return num and ItemSearch:Compare(op, quality, num) or false return num and ItemSearch:Compare(op, quality, num) or false
end, end,
} }
--[[ item level search: lvl(sign)(%d+) ]]-- --[[ item level search: lvl(sign)(%d+) ]]--
ItemSearch:RegisterTypedSearch{ ItemSearch:RegisterTypedSearch{
id = 'itemLevel', id = 'itemLevel',
isSearch = function(self, search) isSearch = function(self, search)
if search then if search then
return search:match('^ilvl([:<>=!]+)(%d+)$') return search:match('^ilvl([:<>=!]+)(%d+)$')
end end
end, end,
findItem = function(self, itemLink, op, search) findItem = function(self, itemLink, op, search)
local name, link, quality, iLvl = GetItemInfo(itemLink) local name, link, quality, iLvl = GetItemInfo(itemLink)
if not iLvl then if not iLvl then
return false return false
end end
local num = tonumber(search) local num = tonumber(search)
return num and ItemSearch:Compare(op, iLvl, num) or false return num and ItemSearch:Compare(op, iLvl, num) or false
end, end,
} }
--[[ tooltip keyword search ]]-- --[[ tooltip keyword search ]]--
local tooltipCache = setmetatable({}, {__index = function(t, k) local v = {} t[k] = v return v end}) local tooltipCache = setmetatable({}, {__index = function(t, k) local v = {} t[k] = v return v end})
local tooltipScanner = _G['LibItemSearchTooltipScanner'] or CreateFrame('GameTooltip', 'LibItemSearchTooltipScanner', UIParent, 'GameTooltipTemplate') local tooltipScanner = _G['LibItemSearchTooltipScanner'] or CreateFrame('GameTooltip', 'LibItemSearchTooltipScanner', UIParent, 'GameTooltipTemplate')
local function link_FindSearchInTooltip(itemLink, search) local function link_FindSearchInTooltip(itemLink, search)
--look in the cache for the result --look in the cache for the result
local itemID = itemLink:match('item:(%d+)') local itemID = itemLink:match('item:(%d+)')
local cachedResult = tooltipCache[search][itemID] local cachedResult = tooltipCache[search][itemID]
if cachedResult ~= nil then if cachedResult ~= nil then
return cachedResult return cachedResult
end end
--no match?, pull in the resut from tooltip parsing --no match?, pull in the resut from tooltip parsing
tooltipScanner:SetOwner(UIParent, 'ANCHOR_NONE') tooltipScanner:SetOwner(UIParent, 'ANCHOR_NONE')
tooltipScanner:SetHyperlink(itemLink) tooltipScanner:SetHyperlink(itemLink)
local result = false local result = false
if tooltipScanner:NumLines() > 1 and _G[tooltipScanner:GetName() .. 'TextLeft2']:GetText() == search then if tooltipScanner:NumLines() > 1 and _G[tooltipScanner:GetName() .. 'TextLeft2']:GetText() == search then
result = true result = true
elseif tooltipScanner:NumLines() > 2 and _G[tooltipScanner:GetName() .. 'TextLeft3']:GetText() == search then elseif tooltipScanner:NumLines() > 2 and _G[tooltipScanner:GetName() .. 'TextLeft3']:GetText() == search then
result = true result = true
end end
tooltipScanner:Hide() tooltipScanner:Hide()
tooltipCache[search][itemID] = result tooltipCache[search][itemID] = result
return result return result
end end
ItemSearch:RegisterTypedSearch{ ItemSearch:RegisterTypedSearch{
id = 'tooltip', id = 'tooltip',
isSearch = function(self, search) isSearch = function(self, search)
return self.keywords[search] return self.keywords[search]
end, end,
findItem = function(self, itemLink, search) findItem = function(self, itemLink, search)
return search and link_FindSearchInTooltip(itemLink, search) return search and link_FindSearchInTooltip(itemLink, search)
end, end,
keywords = { keywords = {
['boe'] = ITEM_BIND_ON_EQUIP, ['boe'] = ITEM_BIND_ON_EQUIP,
['bop'] = ITEM_BIND_ON_PICKUP, ['bop'] = ITEM_BIND_ON_PICKUP,
['bou'] = ITEM_BIND_ON_USE, ['bou'] = ITEM_BIND_ON_USE,
['quest'] = ITEM_BIND_QUEST, ['quest'] = ITEM_BIND_QUEST,
['boa'] = ITEM_BIND_TO_ACCOUNT ['boa'] = ITEM_BIND_TO_ACCOUNT
} }
} }
ItemSearch:RegisterTypedSearch{ ItemSearch:RegisterTypedSearch{
id = 'tooltipDesc', id = 'tooltipDesc',
isSearch = function(self, search) isSearch = function(self, search)
return search and search:match('^tt:(.+)$') return search and search:match('^tt:(.+)$')
end, end,
findItem = function(self, itemLink, search) findItem = function(self, itemLink, search)
--no match?, pull in the resut from tooltip parsing --no match?, pull in the resut from tooltip parsing
tooltipScanner:SetOwner(UIParent, 'ANCHOR_NONE') tooltipScanner:SetOwner(UIParent, 'ANCHOR_NONE')
tooltipScanner:SetHyperlink(itemLink) tooltipScanner:SetHyperlink(itemLink)
local i = 1 local i = 1
while i <= tooltipScanner:NumLines() do while i <= tooltipScanner:NumLines() do
local text = _G[tooltipScanner:GetName() .. 'TextLeft' .. i]:GetText():lower() local text = _G[tooltipScanner:GetName() .. 'TextLeft' .. i]:GetText():lower()
if text and text:match(search) then if text and text:match(search) then
tooltipScanner:Hide() tooltipScanner:Hide()
return true return true
end end
i = i + 1 i = i + 1
end end
tooltipScanner:Hide() tooltipScanner:Hide()
return false return false
end, end,
} }
--[[ equipment set search ]]-- --[[ equipment set search ]]--
local function IsWardrobeLoaded() local function IsWardrobeLoaded()
local name, title, notes, enabled, loadable, reason, security = GetAddOnInfo('Wardrobe') local name, title, notes, enabled, loadable, reason, security = GetAddOnInfo('Wardrobe')
return enabled return enabled
end end
local function findEquipmentSetByName(search) local function findEquipmentSetByName(search)
local startsWithSearch = '^' .. search local startsWithSearch = '^' .. search
local partialMatch = nil local partialMatch = nil
for i = 1, GetNumEquipmentSets() do for i = 1, GetNumEquipmentSets() do
local setName = (GetEquipmentSetInfo(i)) local setName = (GetEquipmentSetInfo(i))
local lSetName = setName:lower() local lSetName = setName:lower()
if lSetName == search then if lSetName == search then
return setName return setName
end end
if lSetName:match(startsWithSearch) then if lSetName:match(startsWithSearch) then
partialMatch = setName partialMatch = setName
end end
end end
-- Wardrobe Support -- Wardrobe Support
if Wardrobe then if Wardrobe then
for i, outfit in ipairs( Wardrobe.CurrentConfig.Outfit) do for i, outfit in ipairs( Wardrobe.CurrentConfig.Outfit) do
local setName = outfit.OutfitName local setName = outfit.OutfitName
local lSetName = setName:lower() local lSetName = setName:lower()
if lSetName == search then if lSetName == search then
return setName return setName
end end
if lSetName:match(startsWithSearch) then if lSetName:match(startsWithSearch) then
partialMatch = setName partialMatch = setName
end end
end end
end end
return partialMatch return partialMatch
end end
local function isItemInEquipmentSet(itemLink, setName) local function isItemInEquipmentSet(itemLink, setName)
if not setName then if not setName then
return false return false
end end
local itemIDs = GetEquipmentSetItemIDs(setName) local itemIDs = GetEquipmentSetItemIDs(setName)
if not itemIDs then if not itemIDs then
return false return false
end end
local itemID = tonumber(itemLink:match('item:(%d+)')) local itemID = tonumber(itemLink:match('item:(%d+)'))
for inventoryID, setItemID in pairs(itemIDs) do for inventoryID, setItemID in pairs(itemIDs) do
if itemID == setItemID then if itemID == setItemID then
return true return true
end end
end end
return false return false
end end
local function isItemInWardrobeSet(itemLink, setName) local function isItemInWardrobeSet(itemLink, setName)
if not Wardrobe then return false end if not Wardrobe then return false end
local itemName = (GetItemInfo(itemLink)) local itemName = (GetItemInfo(itemLink))
for i, outfit in ipairs(Wardrobe.CurrentConfig.Outfit) do for i, outfit in ipairs(Wardrobe.CurrentConfig.Outfit) do
if outfit.OutfitName == setName then if outfit.OutfitName == setName then
for j, item in pairs(outfit.Item) do for j, item in pairs(outfit.Item) do
if item and (item.IsSlotUsed == 1) and (item.Name == itemName) then if item and (item.IsSlotUsed == 1) and (item.Name == itemName) then
return true return true
end end
end end
end end
end end
return false return false
end end
ItemSearch:RegisterTypedSearch{ ItemSearch:RegisterTypedSearch{
id = 'equipmentSet', id = 'equipmentSet',
isSearch = function(self, search) isSearch = function(self, search)
return search and search:match('^s:(.+)$') return search and search:match('^s:(.+)$')
end, end,
findItem = function(self, itemLink, search) findItem = function(self, itemLink, search)
local setName = findEquipmentSetByName(search) local setName = findEquipmentSetByName(search)
if not setName then if not setName then
return false return false
end end
return isItemInEquipmentSet(itemLink, setName) return isItemInEquipmentSet(itemLink, setName)
or isItemInWardrobeSet(itemLink, setName) or isItemInWardrobeSet(itemLink, setName)
end, end,
} }

View File

@ -1,4 +0,0 @@
<Ui xmlns="http://www.blizzard.com/wow/ui/">
<Script file="libs\LibItemSearch-1.0\LibStub.lua"/>
<Script file="libs\LibItemSearch-1.0\LibItemSearch-1.0.lua"/>
</Ui>

View File

@ -1,7 +0,0 @@
## Interface: 40000
## Title: LibItemSearch
## Notes: An item search library
## Author: Tuller
## LoadOnDemand: 1
LibStub.lua
LibItemSearch-1.0.lua

View File

@ -1,7 +0,0 @@
## Interface: 40000
## Title: LibItemSearch
## Notes: An item search library
## Author: Tuller
## LoadOnDemand: 1
LibStub.lua
LibItemSearch-1.0.lua

View File

@ -1,30 +0,0 @@
-- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info
-- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke
local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS!
local LibStub = _G[LIBSTUB_MAJOR]
if not LibStub or LibStub.minor < LIBSTUB_MINOR then
LibStub = LibStub or {libs = {}, minors = {} }
_G[LIBSTUB_MAJOR] = LibStub
LibStub.minor = LIBSTUB_MINOR
function LibStub:NewLibrary(major, minor)
assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)")
minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.")
local oldminor = self.minors[major]
if oldminor and oldminor >= minor then return nil end
self.minors[major], self.libs[major] = minor, self.libs[major] or {}
return self.libs[major], oldminor
end
function LibStub:GetLibrary(major, silent)
if not self.libs[major] and not silent then
error(("Cannot find a library instance of %q."):format(tostring(major)), 2)
end
return self.libs[major], self.minors[major]
end
function LibStub:IterateLibraries() return pairs(self.libs) end
setmetatable(LibStub, { __call = LibStub.GetLibrary })
end

View File

@ -1,15 +0,0 @@
LibItemSearch
An item text search engine of some sort
Grammar:
<search> := <intersect search>
<intersect search> := <union search> & <union search> ; <union search>
<union search> := <negatable search> | <negatable search> ; <negatable search>
<negatable search> := !<primitive search> ; <primitive search>
<primitive search> := <tooltip search> ; <quality search> ; <type search> ; <text search>
<tooltip search> := bop ; boa ; bou ; boe ; quest
<quality search> := q<op><text> ; q<op><digit>
<ilvl search> := ilvl<op><number>
<type search> := t:<text>
<text search> := <text>
<op> := : | = | == | != | ~= | < | > | <= | >=