@@ -41,7 +41,7 @@ TMW.IE:RegisterDatabaseDefaults{
4141 },
4242}
4343
44- TMW .IE :RegisterUpgrade (72310 , {
44+ TMW .IE :RegisterUpgrade (90403 , {
4545 locale = function (self , locale )
4646 locale .ItemCache = nil
4747 locale .XPac_ItemCache = nil
@@ -59,7 +59,7 @@ TMW.IE:RegisterUpgrade(62217, {
5959
6060--[[ Returns the main cache table. Structure:
6161Cache = {
62- [itemID ] = 1,
62+ [link ] = 1,
6363}
6464]]
6565function ItemCache :GetCache ()
7474
7575--[[ Returns a list of items that the player currently has. Structure:
7676Cache = {
77- [itemID ] = name ,
78- [name] = itemID ,
77+ [link ] = 1 ,
78+ [name] = link ,
7979}
8080]]
8181function ItemCache :GetCurrentItems ()
@@ -119,14 +119,14 @@ TMW:RegisterCallback("TMW_OPTIONS_LOADED", function()
119119 -- Compile all items from all timesegments into a cohesive table for
120120 -- fast lookups and easy iteration.
121121 for timestamp , items in pairs (Cache ) do
122- for id , name in pairs (items ) do
123- CompiledCache [id ] = name
122+ for link in pairs (items ) do
123+ CompiledCache [link ] = 1
124124 end
125125 end
126126
127127 -- Start requests so that we can validate itemIDs.
128- for id in pairs (CompiledCache ) do
129- GetItemInfo (id )
128+ for link in pairs (CompiledCache ) do
129+ GetItemInfo (link )
130130 end
131131
132132 ItemCache :RegisterEvent (" BAG_UPDATE" )
@@ -135,21 +135,36 @@ TMW:RegisterCallback("TMW_OPTIONS_LOADED", function()
135135 ItemCache :CacheItems ()
136136end )
137137
138- local function cacheItem (itemID , name )
138+ local function cacheItem (itemID , link )
139+ -- Sanitize the link:
140+ -- strip out all gems/enchants (not an important distinction for TMW)
141+ -- LEAVE suffixID alone (makes sure that the name is correct)
142+ -- strip out uniqueID (not an important distinction for TMW)
143+ -- strip out linkLevel,specializationId
144+ link = link :gsub (" (item:%d+):%-?%d*:%-?%d*:%-?%d*:%-?%d*:%-?%d*:(%-?%d*):%-?%d*:%-?%d*:%-?%d*" , " %1:::::%2::::" )
145+
146+ if link :find (" |h%[%]|h" ) then
147+ -- Links that don't have the item name loaded
148+ -- will just have brackets in the position of the name and nothing else.
149+ return
150+ end
151+
152+ CurrentItems [link ] = 1
153+
139154 -- The item is not cached at all.
140- if not CompiledCache [itemID ] then
141- Cache [currentTimestamp ][itemID ] = name
142- CompiledCache [itemID ] = name
155+ if not CompiledCache [link ] then
156+ Cache [currentTimestamp ][link ] = 1
157+ CompiledCache [link ] = 1
143158
144159 -- The item is in an old cache timesegment.
145- elseif not Cache [currentTimestamp ][itemID ] then
160+ elseif not Cache [currentTimestamp ][link ] then
146161 -- Remove the item from the old cache.
147162 for timestamp , items in pairs (Cache ) do
148- items [itemID ] = nil
163+ items [link ] = nil
149164 end
150165
151166 -- Add it to the current cache timesegment.
152- Cache [currentTimestamp ][itemID ] = name
167+ Cache [currentTimestamp ][link ] = 1
153168 end
154169end
155170
@@ -169,30 +184,29 @@ function ItemCache:CacheItems(force)
169184 for container = 0 , NUM_BAG_SLOTS do
170185 for slot = 1 , GetContainerNumSlots (container ) do
171186 local id = GetContainerItemID (container , slot )
187+ local link = GetContainerItemLink (container , slot )
172188 if id then
173- local name = GetItemInfo (id )
174- name = name and strlower (name )
175-
176- CurrentItems [id ] = name
177- cacheItem (id , name )
189+ cacheItem (id , link )
178190 end
179191 end
180192 end
181193
182194 -- Cache equipped items
183195 for slot = 1 , 19 do
184196 local id = GetInventoryItemID (" player" , slot )
197+ local link = GetInventoryItemLink (" player" , slot )
185198 if id then
186- local name = GetItemInfo (id )
187- name = name and strlower (name )
188-
189- CurrentItems [id ] = name
190- cacheItem (id , name )
199+ cacheItem (id , link )
191200 end
192201 end
193202
194- for id , name in pairs (CurrentItems ) do
195- CurrentItems [name ] = id
203+ local reverseMap = {}
204+ for link in pairs (CurrentItems ) do
205+ local name = link :match (" %[(.-)%]" )
206+ reverseMap [strlower (name )] = link
207+ end
208+ for k , v in pairs (reverseMap ) do
209+ CurrentItems [k ] = v
196210 end
197211
198212 doUpdateCache = nil
0 commit comments