-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRave.lua
160 lines (125 loc) · 4.14 KB
/
Rave.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
----------------------------------------------------------
-- Rave - a chat addon
--
-- @author Pawkette ( [email protected] )
----------------------------------------------------------
local kAddonName, kVersion = 'Rave', 1.0
local Rave = Rave
local Constants = Rave.Constants
local tinsert = table.insert
local tremove = table.remove
local ZO_SavedVars = ZO_SavedVars
local CBM = CALLBACK_MANAGER
local LINK_HANDLER = LINK_HANDLER
function Rave:Initialize( control )
self.Window:Initialize( control )
self.Edit:Initialize( control:GetNamedChild( 'Edit' ) )
self:RegisterEvent( EVENT_ADD_ON_LOADED, function( ... ) self:HandleAddonLoaded( ... ) end )
self:RegisterEvent( EVENT_CHAT_MESSAGE_CHANNEL, function( ... ) self:HandleChatMessage( ... ) end )
self:RegisterEvent( EVENT_CHAT_CHANNEL_JOIN, function( ... ) self:HandleChatChannelJoin( ... ) end )
self:RegisterEvent( EVENT_CHAT_CHANNEL_LEAVE, function( ... ) self:HandleChatChannelLeave( ... ) end )
end
function Rave:HandleAddonLoaded( addon )
if ( addon ~= kAddonName ) then
return
end
self.db = ZO_SavedVars:NewAccountWide( 'RAVE_DB', kVersion, nil, nil )
ZO_CreateStringId("SI_BINDING_NAME_RAVE_GUILD1", "Guild 1")
ZO_CreateStringId("SI_BINDING_NAME_RAVE_GUILD2", "Guild 2")
ZO_CreateStringId("SI_BINDING_NAME_RAVE_GUILD3", "Guild 3")
ZO_CreateStringId("SI_BINDING_NAME_RAVE_GUILD4", "Guild 4")
ZO_CreateStringId("SI_BINDING_NAME_RAVE_GUILD5", "Guild 5")
CBM:FireCallbacks( Constants.Callbacks.Loaded )
end
function Rave:OnUpdate( frameTime )
if ( not #self.Modules ) then
return
end
local modules = self.Modules
for i=1,#modules do
modules[ i ]:OnUpdate( frameTime )
end
end
function Rave:RegisterModule( moduleId, module, version )
if ( self.Modules[ moduleId ] and self.Modules[ moduleId ].__version > version ) then
return
end
print( 'Rave module registered %s', tostring( moduleId ) )
self.Modules[ moduleId ] = module:New( moduleId, version )
end
function Rave:GetModule( moduleId )
if ( not self.Modules[ moduleId ] ) then
return nil
end
return self.Modules[ moduleId ]
end
function Rave:RegisterEvent( event, callback )
if ( not self.EventRegistry[ event ] ) then
self.EventRegistry[ event ] = {}
end
tinsert( self.EventRegistry[ event ], callback )
self.Window:RegisterEvent( event, function( ... ) self:HandleEvent( ... ) end )
end
function Rave:UnregisterEvent( event, callback )
if ( not self.EventRegistry[ event ] ) then
return
end
local listeners = self.EventRegistry[ event ]
for i=#listeners,1,-1 do
if ( listeners[ i ] == callback ) then
tremove( listeners, i )
break
end
end
if ( #listeners == 0 ) then
self.EventRegistry[ event ] = nil
end
end
function Rave:HandleEvent( event, ... )
if ( not self.EventRegistry[ event ] ) then
return
end
local listeners = self.EventRegistry[ event ]
for i=1,#listeners do
listeners[ i ]( ... )
end
end
function Rave:GetModuleSettings( moduleId )
if ( not self.db[ moduleId ] ) then
self.db[ moduleId ] = {}
end
return self.db[ moduleId ]
end
function Rave:SetModuleSettings( moduleId, settings )
self.db[ moduleId ] = settings
end
function Rave:RegisterKey( keyId, callback )
if ( self.KeyRegistry[ keyId ] ) then
print( 'This key is already registered, sorry.' )
return
end
self.KeyRegistry[ keyId ] = callback
end
function Rave:UnregisterKey( keyId, callback )
if ( not self.KeyRegistry[ keyId ] ) then
return
end
self.KeyRegistry[ keyId ] = nil
end
function Rave:KeyUp( keyId )
if ( not self.KeyRegistry[ keyId ] ) then
return
end
self.KeyRegistry[ keyId ]()
end
function Rave:HandleChatMessage( messageType, from, text )
end
function Rave:HandleChatChannelJoin( ... )
-- body
end
function Rave:HandleChatChannelLeave( ... )
-- body
end
function Rave:StartChatInput( text, channel, target )
-- body
end