forked from LetsTimeIt/DungeonTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LiveSession.lua
286 lines (262 loc) · 11.4 KB
/
LiveSession.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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
local MDT = DungeonTools
local L = MDT.L
local commsObject = MDT.commsObject
local twipe,tinsert = table.wipe,table.insert
local timer
local requestTimer
---LiveSession_Enable
function MDT:LiveSession_Enable()
if self.liveSessionActive then return end
self.main_frame.LiveSessionButton:SetText(L["*Live*"])
self.main_frame.LiveSessionButton.text:SetTextColor(0,1,0)
self.main_frame.LinkToChatButton:SetDisabled(true)
self.main_frame.LinkToChatButton.text:SetTextColor(0.5,0.5,0.5)
self.main_frame.sidePanelDeleteButton:SetDisabled(true)
self.main_frame.sidePanelDeleteButton.text:SetTextColor(0.5,0.5,0.5)
self.liveSessionActive = true
--check if there is other clients having live mode active
self:LiveSession_RequestSession()
--set id here incase there is no other sessions
self:SetUniqueID(self:GetCurrentPreset())
self.livePresetUID = self:GetCurrentPreset().uid
self:UpdatePresetDropdownTextColor()
self:SetThrottleValues()
timer = C_Timer.NewTimer(2, function()
self.liveSessionRequested = false
local distribution = self:IsPlayerInGroup()
local preset = self:GetCurrentPreset()
local prefix = "[MDTLive: "
local dungeon = self:GetDungeonName(preset.value.currentDungeonIdx)
local presetName = preset.text
local name, realm = UnitFullName("player")
local fullName = name.."+"..realm
SendChatMessage(prefix..fullName.." - "..dungeon..": "..presetName.."]",distribution)
end)
end
---LiveSession_Disable
function MDT:LiveSession_Disable()
local widget = MDT.main_frame.LiveSessionButton
widget.text:SetTextColor(widget.normalTextColor.r,widget.normalTextColor.g,widget.normalTextColor.b)
widget.text:SetText(L["Live"])
MDT.main_frame.LinkToChatButton:SetDisabled(false)
self.main_frame.LinkToChatButton.text:SetTextColor(1,0.8196,0)
local db = MDT:GetDB()
if db.presets[db.currentDungeonIdx][1] == MDT:GetCurrentPreset() then
MDT.main_frame.sidePanelDeleteButton:SetDisabled(true)
MDT.main_frame.sidePanelDeleteButton.text:SetTextColor(0.5,0.5,0.5)
else
self.main_frame.sidePanelDeleteButton:SetDisabled(false)
self.main_frame.sidePanelDeleteButton.text:SetTextColor(1,0.8196,0)
end
self.liveSessionActive = false
self.liveSessionAcceptingPreset = false
self:UpdatePresetDropdownTextColor()
self.main_frame.liveReturnButton:Hide()
self.main_frame.setLivePresetButton:Hide()
if timer then timer:Cancel() end
self.liveSessionRequested = false
self.main_frame.SendingStatusBar:Hide()
self:SetThrottleValues(true)
if self.main_frame.LoadingSpinner then
self.main_frame.LoadingSpinner:Hide()
self.main_frame.LoadingSpinner.Anim:Stop()
end
end
---Notify specific group member that my live session is active
local lastNotify
function MDT:LiveSession_NotifyEnabled()
local now = GetTime()
if not lastNotify or lastNotify < now - 0.2 then
lastNotify = now
local distribution = self:IsPlayerInGroup()
if (not distribution) or (not self.liveSessionActive) then return end
local uid = self.livePresetUID
commsObject:SendCommMessage(self.liveSessionPrefixes.enabled, uid, distribution, nil, "ALERT")
end
--self:SendToGroup(self:IsPlayerInGroup(),true,self:GetCurrentLivePreset())
end
---Send a request to the group to send notify messages for active sessions
function MDT:LiveSession_RequestSession()
local distribution = self:IsPlayerInGroup()
if (not distribution) or (not self.liveSessionActive) then return end
self.liveSessionRequested = true
self.liveSessionActiveSessions = self.liveSessionActiveSessions or {}
twipe(self.liveSessionActiveSessions)
commsObject:SendCommMessage(self.liveSessionPrefixes.request, "0", distribution, nil, "ALERT")
end
function MDT:LiveSession_SessionFound(fullName, uid)
local fullNamePlayer,realm = UnitFullName("player")
fullNamePlayer = fullNamePlayer.."-"..realm
if (not self.liveSessionAcceptingPreset) and fullNamePlayer ~= fullName then
if timer then timer:Cancel() end
self.liveSessionAcceptingPreset = true
--request the preset from one client only after a short delay
--we have to delay a bit to catch all active clients
requestTimer = C_Timer.NewTimer(0.5, function()
if self.liveSessionActiveSessions[1][1] ~= fullNamePlayer then
self.main_frame.SendingStatusBar:Show()
self.main_frame.SendingStatusBar:SetValue(0/1)
self.main_frame.SendingStatusBar.value:SetText(L["Receiving: ..."])
if not self.main_frame.LoadingSpinner then
self.main_frame.LoadingSpinner = CreateFrame("Button", "MDTLoadingSpinner", self.main_frame, "LoadingSpinnerTemplate")
self.main_frame.LoadingSpinner:SetPoint("CENTER",self.main_frame,"CENTER")
self.main_frame.LoadingSpinner:SetSize(60,60)
end
self.main_frame.LoadingSpinner:Show()
self.main_frame.LoadingSpinner.Anim:Play()
self:UpdatePresetDropdownTextColor(true)
self.liveSessionRequested = false
self:LiveSession_RequestPreset(self.liveSessionActiveSessions[1][1])
self.livePresetUID = self.liveSessionActiveSessions[1][2]
else
self.liveSessionAcceptingPreset = false
self.liveSessionRequested = false
end
end)
end
--catch clients
tinsert(self.liveSessionActiveSessions,{fullName,uid})
end
function MDT:LiveSession_RequestPreset(fullName)
local distribution = self:IsPlayerInGroup()
if (not distribution) or (not self.liveSessionActive) then return end
commsObject:SendCommMessage(self.liveSessionPrefixes.reqPre, fullName, distribution,nil, "ALERT")
end
---Sends a map ping
function MDT:LiveSession_SendPing(x, y, sublevel)
--only send ping if we are in the livesession preset
if self:GetCurrentPreset().uid == self.livePresetUID then
local distribution = self:IsPlayerInGroup()
if distribution then
local scale = self:GetScale()
commsObject:SendCommMessage(self.liveSessionPrefixes.ping, x*(1/scale)..":"..y*(1/scale)..":"..sublevel, distribution, nil, "ALERT")
end
end
end
---Sends a preset object
function MDT:LiveSession_SendObject(obj)
if self:GetCurrentPreset().uid == self.livePresetUID then
local distribution = self:IsPlayerInGroup()
if distribution then
local export = MDT:TableToString(obj,false,5)
commsObject:SendCommMessage(self.liveSessionPrefixes.obj, export, distribution, nil, "ALERT")
end
end
end
---Sends updated object offsets (move object)
function MDT:LiveSession_SendObjectOffsets(objIdx, x, y)
if self:GetCurrentPreset().uid == self.livePresetUID then
local distribution = self:IsPlayerInGroup()
if distribution then
commsObject:SendCommMessage(self.liveSessionPrefixes.objOff, objIdx..":"..x..":"..y, distribution, nil, "ALERT")
end
end
end
---Sends updated objects - instead of sending an update every time we erase a part of an object we send one message after mouse up
function MDT:LiveSession_SendUpdatedObjects(changedObjects)
if self:GetCurrentPreset().uid == self.livePresetUID then
local distribution = self:IsPlayerInGroup()
if distribution then
local export = MDT:TableToString(changedObjects,false,5)
commsObject:SendCommMessage(self.liveSessionPrefixes.objChg, export, distribution, nil, "ALERT")
end
end
end
---Sends various commands: delete all drawings, clear preset, undo, redo
function MDT:LiveSession_SendCommand(cmd)
if self:GetCurrentPreset().uid == self.livePresetUID then
local distribution = self:IsPlayerInGroup()
if distribution then
commsObject:SendCommMessage(self.liveSessionPrefixes.cmd, cmd, distribution, nil, "ALERT")
end
end
end
---Sends a note text update
function MDT:LiveSession_SendNoteCommand(cmd, noteIdx, text, y)
if self:GetCurrentPreset().uid == self.livePresetUID then
local distribution = self:IsPlayerInGroup()
if distribution then
text = text..":"..(y or "0")
commsObject:SendCommMessage(self.liveSessionPrefixes.note, cmd..":"..noteIdx..":"..text, distribution, nil, "ALERT")
end
end
end
---Sends a new preset to be used as the new live session preset
function MDT:LiveSession_SendPreset(preset)
local distribution = self:IsPlayerInGroup()
if distribution then
local db = self:GetDB()
preset.mdiEnabled = db.MDI.enabled
preset.difficulty = db.currentDifficulty
local export = MDT:TableToString(preset,false,5)
commsObject:SendCommMessage(self.liveSessionPrefixes.preset, export, distribution, nil, "ALERT")
end
end
---Sends all pulls
function MDT:LiveSession_SendPulls(pulls)
local distribution = self:IsPlayerInGroup()
if distribution then
local msg = MDT:TableToString(pulls,false,5)
commsObject:SendCommMessage(self.liveSessionPrefixes.pull, msg, distribution, nil, "ALERT")
end
end
---Sends Affix Week Change
function MDT:LiveSession_SendAffixWeek(week)
local distribution = self:IsPlayerInGroup()
if distribution then
commsObject:SendCommMessage(self.liveSessionPrefixes.week, week.."", distribution, nil, "ALERT")
end
end
---Sends freehold selector updates
function MDT:LiveSession_SendFreeholdSelector(value, week)
local distribution = self:IsPlayerInGroup()
if distribution then
value = value and "T:" or "F:"
local msg = value..week
commsObject:SendCommMessage(self.liveSessionPrefixes.free, msg, distribution, nil, "ALERT")
end
end
---sends boralus selector updates
function MDT:LiveSession_SendBoralusSelector(faction)
local distribution = self:IsPlayerInGroup()
if distribution then
local msg = faction..""
commsObject:SendCommMessage(self.liveSessionPrefixes.bora, msg, distribution, nil, "ALERT")
end
end
---Sends MDI selector updates
function MDT:LiveSession_SendMDI(action, data)
local distribution = self:IsPlayerInGroup()
if distribution then
local msg = action..":"..data
commsObject:SendCommMessage(self.liveSessionPrefixes.mdi, msg, distribution, nil, "ALERT")
end
end
do
local timer
---LiveSession_QueueColorUpdate
---Disgusting workaround for shitty colorpicker
---Only send an update once a color of a pull has not changed for 0.2 seconds
function MDT:LiveSession_QueueColorUpdate()
if timer then timer:Cancel() end
timer = C_Timer.NewTimer(0.2, function()
self:LiveSession_SendPulls(self:GetPulls())
end)
end
end
---Sends Corrupted NPC Offset Positions
function MDT:LiveSession_SendCorruptedPositions(offsets)
local distribution = self:IsPlayerInGroup()
if distribution then
local export = MDT:TableToString(offsets,false,5)
commsObject:SendCommMessage(self.liveSessionPrefixes.corrupted, export, distribution, nil, "ALERT")
end
end
---Sends current difficulty
function MDT:LiveSession_SendDifficulty()
local distribution = self:IsPlayerInGroup()
if distribution then
local export = self:GetDB().currentDifficulty
commsObject:SendCommMessage(self.liveSessionPrefixes.difficulty, export.."", distribution, nil, "ALERT")
end
end