-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatatexts.lua
More file actions
157 lines (125 loc) · 3.89 KB
/
Datatexts.lua
File metadata and controls
157 lines (125 loc) · 3.89 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
local app = select(2, ...);
local L = app.L;
--[[
--
-- General Utility stuff
--
--]]
app.print = function(self, msg, ...)
self:_print("", msg, ...);
end
app.log = function(self, msg, ...)
if self.Settings:Get("Debug", "Enabled") then
self:_print("DEBUG ", msg, ...);
end
end
app._print = function(self, prefix, msg, ...)
local args = {...};
local lines = { strsplit("\n", type(msg) == "string" and msg or tostring(msg)) };
for _,line in ipairs(lines) do
print(string.format("%s[%s]: %s", prefix, L["TITLE"], line));
end
if args and #args > 0 then
self:_print(prefix, unpack(args));
end
end
app.stringify = function(t)
if type(t) == "table" then
local text = "{ ";
local first = true;
for k,v in pairs(t) do
if not first then
text = text .. ", ";
end
first = false;
text = text .. string.format("[%s] = %s", app.stringify(k), app.stringify(v));
end
text = text .. " }";
return text;
elseif type(t) == "boolean" then
return t and "true" or "false"
elseif type(t) == "number" then
return "" .. t;
elseif type(t) == "string" then
return app.stringEscape(t);
elseif type(t) == "function" then
if debug then
local info = debug.getinfo(t, "S");
if info.what == "Lua" then
local where, _ = info.source:gsub("(@)(.*" .. app:GetName() .. ")(.*)", "%1%3");
return string.format("<function%s:%s>", where, info.linedefined);
else
return "<C function:?>";
end
else
return "<function>";
end
elseif type(t) == "nil" then
return "nil";
end
end
app.Windows = {};
app.RegisterWindow = function(self, suffix, window)
self.Windows[suffix] = window;
end
app.CreateWindow = function(self, suffix, parent)
local WindowCreator = {
["WorldQuestTracker"] = app.WorldQuestTracker.CreateWorldQuestTrackerFrame;
};
if WindowCreator[suffix] then
return WindowCreator[suffix](suffix, parent or UIParent);
else
return nil;
end
end
app.GetWindow = function(self, suffix, parent)
local window = self.Windows[suffix];
if not window then
window = self:CreateWindow(suffix, parent);
self.Windows[suffix] = window;
end
return window;
end
app.stringEscape = function(str)
return string.gsub(string.format("%q", str), "\n", "n");
end
app.colorString = function(str)
return GetClassColoredTextForUnit("player", str)
end
app.UpdateFramePosition = function(self)
local settings = app.Settings:Get("General");
app.Frame:ClearAllPoints()
app.Frame:SetPoint(settings.anchor, UIParent, settings.anchor, settings.offsetX, -settings.offsetY);
end
app:RegisterEvent("ADDON_LOADED", "Datatexts", function(addon)
if addon ~= app:GetName() then
return;
end
app.Frame = CreateFrame("Frame", "Datatexts-Frame", UIParent);
app.Frame:SetSize(250, 60);
app.Frame:Show();
app.Version = C_AddOns.GetAddOnMetadata(app:GetName(), "Version");
app.Settings:Initialize();
app:UpdateFramePosition();
app.Time.Initialize();
app.SystemStats.Initialize();
app.Durability.Initialize();
app.LootSpec.Initialize();
app.WarMode.Initialize();
app.Combat.Initialize();
app:UnregisterEvent("ADDON_LOADED", "Datatexts");
end);
app.lastTimeUpdate = -1;
app.lastSystemStatUpdate = -1;
local UPDATE_THRESHOLD = 10;
app:RegisterUpdate("Datatexts", function()
local time = GetTime();
if time - app.lastTimeUpdate > UPDATE_THRESHOLD then
app.lastTimeUpdate = time;
app.Time.OnUpdate();
end
if time - app.lastSystemStatUpdate > app.Settings:Get("SystemStats", "fpsRefresh") then
app.lastSystemStatUpdate = time;
app.SystemStats.OnUpdate();
end
end)