@@ -55,9 +55,11 @@ local GetNumTalentTabs = GetNumTalentTabs
5555local GetNumTalents = GetNumTalents
5656local GetTalentInfo = GetTalentInfo
5757local GetNumSpellTabs = GetNumSpellTabs
58+ local IsSpellKnown = IsSpellKnown
5859
5960local GetPlayerFacing = GetPlayerFacing
6061local UnitLevel = UnitLevel
62+ local UnitLevelSafe = DataToColor .UnitLevelSafe
6163local UnitHealthMax = UnitHealthMax
6264local UnitHealth = UnitHealth
6365local UnitPowerMax = UnitPowerMax
@@ -199,6 +201,8 @@ DataToColor.customTrigger1 = {}
199201
200202DataToColor .sessionKillCount = 0
201203
204+ local SpellQueueWindow = min (tonumber (GetCVar (DataToColor .C .SpellQueueWindow )) or 0 , 999 )
205+
202206function DataToColor :RegisterSlashCommands ()
203207 DataToColor :RegisterChatCommand (' dc' , ' StartSetup' )
204208 DataToColor :RegisterChatCommand (' dccpu' , ' GetCPUImpact' )
226230
227231-- This function runs when addon is initialized/player logs in
228232function DataToColor :OnInitialize ()
233+ DataToColor :CreateConstants ()
229234 DataToColor :SetupRequirements ()
230235 DataToColor :CreateFrames ()
231236 DataToColor :RegisterSlashCommands ()
@@ -253,6 +258,13 @@ function DataToColor:SetupRequirements()
253258 SetCVar (' Gamma' , 1 , ' []' )
254259end
255260
261+ function DataToColor :CreateConstants ()
262+ for i = 1 , 4 do
263+ DataToColor .C .unitPartyNames [i ] = DataToColor .C .unitParty .. i
264+ DataToColor .C .unitPartyPetNames [i ] = DataToColor .C .unitPartyNames [i ] .. DataToColor .C .unitPet
265+ end
266+ end
267+
256268function DataToColor :Reset ()
257269 DataToColor .S .playerSpellBookName = {}
258270 DataToColor .S .playerSpellBookId = {}
@@ -366,17 +378,23 @@ end
366378function DataToColor :BagSlotChanged (container , slot )
367379 local _ , count , _ , _ , _ , _ , _ , _ , _ , id = GetContainerItemInfo (container , slot )
368380
369- if id == nil then
381+ if not id then
370382 count = 0
371383 id = 0
372384 end
373385
374386 local index = container * 1000 + slot
375- if bagCache [index ] == nil or bagCache [index ].id ~= id or bagCache [index ].count ~= count then
387+ local cache = bagCache [index ]
388+ if cache then
389+ if cache .id ~= id or cache .count ~= count then
390+ cache .id = id
391+ cache .count = count
392+ return true
393+ end
394+ else
376395 bagCache [index ] = { id = id , count = count }
377396 return true
378397 end
379-
380398 return false
381399end
382400
@@ -398,14 +416,14 @@ end
398416
399417function DataToColor :PopulateSpellBookInfo ()
400418 local num , type = 1 , 1
401- if GetNumSpellTabs == nil then
419+ if not GetNumSpellTabs then
402420 while true do
403421 local name , _ , id = GetSpellBookItemName (num , type )
404422 if not name then
405423 break
406424 end
407425
408- if id ~= nil then
426+ if id then
409427 local texture = GetSpellBookItemTexture (num , type )
410428 DataToColor .S .playerSpellBookId [id ] = true
411429 DataToColor .S .playerSpellBookName [texture ] = name
@@ -419,15 +437,16 @@ function DataToColor:PopulateSpellBookInfo()
419437 end
420438 end
421439 else
440+ -- Cataclysm Classic
422441 for i = 1 , GetNumSpellTabs () do
423442 local offset , numSlots = select (3 , GetSpellTabInfo (i ))
424- for j = offset + 1 , offset + numSlots do
443+ for j = offset + 1 , offset + numSlots do
425444 local name , _ , id = GetSpellBookItemName (j , type )
426445 if not name then
427446 break
428447 end
429448
430- if id ~= nil then
449+ if id and IsSpellKnown ( id ) then
431450 local texture = GetSpellBookItemTexture (j , type )
432451 DataToColor .S .playerSpellBookId [id ] = true
433452 DataToColor .S .playerSpellBookName [texture ] = name
@@ -656,19 +675,19 @@ function DataToColor:CreateFrames()
656675 Pixel (int , costMeta or 0 , 35 )
657676 Pixel (int , costValue or 0 , 36 )
658677
659- local slot , expireTime = DataToColor .actionBarCooldownQueue :getTimed (globalTick )
660- if slot then
661- DataToColor .actionBarCooldownQueue :setDirtyAfterTime (slot , globalTick )
678+ local actionSlot , expireTime = DataToColor .actionBarCooldownQueue :getTimed (globalTick )
679+ if actionSlot then
680+ DataToColor .actionBarCooldownQueue :setDirtyAfterTime (actionSlot , globalTick )
662681
663682 local duration = max (0 , floor ((expireTime - GetTime ()) * 10 ))
664683 -- if duration > 0 then
665- -- DataToColor:Print("actionBarCooldownQueue: ", slot , " ", duration, " ", expireTime - GetTime())
684+ -- DataToColor:Print("actionBarCooldownQueue: ", actionSlot , " ", duration, " ", expireTime - GetTime())
666685 -- end
667- Pixel (int , slot * 100000 + duration , 37 )
686+ Pixel (int , actionSlot * 100000 + duration , 37 )
668687
669688 if duration == 0 then
670- DataToColor .actionBarCooldownQueue :removeWhenExpired (slot , globalTick )
671- -- DataToColor:Print("actionBarCooldownQueue: ", slot , " expired")
689+ DataToColor .actionBarCooldownQueue :removeWhenExpired (actionSlot , globalTick )
690+ -- DataToColor:Print("actionBarCooldownQueue: ", actionSlot , " expired")
672691 end
673692 else
674693 Pixel (int , 0 , 37 )
@@ -681,11 +700,8 @@ function DataToColor:CreateFrames()
681700 Pixel (int , DataToColor :getAuraMaskForClass (UnitBuff , DataToColor .C .unitPlayer , DataToColor .S .playerBuffs ), 41 )
682701 Pixel (int , DataToColor :getAuraMaskForClass (UnitDebuff , DataToColor .C .unitTarget , DataToColor .S .targetDebuffs ), 42 )
683702
684- local targetLevel = UnitLevel (DataToColor .C .unitTarget )
685- if targetLevel == - 1 then
686- targetLevel = playerLevel + 10
687- end
688- Pixel (int , targetLevel * 100 + DataToColor .unitClassification [UnitClassification (DataToColor .C .unitTarget )], 43 )
703+ local targetLevel = UnitLevelSafe (DataToColor .C .unitTarget , playerLevel )
704+ Pixel (int , targetLevel * 100 + DataToColor .C .unitClassification [UnitClassification (DataToColor .C .unitTarget )], 43 )
689705
690706 -- Amount of money in coppers
691707 Pixel (int , GetMoney () % 1000000 , 44 ) -- Represents amount of money held (in copper)
@@ -701,8 +717,8 @@ function DataToColor:CreateFrames()
701717 Pixel (int , DataToColor .uiErrorMessage , 52 ) -- Last UI Error message
702718 DataToColor .uiErrorMessage = 0
703719
704- Pixel (int , DataToColor :CastingInfoSpellId (DataToColor .C .unitPlayer ), 53 ) -- SpellId being cast
705- Pixel (int , DataToColor :getAvgEquipmentDurability () * 100 + ((DataToColor .C .CHARACTER_CLASS_ID == 2 and UnitPower (DataToColor .C .unitPlayer , Enum .PowerType .HolyPower ) or GetComboPoints (DataToColor .C .unitPlayer , DataToColor .C .unitTarget )) or 0 ), 54 ) -- for paladin holy power or combo points
720+ Pixel (int , DataToColor :CastingInfoSpellId (DataToColor .C .unitPlayer ), 53 ) -- SpellId being cast
721+ Pixel (int , DataToColor :getAvgEquipmentDurability () * 100 + ((DataToColor .C .CHARACTER_CLASS_ID == 2 and UnitPower (DataToColor .C .unitPlayer , Enum .PowerType .HolyPower ) or GetComboPoints (DataToColor .C .unitPlayer , DataToColor .C .unitTarget )) or 0 ), 54 ) -- for paladin holy power or combo points
706722
707723 local playerBuffCount = DataToColor :populateAuraTimer (UnitBuff , DataToColor .C .unitPlayer , DataToColor .playerBuffTime )
708724 local playerDebuffCount = DataToColor :populateAuraTimer (UnitDebuff , DataToColor .C .unitPlayer , nil )
@@ -853,11 +869,8 @@ function DataToColor:CreateFrames()
853869 Pixel (int , 0 , 93 )
854870 end
855871
856- local mouseoverLevel = UnitLevel (DataToColor .C .unitmouseover )
857- if mouseoverLevel == - 1 then
858- mouseoverLevel = playerLevel + 10
859- end
860- Pixel (int , mouseoverLevel * 100 + DataToColor .unitClassification [UnitClassification (DataToColor .C .unitmouseover )], 85 )
872+ local mouseoverLevel = UnitLevelSafe (DataToColor .C .unitmouseover , playerLevel )
873+ Pixel (int , mouseoverLevel * 100 + DataToColor .C .unitClassification [UnitClassification (DataToColor .C .unitmouseover )], 85 )
861874
862875 Pixel (int , DataToColor :NpcId (DataToColor .C .unitmouseover ), 86 )
863876 Pixel (int , DataToColor :getGuidFromUnit (DataToColor .C .unitmouseover ), 87 )
@@ -880,10 +893,9 @@ function DataToColor:CreateFrames()
880893 if globalTick % LATENCY_ITERATION_FRAME_CHANGE_RATE == 0 then
881894 local _ , _ , lagHome , lagWorld = GetNetStats ()
882895
883- local spellQueue = min (tonumber (GetCVar (DataToColor .C .SpellQueueWindow )) or 0 , 999 )
884896 local lag = min (max (lagHome , lagWorld ), 9999 )
885897
886- Pixel (int , 10000 * spellQueue + lag , 96 )
898+ Pixel (int , 10000 * SpellQueueWindow + lag , 96 )
887899 end
888900
889901 -- Timers
@@ -895,7 +907,7 @@ function DataToColor:CreateFrames()
895907 Pixel (int , lootItemCount * 10 + DataToColor .lastLoot , 97 )
896908
897909 local e = DataToColor .ChatQueue :peek ()
898- if e == nil then
910+ if not e then
899911 Pixel (int , 0 , 98 )
900912 Pixel (int , 0 , 99 )
901913 else
@@ -1049,7 +1061,7 @@ function DataToColor:sell(items)
10491061 end
10501062
10511063 local item = GetMerchantItemLink (1 )
1052- if item == nil then
1064+ if not item then
10531065 DataToColor :Print (" Merchant is not open to sell to, please approach and open." )
10541066 return
10551067 end
0 commit comments