EquipDoll - Clean Item Names

A place to post your add ons and ideas for them

Moderator: Moderator

Post Reply
Message
Author
deogo
Wayist
Posts: 17
Joined: Mon Jun 16, 2014 4:32 pm

EquipDoll - Clean Item Names

#1 Post by deogo »


Steven Aus
Archmage
Posts: 366
Joined: Sat Dec 13, 2014 3:38 pm

Re: EquipDoll - Clean Item Names

#2 Post by Steven Aus »

Great little QoL addon. :)

Zizzo
Sher'Tul Godslayer
Posts: 2521
Joined: Thu Jan 23, 2003 8:13 pm
Location: A shallow water area south of Bree
Contact:

Re: EquipDoll - Clean Item Names

#3 Post by Zizzo »

(Was going to PM this, but the send-a-private-message page apparently does not support attachments; We Apologize for the Inconvenience.™)

I hope that you're still maintaining this addon, because I'd like to suggest a (well, maybe not so) small revision:

As you may have noticed earlier, there was a conflict between your addon and my own Curse Levels addon (which is included in ZOmnibus, so a fair number of people tripped over it). The code causing the conflict is in your superloaded EquipDollFrame:drawShortItemName() method:

Code: Select all

  local temp = o.getShortName
  o.getShortName = o.getName
  -- [...]
  o.getShortName = temp
The problem is that that code doesn't do do what it looks like it does. The actual object table 'o' doesn't have a .getShortName field, so what you're assigning to 'temp' is the Object.getShortName method defined in mod/class/Object.lua. When you assign it back to o.getShortName, though, you're setting the field directly in the object table as an instance method — which superficially has the same effect, but that instance method will be saved to and loaded back from the savefile, which breaks superloading.

Now, I've added a workaround for the conflict to Curse Levels, but this could still cause conflicts with other addons, so I think it's still worth fixing. There are two approaches I can think of:
  • Rather than manipulating the object directly, which is fraught with risks (ask me how I know… :oops: :roll: ), the approach I would suggest is to superload Object:getShortName() and have it divert to Object:getName() if it's called from EquipDollFrame:drawShortItemName(). I've attached a proof-of-concept implementation that appears to yield the same results as yours in testing, which I offer freely for your use.
  • If you prefer to keep your code mostly unchanged, you should at least be using rawget() and rawset(). So your code would change to:

    Code: Select all

      local temp = rawget(o, 'getShortName')
      rawset(o, 'getShortName', o.getName)
      -- [...]
      rawset(o, 'getShortName', temp)
    
    I'd also encourage you to wrap your call to the parent method in an xpcall(), so that even if the parent method throws an error, you can still clean up behind it. So this line:

    Code: Select all

      local ret = base( self, o, x, y )
    
    would change to:

    Code: Select all

      local ok, ret = xpcall(function() return base( self, o, x, y ) end, debug.traceback)
    
    and below where you restore all your saved original values, you'd add the line:

    Code: Select all

      if not ok then error(ret) end
    
We Apologize for the Interruption,™ and I hope this helps.
Attachments
tome-clean_doll_z.zip
(4.58 KiB) Downloaded 26 times
"Blessed are the yeeks, for they shall inherit Arda..."

Post Reply