comparison CyborgMMO7.lua @ 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
comparison
equal deleted inserted replaced
34:6ce173840e68 35:16b2ff47b6db
100 end 100 end
101 end 101 end
102 CyborgMMO_GetSaveData().Rat = saveData 102 CyborgMMO_GetSaveData().Rat = saveData
103 end 103 end
104 104
105 local function GetSpellID(name)
106 local link = GetSpellLink(name)
107 if link then
108 local id = link:match('spell:(%d+)|')
109 if id then
110 return tonumber(id)
111 end
112 end
113 end
114
115 local function ConvertOldRatData(oldData)
116 local newData = {}
117 for mode,modeData in ipairs(oldData) do
118 newData[mode] = {}
119 for button,buttonData in ipairs(modeData) do
120 CyborgMMO_DPrint("converting mode:", mode, "button:", button)
121 local type = buttonData.Type
122 if type=='item' then
123 -- not possible, the WowObject 'Type' field was overwritten by the item type
124 elseif type=='macro' then
125 local name = buttonData.Name
126 newData[mode][button] = {
127 type = type,
128 detail = name,
129 }
130 elseif type=='spell' then
131 local id = GetSpellID(buttonData.Name)
132 CyborgMMO_DPrint("converting spell:", buttonData.Name, id)
133 if id then
134 newData[mode][button] = {
135 type = type,
136 detail = id,
137 }
138 end
139 elseif type=='petaction' then
140 -- no longer supported
141 elseif type=='merchant' then
142 -- no longer supported
143 elseif type=='companion' then
144 local id = GetSpellID(buttonData.Name)
145 CyborgMMO_DPrint("converting companion:", buttonData.Name, id)
146 if id then
147 newData[mode][button] = {
148 type = type,
149 detail = buttonData.Subdetail,
150 subdetail = id,
151 }
152 end
153 elseif type=='equipmentset' then
154 CyborgMMO_DPrint("converting equipment set:", buttonData.Detail)
155 newData[mode][button] = {
156 type = type,
157 detail = buttonData.Detail,
158 }
159 elseif type=='callback' then
160 CyborgMMO_DPrint("converting callback:", buttonData.Detail)
161 newData[mode][button] = {
162 type = type,
163 detail = buttonData.Detail,
164 }
165 elseif type then
166 -- maybe it's an item type
167 local id = buttonData.Detail
168 local class = select(6, GetItemInfo(id)) -- :NOTE: this may fail if the item is not yet in the cache
169 if class == type then
170 CyborgMMO_DPrint("converting item:", id, type, class)
171 newData[mode][button] = {
172 type = "item",
173 detail = id,
174 }
175 end
176 else
177 CyborgMMO_DPrint("cannot convert:", type)
178 end
179 end
180 end
181 return newData
182 end
183
105 function CyborgMMO_Event(self, event, ...) 184 function CyborgMMO_Event(self, event, ...)
106 if event == "VARIABLES_LOADED" then 185 if event == "VARIABLES_LOADED" then
107 VarsLoaded = true 186 VarsLoaded = true
187 -- convert old profile
188 if CyborgMMO7SaveData[SaveName] and not CyborgMMO7SaveData.Settings then
189 local oldData = CyborgMMO7SaveData[SaveName]
190 CyborgMMO7SaveData = {}
191 CyborgMMO7SaveData.Settings = oldData.Settings
192 CyborgMMO7SaveData.Rat = ConvertOldRatData(oldData.Rat)
193 CyborgMMO7SaveData[SaveName] = oldData -- for now keep the data, we may have missed something in the conversion
194 end
108 elseif event == "PLAYER_ENTERING_WORLD" then 195 elseif event == "PLAYER_ENTERING_WORLD" then
109 EnteredWorld = true 196 EnteredWorld = true
110 elseif event == "PLAYER_REGEN_DISABLED" then 197 elseif event == "PLAYER_REGEN_DISABLED" then
111 CyborgMMO_Close() 198 CyborgMMO_Close()
112 else 199 else