forked from EllesmereGaming/EllesmereUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEllesmereUI_Migration.lua
More file actions
3823 lines (3590 loc) · 174 KB
/
Copy pathEllesmereUI_Migration.lua
File metadata and controls
3823 lines (3590 loc) · 174 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
if EUI_CLIENT_BLOCKED then return end -- pre-12.1 client failsafe (EllesmereUI_ClientGate.lua)
--------------------------------------------------------------------------------
-- EllesmereUI_Migration.lua -- loaded after EllesmereUI_Lite.lua, before
-- EllesmereUI_Profiles.lua; runs at ADDON_LOADED for "EllesmereUI" (before
-- child addons init). Legacy migrations removed: the beta-exit wipe (reset
-- version 5) guarantees a clean slate for every user.
--------------------------------------------------------------------------------
local floor = math.floor
--- Round all width/height values in a table to whole pixels. Call from each child
--- addon's OnInitialize after its DB loads. keys: field names to round (e.g.
--- {"width", "height"}); tables: profile sub-tables to scan.
function EllesmereUI.RoundSizeFields(keys, tables)
for _, tbl in ipairs(tables) do
if type(tbl) == "table" then
for _, key in ipairs(keys) do
local v = tbl[key]
if type(v) == "number" then
tbl[key] = floor(v + 0.5)
end
end
end
end
end
--------------------------------------------------------------------------------
-- ONE-TIME MIGRATION RUNNER
--
-- RegisterMigration({id, scope, description, body}) runs a one-time migration
-- reliably across upgrades/characters/profiles/specs. scope picks ctx + flag
-- host: "global" -> ctx.db=EllesmereUIDB (flag on EllesmereUIDB); "profile" ->
-- ctx.profile/profileName (flag on profileData); "specProfile" ->
-- ctx.specProfile/specKey (flag on specProfData) -- all under ._migrations[id].
-- Runner walks ALL profiles/spec profiles each pass. Bodies run in pcall; flag
-- stamps only on success so a failed body retries next session. Only the
-- "early" phase exists (parent ADDON_LOADED, before child addons init).
--
-- RULES: (1) IDs are forever, never change one -- register a new id instead.
-- (2) Bodies must be idempotent (predicate-gated) even with the flag. (3)
-- Don't iterate profiles/specs inside a body, the runner does that. (4) No
-- live game APIs (UnitClass, GetSpecialization, C_CooldownViewer) -- unreliable
-- at "early" phase. (5) Walk raw ctx.profile/ctx.specProfile, never
-- child.db.profile: child addons haven't initialized.
--------------------------------------------------------------------------------
local _migrations = {} -- ordered registration list (1..N)
local _migrationsById = {} -- id -> spec, for dedup + lookup
local _migrationErrors = {} -- session-only error buffer for /eui migrations
EllesmereUI._migrationErrors = _migrationErrors
local VALID_SCOPES = { global = true, profile = true, specProfile = true }
function EllesmereUI.RegisterMigration(spec)
if type(spec) ~= "table" then
error("RegisterMigration: spec must be a table", 2)
end
if type(spec.id) ~= "string" or spec.id == "" then
error("RegisterMigration: spec.id must be a non-empty string", 2)
end
if type(spec.body) ~= "function" then
error("RegisterMigration: spec.body must be a function", 2)
end
if not VALID_SCOPES[spec.scope] then
error("RegisterMigration: spec.scope must be 'global', 'profile', or 'specProfile' (got '" .. tostring(spec.scope) .. "')", 2)
end
if _migrationsById[spec.id] then
error("RegisterMigration: duplicate migration id '" .. spec.id .. "'", 2)
end
_migrations[#_migrations + 1] = spec
_migrationsById[spec.id] = spec
end
-- Get (and lazily create) the per-scope flag table on the host table.
local function GetFlagTable(host)
if not host._migrations then host._migrations = {} end
return host._migrations
end
-- Run a single migration body, stamp the flag on success, log on error.
local function RunOne(spec, ctx, flagHost)
local flags = GetFlagTable(flagHost)
if flags[spec.id] then return end
local ok, err = pcall(spec.body, ctx)
if ok then
flags[spec.id] = true
else
_migrationErrors[#_migrationErrors + 1] = {
id = spec.id,
scope = spec.scope,
err = tostring(err),
time = GetTime(),
}
end
end
-- Iterate one migration across the appropriate set of targets for its scope.
local function RunMigration(spec)
if spec.scope == "global" then
RunOne(spec, { db = EllesmereUIDB }, EllesmereUIDB)
elseif spec.scope == "profile" then
if EllesmereUIDB.profiles then
for profName, profData in pairs(EllesmereUIDB.profiles) do
if type(profData) == "table" then
RunOne(spec, {
profile = profData,
profileName = profName,
}, profData)
end
end
end
elseif spec.scope == "specProfile" then
-- Per-profile store: spellAssignments.profiles[name].specProfiles, seeded
-- from the legacy flat store by cdm_per_profile_spell_store_v1 (registered
-- first). Flags ride on each specProfData._migrations, carried by seeding.
local sa = EllesmereUIDB.spellAssignments
local profiles = sa and sa.profiles
if profiles then
for profName, bucket in pairs(profiles) do
local sp = type(bucket) == "table" and bucket.specProfiles
if type(sp) == "table" then
for specKey, specProfData in pairs(sp) do
if type(specProfData) == "table" then
RunOne(spec, {
specProfile = specProfData,
specKey = specKey,
profileName = profName,
}, specProfData)
end
end
end
end
end
end
end
-- Public: run all migrations. Called once from the parent ADDON_LOADED handler.
function EllesmereUI.RunRegisteredMigrations()
if not EllesmereUIDB then
-- Fresh install: no SavedVariables yet. Must stamp globals now, not skip --
-- an unstamped catalog would run the whole chain at next load against
-- whatever exists by then (e.g. an imported profile), treating current-format
-- data as legacy (concretely: CDM consolidate/detach would rebuild an
-- imported spell store, pixel-rounding would floor imported positions/sizes,
-- the colors seed would replace imported palettes). Profile-scoped stamps
-- live inside each profile (and ride exports), so they need no genesis pass.
EllesmereUIDB = {}
local flags = GetFlagTable(EllesmereUIDB)
for _, spec in ipairs(_migrations) do
if spec.scope == "global" then
flags[spec.id] = true
end
end
return
end
for _, spec in ipairs(_migrations) do
RunMigration(spec)
end
end
--------------------------------------------------------------------------------
-- Registered migrations
--------------------------------------------------------------------------------
-- Hovercast macro bindings ignored their Friendly/Enemy toggles (filter applied
-- only to spell bindings). Now honored: creation defaults (hoverFriendly=true,
-- hoverEnemy=false) would silently break enemy macros, so seed both flags true
-- on existing bindings to stay unfiltered; toggles apply going forward.
EllesmereUI.RegisterMigration({
id = "clickcast_macro_hover_reaction_v1",
scope = "profile",
description = "Keep existing hovercast macro bindings unfiltered now that Friendly/Enemy applies to them",
body = function(ctx)
local rf = ctx.profile.addons and ctx.profile.addons.EllesmereUIRaidFrames
local cc = rf and rf.clickCast
if type(cc) ~= "table" then return end
local function seed(list)
if type(list) ~= "table" then return end
for _, b in ipairs(list) do
if type(b) == "table" and b.type == "macro" and b.hovercast then
b.hoverFriendly = true
b.hoverEnemy = true
end
end
end
seed(cc.globals)
if type(cc.specs) == "table" then
for _, list in pairs(cc.specs) do seed(list) end
end
end,
})
--------------------------------------------------------------------------------
-- Position snap helpers
-- Used by position_snap_v3 and exposed as EllesmereUI.SnapProfilePositions for
-- profile import. MakeSnappers reads EllesmereUIDB.ppUIScale and
-- GetPhysicalScreenSize() at CALL time (once SavedVariables + screen API are up).
--------------------------------------------------------------------------------
local function MakeSnappers()
local physH = select(2, GetPhysicalScreenSize())
local perfect = physH and physH > 0 and (768 / physH) or 1
local uiScale = EllesmereUIDB and EllesmereUIDB.ppUIScale or perfect
if uiScale <= 0 then uiScale = perfect end
local onePixel = perfect / uiScale
local function snap(v)
if type(v) ~= "number" or v == 0 then return v end
-- Epsilon-guarded round (matches PP.SnapForES): values a hair off a
-- half-pixel boundary must snap as at runtime, or frames shift 1px.
local result = floor(v / onePixel + 0.5 + 0.001) * onePixel
-- Clean floating point dust
local rounded = floor(result + 0.5)
if math.abs(result - rounded) < 0.001 then result = rounded end
return result
end
local function snapPos(tbl)
if type(tbl) ~= "table" then return end
if tbl.x then tbl.x = snap(tbl.x) end
if tbl.y then tbl.y = snap(tbl.y) end
end
local function snapPosMap(map)
if type(map) ~= "table" then return end
for _, pos in pairs(map) do snapPos(pos) end
end
local function snapAnchors(anchors)
if type(anchors) ~= "table" then return end
for _, info in pairs(anchors) do
if type(info) == "table" then
if info.offsetX then info.offsetX = snap(info.offsetX) end
if info.offsetY then info.offsetY = snap(info.offsetY) end
end
end
end
return snapPos, snapPosMap, snapAnchors, snap
end
-- Snap all positions in a single profile data table. Called per profile by the
-- position_snap_v3 migration, and once by profile import.
local function SnapProfilePositions(profData)
if type(profData) ~= "table" then return end
local snapPos, snapPosMap, snapAnchors = MakeSnappers()
local ul = profData.unlockLayout
if ul then snapAnchors(ul.anchors) end
local addons = profData.addons
if type(addons) ~= "table" then return end
local uf = addons.EllesmereUIUnitFrames
if uf then snapPosMap(uf.positions) end
local eab = addons.EllesmereUIActionBars
if eab then snapPosMap(eab.barPositions) end
local cdm = addons.EllesmereUICooldownManager
if cdm then snapPosMap(cdm.cdmBarPositions) end
local erb = addons.EllesmereUIResourceBars
if type(erb) == "table" then
for _, section in pairs(erb) do
if type(section) == "table" and section.unlockPos then
snapPos(section.unlockPos)
end
end
end
local abr = addons.EllesmereUIAuraBuffReminders
if type(abr) == "table" and abr.unlockPos then
snapPos(abr.unlockPos)
end
local cursor = addons.EllesmereUICursor
if type(cursor) == "table" then
if cursor.gcd then snapPos(cursor.gcd.pos) end
if cursor.cast then snapPos(cursor.cast.pos) end
end
end
-- Expose for profile import
EllesmereUI.SnapProfilePositions = SnapProfilePositions
-- Flattens every per-profile spec-profile table into one array. After seeding
-- (cdm_per_profile_spell_store_v1), CDM data lives at profiles[name].specProfiles,
-- not the flat legacy store -- global-scope bodies call this for LIVE data.
local function CollectSpecProfiles(sa)
local out = {}
if type(sa) ~= "table" then return out end
local profiles = sa.profiles
if type(profiles) == "table" then
for _, bucket in pairs(profiles) do
local sp = type(bucket) == "table" and bucket.specProfiles
if type(sp) == "table" then
for _, specProfData in pairs(sp) do
if type(specProfData) == "table" then
out[#out + 1] = specProfData
end
end
end
end
end
return out
end
--------------------------------------------------------------------------------
-- Registered migrations -- one-time transforms gated by the runner's per-scope
-- flag; bodies must be idempotent. Legacy flag checks bridge old inline
-- migrations and can be dropped once all users have passed through.
--------------------------------------------------------------------------------
-- Registered FIRST (precedes all specProfile migrations). Forks the legacy account-wide
-- CDM store (spellAssignments.specProfiles, shared per spec) into per-profile stores
-- (profiles[name].specProfiles), DeepCopied into every profile so copies own
-- independent CDM data (else deleting a bar in one mutates the shared bucket and wipes
-- the origin). DeepCopy keeps _migrations flags, so specProfile migrations already run
-- don't re-run. Legacy flat table stays as a dormant, unread backup -- distinct from
-- EllesmereUIDB.specProfiles (the spec-to-profile auto-switch map).
--
-- Below: Spec Overrides fresh start wipes groups/value entries/unlock overrides
-- (backend moved to whole-layout LAYERS). RB Advanced output lives there, so an
-- already-migrated profile is RE-ARMED first (restored from
-- rb.advancedSpecsBackup, flag cleared) so RB init rebuilds cards into the clean
-- store same login. Re-running MergeThresholds converges: first-run inserts are
-- spec-only and get stripped before identical re-insertion.
do
local function RearmRBAdvancedMigration(prof)
local rb = prof and prof.addons and prof.addons.EllesmereUIResourceBars
if type(rb) ~= "table" or not rb._rbAdvMigrated then return end
local backup = rb.advancedSpecsBackup
if type(backup) == "table" then
rb.advancedSpecs = backup.advancedSpecs
if type(backup.disabledSpecs) == "table" then
for secKey, ds in pairs(backup.disabledSpecs) do
if type(rb[secKey]) == "table" then
rb[secKey].disabledSpecs = ds
end
end
end
rb.advancedSpecsBackup = nil
end
rb._rbAdvMigrated = nil
end
EllesmereUI.RegisterMigration({
id = "spec_overrides_fresh_start_v1",
scope = "profile",
description = "Wipe all spec override data (groups, value entries, unlock overrides) for the layer-model fresh start.",
body = function(ctx)
local prof = ctx.profile
if not prof then return end
RearmRBAdvancedMigration(prof)
prof.specOverrideGroups = nil
prof.specOverrides = nil
prof.specUnlockOverrides = nil
end,
})
-- Recovery for profiles wiped WITHOUT the re-arm above: cards are gone but the
-- source sits in rb.advancedSpecsBackup, so re-arm once and RB's init
-- re-creates them. Guard: only re-arm when the store holds no RB-module
-- entries, since cards created AFTER the wipe (early runner precedes RB
-- init) would otherwise get duplicates.
EllesmereUI.RegisterMigration({
id = "rb_adv_remigrate_after_wipe_v1",
scope = "profile",
description = "Re-run the RB Advanced migration for profiles whose migrated spec override cards were wiped by the fresh start.",
body = function(ctx)
local prof = ctx.profile
if not prof then return end
if type(prof.specOverrides) == "table" then
for _, e in ipairs(prof.specOverrides) do
if type(e) == "table" and e.module == "EllesmereUIResourceBars" then
return
end
end
end
RearmRBAdvancedMigration(prof)
end,
})
end
-- Captures made before numeric-segment path walkers existed banked NIL sentinels
-- (reads missed numeric bars[i] keys); applying via the FIXED walkers would null
-- live CDM settings on the next spec swap. Drop every CDM-bars capture from both stores.
EllesmereUI.RegisterMigration({
id = "cdm_bars_capture_reset_v1",
scope = "profile",
description = "Drop corrupt CDM bar captures recorded by the pre-numeric-walker override builds.",
body = function(ctx)
local prof = ctx.profile
if not prof then return end
local PREFIX = "EllesmereUICooldownManager\31cdmBars\30bars\30"
local function sweep(store)
if type(store) ~= "table" then return end
for i = #store, 1, -1 do
local e = store[i]
local def = type(e) == "table" and e.values and e.values.default
if type(def) == "table" then
for fkey in pairs(def) do
if type(fkey) == "string" and fkey:sub(1, #PREFIX) == PREFIX then
table.remove(store, i)
break
end
end
end
end
end
sweep(prof.specOverrides)
sweep(prof.condOverrides)
end,
})
-- The Skyriding HUD sub-DB registers its own folder (EllesmereUIDragonRiding),
-- dodging the BlizzardSkin capture blacklist, so a width-match write could be
-- auto-captured into an unrelated entry; applying it hits a folder with no
-- targeted refresher, so the unmapped-folder fallback escalates every apply
-- into a full RefreshAllAddons (minutes of refresh under spec-change traffic).
-- Folder is now blacklisted; strip its keys from both stores (empty default map = drop whole).
EllesmereUI.RegisterMigration({
id = "specov_strip_dragonriding_fkeys_v1",
scope = "profile",
description = "Strip stowaway Dragon Riding fkeys from spec/conditional override stores (unmapped-folder RefreshAllAddons storm).",
body = function(ctx)
local prof = ctx.profile
if not prof then return end
local PREFIX = "EllesmereUIDragonRiding\31"
local function strip(store)
if type(store) ~= "table" then return end
for i = #store, 1, -1 do
local e = store[i]
local vals = type(e) == "table" and e.values
if type(vals) == "table" then
for _, m in pairs(vals) do
if type(m) == "table" then
for fkey in pairs(m) do
if type(fkey) == "string" and fkey:sub(1, #PREFIX) == PREFIX then
m[fkey] = nil
end
end
end
end
if type(vals.default) ~= "table" or next(vals.default) == nil then
table.remove(store, i)
end
end
end
end
strip(prof.specOverrides)
strip(prof.condOverrides)
end,
})
EllesmereUI.RegisterMigration({
id = "cdm_per_profile_spell_store_v1",
scope = "global",
description = "Fork the shared per-spec CDM spell store into every profile so profile copies own independent CDM data.",
body = function(ctx)
local db = ctx.db
local sa = db and db.spellAssignments
if not sa then return end -- fresh install: nothing stored yet
if sa._perProfileSeeded then return end -- already converted
local legacy = sa.specProfiles -- old account-wide per-spec store
if not sa.profiles then sa.profiles = {} end
local DeepCopy = EllesmereUI._DeepCopy or (EllesmereUI.Lite and EllesmereUI.Lite.DeepCopy)
local function seed(name)
if not name then return end
if sa.profiles[name] then return end -- idempotent: never clobber an existing bucket
local sp = {}
if legacy and DeepCopy then sp = DeepCopy(legacy) end
sa.profiles[name] = { specProfiles = sp }
end
if db.profiles then
for name, pd in pairs(db.profiles) do
if type(pd) == "table" then seed(name) end
end
end
-- Ensure the active/Default profile has a bucket even when db.profiles
-- lacks it (very early / minimal-state installs).
seed(db.activeProfile or "Default")
sa._perProfileSeeded = true
end,
})
-- Consolidates auto-seeded per-profile CDM buckets into spell LAYOUTS: collapses
-- identical duplicates into one, keeps distinct setups as their own layouts,
-- backs up originals (seeding copied one CDM setup into every profile, else
-- users would see a redundant layout each). Only auto-seeded buckets (no
-- `meta`) are touched; user-created/imported layouts are left alone.
EllesmereUI.RegisterMigration({
id = "cdm_consolidate_profile_layouts_v1",
scope = "global",
description = "Collapse identical auto-seeded per-profile CDM buckets into single spell layouts; keep distinct ones; dormant backup at spellAssignments._preConsolidateBackup.",
body = function(ctx)
local db = ctx.db
local sa = db and db.spellAssignments
if not sa or type(sa.profiles) ~= "table" then return end
local DeepCopy = EllesmereUI._DeepCopy or (EllesmereUI.Lite and EllesmereUI.Lite.DeepCopy)
-- Deep value-equality IGNORING "_"-prefixed bookkeeping keys (e.g.
-- _migrations), so copies differing only in flags count as identical.
local function ContentEqual(a, b)
if type(a) ~= type(b) then return false end
if type(a) ~= "table" then return a == b end
for k, v in pairs(a) do
if not (type(k) == "string" and k:sub(1, 1) == "_") then
if not ContentEqual(v, b[k]) then return false end
end
end
for k in pairs(b) do
if not (type(k) == "string" and k:sub(1, 1) == "_") then
if a[k] == nil then return false end
end
end
return true
end
-- Auto-seeded buckets have no `meta`; only they are consolidation candidates.
local seeded = {}
for name, bucket in pairs(sa.profiles) do
if type(bucket) == "table" and not bucket.meta then
seeded[#seeded + 1] = name
end
end
if #seeded <= 1 then return end -- nothing to collapse
-- One-time dormant backup of every bucket (safety net; recoverable).
if DeepCopy and not sa._preConsolidateBackup then
sa._preConsolidateBackup = DeepCopy(sa.profiles)
end
-- Active profile first so its name is the kept representative for the live
-- setup; the rest alphabetically for determinism.
local activeName = db.activeProfile or "Default"
table.sort(seeded)
local ordered = {}
if sa.profiles[activeName] and not sa.profiles[activeName].meta then
ordered[#ordered + 1] = activeName
end
for _, n in ipairs(seeded) do
if n ~= activeName then ordered[#ordered + 1] = n end
end
local kept = {}
local repOf = {} -- every processed seeded name -> its surviving layout
for _, name in ipairs(ordered) do
local bucket = sa.profiles[name]
local rep
for _, kn in ipairs(kept) do
if ContentEqual(sa.profiles[kn].specProfiles or {}, bucket.specProfiles or {}) then
rep = kn; break
end
end
if rep then
sa.profiles[name] = nil -- identical duplicate: drop it
repOf[name] = rep
else
kept[#kept + 1] = name
repOf[name] = name
end
end
-- Active layout is remembered PER EUI PROFILE: point each profile at the
-- surviving layout holding its own pre-consolidation CDM, so a profile
-- switch loads that setup. Never clobber a user-set pointer.
sa.activeLayoutByProfile = sa.activeLayoutByProfile or {}
if db.profiles then
for pname in pairs(db.profiles) do
if not sa.activeLayoutByProfile[pname] and repOf[pname] then
sa.activeLayoutByProfile[pname] = repOf[pname]
end
end
end
local activeRep = repOf[activeName] or kept[1] or activeName
if not sa.activeLayoutByProfile[activeName] then
sa.activeLayoutByProfile[activeName] = activeRep
end
-- Global last-active = default for any profile without a pointer yet.
if not sa.activeLayout or not sa.profiles[sa.activeLayout] then
sa.activeLayout = activeRep
end
end,
})
-- Detaches CDM spell layouts from profiles: the implicit per-profile active-layout
-- map (activeLayoutByProfile) becomes OPT-IN bindings (profileBindings) plus one
-- account-wide active layout. Behavior-identical (profiles stay bound to the
-- layout they used; user detaches by removing bindings). Runs AFTER
-- cdm_consolidate_profile_layouts_v1, inheriting deduped layouts+pointers.
EllesmereUI.RegisterMigration({
id = "cdm_detach_spell_layouts_v1",
scope = "global",
description = "Convert per-profile active CDM spell layouts (activeLayoutByProfile) into opt-in profile bindings + a single account-wide active layout. Zero behavior change.",
body = function(ctx)
local db = ctx.db
local sa = db and db.spellAssignments
if type(sa) ~= "table" then return end
local byProfile = sa.activeLayoutByProfile
sa.profileBindings = sa.profileBindings or {}
if type(byProfile) == "table" then
for prof, layout in pairs(byProfile) do
if type(prof) == "string" and type(layout) == "string"
and type(sa.profiles) == "table" and type(sa.profiles[layout]) == "table" then
-- Don't clobber a binding the user may already have set.
if sa.profileBindings[prof] == nil then
sa.profileBindings[prof] = layout
end
end
end
end
-- Account-wide active = current profile's layout, so the live CDM is
-- byte-for-byte unchanged here. Fall back to the old global pointer,
-- then any valid layout.
local cur = db.activeProfile or "Default"
local active = sa.profileBindings[cur]
if type(active) ~= "string" or not (sa.profiles and sa.profiles[active]) then
if type(sa.activeLayout) == "string" and sa.profiles and sa.profiles[sa.activeLayout] then
active = sa.activeLayout
else
active = nil
if type(sa.profiles) == "table" then
for n, v in pairs(sa.profiles) do if type(v) == "table" then active = n; break end end
end
end
end
sa.activeLayout = active
-- Retire the old per-profile resolution table (back up first, then clear).
if byProfile then
sa._preDetachBackup = byProfile
sa.activeLayoutByProfile = nil
end
end,
})
EllesmereUI.RegisterMigration({
id = "quest_tracker_blizzard_skin_rebuild_v1",
scope = "global",
description = "Archive obsolete custom-tracker keys (width/height/alignment/bg/font/color/zone/world/prey/topLine) into _legacy so they stop polluting questTracker defaults after the rebuild to a skin+QoL layer.",
body = function()
local sv = _G.EllesmereUIQuestTrackerDB
if type(sv) ~= "table" then return end
local profiles = sv.profiles
if type(profiles) ~= "table" then return end
local OBSOLETE = {
"width", "height", "alignment",
"bgR", "bgG", "bgB", "bgAlpha",
"showTopLine",
"showZoneQuests", "showWorldQuests", "showPreyQuests",
"showQuestItems", "questItemSize",
"zoneCollapsed", "worldCollapsed", "preyCollapsed",
"delveCollapsed", "questsCollapsed", "achievementsCollapsed",
"titleFontSize", "objFontSize", "completedFontSize",
"secFontSize", "focusedFontSize",
"titleColor", "objColor", "completedColor", "secColor", "focusedColor",
"secColorUseAccent",
"focusBgOpacity",
"hideBlizzardTracker",
}
for _, prof in pairs(profiles) do
if type(prof) == "table" and type(prof.questTracker) == "table" then
local qt = prof.questTracker
local legacy = qt._legacy or {}
local moved = false
for _, k in ipairs(OBSOLETE) do
if qt[k] ~= nil then
legacy[k] = qt[k]
qt[k] = nil
moved = true
end
end
if moved then qt._legacy = legacy end
end
end
end,
})
EllesmereUI.RegisterMigration({
id = "friend_notes_wipe_v1",
scope = "global",
description = "Wipe legacy bnetAccountID-keyed friendAssignments and friendNotes (sessions 15-17 rebuild).",
body = function(ctx)
-- DESTRUCTIVE (wipes global.friendAssignments + .friendNotes): the
-- _friendNotesMigrated bridge is critical, a re-run destroys data since.
if EllesmereUIDB and EllesmereUIDB.global
and EllesmereUIDB.global._friendNotesMigrated then return end
local g = ctx.db.global
if not g then return end
-- One-time popup flag only if the user actually had group assignments
-- pre-wipe, so users who never used the feature see no "reset" popup.
local hadAssignments = false
if g.friendAssignments then
for _ in pairs(g.friendAssignments) do
hadAssignments = true
break
end
end
if hadAssignments then
g._friendGroupReassignPopup = true
end
g.friendAssignments = {}
g.friendNotes = {}
end,
})
-- Pixel-perfect snapping splits global (unlock anchors, spec profiles) from
-- per-profile (positions+sizes). Per-profile half runs on every profile incl.
-- future imports; global half keeps its original flag so existing users skip it.
EllesmereUI.RegisterMigration({
id = "pixel_perfect_comprehensive_v11",
scope = "global",
description = "Snap global unlock anchors and spec-profile TBB positions/sizes to the physical pixel grid.",
body = function(ctx)
local snapPos, snapPosMap, snapAnchors, snapVal = MakeSnappers()
local function roundFields(tbl, keys)
if not tbl then return end
for _, key in ipairs(keys) do
if type(tbl[key]) == "number" then
tbl[key] = snapVal(tbl[key])
end
end
end
snapAnchors(ctx.db.unlockAnchors)
-- Spec profiles (per-profile store): TBB positions + bar sizes
for _, specData in ipairs(CollectSpecProfiles(ctx.db.spellAssignments)) do
local tbbPos = specData.tbbPositions
if tbbPos then
for _, pos in pairs(tbbPos) do
if type(pos) == "table" then snapPos(pos) end
end
end
local tbb = specData.trackedBuffBars
local tbbBars = tbb and tbb.bars
if tbbBars then
for _, bar in ipairs(tbbBars) do
if type(bar) == "table" then
roundFields(bar, { "width", "height" })
end
end
end
end
end,
})
EllesmereUI.RegisterMigration({
id = "pixel_perfect_profile_v1",
scope = "profile",
description = "Snap all per-profile positions and sizes to the physical pixel grid. Runs on each profile individually so imported profiles are covered.",
body = function(ctx)
local snapPos, snapPosMap, _, snapVal = MakeSnappers()
local function roundFields(tbl, keys)
if not tbl then return end
for _, key in ipairs(keys) do
if type(tbl[key]) == "number" then
tbl[key] = snapVal(tbl[key])
end
end
end
local function snapSection(section, sizeKeys)
if not section then return end
roundFields(section, sizeKeys)
snapPos(section.unlockPos)
end
local addons = ctx.profile.addons
if type(addons) ~= "table" then return end
local eab = addons.EllesmereUIActionBars
if eab then
snapPosMap(eab.barPositions)
if eab.bars then
for _, bs in pairs(eab.bars) do
if type(bs) == "table" then
roundFields(bs, { "buttonWidth", "buttonHeight", "width", "height" })
end
end
end
end
local erb = addons.EllesmereUIResourceBars
if erb then
local erbSizeKeys = { "width", "height", "pipWidth", "pipHeight" }
snapSection(erb.primary, erbSizeKeys)
snapSection(erb.secondary, erbSizeKeys)
snapSection(erb.health, erbSizeKeys)
snapSection(erb.castBar or erb.castbar, erbSizeKeys)
end
local uf = addons.EllesmereUIUnitFrames
if uf then
snapPosMap(uf.unlockPositions or uf.positions)
local ufSizeKeys = { "frameWidth", "healthHeight", "powerHeight",
"castbarWidth", "castbarHeight", "playerCastbarWidth", "playerCastbarHeight",
"bottomTextBarHeight" }
for _, unitKey in ipairs({ "player", "target", "focus", "boss" }) do
if uf[unitKey] then
roundFields(uf[unitKey], ufSizeKeys)
end
end
end
local cdm = addons.EllesmereUICooldownManager
if cdm then
snapPosMap(cdm.cdmBarPositions)
if cdm.cdmBars and cdm.cdmBars.bars then
for _, bd in ipairs(cdm.cdmBars.bars) do
roundFields(bd, { "iconSize", "spacing", "width", "height" })
end
end
end
local dm = addons.EllesmereUIDamageMeters
if dm then
snapPos(dm.unlockPos)
roundFields(dm, { "dmWidth", "dmHeight" })
end
local chat = addons.EllesmereUIChat
if chat then
snapPos(chat.unlockPos)
roundFields(chat, { "chatWidth", "chatHeight" })
end
local abr = addons.EllesmereUIAuraBuffReminders
if abr and abr.display then
snapPos(abr.display.unlockPos)
roundFields(abr.display, { "iconSize", "iconSpacing" })
end
end,
})
EllesmereUI.RegisterMigration({
id = "rf_targeted_spells_bool_to_mode_v1",
scope = "profile",
description = "Convert RaidFrames PARTY Targeted Spells tsEnabled boolean to tsMode (false->never, true->whenHealing; nil leaves the default). Raid is NOT migrated -- it hard-defaults to never.",
body = function(ctx)
local rf = ctx.profile.addons and ctx.profile.addons.EllesmereUIRaidFrames
if type(rf) ~= "table" then return end
-- Self-gating on the new key: idempotent, never clobbers a user choice.
if rf.tsMode == nil then
if rf.tsEnabled == false then rf.tsMode = "never"
elseif rf.tsEnabled == true then rf.tsMode = "whenHealing" end
-- tsEnabled == nil: leave unset so DeepMergeDefaults applies the default.
end
-- Raid intentionally NOT migrated: tsRaidEnabled ignored, tsRaidMode left
-- unset so DeepMergeDefaults applies the "never" default.
end,
})
EllesmereUI.RegisterMigration({
id = "nameplates_miniboss_boss_color_split_v1",
scope = "profile",
description = "Split nameplate mini-boss/boss colors: seed the new 'boss' color from the user's existing 'miniboss' color so bosses keep their current color until changed.",
body = function(ctx)
-- Self-gating on boss == nil: idempotent, never clobbers a user choice.
-- Copies only a customized miniboss; unset leaves both to default via
-- DeepMergeDefaults. Import forward-copies in ApplyProfileData.
local np = ctx.profile.addons and ctx.profile.addons.EllesmereUINameplates
if type(np) ~= "table" then return end
if np.boss == nil and type(np.miniboss) == "table" then
np.boss = { r = np.miniboss.r, g = np.miniboss.g, b = np.miniboss.b }
end
end,
})
EllesmereUI.RegisterMigration({
id = "uf_power_border_size_zero_v1",
scope = "profile",
description = "Zero out Unit Frames per-unit powerBorderSize. The detached power bar border size only became functional this build; older non-zero values were set while the control did nothing, so clear them so each UI stays visually identical. Users can re-enable a border afterward.",
body = function(ctx)
-- Self-gating: powerBorderSize of 0 (or absent) is skipped, so this runs
-- once per profile and never touches a border set after the flag stamps.
-- Scoped STRICTLY to EllesmereUIUnitFrames -- RaidFrames' own unrelated
-- powerBorderSize (border already worked) must NOT be zeroed here.
local uf = ctx.profile.addons and ctx.profile.addons.EllesmereUIUnitFrames
if type(uf) ~= "table" then return end
local UNIT_KEYS = { "player", "target", "focus", "targettarget", "focustarget", "pet", "boss" }
for _, unitKey in ipairs(UNIT_KEYS) do
local u = uf[unitKey]
if type(u) == "table" and type(u.powerBorderSize) == "number" and u.powerBorderSize ~= 0 then
u.powerBorderSize = 0
end
end
end,
})
EllesmereUI.RegisterMigration({
id = "cdm_pandemic_glow_color_table",
scope = "profile",
description = "Migrate CDM bar flat pandemicR/G/B keys into a pandemicGlowColor table, plus default pandemicGlowStyle.",
body = function(ctx)
-- No legacy flag to bridge. Idempotent by predicate: fires only when the
-- legacy flat keys exist AND pandemicGlowColor is missing.
local cdm = ctx.profile.addons and ctx.profile.addons.EllesmereUICooldownManager
local cdmBars = cdm and cdm.cdmBars
local bars = cdmBars and cdmBars.bars
if type(bars) ~= "table" then return end
for _, barData in ipairs(bars) do
if type(barData) == "table"
and barData.pandemicR
and not barData.pandemicGlowColor then
barData.pandemicGlowColor = {
r = barData.pandemicR or 1,
g = barData.pandemicG or 1,
b = barData.pandemicB or 0,
}
barData.pandemicGlowStyle = barData.pandemicGlowStyle or 1
end
end
end,
})
EllesmereUI.RegisterMigration({
id = "cdm_repair_bar_keys_v1",
scope = "profile",
description = "Repair CDM bars that lost their `key` field via Lite DB delta-strip. Assigns missing core keys (cooldowns, utility, buffs) in order.",
body = function(ctx)
-- Self-gating via `if not bd.key` -- no-op once every bar has a key. The
-- round-trip (StripDefaults -> save -> load -> DeepMergeDefaults) restores
-- identity fields in every normal path (profile switch, import); this pass
-- is purely one-time recovery for already-broken data.
local cdm = ctx.profile.addons and ctx.profile.addons.EllesmereUICooldownManager
local cdmBars = cdm and cdm.cdmBars
local bars = cdmBars and cdmBars.bars
if type(bars) ~= "table" then return end
local CORE_KEYS = { "cooldowns", "utility", "buffs" }
local CORE_NAMES = { cooldowns = "Cooldowns", utility = "Utility", buffs = "Buffs" }
local present = {}
for _, bd in ipairs(bars) do
if bd.key then present[bd.key] = true end
end
local missing = {}
for _, ck in ipairs(CORE_KEYS) do
if not present[ck] then missing[#missing + 1] = ck end
end
if #missing == 0 then return end
local mi = 1
for _, bd in ipairs(bars) do
if not bd.key and mi <= #missing then
bd.key = missing[mi]
bd.name = bd.name or CORE_NAMES[missing[mi]]
if bd.enabled == nil then bd.enabled = true end
mi = mi + 1
end
end
end,
})
EllesmereUI.RegisterMigration({
id = "cdm_remove_misc_bars",
scope = "profile",
description = "Remove obsolete CDM bars with barType=='misc' and clear anchorTo references that pointed at them.",
body = function(ctx)
-- Self-gating via the barType check: a no-op once misc bars are gone.
local cdm = ctx.profile.addons and ctx.profile.addons.EllesmereUICooldownManager
local cdmBars = cdm and cdm.cdmBars
local bars = cdmBars and cdmBars.bars
if type(bars) ~= "table" then return end
-- Pass 1: remove misc bars (reverse iteration keeps indices valid).
local miscKeys = {}
for i = #bars, 1, -1 do
if bars[i].barType == "misc" then
miscKeys[bars[i].key] = true
table.remove(bars, i)
end
end
-- Pass 2: clear anchorTo on bars that referenced a removed misc bar.
if next(miscKeys) then
for _, bd in ipairs(bars) do
if bd.anchorTo and miscKeys[bd.anchorTo] then
bd.anchorTo = "none"
end
end
end
end,
})
EllesmereUI.RegisterMigration({
id = "cdm_active_state_anim_none_to_hideactive",
scope = "profile",
description = "Rename CDM bar activeStateAnim value 'none' (No Animation) to 'hideActive' (Hide Active State).",
body = function(ctx)
-- Self-gating: no-op once no bar holds 'none'. MUST register before
-- cdm_active_state_per_bar_to_per_icon, which depends on the post-rename
-- 'hideActive' value.
local cdm = ctx.profile.addons and ctx.profile.addons.EllesmereUICooldownManager
local cdmBars = cdm and cdm.cdmBars