Quantcast

Swap saved option to charDB instead of profile

MilleXIV [09-05-16 - 13:42]
Swap saved option to charDB instead of profile
Filename
core.lua
modules/travel.lua
diff --git a/core.lua b/core.lua
index 9bb95c7..ef118b4 100644
--- a/core.lua
+++ b/core.lua
@@ -299,6 +299,16 @@ function XIVBar:HexToRGBA(hex)
   return (tonumber(rhex, 16) / 255), (tonumber(ghex, 16) / 255), (tonumber(bhex, 16) / 255), (tonumber(ahex, 16) / 255)
 end

+function XIVBar:PrintTable(table, prefix)
+  for k,v in pairs(table) do
+    if type(v) == 'table' then
+      self:PrintTable(v, prefix..'.'..k)
+    else
+      print(prefix..'.'..k..': '..tostring(v))
+    end
+  end
+end
+
 function XIVBar:GetGeneralOptions()
   return {
     name = L['General'],
diff --git a/modules/travel.lua b/modules/travel.lua
index 2441b49..97aeebd 100644
--- a/modules/travel.lua
+++ b/modules/travel.lua
@@ -232,13 +232,19 @@ function TravelModule:SetPortColor()
   if InCombatLockdown() then return; end

   local db = xb.db.profile
-  local v = db.modules.travel.portItem.portId
-
-  if not (IsUsableItem(v) or IsPlayerSpell(v)) then
-    self.portButton:Hide()
-    return
+  local v = xb.db.char.portItem.portId
+
+  if not (self:IsUsable(v)) then
+    v = self:FindFirstOption()
+    v = v.portId
+    if not (self:IsUsable(v)) then
+      self.portButton:Hide()
+      return
+    end
   end

+
+
   if self.portButton:IsMouseOver() then
     self.portText:SetTextColor(unpack(xb:HoverColors()))
   else
@@ -315,7 +321,7 @@ function TravelModule:CreatePortPopup()
         end)

         button:SetScript('OnClick', function(self)
-          xb.db.profile.modules.travel.portItem = self.portItem
+          xb.db.char.portItem = self.portItem
           TravelModule:Refresh()
         end)

@@ -361,7 +367,7 @@ function TravelModule:Refresh()

   if InCombatLockdown() then
     self.hearthText:SetText(GetBindLocation())
-    self.portText:SetText(xb.db.profile.modules.travel.portItem.text)
+    self.portText:SetText(xb.db.char.portItem.text)
     self:SetHearthColor()
     self:SetPortColor()
     return
@@ -389,7 +395,7 @@ function TravelModule:Refresh()
   self:SetHearthColor()

   self.portText:SetFont(xb:GetFont(db.text.fontSize))
-  self.portText:SetText(db.modules.travel.portItem.text)
+  self.portText:SetText(xb.db.char.portItem.text)

   self.portButton:SetSize(self.portText:GetWidth() + iconSize + db.general.barPadding, xb:GetHeight())
   self.portButton:SetPoint("LEFT", -(db.general.barPadding), 0)
@@ -417,14 +423,28 @@ function TravelModule:Refresh()
   self.hearthFrame:SetPoint("RIGHT", -(db.general.barPadding), 0)
 end

-function TravelModule:GetDefaultOptions()
-  local firstItem = select(1, self.portOptions)
-  if not firstItem then
-    firstItem = {portId = 140192, text = GetMapNameByID(1014)}
+function TravelModule:FindFirstOption()
+  local firstItem = {portId = 140192, text = GetMapNameByID(1014)}
+  if self.portOptions then
+    for k,v in pairs(self.portOptions) do
+      if self:IsUsable(v.portId) then
+        firstItem = v
+        break
+      end
+    end
   end
+  return firstItem
+end
+
+function TravelModule:IsUsable(id)
+  return IsUsableItem(id) or IsPlayerSpell(id)
+end
+
+function TravelModule:GetDefaultOptions()
+  local firstItem = self:FindFirstOption()
+  xb.db.char.portItem = xb.db.char.portItem or firstItem
   return 'travel', {
-    enabled = true,
-    portItem = firstItem
+    enabled = true
   }
 end