GurliGebis / WoWAddon-BattlePetCompletionist

GNU General Public License v3.0
6 stars 2 forks source link

Change how the pet source is being compared #41

Closed GurliGebis closed 1 month ago

GurliGebis commented 1 month ago

This should fix #21 and #40

GurliGebis commented 1 month ago

@davidmc24 like this?

davidmc24 commented 1 month ago

That looks like it should work. I was thinking something more like this (untested pseudo-code):

local tooltipSource = select(5, C_PetJournal.GetPetInfoBySpeciesID(speciesId))
for i = 1, C_PetJournal.GetNumPetSources() do
    if tooltipSource:find('^|c%w+' .. _G["BATTLE_PET_SOURCE_"..i]) then
        return i
    end
end
return -1
GurliGebis commented 1 month ago

What does the '^|c%w+' mean? :)

GurliGebis commented 1 month ago

Also, should we change it to return an integer, instead of the string value, like it does now?

GurliGebis commented 1 month ago

I have changed the code to use the for loop above - the find function doesn't seem to be working though, so I have kept the other way of checking. It seems to be working - does it look good to you?

davidmc24 commented 1 month ago

Either integer or string value could be fine. Not sure which is actually better in this case. If one allows us to avoid needing to list all possible options and maintain that as Blizzard adds new sources, that would be nice.

The caret is a regex "start of line". The "|c" is the start of a color UI escape. The "%w+" is a lua character class, one or more time, for alphanumeric characters. See https://www.lua.org/manual/5.1/manual.html#5.4.1

Basically, it's trying to find tooltips that start with a color escape followed by a source local string.

davidmc24 commented 1 month ago

Yeah, your version looks good to me.

GurliGebis commented 1 month ago

Okay, for some reason, the regex isn't working for me. I'll merge and create a new release in a few minutes 🚀🙂