Simple iLevel

23 - Add LibDogTag-3.0 support

I use IceHud, which in turn uses LibDogTags-3.0 to show custom text. I would love to be able to show the item level, if known, of my target as part of my tags. This means adding a "tag" to LibDogTags, which I did through this code:

local tag = {
   code = function(unit)
      local ilvl = SIL:Cache(UnitGUID(unit), 'score')
      if type(ilvl) == "number" then
         return ilvl
      else
         return ''
      end
   end,
   arg = {
      'unit', 'string;undef', 'player'
   },
   ret = "number;string",
   events = "UNIT_INVENTORY_CHANGED#$unit;INSPECT_READY#$unit",
   doc = "Return the item level of unit (from Simple iLevel)",
   example = ('[ItemLevel] => "%d"; [ItemLevel] => ""'):format(552.1),
   category = "Characteristics"
}
LibStub("LibDogTag-3.0"):AddTag("Unit", "ItemLevel", tag)

It would be awesome to adopt that into your addon as an optional dependency / protected by "if there is no such library". I have tested that and it works correctly, at least for me.

Note: if you had a custom ever that fired with the unit, when the cache was updated, that would be super-convenient because it would avoid the possible race of hooking in to listen on those two events. That would avoid unnecessary work and ensure correct updates. I didn't look for an event like that in your code though.

Finally, if you don't want this in your code, but are willing to accept it externally, I will turn it into an addon myself -- having confirmation that the API I am using to query the item level out, and a custom event as indicated, would be super-helpful to make that integration work smoothly.

User When Change
scotepi Jan 20, 2015 at 02:01 UTC Changed status from New to Started
slippycheeze Dec 25, 2013 at 00:44 UTC Changed description:
        'unit', 'string;undef', 'player'
     },
     ret = "number;string",
-    events = "UNIT_INVENTORY_CHANGED#$unit",
+    events = "UNIT_INVENTORY_CHANGED#$unit;INSPECT_READY#$unit",
     doc = "Return the item level of unit (from Simple iLevel)",
     example = ('[ItemLevel] => "%d"; [ItemLevel] => ""'):format(552.1),
     category = "Characteristics"
----------------------------------------
  </pre>

  It would be awesome to adopt that into your addon as an optional dependency / protected by "if there is no such library".  I have tested that and it works correctly, at least for me.
+
+ Note: if you had a custom ever that fired with the unit, when the cache was updated, that would be super-convenient because it would avoid the possible race of hooking in to listen on those two events.  That would avoid unnecessary work and ensure correct updates.  I didn't look for an event like that in your code though.
+
+ Finally, if you don't want this in your code, but are willing to accept it externally, I will turn it into an addon myself -- having confirmation that the API I am using to query the item level out, and a custom event as indicated, would be super-helpful to make that integration work smoothly.
slippycheeze Dec 25, 2013 at 00:27 UTC Changed description:
  I use IceHud, which in turn uses LibDogTags-3.0 to show custom text.  I would love to be able to show the item level, if known, of my target as part of my tags.  This means adding a "tag" to LibDogTags, which I did through this code:

- <code>
+ <pre>
  local tag = {
     code = function(unit)
        local ilvl = SIL:Cache(UnitGUID(unit), 'score')
----------------------------------------
     category = "Characteristics"
  }
  LibStub("LibDogTag-3.0"):AddTag("Unit", "ItemLevel", tag)
- </code>
+ </pre>

  It would be awesome to adopt that into your addon as an optional dependency / protected by "if there is no such library".  I have tested that and it works correctly, at least for me.
slippycheeze Dec 25, 2013 at 00:26 UTC Create

You must login to post a comment. Don't have an account? Register to get one!

  • 3 comments
  • Avatar of slippycheeze slippycheeze Feb 26, 2015 at 05:09 UTC - 0 likes

    Heh. I actually ended up releasing a slightly improved version of this as a stand-alone addon since I got no response here. It would be great to make two changes to the version integrated into SiL and I can retire mine:

    ret = "string;nil" and return nil instead of return ''.

    That improves the behaviour so that a unit without a cached ilvl is treated as "empty" and you can use, eg, dogtags coalesce function to make it vanish nicely.

    (Happy to put that in the repo myself if you want to give me the commit bit, btw, or send a patch, or whatever is helpful.)

  • Avatar of scotepi scotepi Jan 20, 2015 at 02:27 UTC - 0 likes

    I'm trying to get this set up but I can't seam to add it to IceHud.

    There are 2 ways you can hook into SIL.

    SIL:AddHook('inspect', function(guid, score, totalItems, age, data.items) {});
    

    or a little simpler would be

    SIL:GetScoreTarget(target, false, function(guid, score, totalItems, age, items, target){});
    

    It's been so long I don't remember the difference between totalItems and items. At some point I need to update the API.txt and docs on here.

  • Avatar of Sharagol Sharagol Jan 14, 2015 at 19:18 UTC - 0 likes

    It's what i was looking for :)

    Can you just tell me where should i add this code ? ( using latest icehud addon )

    After that we should use [ilvl] right ?

    Thanks,

    Last edited Jan 14, 2015 by Sharagol
  • 3 comments

Facts

Last updated
Jan 20, 2015
Reported
Dec 25, 2013
Status
Started - Work on this issue has begun.
Type
Patch - Source code patch for review
Priority
Medium - Normal priority.
Votes
1

Reported by

Possible assignees