More tuning on the loading up of the group info.

Mere [06-15-13 - 14:30]
More tuning on the loading up of the group info.

If a spec doesn't have a unitId force a change through to clear it, it removes strays from a previous raid during logon.

If a player is solo, and that playerinfo object already exists for them, don't recreate one.

Tidy up a few comments.
Filename
RaidManagement_LibUnitChange.lua
diff --git a/RaidManagement_LibUnitChange.lua b/RaidManagement_LibUnitChange.lua
index e1846f2..c06110b 100644
--- a/RaidManagement_LibUnitChange.lua
+++ b/RaidManagement_LibUnitChange.lua
@@ -13,7 +13,7 @@ MereHealingFrames.RaidManagement.LibUnitChange = {}
 MereHealingFrames.Events = MereHealingFrames.Events or {}

 function MereHealingFrames.Events.GroupJoin (handle, UnitId, groupSpecifier)
-    BumpEventCounter("Event.SafesRaidManager.Group.Join")
+    BumpEventCounter("Event.Group.Join")

     local playerInfo = MereHealingFrames.RaidManagement.playerInfo:new(nil, UnitId, groupSpecifier)
     for layoutName, layout in pairs(MereHealingFrames.Layouts) do
@@ -22,7 +22,7 @@ function MereHealingFrames.Events.GroupJoin (handle, UnitId, groupSpecifier)
 end

 function MereHealingFrames.Events.GroupLeave (handle, unitId, groupSpecifier)
-    BumpEventCounter("Event.SafesRaidManager.Group.Leave")
+    BumpEventCounter("Event.Group.Leave")
     if (unitId == MereHealingFrames.PlayerId) then
         -- can't remove the player, just change the specifier
         return MereHealingFrames.Events.GroupChange(handle, unitId, groupSpecifier, "player")
@@ -39,7 +39,7 @@ function MereHealingFrames.Events.GroupLeave (handle, unitId, groupSpecifier)
 end

 function MereHealingFrames.Events.GroupChange (handle, UnitId, oldSpec, newSpec)
-    BumpEventCounter("Event.SafesRaidManager.Group.Change")
+    BumpEventCounter("Event.Group.Change")
     MereHealingFrames.Debug(4, "GroupChange: %s, %s, %s", UnitId, oldSpec, newSpec)

     if (oldSpec == newSpec) then
@@ -58,9 +58,14 @@ function MereHealingFrames.Events.GroupChange (handle, UnitId, oldSpec, newSpec)
 end

 function MereHealingFrames.Events.PlayerSolo (handle)
-    BumpEventCounter("Event.SafesRaidManager.Player.Leave")
+    BumpEventCounter("Event.PlayerSolo")

-    local playerInfo = MereHealingFrames.RaidManagement.playerInfo:new(nil, MereHealingFrames.PlayerId, "player")
+    local playerInfo = RMUnits[MereHealingFrames.PlayerId]
+    if (playerInfo ~= nil) then
+        return
+    end
+
+    playerInfo = MereHealingFrames.RaidManagement.playerInfo:new(nil, MereHealingFrames.PlayerId, "player")

     for layoutName, layout in pairs(MereHealingFrames.Layouts) do
         layout:GroupJoin(playerInfo)
@@ -89,10 +94,6 @@ local function UnitChanged(handle, unitid, spec)
     pendingChanges = pendingChanges + 1
 end

--- three things to handle
--- simple remove: the unitid has been removed
--- simple add: UnitId is brand new
-
 local function UnitChangesComplete(handle, units)
     if (pendingChanges == 0) then
         return
@@ -120,13 +121,14 @@ local function UnitChangesComplete(handle, units)
         local oldUnitId = oldUnitIdBySpec[spec]

         if (oldUnitId ~= nil) then
-            -- so either a remove or move the old unit from this spot
+            -- so either a remove or the old unit moved from this spec
             local newSpec = pendingUnitChanges[oldUnitId]
             if (newSpec == nil) then
+                -- deleted unit
                 MereHealingFrames.Debug(2, "UnitChangeComplete, deleted unit: %s, spec: %s", oldUnitId, spec)
                 MereHealingFrames.Events.GroupLeave (nil, oldUnitId, spec)
             else
-                -- the old unitid moved elsewhere (should be dealt with by the spec if move to)
+                -- the old unitid moved elsewhere (should be dealt with by the spec it move to, so just trace)
                 MereHealingFrames.Debug(2, "UnitChangeComplete, old unit moved unit: %s, from spec: %s, to spec: %s",
                     oldUnitId, spec, newSpec)
                 --MereHealingFrames.Events.GroupChange(nil, oldUnitId, spec, newSpec)
@@ -134,7 +136,7 @@ local function UnitChangesComplete(handle, units)
         end

         if (unitid) then
-            -- then add or move the new unit in
+            -- add or move the new unit in
             local oldSpec = oldSpecByUnitId[unitid]
             if (not oldSpec) then
                 -- brand new unit
@@ -168,9 +170,15 @@ function MereHealingFrames.RaidManagement.LibUnitChange.PrimeSpecs()
     local unitIds = Inspect.Unit.Lookup(specTracking)
     MereHealingFrames.DebugDump(2, unitIds)
     local unitCount = 0
-    for spec, unitid in pairs(unitIds) do
-        UnitChanged(nil, unitid, spec)
-        unitCount = unitCount + 1
+
+    for spec in pairs(specTracking) do
+        local unitId = unitIds[spec]
+        if (unitId ~= nil) then
+            UnitChanged(nil, unitId, spec)
+            unitCount = unitCount + 1
+        else
+            UnitChanged(nil, false, spec)
+        end
     end

     if (unitCount == 0) then