This repository has been archived by the owner on Jan 21, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathNeuron-Startup.lua
82 lines (71 loc) · 2.8 KB
/
Neuron-Startup.lua
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
-- Neuron is a World of Warcraft® user interface addon.
-- Copyright (c) 2017-2023 Britt W. Yazel
-- Copyright (c) 2006-2014 Connor H. Chenoweth
-- This code is licensed under the MIT license (see LICENSE for details)
local _, addonTable = ...
local Neuron = addonTable.Neuron
local L = LibStub("AceLocale-3.0"):GetLocale("Neuron")
local Array = addonTable.utilities.Array
-- this function takes a partial bar config and fills out the missing fields
-- from the database default skeleton to create a complete bar database entry
local function initializeBar(barClass)
return function (bar)
-- MergeTable modifies in place, so copy the default first
local newBar = CopyTable(addonTable.databaseDefaults.profile[barClass]['*'])
-- use the skeleton button from the default database to generate buttons
local newButtons = Array.map(
function(button)
local newButton = CopyTable(newBar.buttons['*'])
local newConfig = CopyTable(newButton.config)
MergeTable(newConfig, button.config or {})
MergeTable(newButton, button)
MergeTable(newButton, {config = newConfig})
return newButton
end,
bar.buttons
)
-- merge the bar config and then the buttons into the skeleton
MergeTable(newBar, bar)
MergeTable(newBar, {buttons=newButtons})
return newBar
end
end
--- this function has no business existing
--- database defaults should be in the database
--- but we have them scattered between neuron-defaults and neuron-db-defaults
function Neuron:InitializeEmptyDatabase(DB)
DB.firstRun = false
--initialize default bars using the skeleton data in defaultProfile
--and pulling from registeredBarData so we create the correct bars for classic/retail
for barClass, registeredData in pairs(Neuron.registeredBarData) do
local newBars = Array.map(
initializeBar(barClass),
addonTable.defaultProfile[barClass]
)
MergeTable(registeredData.barDB, newBars)
end
end
function Neuron:CreateBarsAndButtons(profileData)
-- remove blizzard controlled bars from the list of bars we will create
-- but still keep neuron action bars regardless
local neuronBars =
Array.filter(
function (barPair)
local bar, _ = unpack(barPair)
return not profileData.blizzBars[bar] or bar == "ActionBar"
end,
Array.fromIterator(pairs(Neuron.registeredBarData)))
-- make the frames for the bars now
for _, barData in pairs (neuronBars) do
local barClass, barClassData = unpack(barData)
for id,data in pairs(barClassData.barDB) do
if data ~= nil then
local newBar = Neuron.Bar.new(barClass, id) --this calls the bar constructor
--create all the saved button objects for a given bar
for buttonID=1,#newBar.data.buttons do
newBar.objTemplate.new(newBar, buttonID) --newBar.objTemplate is something like ActionButton or ExtraButton, we just need to code it agnostic
end
end
end
end
end