forked from Total-RP/Total-RP-3
/
events.lua
129 lines (105 loc) · 4.53 KB
/
events.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
----------------------------------------------------------------------------------
--- Total RP 3
--- Events API
--- ---------------------------------------------------------------------------
--- Copyright 2014 Sylvain Cossement (telkostrasz@telkostrasz.be)
--- Copyright 2014-2019 Renaud "Ellypse" Parize <ellypse@totalrp3.info> @EllypseCelwe
---
--- Licensed under the Apache License, Version 2.0 (the "License");
--- you may not use this file except in compliance with the License.
--- You may obtain a copy of the License at
--
--- http://www.apache.org/licenses/LICENSE-2.0
--
--- Unless required by applicable law or agreed to in writing, software
--- distributed under the License is distributed on an "AS IS" BASIS,
--- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--- See the License for the specific language governing permissions and
--- limitations under the License.
----------------------------------------------------------------------------------
---@type TRP3_API
local _, TRP3_API = ...;
local Ellyb = Ellyb(...);
local Events = {
--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
-- Total RP 3 events
--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
-- Workflow
WORKFLOW_ON_API = "WORKFLOW_ON_API",
WORKFLOW_ON_LOAD = "WORKFLOW_ON_LOAD",
WORKFLOW_ON_LOADED = "WORKFLOW_ON_LOADED",
WORKFLOW_ON_FINISH = "WORKFLOW_ON_FINISH",
-- Broadcast
BROADCAST_CHANNEL_CONNECTING = "BROADCAST_CHANNEL_CONNECTING",
BROADCAST_CHANNEL_READY = "BROADCAST_CHANNEL_READY",
BROADCAST_CHANNEL_OFFLINE = "BROADCAST_CHANNEL_OFFLINE",
-- Navigation
NAVIGATION_TUTORIAL_REFRESH = "NAVIGATION_TUTORIAL_REFRESH",
NAVIGATION_RESIZED = "NAVIGATION_RESIZED",
-- Called when the user changes the page in the main frame. (setPage)
-- Arg1 : Page ID
-- Arg2 : Page context
PAGE_OPENED = "PAGE_OPENED",
--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
-- Data changed
--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
-- General event when a data changed in a profile of a certain unitID (character or companion)
-- Arg1 : (optional) unitID or companionFullID
-- Arg2 : profile ID
-- Arg3 : (optional) Data type : either nil or "characteristics", "about", "misc", "character", "unitID"
REGISTER_DATA_UPDATED = "REGISTER_DATA_UPDATED",
-- Called when you switch from one profile to another
-- Use to known when re-compress all of the current profile.
-- Arg1 : profile structure
REGISTER_PROFILES_LOADED = "REGISTER_PROFILES_LOADED",
-- Called when a profile is deleted (character or companion)
-- Arg1 : Profile ID
-- Arg2 : (optional, currently only for characters) A tab containing all the linked unitIDs to the profile
REGISTER_PROFILE_DELETED = "REGISTER_PROFILE_DELETED",
-- Called when as "About" page is shown.
-- This is used by the tooltip and the target bar to be refreshed
REGISTER_ABOUT_READ = "REGISTER_ABOUT_READ",
-- Called when a notifications is created/read/removed
NOTIFICATION_CHANGED = "NOTIFICATION_CHANGED",
-- Called when Wow Event UPDATE_MOUSEOVER_UNIT is fired
-- Arg1 : Target ID
-- Arg2 : Target mode (Character, pet, battle pet ...)
MOUSE_OVER_CHANGED = "MOUSE_OVER_CHANGED",
};
--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
-- EVENT HANDLING
-- Handles Total RP 3 events system
--*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
local log = TRP3_API.Ellyb.Logger("TRP3 Events");
local eventsDispatcher = TRP3_API.Ellyb.EventsDispatcher();
function Events.registerEvent()
log:Warning("DEPRECATED: Registering events is not longer required with the new events system.");
end
function Events.unregisterCallback(handlerID)
Ellyb.Assertions.isType(handlerID, "string", "handlerID");
return eventsDispatcher:UnregisterCallback(handlerID);
end
---@overload fun(event:string, handler:function)
function Events.registerCallback(event, handler, handlerID)
Ellyb.Assertions.isType(event, "string", "event");
Ellyb.Assertions.isType(handler, "function", "handler");
return eventsDispatcher:RegisterCallback(event, handler, handlerID);
end
Events.listenToEvent = Events.registerCallback;
function Events.registerCallbacks(events, handler)
Ellyb.Assertions.isType(events, "table", "events");
Ellyb.Assertions.isType(handler, "function", "handler");
local handlerID;
for _, event in pairs(events) do
handlerID = Events.registerCallback(event, handler, handlerID);
end
return handlerID;
end
Events.listenToEvents = Events.registerCallback;
function Events.triggerEvent(event, ...)
Ellyb.Assertions.isType(event, "string", "event");
eventsDispatcher:TriggerEvent(event, ...);
end
Events.fireEvent = Events.triggerEvent;
TRP3_API.Events = Events;
TRP3_API.events = Events;