-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.lua
More file actions
176 lines (162 loc) · 7.04 KB
/
Copy pathConfig.lua
File metadata and controls
176 lines (162 loc) · 7.04 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
local addonName, L = ...
local LootG = L
local AceDB = LibStub and LibStub("AceDB-3.0", true)
-- ==========================================================================
-- Defaults
-- ==========================================================================
-- Font values are LibSharedMedia names, resolved to paths at draw time via
-- LSM:Fetch("font", cfg.font). enterCombatText / leaveCombatText default to
-- the empty string so that GetEnterCombatText / GetLeaveCombatText in
-- LootG.lua fall back to L["ENTER_COMBAT"] / L["LEAVE_COMBAT"] each call,
-- respecting the current client locale rather than snapshotting one.
LootG.Defaults = {
profile = {
loot = {
enabled = true,
locked = true,
showIcon = true,
anchorX = 0,
anchorY = 250,
scrollDirection = "UP",
displayTime = 1.5,
scrollSpeed = 1,
fadeTime = 0.1,
fontSize = 14,
fontShadow = true,
fontOutline = "OUTLINE",
font = "Friz Quadrata TT",
},
combatState = {
enabled = true,
locked = true,
posX = 0,
posY = 250,
displayMode = "SCROLL",
scrollDirection = "UP",
displayTime = 1,
fadeTime = 0.1,
scrollSpeed = 1.5,
fontSize = 38,
fontShadow = true,
fontOutline = "OUTLINE",
font = "Friz Quadrata TT",
enterCombatText = "",
leaveCombatText = "",
},
},
global = {
minimap = { hide = false },
},
}
-- ==========================================================================
-- Legacy font path → LSM name
-- ==========================================================================
LootG.LEGACY_FONT_MAP = {
["Fonts\\FRIZQT__.TTF"] = "Friz Quadrata TT",
["Fonts\\ARIALN.TTF"] = "Arial Narrow",
["Fonts\\skurri.ttf"] = "Skurri",
["Fonts\\MORPHEUS.TTF"] = "Morpheus",
}
-- Any of these values in enterCombatText / leaveCombatText indicates the
-- user never customized it — the value was seeded from L at Config.lua load
-- time under the old scheme. We zero those out during migration so the new
-- dynamic-localization fallback path kicks in.
local LEGACY_ENTER_DEFAULTS = {
["Enter Combat"] = true,
["进入战斗"] = true,
["進入戰鬥"] = true,
}
local LEGACY_LEAVE_DEFAULTS = {
["Leave Combat"] = true,
["脱离战斗"] = true,
["脫離戰鬥"] = true,
}
-- ==========================================================================
-- Migration: legacy LootGDB (flat + combatState subtable) → new AceDB shape
-- ==========================================================================
local FLAT_LOOT_KEYS = {
"enabled", "locked", "showIcon", "anchorX", "anchorY",
"scrollDirection", "displayTime", "scrollTime", "fadeSpeed",
"fontSize", "fontShadow", "fontOutline",
}
-- ==========================================================================
-- Shape migration: 旧版 loot 动画参数 → 与 combatState 统一的语义
-- ==========================================================================
-- 旧版 scrollTime 是"滚动 100px 所需秒数"(越大越慢),fadeSpeed 名为速度
-- 实为秒数。统一为 scrollSpeed(100px/s 的倍率,越大越快)与 fadeTime(秒),
-- 换算 scrollSpeed = 1/scrollTime,按滑块步长取整并夹到滑块范围内。
-- 对已存在的 LootGAceDB profile 同样需要执行(每个 profile 切换时各跑一次)。
function LootG._MigrateLootShape(loot)
if type(loot) ~= "table" then return end
if type(loot.scrollTime) == "number" and loot.scrollTime > 0 then
local speed = math.floor(1 / loot.scrollTime * 10 + 0.5) / 10
loot.scrollSpeed = math.min(5, math.max(0.1, speed))
end
loot.scrollTime = nil
if type(loot.fadeSpeed) == "number" then
-- 旧值可能为 0(瞬间消失),夹到渐隐滑块范围 [0.1, 3] 避免动画循环除零
loot.fadeTime = math.min(3, math.max(0.1, loot.fadeSpeed))
end
loot.fadeSpeed = nil
end
function LootG._MigrateLegacyDB(db, legacy)
if db.global._migrated then return db end
if type(legacy) == "table" then
for _, key in ipairs(FLAT_LOOT_KEYS) do
if legacy[key] ~= nil then
db.profile.loot[key] = legacy[key]
end
end
if type(legacy.fontPath) == "string" then
local mapped = LootG.LEGACY_FONT_MAP[legacy.fontPath]
if mapped then db.profile.loot.font = mapped end
end
if type(legacy.combatState) == "table" then
for k, v in pairs(legacy.combatState) do
if k == "fontPath" then
local mapped = LootG.LEGACY_FONT_MAP[v]
if mapped then db.profile.combatState.font = mapped end
elseif k == "enterCombatText" then
if type(v) == "string" and not LEGACY_ENTER_DEFAULTS[v] then
db.profile.combatState.enterCombatText = v
end
elseif k == "leaveCombatText" then
if type(v) == "string" and not LEGACY_LEAVE_DEFAULTS[v] then
db.profile.combatState.leaveCombatText = v
end
else
db.profile.combatState[k] = v
end
end
end
end
db.global._migrated = true
return db
end
-- ==========================================================================
-- InitializeConfig: create AceDB, run one-shot migration.
-- Called from LootG.lua's ADDON_LOADED handler after all addon files load.
-- ==========================================================================
function LootG:InitializeConfig()
if not AceDB then
error("LootG: AceDB-3.0 not loaded — check Libs load order in LootG.toc")
end
-- AceDB:New creates the SavedVariable if missing and merges profile with
-- Defaults.profile lazily on access.
LootG.db = AceDB:New("LootGAceDB", LootG.Defaults, true)
-- 切换/复制/重置 profile 后:目标 profile 可能还是旧参数形态,先做
-- shape 迁移,再把新配置应用到屏幕上的锚点框架
LootG.db.RegisterCallback(LootG, "OnProfileChanged", "HandleProfileChanged")
LootG.db.RegisterCallback(LootG, "OnProfileCopied", "HandleProfileChanged")
LootG.db.RegisterCallback(LootG, "OnProfileReset", "HandleProfileChanged")
LootG._MigrateLegacyDB(LootG.db, _G.LootGDB)
LootG._MigrateLootShape(LootG.db.profile.loot)
if _G.LootGDB then
-- 置 nil 后 WoW 在登出时不再写出该 SavedVariable,等效于删除旧存档
_G.LootGDB = nil
end
end
function LootG:HandleProfileChanged()
LootG._MigrateLootShape(LootG.db.profile.loot)
if LootG.RefreshAll then LootG:RefreshAll() end
end