-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathAddon.lua
More file actions
139 lines (117 loc) · 3.75 KB
/
Addon.lua
File metadata and controls
139 lines (117 loc) · 3.75 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
--[[
Addon.lua
@Author : DengSir (tdaddon@163.com)
@Link : https://dengsir.github.io
]]
local ADDON, ns = ...
local Addon = LibStub('AceAddon-3.0'):NewAddon('tdBattlePetScript', 'AceEvent-3.0', 'LibClass-2.0')
local GUI = LibStub('tdGUI-1.0')
ns.Addon = Addon
ns.UI = {}
ns.L = LibStub('AceLocale-3.0'):GetLocale('tdBattlePetScript', true)
ns.ICON = [[Interface\Icons\INV_Misc_PenguinPet]]
_G.tdBattlePetScript = Addon
function Addon:OnInitialize()
local defaults = {
global = {
scripts = {
},
notifies = {
}
},
profile = {
pluginDisabled = {},
pluginOrders = {},
settings = {
autoSelect = true,
hideNoScript = true,
noWaitDeleteScript = false,
editorFontFace = STANDARD_TEXT_FONT,
editorFontSize = 14,
autoButtonHotKey = 'A',
testBreak = true,
lockScriptSelector = false,
},
minimap = {
minimapPos = 50,
},
position = {
point = 'CENTER', x = 0, y = 0, width = 350, height = 450,
},
scriptSelectorPosition = {
point = 'TOP', x = 0, y = -60,
}
}
}
self.db = LibStub('AceDB-3.0'):New('TD_DB_BATTLEPETSCRIPT_GLOBAL', defaults, true)
self.db.RegisterCallback(self, 'OnDatabaseShutdown')
end
function Addon:OnEnable()
self:RegisterMessage('PET_BATTLE_SCRIPT_SCRIPT_ADDED')
self:RegisterMessage('PET_BATTLE_SCRIPT_SCRIPT_REMOVED')
self:InitSettings()
self:UpdateDatabase()
end
function Addon:InitSettings()
for key, value in pairs(self.db.profile.settings) do
self:SetSetting(key, value)
end
end
function Addon:UpdateDatabase()
local oldVersion = self.db.global.version or 0
local newVersion = tonumber(GetAddOnMetadata(ADDON, 'Version')) or 99999.99
if oldVersion ~= newVersion then
self.db.global.version = newVersion
C_Timer.After(0.9, function()
GUI:Notify{
text = format('%s\n|cff00ffff%s%s|r', ADDON, ns.L['Update to version: '], newVersion),
icon = ns.ICON,
help = ''
}
end)
end
end
function Addon:OnModuleCreated(module)
local name = module:GetName()
if name:find('^UI%.') then
ns.UI[name:match('^UI%.(.+)$')] = module
else
ns[name] = module
end
end
function Addon:OnDatabaseShutdown()
self:SendMessage('PET_BATTLE_SCRIPT_DB_SHUTDOWN')
end
function Addon:PET_BATTLE_SCRIPT_SCRIPT_ADDED(_, plugin, key, script)
self.db.global.scripts[plugin:GetPluginName()][key] = script:GetDB()
end
function Addon:PET_BATTLE_SCRIPT_SCRIPT_REMOVED(_, plugin, key)
self.db.global.scripts[plugin:GetPluginName()][key] = nil
end
function Addon:GetSetting(key)
return self.db.profile.settings[key]
end
function Addon:SetSetting(key, value)
self.db.profile.settings[key] = value
self:SendMessage('PET_BATTLE_SCRIPT_SETTING_CHANGED', key, value)
self:SendMessage('PET_BATTLE_SCRIPT_SETTING_CHANGED_' .. key, value)
end
function Addon:ResetSetting(key)
if type(self.db.profile[key]) == 'table' then
wipe(self.db.profile[key])
for k, v in pairs(self.db.defaults.profile[key]) do
if type(v) == 'table' then
self.db.profile[key][k] = CopyTable(v)
else
self.db.profile[key][k] = v
end
end
else
error('not support')
end
end
function Addon:ResetFrames()
self:ResetSetting('position')
self:ResetSetting('scriptSelectorPosition')
self:SendMessage('PET_BATTLE_SCRIPT_RESET_FRAMES')
end