-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxChatReloader.lua
More file actions
125 lines (93 loc) · 4.14 KB
/
xChatReloader.lua
File metadata and controls
125 lines (93 loc) · 4.14 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
-- ------------------------------------------
-- Chat Reloader
-- by: Xsear
-- ------------------------------------------
require "table"
require "lib/lib_Debug"
require "lib/lib_InterfaceOptions"
require "lib/lib_ChatLib"
-- ------------------------------------------
-- CONSTANTS
-- ------------------------------------------
AddonInfo = {
release = "2016-01-22",
version = "1.2",
patch = "1.6.1931",
save = 1,
}
OUTPUT_PREFIX = "[xCR] "
RELOADUI_FLAG = "_ReloadUI"
RELOADUI_DATA_CHATHISTORY = "_ReloadUI_ChatHistory"
MAX_HISTORY_LIMIT = 2048
-- ------------------------------------------
-- VARIABLES
-- ------------------------------------------
local g_ChatHistory = {}
-- ------------------------------------------
-- OPTIONS
-- ------------------------------------------
g_Loaded = false
g_Options = {}
g_Options.Enabled = true
g_Options.Debug = false
g_Options.AllowReRecording = false
g_Options.ChatHistoryLimit = 50
-- Callback for when an options is changed in the Interface Options. Updates the value in g_Options.
function OnOptionChanged(id, value)
if id == "__LOADED" then
OnOptionsLoaded()
elseif id == "Debug" then
Component.SaveSetting("Debug", value)
Debug.EnableLogging(value)
elseif id == "ChatHistoryLimit" or "Enabled" then
g_ChatHistory = {}
end
g_Options[id] = value
end
function OnOptionsLoaded()
g_Loaded = true
end
-- Creating the Interface Options
do
InterfaceOptions.NotifyOnLoaded(true)
InterfaceOptions.SaveVersion(AddonInfo.save)
InterfaceOptions.AddCheckBox({id = "Enabled", label = "Enable addon", tooltip = "If unchecked, the addon will not restore messages. Please note that this doesn't truly stop the addon from functioning - it merely suppresses actions that would otherwise signify that the addon is active. If you are suspecting compatability issues with other addons, it would be better to tempoarily remove the addon in order to verify whether or not it is part of the issue.", default = g_Options.Enabled})
InterfaceOptions.AddCheckBox({id = "Debug", label = "Enable debug", tooltip = "If checked, the addon will log messages into the console that are helpful to the addon creator in order to track down problems.", default = g_Options.Debug})
InterfaceOptions.AddCheckBox({id = "AllowReRecording", label = "Restore previously restored messages", tooltip = "If checked, the addon will restore messages even if they had already been restored in a previous reload. This way, messages can persist through multiple reloads.", default = g_Options.Debug})
InterfaceOptions.AddSlider({id = "ChatHistoryLimit", label = "Message limit", tooltip = "Maximum number of messages that the addon will restore. The addon will wipe its current history when you change this value.", default = g_Options.ChatHistoryLimit, min = 1, max = 2048, inc = 1, format="%0.0f"})
end
-- ------------------------------------------
-- EVENTS
-- ------------------------------------------
function OnComponentLoad(args)
Debug.EnableLogging(Component.GetSetting("Debug"))
InterfaceOptions.SetCallbackFunc(OnOptionChanged, "Chat Reloader")
if Component.GetSetting(RELOADUI_FLAG) then
Component.SaveSetting(RELOADUI_FLAG, false)
OnPostReloadUI()
end
end
function OnPreReloadUI(args)
Debug.Event(args)
Component.SaveSetting(RELOADUI_DATA_CHATHISTORY, g_ChatHistory)
Component.SaveSetting(RELOADUI_FLAG, true)
end
function OnPostReloadUI(args)
Debug.Log("OnPostReloadUI")
local restoredHistory = Component.GetSetting(RELOADUI_DATA_CHATHISTORY)
if g_Options.Enabled then
for index, args in ipairs(Component.GetSetting(RELOADUI_DATA_CHATHISTORY)) do
args.xChatReloader_recordedMessage = true
Component.GenerateEvent("MY_CHAT_MESSAGE", args)
end
end
Component.SaveSetting(RELOADUI_DATA_CHATHISTORY, {})
end
function OnChatMessage(args)
if not args.xChatReloader_recordedMessage or g_Options.AllowReRecording then
if #g_ChatHistory >= g_Options.ChatHistoryLimit then
table.remove(g_ChatHistory, 1)
end
g_ChatHistory[#g_ChatHistory + 1] = args
end
end