View Single Post
06/29/16, 11:52 AM   #8
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,579
In my addons I do not use ZO_SavedVars, so I am definitely in need for an alternative way to do this.

If persistence is a problem, maybe you can just put a "history" somewhere into ZO_Ingame.lua.
When the name of a character is changed in the pregame scene, or a character is deleted, or the displayName is changed you write that information to disk in pregame and once the client was ingame all addons can check what has changed and upgrade their vars accordingly.

It could look like this:

Lua Code:
  1. accountHistory = {
  2.   {ACCOUNT_EVENT_CHARACTER_CREATED, "name", <timestamp>},
  3.   {ACCOUNT_EVENT_CHARACTER_NAME_CHANGED, "oldname", "newname", <timestamp>},
  4.   {ACCOUNT_EVENT_CHARACTER_RACE_CHANGED, <timestamp>},
  5.   {ACCOUNT_EVENT_CHARACTER_LOOK_CHANGED, <timestamp>},
  6.   {ACCOUNT_EVENT_CHARACTER_DELETED, "name", <timestamp>},
  7.   {ACCOUNT_EVENT_DISPLAYNAME_CHANGED, "oldname", "newname", <timestamp>},
  8. }

It should be read-only so that an addon cannot change the information. Race and look change is probably not necessary, but wouldn't hurt either.

EDIT: Maybe instead of providing it via normal saveData you could also just return it from a function called GetAccountHistory.
In addition to timestamps you could give the events an id and if it is passed to GetAccountHistory it would only return events that come after that id.

EDIT2:
The upgrade code would then look something like this:
Lua Code:
  1. for i=1, #accountHistory do
  2.     local id, type, timeStamp, name, newName = unpack(acountHistory[i])
  3.     if(type == ACCOUNT_EVENT_CHARACTER_NAME_CHANGED) then
  4.         saveData[GetDisplayName()][newName] = saveData[GetDisplayName()][name]
  5.         saveData[GetDisplayName()][name] = nil
  6.     elseif(type == ACCOUNT_EVENT_CHARACTER_DELETED) then
  7.         saveData[GetDisplayName()][name] = nil
  8.     elseif(type == ACCOUNT_EVENT_CHARACTER_CREATED) then
  9.         saveData[GetDisplayName()][name] = ZO_DeepTableCopy(defaultData)
  10.     elseif(type == ACCOUNT_EVENT_DISPLAYNAME_CHANGED) then
  11.         saveData[newName] = saveData[name]
  12.         saveData[name] = nil
  13.     end
  14.     lastId = id
  15. end
(I changed the order for the timestamp to make it easier to get the right arguments)

Last edited by sirinsidiator : 06/29/16 at 12:13 PM.