Skip to content

Commit 9bedced

Browse files
committed
Simplify deserialization logic
1 parent a318db5 commit 9bedced

File tree

4 files changed

+28
-34
lines changed

4 files changed

+28
-34
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The format of this changelog is based on [Keep a Changelog](https://keepachangel
2020
* Make key options respect macro condtions where able [#251]
2121
* Add option to automatically fall back to action bar abilities when no other macro conditions are met [#257]
2222
* Automatically populate macro when converting from a spell, item, or cancelaura binding [#264] (by [Gateswong])
23+
* Keep the binding configuration window open when importing a profile [#252] (by [m33shoq])
2324

2425
### Fixed
2526

@@ -29,6 +30,7 @@ The format of this changelog is based on [Keep a Changelog](https://keepachangel
2930
* Fix bindings sometimes not updating after changing their group [#263]
3031
* Fix automatic sorting of macros using the form, bonusbar, or bar macro options
3132
* Fix deleted bindings not being deactivated immediately
33+
* Fix a potential data conflict issue when importing a profile [#252] (by [m33shoq])
3234

3335
## [1.16.11] - 2024-11-07
3436

@@ -1739,6 +1741,7 @@ The format of this changelog is based on [Keep a Changelog](https://keepachangel
17391741
[#264]: https://github.com/Snakybo/Clicked/pull/264
17401742
[#263]: https://github.com/Snakybo/Clicked/issues/263
17411743
[#257]: https://github.com/Snakybo/Clicked/issues/257
1744+
[#252]: https://github.com/Snakybo/Clicked/pull/252
17421745
[#251]: https://github.com/Snakybo/Clicked/issues/251
17431746
[#248]: https://github.com/Snakybo/Clicked/issues/248
17441747
[#247]: https://github.com/Snakybo/Clicked/issues/247

Clicked/BindingConfig/Pages/ImportString.lua

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,22 @@ function Addon.BindingConfig.ImportStringPage:RedrawToReview()
217217
end
218218
end
219219

220+
local type = review.type
220221
Clicked:Import(review)
221-
if review.type == "group" then
222+
223+
if type == "group" then
222224
Addon.BindingConfig.Window:Select(review.group.uid)
223-
elseif review.type == "binding" then
225+
elseif type == "binding" then
224226
Addon.BindingConfig.Window:Select(review.binding.uid)
225-
else
226-
self.controller:PopPage(self)
227-
if not Addon.BindingConfig.Window:IsOpen() then
228-
Addon.BindingConfig.Window:Open()
229-
end
230-
if type(review.groups) == "table" and review.groups[1] then
227+
elseif type == "profile" then
228+
if #review.groups > 0 then
229+
Addon.BindingConfig.Window:SetPage(Addon.BindingConfig.Window.PAGE_GROUP)
231230
Addon.BindingConfig.Window:Select(review.groups[1].uid)
232-
elseif type(review.bindings) == "table" and review.binding[1] then
231+
elseif #review.bindings > 0 then
232+
Addon.BindingConfig.Window:SetPage(Addon.BindingConfig.Window.PAGE_BINDING)
233233
Addon.BindingConfig.Window:Select(review.bindings[1].uid)
234+
else
235+
Addon.BindingConfig.Window:SetPage(Addon.BindingConfig.Window.PAGE_NEW)
234236
end
235237
end
236238
end)

Clicked/Core/Serializer.lua

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ local function RegisterBinding(data)
6262
if data.type ~= "binding" then
6363
error("bad argument #1, expected binding but got " .. data.type)
6464
end
65+
6566
data.binding.uid = nil
6667
Addon:RegisterDataObject(data.binding, Clicked.DataObjectScope.PROFILE)
6768
Addon:ReloadBinding(data.binding, true)
@@ -76,32 +77,24 @@ local function RegisterProfile(data)
7677
data.lightweight = nil
7778
data.type = nil
7879

79-
for key in pairs(data) do
80-
Addon.db.profile[key] = data[key]
81-
end
82-
83-
-- ensure UIDs are unique
84-
if data.groups then
85-
for _, group in pairs(data.groups) do
86-
local oldUID = group.uid
87-
group.uid = Addon:GetNextUid()
80+
--- @type table<integer, integer>
81+
local groupUidMap = {}
8882

89-
if oldUID then
90-
for _, binding in pairs(data.bindings) do
91-
if binding.parent == oldUID then
92-
binding.parent = group.uid
93-
end
94-
end
95-
end
96-
end
83+
-- Assign new UIDs to all imported groups and bindings
84+
for _, group in ipairs(data.groups) do
85+
local uid = Addon:GetNextUid()
86+
groupUidMap[group.uid] = uid
87+
group.uid = uid
9788
end
9889

99-
if data.bindings then
100-
for _, binding in pairs(data.bindings) do
101-
binding.uid = Addon:GetNextUid()
102-
end
90+
for _, binding in ipairs(data.bindings) do
91+
binding.uid = Addon:GetNextUid()
92+
binding.parent = groupUidMap[binding.parent]
10393
end
10494

95+
for key in pairs(data) do
96+
Addon.db.profile[key] = data[key]
97+
end
10598

10699
Clicked:ReloadDatabase()
107100
end
@@ -174,8 +167,6 @@ function Clicked:SerializeProfile(profile, printable, full)
174167
version = profile.version,
175168
bindings = CopyTable(profile.bindings),
176169
groups = CopyTable(profile.groups),
177-
nextGroupId = profile.nextGroupId,
178-
nextBindingId = profile.nextBindingId,
179170
type = "profile",
180171
lightweight = true
181172
}

Clicked/Definitions.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
--- @field public groups Group[]
3030
--- @field public bindings Binding[]
3131
--- @field public blacklist table<string,boolean>
32-
--- @field public nextGroupId integer
33-
--- @field public nextBindingId integer
3432

3533
--- @class Profile.Options
3634
--- @field public onKeyDown boolean

0 commit comments

Comments
 (0)