forked from EllesmereGaming/EllesmereUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEllesmereUI_SpecOverrides.lua
More file actions
7898 lines (7573 loc) · 358 KB
/
Copy pathEllesmereUI_SpecOverrides.lua
File metadata and controls
7898 lines (7573 loc) · 358 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
-------------------------------------------------------------------------------
-- EllesmereUI_SpecOverrides.lua
--
-- Spec Overrides ("Editing as"): per-spec-group values for individual
-- settings inside ONE profile, so users no longer need a full duplicate
-- profile per spec.
--
-- Model:
-- * SPEC GROUPS ("cards"): named icon'd sets of specs (a spec belongs to at
-- most one group). The spec button next to the module search bar opens the
-- cards popup: Yourself (default), saved groups, Add New Spec Group, and a
-- link to the management list.
-- * Selecting a card enters "Editing as <group>": the group's stored values
-- swap into the live profile (captured paths only) and the user edits the
-- suite with the REAL options widgets -- full fidelity by construction.
-- * AUTO-CAPTURE: while editing as a group, any setting the user changes is
-- captured automatically. A watcher diffs the addon profiles on a short
-- ticker; writes are attributed to the options slot under the mouse (or
-- the slot whose dropdown menu / cog popup / color picker is open).
-- Unattributed writes (bar drags, background bookkeeping) are absorbed
-- silently and never captured.
-- * Exiting (selecting Yourself, another card, logging out, switching
-- profiles/specs) harvests the live values of every captured path into
-- ALL member specs of the group, then restores the real spec's values.
-- Values apply per spec on spec change via the profile system's existing
-- handler (save-on-leave / apply-on-enter). Stored maps are the source of
-- truth; a /reload mid-edit self-heals via the login apply.
-- * GOLDEN BORDERS: slots with an active override show a 1px gold pixel
-- border on their real options rows, matched by module + element + page +
-- section + slot label.
-- * Management list ("Spec Overrides" tab under Profiles & Presets): per
-- group, each captured setting with Go To Setting / Remove buttons.
--
-- Storage (active profile root; rides export/import):
-- profile.specOverrides = { { label, slotLabel, crumb, module, page,
-- element, section, group = groupId,
-- values = { default = { [fkey]=v },
-- [specID] = { [fkey]=v } } } }
-- profile.specOverrideGroups = { { id, name, icon = {kind, key}, specs } }
-- profile.specOverrideNextId = counter
-- fkey = folder .. FS .. path; path segments joined with PS (control chars,
-- so keys containing "." can never corrupt a path). NIL_SENT marks "key not
-- present" (a setter that removes its key at the default value).
-------------------------------------------------------------------------------
local PS = "\30" -- path segment separator
local FS = "\31" -- folder/path separator inside an fkey
local NIL_SENT = "__SPECOV_NIL__"
-- Spec Overrides theme color: #c7a65a (antique gold). Used for the slot
-- borders and all accent work in the cards popup / creation popup.
local ACCENT_R, ACCENT_G, ACCENT_B = 199/255, 166/255, 90/255
local EDIT_R, EDIT_G, EDIT_B = 1, 0.72, 0.2
local GOLD_R, GOLD_G, GOLD_B = 199/255, 166/255, 90/255
local PROFILES_MODULE = "_EUIProfiles"
-- The management tab under Profiles & Presets. Both override list pages live
-- behind this ONE tab now (a segmented toggle at the top of the page picks
-- which builder renders); the page builders themselves stayed separate, so
-- every SelectPage target and "am I on the list page?" check just follows
-- this constant.
local LIST_PAGE = "Overrides"
-- Modules excluded wholesale: CDM has its own native per-spec system; the
-- rest are account/character-level UI (window skins, social, bags, chat,
-- minimap, meters, timers, tracker) where per-spec values make no sense.
-- Enforced in BOTH directions plus prune: capture (AutoCapture validate +
-- SweepUncaptured), apply (WriteSpecValues/WriteDefaultValues), and
-- PruneOrphanEntries (strips persisted paths + drops emptied entries).
local FOLDER_BLACKLIST = {
EllesmereUIBlizzardSkin = true,
-- The Skyriding HUD registers its own sub-DB (EllesmereUIDragonRidingDB)
-- from inside BlizzardSkin, so its registry folder dodges the
-- BlizzardSkin entry above. A width-match write to its width key was
-- auto-captured into a user's CDM Icon Scale override; the per-spec
-- apply then touched a folder with no REFRESH_FNS entry, and the
-- unmapped-folder fallback escalated EVERY such apply into a full
-- RefreshAllAddons -- spec-changed event traffic after combat became
-- minutes of continuous full-suite refresh (the 2026-07 post-combat
-- lag storm). Blacklisting blocks both future captures and the apply
-- of already-banked entries; a migration strips those from stores.
EllesmereUIDragonRiding = true,
EllesmereUIDamageMeters = true,
EllesmereUIMythicTimer = true,
EllesmereUIQuestTracker = true,
EllesmereUIFriends = true,
EllesmereUIBags = true,
EllesmereUIQoL = true,
EllesmereUIAuraBuffReminders = true,
-- Minimap + Chat + CooldownManager are override-eligible (2026-07-11);
-- their spell-coupled / engine-coupled settings are excluded per-path
-- via SETTING_BLACKLIST below (CDM spell data itself lives OUTSIDE the
-- profile at EllesmereUIDB.spellAssignments and was never capturable).
}
-- folder -> global apply-function names (mirrors EllesmereUI.RefreshAllAddons).
-- A touched folder with no entry falls back to a full RefreshAllAddons.
-- EVERY override-eligible folder (not in FOLDER_BLACKLIST) MUST have an
-- entry here. An unmapped folder falls back to a FULL RefreshAllAddons,
-- whose tail re-establishes the conditional overlay -- reached from inside
-- a conditional transition that made an unmapped write, that recursion is
-- what froze the game ("script ran too long") when a keybind conditional
-- overrode a Minimap setting.
local REFRESH_FNS = {
EllesmereUICooldownManager = { "_ECME_Apply" },
EllesmereUIMinimap = { "_EMM_FullRebuildMinimap" },
EllesmereUIResourceBars = { "_ERB_Apply" },
EllesmereUIActionBars = { "_EAB_Apply" },
EllesmereUIUnitFrames = { "_EUF_ReloadFrames", "_EUF_RefreshUnitNames" },
EllesmereUIRaidFrames = { "_ERF_RefreshAll" },
EllesmereUINameplates = { "_ENP_RefreshAllSettings" },
EllesmereUIQuestTracker = { "_EQT_RefreshAll" },
EllesmereUIChat = { "_ECHAT_RefreshAll" },
EllesmereUIFriends = { "_EFR_ApplyFriends" },
EllesmereUIMythicTimer = { "_EMT_Apply" },
EllesmereUIDamageMeters = { "_EDM_Apply" },
EllesmereUIDataBars = { "_EDB_Apply" },
EllesmereUIAuraBuffReminders = { "_EABR_RequestRefresh", "_EABR_ApplyUnlockPos" },
-- Folder is capture/apply-blacklisted (see FOLDER_BLACKLIST); this entry
-- is insurance so a key that slips through any future path can never hit
-- the unmapped-folder fallback and escalate into a full RefreshAllAddons.
EllesmereUIDragonRiding = { "_EDR_Rebuild" },
}
-- Class glyph sprite (toolbar button) + modern class sprite (group icons)
local GLYPH_SPRITE = "Interface\\AddOns\\EllesmereUI\\media\\icons\\class-full\\glyph.tga"
local MODERN_SPRITE = "Interface\\AddOns\\EllesmereUI\\media\\icons\\class-full\\modern.tga"
-- Generic multi-spec group icon (standalone image, not a sprite)
local MULTISPEC_ICON = "Interface\\AddOns\\EllesmereUI\\media\\icons\\class-full\\multispec.png"
local CLASS_COORDS = EllesmereUI.CLASS_ICON_SPRITE_COORDS
local CLASS_ORDER = EllesmereUI.CLASS_TOKEN_ORDER
-- Modern role icons (shipped with RaidFrames; loaded by path, no addon dep)
local ROLE_MEDIA = "Interface\\AddOns\\EllesmereUIRaidFrames\\Media\\"
local ROLE_ICONS = {
TANK = ROLE_MEDIA .. "tank-modern.png",
HEALER = ROLE_MEDIA .. "healer-modern.png",
DAMAGER = ROLE_MEDIA .. "dps-modern.png",
}
local ROLE_ORDER = { "TANK", "HEALER", "DAMAGER" }
local L = function(s) return EllesmereUI.L and EllesmereUI.L(s) or s end
-- Forward declarations
local ExitGroupEdit, EnterGroupEdit, ShowEditBanner, HideEditBanner, SetEditStatus
local _unlockRoundtrip = nil -- session to restore when the panel reopens after
-- an options-entered unlock mode roundtrip:
-- { kind = "spec"|"cond", id = groupId }
local UpdateIndicator, RequestGoldWalk, RefreshCardsPopup, SweepUncaptured
local TeardownEditSession, EnterDefaultView, ExitDefaultView
local EnsurePanelHideHook, PanelShown, ApplyEditOverlay
local _enterSnap = nil -- profiles snapshot from session start (set by the
-- editing-as enter flows; exit-sweep baseline, and
-- read by HarvestGroup for revert detection)
local _editGroup = nil -- group table ref while "editing as" is active
local _defaultView = false -- panel open in Default Editing Mode: live holds
-- the stored DEFAULT values for captured paths
-------------------------------------------------------------------------------
-- Small utilities
-------------------------------------------------------------------------------
local function DeepCopy(src)
local t = {}
for k, v in pairs(src) do
if type(v) == "table" then t[k] = DeepCopy(v) else t[k] = v end
end
return t
end
local function CurrentSpecID()
local id = EllesmereUI._specID
if not id or id == 0 then
if EllesmereUI._RefreshSpecID then EllesmereUI._RefreshSpecID() end
id = EllesmereUI._specID
end
return (id and id ~= 0) and id or nil
end
local function SpecName(specID)
local _, name, _, _, _, _, className = GetSpecializationInfoByID(specID)
if name and className then
return name .. " - " .. className:sub(1, 1):upper() .. className:sub(2):lower()
end
return name or ("Spec " .. tostring(specID))
end
-------------------------------------------------------------------------------
-- Storage
-------------------------------------------------------------------------------
local function GetProfileRoot()
return EllesmereUI.GetActiveProfileData and EllesmereUI.GetActiveProfileData()
end
local function GetStore(create)
local prof = GetProfileRoot()
if not prof then return nil end
if not prof.specOverrides and create then prof.specOverrides = {} end
return prof.specOverrides
end
local function GetGroups(create)
local prof = GetProfileRoot()
if not prof then return nil end
if not prof.specOverrideGroups and create then prof.specOverrideGroups = {} end
return prof.specOverrideGroups
end
local function NextGroupId()
local prof = GetProfileRoot()
if not prof then return 1 end
local id = (prof.specOverrideNextId or 0) + 1
prof.specOverrideNextId = id
return id
end
local function GroupById(id)
for _, g in ipairs(GetGroups() or {}) do
if g.id == id then return g end
end
return nil
end
-- True when the spec belongs to at least one spec override group.
local function SpecInAnyGroup(specID)
if not specID then return false end
for _, g in ipairs(GetGroups() or {}) do
for _, sid in ipairs(g.specs or {}) do
if sid == specID then return true end
end
end
return false
end
-- First existing group (creation order) whose member specs hold banked
-- values on the entry. Session exits bank into every non-conflicting entry,
-- so an entry created by group A can carry group B's values: when A is
-- deleted (or its id dangles), the entry is RETAGGED to a holder instead of
-- destroyed, or B's overrides and the shared default would be lost.
local function EntryHolderGroup(e)
for _, og in ipairs(GetGroups() or {}) do
for _, sid in ipairs(og.specs or {}) do
local mv = e.values and e.values[sid]
if type(mv) == "table" and next(mv) ~= nil then
return og
end
end
end
return nil
end
-- While editing group G, an entry OWNED by another group whose member specs
-- overlap G's is a CONFLICT: the other group's values own that setting for
-- the shared spec(s). Returns the first overlapping specID, or nil.
local function ConflictSpec(entry, group)
group = group or _editGroup
if not group or not entry.group or entry.group == group.id then return nil end
local og = GroupById(entry.group)
if not og then return nil end
for _, sid in ipairs(group.specs or {}) do
for _, osid in ipairs(og.specs or {}) do
if sid == osid then return sid end
end
end
return nil
end
-- A per-spec value is STRANDED on a group-owned entry when the spec is not
-- a member of the owning group and every group the spec DOES belong to is
-- conflict-locked against the owner (shares at least one spec with it). No
-- editing session can ever reach the value again: the owner's sessions only
-- bank into member specs, and the spec's own groups see the entry as a
-- conflict -- yet the value still applies at every boundary, pinning the
-- spec off the shared default with no sanctioned way to edit or remove it.
-- Specs in NO group are not stranded (the phantom self-heal owns those),
-- and legacy entries (group == nil) keep per-spec values by design.
local function SpecStrandedOnEntry(entry, specID)
if entry.group == nil then return false end
local owner = GroupById(entry.group)
if not owner then return false end
for _, sid in ipairs(owner.specs or {}) do
if sid == specID then return false end
end
local inAnyGroup = false
for _, g in ipairs(GetGroups() or {}) do
local hasSpec = false
for _, sid in ipairs(g.specs or {}) do
if sid == specID then hasSpec = true; break end
end
if hasSpec then
inAnyGroup = true
if not ConflictSpec(entry, g) then return false end
end
end
return inAnyGroup
end
-- fkey -> owning entry index (rebuilt whenever entries change)
local _fkeyIndex = nil
local function RebuildFKeyIndex()
_fkeyIndex = {}
for _, entry in ipairs(GetStore() or {}) do
for fkey in pairs(entry.values and entry.values.default or {}) do
_fkeyIndex[fkey] = entry
end
end
end
local function EntryOwning(fkey)
if not _fkeyIndex then RebuildFKeyIndex() end
return _fkeyIndex[fkey]
end
-------------------------------------------------------------------------------
-- Live profile access by fkey
-------------------------------------------------------------------------------
local function DBFor(folder)
local reg = EllesmereUI.Lite and EllesmereUI.Lite._dbRegistry
if not reg then return nil end
for _, db in ipairs(reg) do
if db.folder == folder then return db.profile end
end
return nil
end
local function SplitFKey(fkey)
return fkey:match("^([^\31]+)\31(.*)$")
end
-- True when the fkey's owning child addon registered its DB this session.
-- A DISABLED module reads nil for every one of its paths: any harvest that
-- banks those reads overwrites real stored data with deletion markers
-- (NIL_SENT) on the very next panel close, spec change, or logout. Every
-- bank must treat "module not loaded" as "unknown right now", never as
-- "value removed" -- same principle as the unlock registry rule.
local function FKeyLoaded(fkey)
local folder = SplitFKey(fkey)
return folder ~= nil and DBFor(folder) ~= nil
end
-- Single-SETTING exclusions, matched against EVERY path segment of the fkey
-- per folder (covers flat keys, nested maps, and whole subtrees).
-- Chat: the Sidebar Icons set is engine-coupled (icon buttons build at
-- login from these keys, order applies on reload).
-- CooldownManager: spell-coupled subtrees (per-spell tiers, active states)
-- plus stores owned by the unlock LAYER system (positions, grow).
local SETTING_BLACKLIST = {
EllesmereUIChat = {
showFriends = true, showDurability = true, showCopy = true,
showPortals = true, showVoice = true, showSettings = true,
showScroll = true, sidebarIconOrder = true,
},
EllesmereUICooldownManager = {
barSpellSettings = true, -- "Apply to Bar (All Specs)" per-spell tier
customActiveStates = true, -- per-spell active state rules
cdmBarPositions = true, -- unlock-layer territory
growDirection = true, -- unlock-layer territory
},
EllesmereUIRaidFrames = {
bmIndicators = true, -- buff-manager layer territory
bmSimple = true, -- buff-manager layer territory
bmDisplayMode = true, -- buff-manager layer territory
bmIconZoom = true, -- buff-manager layer territory
},
}
-- The one predicate every capture/apply/prune gate uses: folder-blacklisted
-- OR setting-blacklisted. Enforced in BOTH directions plus prune, exactly
-- like FOLDER_BLACKLIST always was.
local function BlacklistedFKey(fkey)
local folder, path = SplitFKey(fkey)
if not folder then return false end
if FOLDER_BLACKLIST[folder] then return true end
local set = SETTING_BLACKLIST[folder]
if not set or not path then return false end
for seg in path:gmatch("[^\30]+") do
if set[seg] then return true end
end
return false
end
-- Width/height-match ownership for module size keys. A size key whose
-- unlock element is a match CHILD has the match engine as its writer of
-- record: propagation persists the matched size into the module DB on
-- every target resize, unlock mode open or closed. A captured VALUE for
-- such a key is only a stale copy of whatever the match last wrote under
-- some other layer's link set -- applying or banking it fights the engine
-- (the "bar reverts to a stale width" class: a poisoned values.default
-- wins wherever the incoming spec's layer lacks the correcting link).
-- These keys are skipped at value APPLY time (WriteSpecValues /
-- WriteDefaultValues / conditional overlay) and at values.default BANK
-- time (HarvestDefaults, unlock-session SnapCommit) while a live match
-- link exists for the element -- checked against the account-global link
-- tables, which ApplyLayer keeps swapped to the active layer's set.
-- Static map, Resource Bars only for now (the reported corruption
-- family). The GCD bar's setters swap dims by orientation, so either
-- link kind owns both of its keys.
local MATCH_OWNED_FKEYS = {
["EllesmereUIResourceBars\31health\30width"] = { elem = "ERB_Health", dim = "w" },
["EllesmereUIResourceBars\31health\30height"] = { elem = "ERB_Health", dim = "h" },
["EllesmereUIResourceBars\31primary\30width"] = { elem = "ERB_Power", dim = "w" },
["EllesmereUIResourceBars\31primary\30height"] = { elem = "ERB_Power", dim = "h" },
["EllesmereUIResourceBars\31secondary\30pipWidth"] = { elem = "ERB_ClassResource", dim = "w" },
["EllesmereUIResourceBars\31secondary\30pipHeight"] = { elem = "ERB_ClassResource", dim = "h" },
["EllesmereUIResourceBars\31castBar\30width"] = { elem = "ERB_CastBar", dim = "w" },
["EllesmereUIResourceBars\31castBar\30height"] = { elem = "ERB_CastBar", dim = "h" },
["EllesmereUIResourceBars\31gcdBar\30width"] = { elem = "ERB_GCDBar", dim = "both" },
["EllesmereUIResourceBars\31gcdBar\30height"] = { elem = "ERB_GCDBar", dim = "both" },
}
local function MatchOwnedFKey(fkey)
local info = MATCH_OWNED_FKEYS[fkey]
if not info then return false end
if not EllesmereUIDB then return false end
local dim = info.dim
if dim ~= "h" then
local wm = EllesmereUIDB.unlockWidthMatch
if wm and wm[info.elem] ~= nil then return true end
end
if dim ~= "w" then
local hm = EllesmereUIDB.unlockHeightMatch
if hm and hm[info.elem] ~= nil then return true end
end
-- While a group/cond layer is LIVE, the account-global tables hold that
-- layer's links -- but a key the BASELINE matches is match-owned
-- everywhere: its recorded default is definitionally a match-written
-- artifact (banked under the baseline's link set), and applying it on a
-- spec whose layer drops the link stomps that layer's own stamped size
-- with a stale number no corrector can fix (field dump 2026-07-16:
-- baseline matched Power, group layer didn't; default 360 overwrote the
-- layer's 280). UnlockBaselineLinks returns nil when live IS baseline;
-- the live-table checks above already covered that case. Runtime
-- namespace lookup on purpose: the function is defined later in this
-- file, a direct local reference here would read nil.
if EllesmereUI.SpecOverrides_UnlockBaselineLinks then
local _, bw, bh = EllesmereUI.SpecOverrides_UnlockBaselineLinks()
if bw and dim ~= "h" and bw[info.elem] ~= nil then return true end
if bh and dim ~= "w" and bh[info.elem] ~= nil then return true end
end
return false
end
-- CDM bar-def settings live in an ARRAY (cdmBars.bars[i].*): numeric-path
-- capture is allowed for EXACTLY that subtree and nowhere else. Index
-- safety: bars only APPEND (no shift); any bar DELETION shifts later
-- indices, so the delete flow calls SpecOverrides_OnCDMBarsRestructured to
-- drop every capture in the subtree (users re-capture; honest beats
-- silently applying one bar's override onto another).
local CDM_BARS_PREFIX = "EllesmereUICooldownManager\31cdmBars\30bars\30"
local RAID_SIZE_OV_PREFIX = "EllesmereUIRaidFrames\31raidSizeOverrides\30"
local function NumAllowedFKey(fkey)
return fkey:sub(1, #CDM_BARS_PREFIX) == CDM_BARS_PREFIX
or fkey:sub(1, #RAID_SIZE_OV_PREFIX) == RAID_SIZE_OV_PREFIX
end
function EllesmereUI.SpecOverrides_OnCDMBarsRestructured()
local function sweep(store, rebuild)
if not store then return end
local removed = false
for i = #store, 1, -1 do
local e = store[i]
local hit = false
if e.values and e.values.default then
for fkey in pairs(e.values.default) do
-- CDM bars ONLY -- NumAllowedFKey also matches the
-- raid-size tier subtree (added to it later for capture
-- allowlisting), and sweeping on it here destroyed
-- users' captured raid-size overrides whenever a CDM
-- bar was deleted.
if fkey:sub(1, #CDM_BARS_PREFIX) == CDM_BARS_PREFIX then hit = true; break end
end
end
if hit then
table.remove(store, i)
removed = true
end
end
if removed and rebuild then rebuild() end
end
sweep(GetStore(), RebuildFKeyIndex)
if EllesmereUI._CondOv then
sweep(EllesmereUI._CondOv.GetStore(), EllesmereUI._CondOv.RebuildIndex)
end
RequestGoldWalk()
end
-- Fkey paths store NUMERIC table keys as strings (DiffTables builds paths
-- with tostring(k)): the CDM bars subtree is indexed cdmBars.bars[5], but
-- its fkey segment is "5". Every path walk must convert back or numeric
-- subtrees silently read nil / write string-key garbage. The stored string
-- key wins when it exists (settings tables never mix "5" and 5).
local function SegKey(t, seg)
if t[seg] ~= nil then return seg end
local n = tonumber(seg)
if n ~= nil and t[n] ~= nil then return n end
return seg
end
local function ReadLive(fkey)
local folder, path = SplitFKey(fkey)
local t = folder and DBFor(folder)
if type(t) ~= "table" then return nil end
local segs = { strsplit(PS, path) }
for i = 1, #segs - 1 do
t = t[SegKey(t, segs[i])]
if type(t) ~= "table" then return nil end
end
return t[SegKey(t, segs[#segs])]
end
--- True when the fkey's path resolves to a REGISTERED DEFAULT in the owning
--- module's defaults table (same walk as ReadLive, against _profileDefaults).
--- A stored NIL_SENT ("key removed") for such a key can never be legitimate
--- state: the Lite defaults merge guarantees the key exists live at every
--- login, so honoring the removal strips a key module code reads RAW under
--- the completeness contract -- e.g. the new-char SetFont crash, where an
--- imported store carried NIL_SENT for the resource bar text size (banked on
--- the exporter's machine by the pre-guard disabled-module harvest bug) and
--- every spec apply nilled the live key after the login merge had filled it.
--- Apply sites skip those writes; the next boundary harvest then banks live
--- (the default) over the marker, so poisoned stores self-heal.
local function HasRegisteredDefault(fkey)
local folder, path = SplitFKey(fkey)
if not folder or not path then return false end
local reg = EllesmereUI.Lite and EllesmereUI.Lite._dbRegistry
if not reg then return false end
local t
for _, db in ipairs(reg) do
if db.folder == folder then t = db._profileDefaults; break end
end
if type(t) ~= "table" then return false end
local segs = { strsplit(PS, path) }
for i = 1, #segs - 1 do
t = t[SegKey(t, segs[i])]
if type(t) ~= "table" then return false end
end
return t[SegKey(t, segs[#segs])] ~= nil
end
local function WriteLive(fkey, v)
local folder, path = SplitFKey(fkey)
local t = folder and DBFor(folder)
if type(t) ~= "table" then return false end
-- Raid-size tier overrides are the ONE allowlisted subtree whose numeric
-- segments are DICTIONARY keys (tier 10/15/25/30), not array indices:
-- absent means "not customized yet" and the RF options UI fabricates the
-- sub-tables on demand too. Everything RF-side nil-guards sparse tier
-- tables, so fabricate-and-write is safe. Without this, a captured tier
-- width/height override silently stopped applying whenever the tier's
-- sub-table was absent at apply time (tier removed after capture, or a
-- profile that never created it).
local isRaidSizeOv = fkey:sub(1, #RAID_SIZE_OV_PREFIX) == RAID_SIZE_OV_PREFIX
local segs = { strsplit(PS, path) }
for i = 1, #segs - 1 do
local k = SegKey(t, segs[i])
local nxt = t[k]
if type(nxt) ~= "table" then
if v == nil then return false end -- nothing to remove
-- NEVER fabricate a container for a purely-numeric segment: a
-- numeric path points at an ARRAY ENTRY (e.g. a CDM bar by
-- index), and if it doesn't exist the entry it referred to is
-- gone (deleted bar, different profile after an import).
-- Creating it here plants a skeleton "ghost" row -- e.g. a CDM
-- bar { barVisibility = ... } with no key -- that crashes every
-- keyed consumer downstream. Skip the write instead.
-- (Raid-size tier keys are exempt -- see isRaidSizeOv above.)
if tonumber(segs[i]) ~= nil and not isRaidSizeOv then return false end
nxt = {}
-- A fresh raidSizeOverrides ROOT must carry the offset-scheme
-- markers RF stamps at its own creation point
-- (_EnsureRaidSizeOverrides); without them the next
-- _NormalizeTierOffsetAnchors pass would "convert" (silently
-- shift) offsets that were never old-scheme.
if isRaidSizeOv and i == 1 then
nxt._topLeftAnchored = true
nxt._cornerAnchored = true
end
-- Fabricate numeric-named containers under the NUMERIC key
-- (mirrors the leaf write below): RF reads tiers numerically, so
-- a string-keyed fabrication never renders, and SegKey would
-- prefer the phantom over the real tier forever after. Only
-- raid-size tier segments can reach this (other numeric
-- segments returned false above).
local n = tonumber(k)
if type(k) == "string" and n ~= nil then k = n end
t[k] = nxt
end
t = nxt
end
local k = SegKey(t, segs[#segs])
if t[k] == nil and v ~= nil then
local n = tonumber(k)
if type(k) == "string" and n ~= nil then k = n end
end
t[k] = v
return true
end
-- Reads a value out of a profiles snapshot (pre-change originals).
local function SnapValue(snap, fkey)
local folder, path = SplitFKey(fkey)
local t = folder and snap[folder]
if type(t) ~= "table" then return nil end
local segs = { strsplit(PS, path) }
for i = 1, #segs - 1 do
t = t[SegKey(t, segs[i])]
if type(t) ~= "table" then return nil end
end
return t[SegKey(t, segs[#segs])]
end
-------------------------------------------------------------------------------
-- Targeted addon refresh (combat-deferred)
-------------------------------------------------------------------------------
local _combatFolders = nil
local function RunRefreshers(folders)
if InCombatLockdown() then
_combatFolders = _combatFolders or {}
for f in pairs(folders) do _combatFolders[f] = true end
return
end
local fallback = false
for f in pairs(folders) do
local fns = REFRESH_FNS[f]
if fns then
for _, name in ipairs(fns) do
local fn = _G[name]
if fn then pcall(fn) end
end
else
fallback = true
end
end
if fallback and EllesmereUI.RefreshAllAddons then
EllesmereUI.RefreshAllAddons()
end
end
-------------------------------------------------------------------------------
-- Harvest / Apply (save-on-leave, apply-on-enter)
-------------------------------------------------------------------------------
local _inTransition = false -- suppresses HarvestCurrent between leave & apply
local _activeSpec = nil -- spec whose values currently sit in the live db
-- (ignoring a temporary Editing-as swap)
-- Reads the live value of every captured path into a map.
local function HarvestMap()
local store = GetStore()
if not store or #store == 0 then return nil end
local maps = {}
for i, entry in ipairs(store) do
local m = {}
for fkey in pairs(entry.values.default) do
if not FKeyLoaded(fkey) then
-- Disabled child addon: keep the recorded default. The
-- harvests' equality branch then retains each spec's stored
-- value untouched instead of banking NIL_SENT over it.
m[fkey] = entry.values.default[fkey]
else
local v = ReadLive(fkey)
if v == nil then
m[fkey] = NIL_SENT
elseif type(v) == "table" then
m[fkey] = entry.values.default[fkey] -- structure changed; keep default
else
m[fkey] = v
end
end
end
maps[i] = m
end
return maps
end
-- REVERT SEMANTICS shared by the spec-side banks: a value the USER moved
-- back onto the entry's recorded default is a REVERT ("set back to default =
-- no longer an override" -- user rule) and clears instead of storing.
-- CRITICAL: bare equality is NOT proof of a revert. The default is movable
-- (Default Editing Mode edits rewrite it), and once it is edited ONTO a
-- group's value every held override compares equal; clearing on equality
-- alone dissolved those overrides one harvest at a time, and the next
-- default edit then dragged every "override" along with it. HarvestGroup
-- treats equality as a revert ONLY when the session actually changed the
-- value (live differs from the session-start snapshot); Harvest has no
-- session context and therefore NEVER clears a held key on equality -- it
-- retains the stored value.
local function Harvest(specID)
if not specID then return end
local store = GetStore()
local maps = HarvestMap()
if not maps then return end
-- Per-spec adoption is for GROUP MEMBERS only: an ungrouped spec's live
-- data always mirrors the shared defaults (panel edits go through the
-- Default view), so any diff seen here is a foreign write -- an unlock
-- layer size stamp, a leftover value from a deleted group, an
-- out-of-panel edit. Adopting it would plant a permanent, self-renewing
-- phantom override on a spec the user never assigned to any group.
-- Ungrouped specs keep whatever stored maps they already have (legacy
-- pre-group data) untouched.
if not SpecInAnyGroup(specID) then return end
for i, entry in ipairs(store) do
local m = maps[i]
local prev = entry.values[specID]
local has = false
for fkey, dv in pairs(entry.values.default) do
if MatchOwnedFKey(fkey) then
-- Match-owned size keys: live is the match engine's write,
-- never a user edit. With apply skipping these keys, live
-- permanently diverges from stored values; banking it here
-- adopted the matched width into every spec map it touched
-- (store-wide homogenization, 2026-07-16 field data).
-- Retain the stored value verbatim, like HarvestDefaults.
if prev then m[fkey] = prev[fkey] else m[fkey] = nil end
elseif m[fkey] == dv then
-- Live equals the default: never a revert outside a session
-- (the default may have moved onto the override). Retain the
-- previously stored value, if any. (No and/or chain: a stored
-- boolean false must survive retention.)
if prev then m[fkey] = prev[fkey] else m[fkey] = nil end
end
if m[fkey] ~= nil then has = true end
end
entry.values[specID] = has and m or nil
end
end
-- Garbage-collects fkeys no group map holds any value for (their harvests
-- all diff-cleared as reverts), and entries left with no fkeys. NEVER judges
-- by equality against the default here -- the default is movable (Default
-- view edits rewrite it), and equality-pruning against a moved default is
-- exactly what deleted intentional overrides ("changes on both").
local function PruneRedundantValues()
local store = GetStore()
if not store then return end
local changed = false
for i = #store, 1, -1 do
local e = store[i]
local def = e.values and e.values.default
if def then
for fkey in pairs(def) do
local held = false
for k, m in pairs(e.values) do
if k ~= "default" and type(m) == "table" and m[fkey] ~= nil then
held = true
break
end
end
if not held then
-- GC only when live actually matches the recorded
-- default: a cleared holder whose repaint has not landed
-- yet (spec-nil login window, the deferred heal apply)
-- still has the override LIVE, and dropping the default
-- here would orphan that value permanently. Blacklisted
-- paths are never applied and GC freely; an unloaded
-- module cannot be verified and is kept until it loads.
local canGC = BlacklistedFKey(fkey)
if not canGC and FKeyLoaded(fkey) then
local dv = def[fkey]
if dv == NIL_SENT then dv = nil end
local cur = ReadLive(fkey)
if type(dv) == "table" or type(cur) == "table" or cur == dv then
canGC = true
end
end
if canGC then
def[fkey] = nil
changed = true
end
end
end
if not next(def) then
table.remove(store, i)
changed = true
end
end
end
if changed then
RebuildFKeyIndex()
RequestGoldWalk()
end
end
-- Banks live values into EVERY member spec of a group. Entries owned by a
-- CONFLICTING group (shared specs) are skipped entirely -- those slots are
-- blocked in the UI and the other group's values must survive untouched.
-- Revert detection: a live value equal to the recorded default clears the
-- members' override ONLY when this session actually moved it there (live
-- differs from the session-start snapshot). A key that is untouched and
-- merely compares equal -- the default was edited onto the override's value
-- at some point -- retains each member's previously stored value instead of
-- silently dissolving it.
local function HarvestGroup(group)
if not group then return end
local store = GetStore()
local maps = HarvestMap()
if not maps then return end
for i, entry in ipairs(store) do
if not ConflictSpec(entry, group) then
local m = maps[i]
local preserve
for fkey, dv in pairs(entry.values.default) do
if MatchOwnedFKey(fkey) then
-- Match-owned size keys never bank FROM live (see
-- Harvest): the broadcast below would stamp the match
-- engine's current write onto EVERY member at once (the
-- group-wide homogenization). Route through preserve so
-- each member keeps its own stored value.
preserve = preserve or {}
preserve[fkey] = true
m[fkey] = nil
elseif m[fkey] == dv then
local s = _enterSnap and SnapValue(_enterSnap, fkey)
if type(s) == "table" then s = nil end
s = (s == nil) and NIL_SENT or s
if not _enterSnap or s == m[fkey] then
-- Untouched this session: not a revert. Each member
-- keeps its own stored value below.
preserve = preserve or {}
preserve[fkey] = true
end
m[fkey] = nil
end
end
for _, specID in ipairs(group.specs or {}) do
local prev = entry.values[specID]
local out = next(m) ~= nil and DeepCopy(m) or nil
if preserve and prev then
for fkey in pairs(preserve) do
local pv = prev[fkey]
if pv ~= nil then
out = out or {}
out[fkey] = (type(pv) == "table") and DeepCopy(pv) or pv
end
end
end
entry.values[specID] = out
end
end
end
PruneRedundantValues()
end
-- Raw writer: puts the given spec's stored values into the live profile
-- tables. Returns the set of folders whose values actually changed, or nil.
local function WriteSpecValues(specID)
local store = GetStore()
if not store or #store == 0 or not specID then return nil end
local touched = nil
for _, entry in ipairs(store) do
local m = entry.values[specID] or entry.values.default
for fkey, def in pairs(entry.values.default) do
-- Apply-side folder blacklist: entries adopted before the
-- capture-side blacklist existed can carry paths into hands-off
-- addons (Cooldown Manager runs its own per-spec system; a stale
-- write here re-injects frozen spell data and its unmapped folder
-- forces a full RefreshAllAddons mid-play). Never write them.
-- Match-owned size keys: the match engine is the writer of
-- record while a link exists; a stored value is a stale copy.
if not BlacklistedFKey(fkey) and not MatchOwnedFKey(fkey) then
local v = m[fkey]
if v == nil then v = def end
if v == NIL_SENT then v = nil end
-- Key-removal markers are honored ONLY for keys with no
-- registered default: for defaults-backed keys the marker is
-- harvest residue (see HasRegisteredDefault) and writing the
-- nil strips a key consumers read raw. Skip; live keeps the
-- merged default and the next harvest self-heals the store.
local nilPoison = (v == nil) and HasRegisteredDefault(fkey)
local cur = ReadLive(fkey)
-- Table values are never written or compared (a stored table
-- reference NEVER equals live -> phantom "write" + a full
-- module refresh on every apply).
if not nilPoison and type(v) ~= "table" and type(cur) ~= "table" and cur ~= v then
if WriteLive(fkey, v) then
local folder = SplitFKey(fkey)
if folder then
touched = touched or {}
touched[folder] = true
end
end
end
end
end
end
return touched
end
-- Group variant: seeds from the group's first member spec.
local function WriteGroupValues(group)
local seed = group and group.specs and group.specs[1]
if not seed then return nil end
return WriteSpecValues(seed)
end
-- Default variant: writes the stored DEFAULT values (what specs outside any
-- group use). Powers the panel's Default Editing Mode view.
local function WriteDefaultValues()
local store = GetStore()
if not store or #store == 0 then return nil end
local touched = nil
for _, entry in ipairs(store) do
for fkey, def in pairs(entry.values.default) do
-- Same apply-side blacklist + match-ownership skip as
-- WriteSpecValues.
if not BlacklistedFKey(fkey) and not MatchOwnedFKey(fkey) then
local v = def
if v == NIL_SENT then v = nil end
-- Same defaults-backed nil-poison skip as WriteSpecValues.
if not ((v == nil) and HasRegisteredDefault(fkey)) and ReadLive(fkey) ~= v then
if WriteLive(fkey, v) then
local folder = SplitFKey(fkey)
if folder then
touched = touched or {}
touched[folder] = true
end
end
end
end
end
end
return touched
end
-- Banks live values into the entries' DEFAULT maps (Default Editing Mode
-- edits are edits to the shared baseline).
local function HarvestDefaults()
local store = GetStore()
local maps = HarvestMap()
if not maps then return end
for i, entry in ipairs(store) do
-- Match-owned size keys never bank FROM live: live holds whatever
-- the match engine last wrote (it re-pulls and persists on every
-- target resize, including the Default view's own value writes),
-- never a user default edit. Keep the recorded default verbatim.
local m = maps[i]
local prev = entry.values.default
for fkey in pairs(m) do
if MatchOwnedFKey(fkey) then
if prev ~= nil then m[fkey] = prev[fkey] else m[fkey] = nil end
end
end
entry.values.default = m
end
PruneRedundantValues()
end
local function ApplyValuesFor(specID)
_inTransition = false
if specID then _activeSpec = specID end
-- While Editing-as (or the panel's Default view) holds swapped values
-- live, generic re-applies (e.g. a fallback RefreshAllAddons) must
-- preserve the swap.
if _editGroup then
return WriteGroupValues(_editGroup)
end
if EllesmereUI._CondOv and EllesmereUI._CondOv._edit then
-- Editing-as-conditional view: shared defaults with the session
-- group's values overlaid (forSession: the conditional's values show
-- even over spec-owned fkeys). Falling through to WriteSpecValues
-- would repaint spec values into the open session, and the exit bank
-- would then record them as the conditional's own edits.
local touched = WriteDefaultValues()
local t2 = EllesmereUI._CondOv.WriteValues(EllesmereUI._CondOv._edit.id, true)
if t2 then
touched = touched or {}
for k in pairs(t2) do touched[k] = true end
end
return touched
end
if _defaultView then
return WriteDefaultValues()
end
return WriteSpecValues(specID)
end
--- Values-only apply, called at the TOP of EllesmereUI.RefreshAllAddons so
--- every profile swap / import picks the current spec's overrides up through
--- the full refresh that follows. No refresh of its own.
function EllesmereUI.SpecOverrides_ApplyValues(specID)
ApplyValuesFor(specID or _activeSpec or CurrentSpecID())
-- Unlock layout overrides ride the same hook: stores must hold the
-- current spec's effective layout before every module refresh that
-- follows. Always keyed to the REAL spec -- editing-as swaps option
-- values, never the on-screen layout.
if EllesmereUI.SpecOverrides_ApplyUnlock then
EllesmereUI.SpecOverrides_ApplyUnlock(specID or _activeSpec or CurrentSpecID())
end
if EllesmereUI.SpecOverrides_ApplyBm then
EllesmereUI.SpecOverrides_ApplyBm(specID or _activeSpec or CurrentSpecID())
end
-- Conditional value overlay rides last (spec values always win their
-- own fkeys; the two sets are disjoint by the ownership gate).
if EllesmereUI._CondOv then EllesmereUI._CondOv.ApplyValues() end
-- Close the import window (see ImportProfile): first apply on a session
-- OTHER than the importing one -- its runtime flag died at the ReloadUI.
-- Then converge live to the imported store's layer truth exactly once:
-- the exported module blob carries whatever layer was LIVE on the
-- exporter at export time (SnapshotAllAddons copies live stores
-- verbatim), and nothing on the normal login path re-applies the
-- recipient spec's layer over it -- the import-tail ApplyLayer's flush
-- died at the ReloadUI, and the plain login apply early-outs on
-- want == s.active. Forced, the apply resolves the spec's fork, else