ALL THE THINGS

ALL THE THINGS

31M Downloads

API for other addons

Urtgard opened this issue ยท 4 comments

commented

I tried to use ATT to determine whether I collected an appearance or not.
I need a function where the input is an itemLink and the output is whether I knew the appearance from another item, knew the appearance from this item or don't know the appearance at all.
This would be especially helpful for me with race or class locked items.

I tried a few things but I didn't found the stuff needed for this.

Is there an easy way to get the infos I need or could you add something like this?

Greetings

commented

If you know the itemLink, you can use AllTheThings.SearchForLink(itemLink);

This function will return all of the entries in the ATT Database where that item can be found as a list. If you want to know if you have that item collected, you can check the first entry in the list and check the "collected" field. If it is a 1, then you have collected the item based on the user's current filters. If it is a 2, then you have collected the item's appearance from another item. (Technically "Collected", but not really.)

commented

The collected state of 2 only gets assigned while the user is in Unique Mode since that requires extra computations. If you wish to run the calculation yourself, you can access the object's "s" property, which represents the Source ID of that appearance. The rest of what you're asking can be solved using Blizzard's API.

As for class locked items, you can access the "nmc" property. If this is a 1, then the item is not for your class. You can always refer to the object's "c" property, which is a list of the classes that the item is restricted to. (it usually does not exist, so check that it exists before accessing it.)

Similarly, for race locked items, you can access the "nmr" property. If this is a 1, then the item is not for your race. You can always refer to the object's "races" property, which is a list of the races that the item is restricted to. (it usually does not exist, so check that it exists before accessing it.)

You can calculate the full source of the appearance by accessing each of the entries in the AllTheThings.SearchForLink function and then check out the BuildSourceTextForChat function. It is not globally scoped, so you can't access it outside of ATT, but the logic is there and pretty easy to follow by using the "text" property and then checking the "parent" field for the next node in the hierarchy.

commented

The answer to that can be a bit confusing: Essentially every object (a table pointer) we have in the database is an instance of one of our object types / classes (metatable in Lua) to keep repeated common fields from bloating our memory usage. When working with a table that has a metatable, only properties whose values are different than the default state of the metatable or have been explicitly assigned to a value will appear as part of an iterator (a for loop). All derived properties will need to be explicitly requested for them to return their metatable's default value. (which is sometimes a computation that later gets assigned to the instance itself in order to prevent unnecessary calculations - the "text" property is like this)

Properties that do not exist in the object, such as the "collected" state only indicate that the object is not collected, can be assumed that their final value is derived from their metatable. Once it is collected, the "collected" state will appear with the iterator. You can simply check for the existence of the "collected" field prior to doing the rest of your calculations.

Objects with Source IDs typically derive from the AllTheThings.BaseItemSource metatable.

commented

Thanks for the detailed answer. Very helpful.

One question remains. I found SearchForLink myself and tried to see what's inside the table we got as a return.

-- This snippet
local group = AllTheThings.SearchForLink(itemLink)
for k,v in pairs(group[1]) do
  print(k,v)
end

--  returns something like this
--[[
  visible false
  parent table: 000001D7F2DF0EA0
  s 95827
  lvl 110
  bonusID 4796
  itemID 159820
  b 2
  f 1
--]]

Why is there no collected field?