-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDeveloperSuiteConsole.lua
More file actions
162 lines (131 loc) · 4.46 KB
/
DeveloperSuiteConsole.lua
File metadata and controls
162 lines (131 loc) · 4.46 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
-- Developer Suite
-- The MIT License © Arthur Corenzan
local NAMESPACE = "DeveloperSuite"
--
--
--
local function dump(target, indent, tableHistory)
output = ""
indent = indent or ""
tableHistory = tableHistory or {}
local targetType = type(target)
local targetToString = tostring(target)
if (targetType == "table") then
for key, value in pairs(target) do
output = output..indent..tostring(key).." = "
if (type(value) == "table") then
output = output.."(table)".."\n"
if tableHistory[value] then
output = output.." Avoiding cycle on table..."
else
tableHistory[value] = true
output = output..dump(value, indent.." ", tableHistory)
end
else
output = output..dump(value)
end
end
else
output = "("..targetType..") "..targetToString.."\n"
end
return output
end
--
--
--
local DeveloperSuite_Console = ZO_Object:Subclass()
function DeveloperSuite_Console:New(...)
local console = ZO_Object.New(self)
console:Initialize(...)
return console
end
function DeveloperSuite_Console:Initialize(control, savedVars)
DeveloperSuite_TopLevelControl_Initialize(self, control, savedVars)
self.outputScrollContainer = self.control:GetNamedChild("OutputScrollContainer")
self.outputLabel = self.control:GetNamedChild("OutputLabel")
self.inputEditBox = self.control:GetNamedChild("InputEditBox")
local function onScrollExtentsChanged(scroll)
ZO_Scroll_OnExtentsChanged(self.outputScrollContainer)
if self.outputScrollContainer.scrollbar then
self.outputScrollContainer.scrollbar:SetValue(100)
end
end
self.outputScrollContainer.scroll:SetHandler("OnScrollExtentsChanged", onScrollExtentsChanged)
self:AddOutput()
local function onEnter()
self:Run(self.inputEditBox:GetText())
self.inputEditBox:SetText("")
end
self.inputEditBox:SetHandler("OnEnter", onEnter)
local function onUpArrow()
self:NavigateHistoryUp()
end
self.inputEditBox:SetHandler("OnUpArrow", onUpArrow)
local function onDownArrow()
self:NavigateHistoryDown()
end
self.inputEditBox:SetHandler("OnDownArrow", onDownArrow)
self:RefreshHistoryIndex()
end
function DeveloperSuite_Console:Run(text)
if text == "" then
return nil
elseif text == "/clear" then
self:ClearOutput()
elseif (text:byte(1) == 47) then -- Byte (47) is a division slash.
DoCommand(text)
else
local script = zo_loadstring(string.format("return %s", text))
local value = script()
if script then
self:AddOutput(dump(value))
self:AddToHistory(text)
end
end
end
function DeveloperSuite_Console:RefreshHistoryIndex()
self.historyIndex = #self.savedVars.history + 1
end
function DeveloperSuite_Console:AddToHistory(text)
table.insert(self.savedVars.history, text)
self:RefreshHistoryIndex()
end
function DeveloperSuite_Console:NavigateHistoryUp()
if (self.historyIndex > 1) then
self.historyIndex = self.historyIndex - 1
self.inputEditBox:SetText(self.savedVars.history[self.historyIndex])
end
end
function DeveloperSuite_Console:NavigateHistoryDown()
if (self.historyIndex <= #self.savedVars.history) then
self.historyIndex = self.historyIndex + 1
self.inputEditBox:SetText(self.savedVars.history[self.historyIndex])
end
end
function DeveloperSuite_Console:ClearOutput()
self.savedVars.output = ""
self:AddOutput()
end
function DeveloperSuite_Console:AddOutput(output)
self.savedVars.output = self.savedVars.output..tostring(output or "")
self.outputLabel:SetText(self.savedVars.output)
end
function DeveloperSuite_Console:Show()
DeveloperSuite_TopLevelControl_Show(self.control)
end
function DeveloperSuite_Console:Hide()
DeveloperSuite_TopLevelControl_Show(self.control)
end
function DeveloperSuite_Console:Toggle()
DeveloperSuite_TopLevelControl_Toggle(self.control, self.inputEditBox)
end
--
--
--
local function OnAddOnLoaded(savedVars)
DEVELOPER_SUITE_CONSOLE = DeveloperSuite_Console:New(DeveloperSuite_ConsoleTopLevelControl, savedVars.console)
SLASH_COMMANDS["/console"] = function()
DEVELOPER_SUITE_CONSOLE:Toggle()
end
end
CALLBACK_MANAGER:RegisterCallback(NAMESPACE.."_OnAddOnLoaded", OnAddOnLoaded)