comparison AskMrRobot.lua @ 41:0e78d6424532 v13

added region to import/export, some prep for new combat logging
author yellowfive
date Fri, 24 Oct 2014 12:08:47 -0700
parents 4d1a9865c90e
children 262083330ac9
comparison
equal deleted inserted replaced
40:a489324103e5 41:0e78d6424532
137 -- initialize settings when the addon loads 137 -- initialize settings when the addon loads
138 function AskMrRobot.InitializeSettings() 138 function AskMrRobot.InitializeSettings()
139 139
140 -- global settings 140 -- global settings
141 if not AmrSettings then AmrSettings = {} end 141 if not AmrSettings then AmrSettings = {} end
142 if not AmrSettings.Logins then AmrSettings.Logins = {} end
143 142
144 -- per-character settings 143 -- per-character settings
145 if not AmrDb then AmrDb = {} end 144 if not AmrDb then AmrDb = {} end
146 145
147 -- addon stuff 146 -- addon stuff
177 end 176 end
178 177
179 -- record logins when the addon starts up, used to help figure out which character logged which parts of a log file 178 -- record logins when the addon starts up, used to help figure out which character logged which parts of a log file
180 function AskMrRobot.RecordLogin() 179 function AskMrRobot.RecordLogin()
181 180
182 -- delete entries that are more than 10 days old to prevent the table from growing indefinitely 181 -- only need to record the region now (only thing we can't get from the log file still)
183 if AmrSettings.Logins and #AmrSettings.Logins > 0 then 182 AmrSettings.Region = AskMrRobot.regionNames[GetCurrentRegion()]
184 local now = time() 183
185 local oldDuration = 60 * 60 * 24 * 10 184 -- remove the old Logins data, don't need it anymore
186 local entryTime 185 AmrSettings.Logins = nil
187 repeat
188 -- parse entry and get time
189 local parts = {}
190 for part in string.gmatch(AmrSettings.Logins[1], "([^;]+)") do
191 tinsert(parts, part)
192 end
193 entryTime = tonumber(parts[3])
194
195 -- entries are in order, remove first entry if it is old
196 if difftime(now, entryTime) > oldDuration then
197 tremove(AmrSettings.Logins, 1)
198 end
199 until #AmrSettings.Logins == 0 or difftime(now, entryTime) <= oldDuration
200 end
201
202 -- record the time a player logs in, used to figure out which player logged which parts of their log file
203 local key = AmrDb.RealmName .. ";" .. AmrDb.CharacterName .. ";"
204 local loginData = key .. time()
205 if AmrSettings.Logins and #AmrSettings.Logins > 0 then
206 local last = AmrSettings.Logins[#AmrSettings.Logins]
207 if string.len(last) >= string.len(key) and string.sub(last, 1, string.len(key)) ~= key then
208 table.insert(AmrSettings.Logins, loginData)
209 end
210 else
211 table.insert(AmrSettings.Logins, loginData)
212 end
213 end 186 end
214 187
215 function AskMrRobot.InitializeMinimap() 188 function AskMrRobot.InitializeMinimap()
216 189
217 -- minimap icon and data broker icon plugin thingy 190 -- minimap icon and data broker icon plugin thingy
269 AskMrRobot.GetSpecs() 242 AskMrRobot.GetSpecs()
270 end 243 end
271 244
272 -- gets all basic character properties 245 -- gets all basic character properties
273 function AskMrRobot.ScanCharacter() 246 function AskMrRobot.ScanCharacter()
247 AmrDb.Region = AskMrRobot.regionNames[GetCurrentRegion()]
274 AmrDb.RealmName = GetRealmName() 248 AmrDb.RealmName = GetRealmName()
275 AmrDb.CharacterName = UnitName("player") 249 AmrDb.CharacterName = UnitName("player")
276 AmrDb.Guild = GetGuildInfo("player") 250 AmrDb.Guild = GetGuildInfo("player")
277 AmrDb.ActiveSpec = GetActiveSpecGroup() 251 AmrDb.ActiveSpec = GetActiveSpecGroup()
278 AmrDb.Level = UnitLevel("player"); 252 AmrDb.Level = UnitLevel("player");
630 function AskMrRobot.ExportToCompressedString(complete) 604 function AskMrRobot.ExportToCompressedString(complete)
631 local fields = {} 605 local fields = {}
632 606
633 -- compressed string uses a fixed order rather than inserting identifiers 607 -- compressed string uses a fixed order rather than inserting identifiers
634 table.insert(fields, GetAddOnMetadata(AskMrRobot.AddonName, "Version")) 608 table.insert(fields, GetAddOnMetadata(AskMrRobot.AddonName, "Version"))
609 table.insert(fields, AmrDb.Region)
635 table.insert(fields, AmrDb.RealmName) 610 table.insert(fields, AmrDb.RealmName)
636 table.insert(fields, AmrDb.CharacterName) 611 table.insert(fields, AmrDb.CharacterName)
637 612
638 -- guild name 613 -- guild name
639 local guildName = GetGuildInfo("player") 614 local guildName = GetGuildInfo("player")
764 return "$" .. table.concat(fields, ";") .. "$" 739 return "$" .. table.concat(fields, ";") .. "$"
765 end 740 end
766 741
767 function AskMrRobot.ExportToAddonChat(timestamp) 742 function AskMrRobot.ExportToAddonChat(timestamp)
768 local msg = AskMrRobot.ExportToCompressedString(false) 743 local msg = AskMrRobot.ExportToCompressedString(false)
769 local msgPrefix = timestamp .. "\n" .. AmrDb.RealmName .. "\n" .. AmrDb.CharacterName .. "\n" 744 local msgPrefix = timestamp .. "\n" .. AmrDb.Region .. "\n" .. AmrDb.RealmName .. "\n" .. AmrDb.CharacterName .. "\n"
770 745
771 -- break the data into 250 character chunks (to deal with the short limit on addon message size) 746 -- break the data into 250 character chunks (to deal with the short limit on addon message size)
772 local chunks = {} 747 local chunks = {}
773 local i = 1 748 local i = 1
774 local length = string.len(msg) 749 local length = string.len(msg)
830 local ver = tonumber(parts[1]) 805 local ver = tonumber(parts[1])
831 if ver < MIN_IMPORT_VERSION then 806 if ver < MIN_IMPORT_VERSION then
832 return L.AMR_IMPORT_ERROR_VERSION 807 return L.AMR_IMPORT_ERROR_VERSION
833 end 808 end
834 809
835 -- require realm/name match 810 -- require name match (don't match realm due to language issues for now)
836 if not isTest then 811 if not isTest then
837 local realm = parts[2] 812 local realm = parts[2]
838 local name = parts[3] 813 local name = parts[3]
839 if name ~= AmrDb.CharacterName then 814 if name ~= AmrDb.CharacterName then
840 local badPers = name .. " (" .. realm .. ")" 815 local badPers = name .. " (" .. realm .. ")"
861 end 836 end
862 837
863 -- require spec match 838 -- require spec match
864 local spec = tonumber(parts[11]) 839 local spec = tonumber(parts[11])
865 if spec ~= AmrDb.Specs[AmrDb.ActiveSpec] then 840 if spec ~= AmrDb.Specs[AmrDb.ActiveSpec] then
866 print(AmrDb.ActiveSpec) 841 --print(AmrDb.ActiveSpec)
867 print(spec) 842 --print(spec)
868 print(AmrDb.Specs[AmrDb.ActiveSpec]) 843 --print(AmrDb.Specs[AmrDb.ActiveSpec])
869 local _, specName = GetSpecializationInfoByID(AskMrRobot.gameSpecIds[spec]) 844 local _, specName = GetSpecializationInfoByID(AskMrRobot.gameSpecIds[spec])
870 return L.AMR_IMPORT_ERROR_SPEC:format(specName) 845 return L.AMR_IMPORT_ERROR_SPEC:format(specName)
871 end 846 end
872 847
873 -- require talent match 848 -- require talent match