-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcore.lua
More file actions
215 lines (173 loc) · 6.38 KB
/
Copy pathcore.lua
File metadata and controls
215 lines (173 loc) · 6.38 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
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
local _, ADDONSELF = ...
LightningAddress = LibStub("AceAddon-3.0"):NewAddon("LightningAddress", "AceConsole-3.0", "AceComm-3.0")
local options = {
name = "LightningAddress",
handler = LightningAddress,
type = 'group',
args = {
msg = {
type = 'input',
name = 'Lightning Address',
desc = 'Set your LightningAddress Lightning Address',
set = 'SetMyLightningAddress',
get = 'GetMyLightningAddress',
},
},
}
function LightningAddress:GetMyLightningAddress(info)
return self.db.global.lightningaddress
end
function LightningAddress:SetMyLightningAddress(info, input)
self.db.global.lightningaddress = input
end
function LightningAddress:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("LightningAddressDB")
LibStub("AceConfig-3.0"):RegisterOptionsTable("LightningAddress", options, {"la", "la2"})
LibStub("AceConfigDialog-3.0"):AddToBlizOptions("LightningAddress", "LightningAddress")
LightningAddress:Print("LightningAddressDB initialized")
LightningAddress:RegisterComm("lightningaddress")
end
local qrcode = ADDONSELF.qrcode
local BLOCK_SIZE = 5
local bdInfo = {
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileEdge = true,
tileSize = 16,
edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 },
}
local function CreateQRTip(qrsize, name)
local f = CreateFrame("Frame", name, UIParent, "BackdropTemplate")
f.backdropInfo = bdInfo
f:ApplyBackdrop()
f:SetBackdropColor(1, 1, 1, 1);
local function CreateBlock(idx)
local t = CreateFrame("Frame", nil, f)
t:SetWidth(BLOCK_SIZE)
t:SetHeight(BLOCK_SIZE)
t.texture = t:CreateTexture(nil, "OVERLAY")
t.texture:SetAllPoints(t)
local x = (idx % qrsize) * BLOCK_SIZE
local y = (math.floor(idx / qrsize)) * BLOCK_SIZE
t:SetPoint("TOPLEFT", f, 20 + x, - 20 - y);
return t
end
do
f:SetFrameStrata("BACKGROUND")
f:SetWidth(qrsize * BLOCK_SIZE + 40)
f:SetHeight(qrsize * BLOCK_SIZE + 40)
f:SetMovable(true)
f:EnableMouse(true)
f:SetPoint("CENTER", 0, 0)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", function(self) self:StartMoving() end)
f:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
end
do
local b = CreateFrame("Button", nil, f, "UIPanelCloseButton")
b:SetPoint("TOPRIGHT", f, 0, 0);
end
f.boxes = {}
f.SetBlack = function(idx)
f.boxes[idx].texture:SetColorTexture(0, 0, 0)
end
f.SetWhite = function(idx)
f.boxes[idx].texture:SetColorTexture(1, 1, 1)
end
for i = 1, qrsize * qrsize do
tinsert(f.boxes, CreateBlock(i - 1))
end
return f
end
LightningAddress:RegisterChatCommand("qrcode", "OpenQrCode")
function LightningAddress:OpenQrCode(msg)
-- Process the slash command ('input' contains whatever follows the slash command)
local ok, tab_or_message = qrcode(msg, 4)
if not ok then
print(tab_or_message)
else
local tab = tab_or_message
local size = #tab
local f = CreateQRTip(size, msg)
f:Show()
for x = 1, #tab do
for y = 1, #tab do
if tab[x][y] > 0 then
f.SetBlack((y - 1) * size + x - 1 + 1)
else
f.SetWhite((y - 1) * size + x - 1 + 1)
end
end
end
end
end
LightningAddress:RegisterChatCommand("tip", "TipTarget")
RAIDTARGET = ""
function LightningAddress:TipTarget(msg)
local target = getNameOrTarget(msg)
if target == nil then
return
end
if string.find(target, "-") ~= nil then
LightningAddress:Print("Trying to Raid tip: " .. target)
RAIDTARGET = target
LightningAddress:SendCommMessage("lightningaddress", "raidrequest@"..target, "RAID")
else
LightningAddress:Print("Trying to tip: " .. target)
LightningAddress:SendCommMessage("lightningaddress", "request", "WHISPER", target)
end
end
function getNameOrTarget(msg)
if msg ~= nil and msg ~= "" then return msg end
local name, realm = UnitName("target")
if name == nil then
LightningAddress:Print("no target selected")
return
end
local target = name
if realm ~= nil then
target = name .. "-" .. realm
end
return target
end
function LightningAddress:OnCommReceived(prefix, message, distribution, sender)
if prefix ~= "lightningaddress" then return end
if string.find(message, "raidrequest") ~= nil then
local sender = string.sub(message, 13)
RAIDSENDER = sender
local address = LightningAddress:GetMyLightningAddress(nil)
LightningAddress:SendCommMessage("lightningaddress", "raidresponse@"..lnprefix(address), "RAID")
return
elseif message == "request" then
local address = LightningAddress:GetMyLightningAddress(nil)
if address == nil then
LightningAddress:Print("No lightning address set")
return
end
LightningAddress:SendCommMessage("lightningaddress", "response"..lnprefix(address), "WHISPER", sender)
elseif string.find(message, "raidresponse") ~= nil then
if sender ~= RAIDTARGET then
return
end
RAIDTARGET = ""
local address = string.sub(message, 14)
LightningAddress:Print("Response received from " .. sender .. " Address: " .. address)
LightningAddress:OpenQrCode(address)
elseif string.find(message, "response") ~= nil then
local address = string.sub(message, 10)
LightningAddress:Print("Response received from " .. sender .. " Address: " .. address)
LightningAddress:OpenQrCode(address)
end
end
function lnprefix(address)
if string.find(address, "lightning:") ~= nil then
return address
end
return "lightning:" .. address
end
function LightningAddress:MyFunction()
self.db.char.myVal = "My character-specific saved value"
self.db.global.myOtherVal = "My global saved value"
end