-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommand.lua
208 lines (190 loc) · 4.44 KB
/
Command.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
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
--$GITINFO_PREFIX$C.GitInfo
--[[
* Copyright (c) 2011-2012 by Adam Hellberg.
*
* This file is part of Command.
*
* Command is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Command is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Command. If not, see <http://www.gnu.org/licenses/>.
--]]
-- Upvalues
local type = type
local wipe = wipe
local assert = assert
--- Table containing all Command methods.
-- This is referenced "C" in Command.lua
-- @name Command
-- @class table
-- @field Name AddOn name.
-- @field Version AddOn version.
-- @field VarVersion SavedVariables version.
-- @field Enabled Enabled state.
-- @field Global Contains the saved variables.
-- @field Settings Contains settings specific to Command.
-- @field Events Contains all registered event handlers.
--
Command = {
Name = "Command",
Version = GetAddOnMetadata("Command", "Version"),
VersionNum = 9, -- Increment on every release
VersionChecked = false, -- Prevent spam of "New Version" notice
Loaded = false,
VarVersion = 3,
Global = {},
Settings = {},
Events = {},
Data = {},
GitInfo = {}
}
local C = Command
local L
local Cmd
local CM
local PM
local RM
local AC
local DM
local SM
local IM
local FM
local CDM
local CRM
local RCM
local log
-- :BEGIN: Automatic insertion of git information
--$WRITE_GITINFO$
-- :END: Automatic insertion of git information
--- Initialize Command.
--
function C:Init()
if self.Version == "@" .. "project-version" .. "@" then
self.Version = "Dev"
end
L = self.LocaleManager
Cmd = self.CommandManager
CM = self.ChatManager
PM = self.PlayerManager
RM = self.RollManager
AC = self.AddonComm
DM = self.DeathManager
SM = self.SummonManager
IM = self.InviteManager
FM = self.FactsManager
CDM = self.DuelManager
CRM = self.RoleManager
RCM = self.ReadyCheckManager
log = self.Logger
self:LoadSavedVars()
log:Normal(L("ADDON_LOAD"))
self.Loaded = true
end
--- Load the saved variables.
-- Also call Init() on modules that need it.
--
function C:LoadSavedVars()
if type(_G["COMMAND"]) ~= "table" then
_G["COMMAND"] = {}
elseif type(_G["COMMAND"]["VERSION"]) == "number" then
if _G["COMMAND"]["VERSION"] < self.VarVersion then
wipe(_G["COMMAND"])
_G["COMMAND"] = {}
end
end
self.Global = _G["COMMAND"]
if type(self.Global.SETTINGS) ~= "table" then
self.Global.SETTINGS = {}
end
self.Settings = self.Global.SETTINGS
if type(self.Settings.DEBUG) ~= "boolean" then
self.Settings.DEBUG = false
end
if type(self.Settings.ENABLED) ~= "bolean" then
self.Settings.ENABLED = true
end
L:Init()
CM:Init()
PM:Init()
RM:Init()
AC:Init()
DM:Init()
SM:Init()
IM:Init()
FM:Init()
CDM:Init()
CRM:Init()
RCM:Init()
Cmd:Init()
log:SetDebug(self.Settings.DEBUG)
self.Global.VERSION = self.VarVersion
end
--- Check AddOn version and display notice in chat if a newer is detected.
--
function C:CheckVersion(ver)
if self.VersionChecked then return end
ver = ver or 0
if ver > self.VersionNum then
log:Normal(L("NEWVERSION_NOTICE"):format(self.Name))
self.VersionChecked = true
end
end
--- Control AddOn state.
-- @param enabled Boolean indicating enabled or disabled state.
--
function C:SetEnabled(enabled)
self.Settings.ENABLED = enabled
if self.Settings.ENABLED then
return "ENABLED"
end
return "DISABLED"
end
--- Enable AddOn.
--
function C:Enable()
return self:SetEnabled(true)
end
--- Disable AddOn.
--
function C:Disable()
return self:SetEnabled(false)
end
--- Toggle AddOn on and off.
--
function C:Toggle()
return self:SetEnabled(not self.Settings.ENABLED)
end
--- Control debugging state.
-- @param enabled Boolean indicating enabled or disabled state.
--
function C:SetDebug(enabled)
self.Settings.DEBUG = enabled
log:SetDebug(enabled)
if self.Settings.DEBUG then
return "DEBUGENABLED"
end
return "DEBUGDISABLED"
end
--- Enable debugging.
--
function C:EnableDebug()
return self:SetDebug(true)
end
--- Disable debugging.
--
function C:DisableDebug()
return self:SetDebug(false)
end
--- Toggle debugging.
--
function C:ToggleDebug()
return self:SetDebug(not self.Settings.DEBUG)
end