changeset 35:16b2ff47b6db

Added a conversion function to extract as much information as possible from old profiles.
author madcatzinc@35b17cf1-18cd-47ff-9ca3-31d6b526ef09
date Thu, 25 Apr 2013 01:31:36 +0000
parents 6ce173840e68
children 8fc4f8a25225
files CyborgMMO7.lua
diffstat 1 files changed, 87 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/CyborgMMO7.lua	Thu Apr 25 01:31:31 2013 +0000
+++ b/CyborgMMO7.lua	Thu Apr 25 01:31:36 2013 +0000
@@ -102,9 +102,96 @@
 	CyborgMMO_GetSaveData().Rat = saveData
 end
 
+local function GetSpellID(name)
+	local link = GetSpellLink(name)
+	if link then
+		local id = link:match('spell:(%d+)|')
+		if id then
+			return tonumber(id)
+		end
+	end
+end
+
+local function ConvertOldRatData(oldData)
+	local newData = {}
+	for mode,modeData in ipairs(oldData) do
+		newData[mode] = {}
+		for button,buttonData in ipairs(modeData) do
+			CyborgMMO_DPrint("converting mode:", mode, "button:", button)
+			local type = buttonData.Type
+			if type=='item' then
+				-- not possible, the WowObject 'Type' field was overwritten by the item type
+			elseif type=='macro' then
+				local name = buttonData.Name
+				newData[mode][button] = {
+					type = type,
+					detail = name,
+				}
+			elseif type=='spell' then
+				local id = GetSpellID(buttonData.Name)
+				CyborgMMO_DPrint("converting spell:", buttonData.Name, id)
+				if id then
+					newData[mode][button] = {
+						type = type,
+						detail = id,
+					}
+				end
+			elseif type=='petaction' then
+				-- no longer supported
+			elseif type=='merchant' then
+				-- no longer supported
+			elseif type=='companion' then
+				local id = GetSpellID(buttonData.Name)
+				CyborgMMO_DPrint("converting companion:", buttonData.Name, id)
+				if id then
+					newData[mode][button] = {
+						type = type,
+						detail = buttonData.Subdetail,
+						subdetail = id,
+					}
+				end
+			elseif type=='equipmentset' then
+				CyborgMMO_DPrint("converting equipment set:", buttonData.Detail)
+				newData[mode][button] = {
+					type = type,
+					detail = buttonData.Detail,
+				}
+			elseif type=='callback' then
+				CyborgMMO_DPrint("converting callback:", buttonData.Detail)
+				newData[mode][button] = {
+					type = type,
+					detail = buttonData.Detail,
+				}
+			elseif type then
+				-- maybe it's an item type
+				local id = buttonData.Detail
+				local class = select(6, GetItemInfo(id)) -- :NOTE: this may fail if the item is not yet in the cache
+				if class == type then
+					CyborgMMO_DPrint("converting item:", id, type, class)
+					newData[mode][button] = {
+						type = "item",
+						detail = id,
+					}
+				end
+			else
+				CyborgMMO_DPrint("cannot convert:", type)
+			end
+		end
+	end
+	return newData
+end
+
 function CyborgMMO_Event(self, event, ...)
 	if event == "VARIABLES_LOADED" then
 		VarsLoaded = true
+		-- convert old profile
+		if CyborgMMO7SaveData[SaveName] and not CyborgMMO7SaveData.Settings then
+			local oldData = CyborgMMO7SaveData[SaveName]
+			CyborgMMO7SaveData = {}
+			CyborgMMO7SaveData.Settings = oldData.Settings
+			CyborgMMO7SaveData.Rat = ConvertOldRatData(oldData.Rat)
+			CyborgMMO7SaveData[SaveName] = oldData -- for now keep the data, we may have missed something in the conversion
+		end
 	elseif event == "PLAYER_ENTERING_WORLD" then
 		EnteredWorld = true
 	elseif event == "PLAYER_REGEN_DISABLED" then