-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.lua
50 lines (49 loc) · 1.8 KB
/
Utils.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
local addonName, vm = ...
vm.Utils = {
dump = function (o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. vm.Utils.dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end,
formatCoords = function(x, y)
return vm.Utils.round(x * 100, 2) .. " / " .. vm.Utils.round(y * 100, 2)
end,
round = function(float, digits)
local mult = 10 ^ (digits or 0)
return math.floor(float * mult + 0.5) / mult
-- return floor(float + 0.5)
end,
showTooltip = function (marker, tooltip, full)
tooltip:SetOwner(marker)
local line = full == nil and strsub(VadeMecum_Notes[marker.id].note, 1 , 20) .. "..." or VadeMecum_Notes[marker.id].note
tooltip:AddLine(line)
tooltip:SetFrameLevel(tooltip:GetParent():GetFrameLevel() + 1)
tooltip:Show()
end,
cursorMapPosition = function() -- stolen from MapCoords
local c = GetCurrentMapContinent()
if c < 1 then
return {c = 0, z = 0, x = 0, y = 0}
end
local scale = WorldMapDetailFrame:GetEffectiveScale()
local width = WorldMapDetailFrame:GetWidth()
local height = WorldMapDetailFrame:GetHeight()
local centerX, centerY = WorldMapDetailFrame:GetCenter()
local x, y = GetCursorPosition()
local adjustedX = (x / scale - (centerX - (width/2))) / width
local adjustedY = (centerY + (height/2) - y / scale) / height
local z = GetCurrentMapZone()
if z == 0 then
ProcessMapClick(adjustedX, adjustedY)
z = GetCurrentMapZone()
end
return {c = c, z = z, x = adjustedX, y = adjustedY}
end
}