diff Profile.lua @ 257:920d17851a93 stable

Merge 1.1 beta 4 to stable
author Flick
date Tue, 12 Apr 2011 16:06:31 -0700
parents afb5ff4eccc0
children 36a29870bf34
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Profile.lua	Tue Apr 12 16:06:31 2011 -0700
@@ -0,0 +1,157 @@
+local _, addonTable = ...
+local ReAction = addonTable.ReAction
+
+ReAction.PROFILEVERSION_LATEST = 2
+
+ReAction.defaultProfile = { 
+  profile = {
+    dbversion = nil,
+    bars = { },
+    options = { 
+      hideBlizzardBars = false,
+      hideBlizzardVehicleBar = false,
+    },
+  },
+  global = {
+    skipKeybindWarning = false,
+  }
+}
+
+function ReAction:UpgradeProfile()
+  local db = self.db
+
+  if not db.profile.dbversion then
+    -- upgrade from legacy db to v1
+
+    -- (1) remove unused defaultBars table (cleanup)
+    db.profile.defaultBars = nil
+
+    -- (2) HideBlizzard is no longer a module
+    local hb = db:GetNamespace("HideBlizzard",true) or db:RegisterNamespace("HideBlizzard")
+    if hb then
+      db.profile.options.hideBlizzardBars = hb.profile.hide
+      db.profile.options.hideBlizzardVehicleBar = hb.profile.hideVehicle
+      hb:ResetProfile()
+    end
+
+    -- (3) LBF is no longer a module
+    local bf = db:GetNamespace("ButtonFacade",true) or db:RegisterNamespace("ButtonFacade")
+    if bf then
+      for name, bar in pairs(db.profile.bars) do
+        bar.ButtonFacade = bf.profile[name] or bar.ButtonFacade
+      end
+      bf:ResetProfile()
+    end
+
+    -- (4) Action module uses the bar config directly
+    local action = db:GetNamespace("Action",true) or db:RegisterNamespace("Action")
+    if action then
+      for name, bar in pairs(db.profile.bars) do
+        local ac = action.profile.bars and action.profile.bars[name]
+        if ac then
+          for key, value in pairs(ac) do
+            bar[key] = value
+          end
+        end
+      end
+      action:ResetProfile()
+    end
+
+    -- (5) Bags module uses the bar config directly
+    local bag = db:GetNamespace("Bag",true) or db:RegisterNamespace("Bag")
+    if bag then
+      for name, bar in pairs(db.profile.bars) do
+        local bc = bag.profile.buttons and bag.profile.buttons[name]
+        if bc then
+          bar.buttons = bc
+        end
+      end
+      bag:ResetProfile()
+    end
+
+    -- (6) Pet module uses the bar config directly
+    local pet = db:GetNamespace("PetAction",true) or db:RegisterNamespace("PetAction")
+    if pet then
+      for name, bar in pairs(db.profile.bars) do
+        local pc = pet.profile.buttons and pet.profile.buttons[name]
+        if pc then
+          bar.buttons = pc
+        end
+      end
+      pet:ResetProfile()
+    end
+
+    -- (7) Stance module uses the bar config directly
+    local stance = db:GetNamespace("Stance",true) or db:RegisterNamespace("Stance")
+    if stance then
+      for name, bar in pairs(db.profile.bars) do
+        local sc = stance.profile.buttons and stance.profile.buttons[name]
+        if sc then
+          bar.buttons = sc
+        end
+      end
+      stance:ResetProfile()
+    end
+
+    -- (8) Totem module uses the bar config directly
+    local totem = db:GetNamespace("Totem",true) or db:RegisterNamespace("Totem")
+    if totem then
+      for name, bar in pairs(db.profile.bars) do
+        local tc = totem.profile.buttons and totem.profile.buttons[name]
+        if tc then 
+          bar.buttons = tc
+        end
+      end
+      totem:ResetProfile()
+    end
+
+    -- (9) Vehicle exit button uses the bar config directly
+    local vehicle = db:GetNamespace("VehicleExit",true) or db:RegisterNamespace("VehicleExit")
+    if vehicle then
+      for name, bar in pairs(db.profile.bars) do
+        local vc = vehicle.profile.buttons and vehicle.profile.buttons[name]
+        if vc then
+          bar.buttons = vc
+        end
+      end
+      vehicle:ResetProfile()
+    end
+
+    db.profile.dbversion = 1
+  end
+
+
+  if db.profile.dbversion < 2 then
+    -- upgrade from v1 to v2
+
+    -- (10) State module uses the bar config directly
+    local state = db:GetNamespace("State",true) or db:RegisterNamespace("State")
+    if state then
+      for name, bar in pairs(db.profile.bars) do
+        local sc = state.profile.bars and state.profile.bars[name] and state.profile.bars[name].states
+        if sc then
+          bar.states = sc
+        end
+      end
+      state:ResetProfile()
+    end
+
+    db.profile.dbversion = 2
+  end
+
+  db.profile.dbversion = self.PROFILEVERSION_LATEST
+end
+
+function ReAction:OnProfileChanged()
+  self:UpgradeProfile()
+  self:RebuildAll()
+  if not self.db.global.skipKeybindWarning then
+    StaticPopup_Show("REACTION_KB_WARN") -- see Options.lua
+  end
+end
+
+function ReAction:OnNewProfile()
+  self.db.profile.dbversion = ReAction.PROFILEVERSION_LATEST
+  self:OnProfileChanged()
+end
+