-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
184 lines (154 loc) · 5.42 KB
/
Copy pathCore.lua
File metadata and controls
184 lines (154 loc) · 5.42 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
local addonName, SNEK = ...
SNEK = SNEK or {}
-- Single source of truth for the version string
SNEK.VERSION = "0.8.4"
-- Binding display names
_G["BINDING_NAME_SNEK_TOGGLE_RECORDER"] = "Toggle Recorder (Start/Stop)"
_G["BINDING_NAME_SNEK_RESET"] = "Reset / Abort Sequence"
for i = 1, 10 do
_G["BINDING_NAME_SNEK_KEY" .. i] = "Key " .. i
end
-- Runtime state
SNEK.sequence = {}
SNEK.isPlaying = false
SNEK.playGeneration = 0
-------------------------------------------------
-- Global functions required by Bindings.xml
-------------------------------------------------
function SNEK_ToggleRecorder()
if GetCurrentKeyBoardFocus() then return end
local db = SNEK.DB.Get()
if not db.enabled then return end
if db.isRecording then
-- Turning OFF → stop recording and auto-start playback if we have steps
db.isRecording = false
local count = #SNEK.sequence
print("|cff00ff00S.N.E.K.:|r Recorder |cffff9900STOPPED|r (" .. count .. " steps)")
if count > 0 then
SNEK_Finalize()
end
else
-- Turning ON
db.isRecording = true
print("|cff00ff00S.N.E.K.:|r Recorder |cff00ff00STARTED|r")
end
end
function SNEK_AddKey(index)
if GetCurrentKeyBoardFocus() then return end
local db = SNEK.DB.Get()
if not db.enabled or not db.isRecording then return end
local label = db.labels[index]
if type(label) ~= "string" or label == "" then return end
-- Sequence limit check
if #SNEK.sequence >= (tonumber(db.sequenceLimit) or 7) then
db.isRecording = false
print("|cffff9900S.N.E.K.:|r Sequence limit reached (" .. db.sequenceLimit .. "). Recorder stopped.")
if db.autoFinalizeOnLimit then
SNEK_Finalize()
end
return
end
table.insert(SNEK.sequence, label)
if db.showKeyFeedback then
print("|cff00ff00S.N.E.K.:|r + '" .. label .. "' (" .. #SNEK.sequence .. "/" .. db.sequenceLimit .. ")")
end
-- Check limit again after adding
if #SNEK.sequence >= (tonumber(db.sequenceLimit) or 7) then
db.isRecording = false
print("|cffff9900S.N.E.K.:|r Sequence limit reached. Recorder stopped.")
if db.autoFinalizeOnLimit then
SNEK_Finalize()
end
end
end
function SNEK_Finalize()
local db = SNEK.DB.Get()
if not db.enabled then return end
local seq = SNEK.sequence
if #seq == 0 then
print("|cffff9900S.N.E.K.:|r Nothing to play.")
return
end
if SNEK.isPlaying then
print("|cffff9900S.N.E.K.:|r Already playing.")
return
end
local delay = tonumber(db.delay) or 2.8
local initialDelay = tonumber(db.initialDelay) or 2.5
local snapshot = {}
for i, v in ipairs(seq) do
snapshot[i] = v
end
wipe(seq)
db.isRecording = false
SNEK.isPlaying = true
SNEK.playGeneration = SNEK.playGeneration + 1
local gen = SNEK.playGeneration
-- Decide output mode once at the start of playback
local useSay = db.useSayChat and MessageQueue
if db.useSayChat and not MessageQueue then
print("|cffff9900S.N.E.K.:|r MessageQueue not found – falling back to local print.")
useSay = false
end
local modeText = useSay and "SAY" or "local print"
print("|cff00ff00S.N.E.K.:|r Sequence locked (" .. #snapshot .. " steps, " .. modeText .. "). Starting in " .. initialDelay .. "s...")
local i = 1
local function finish()
if gen ~= SNEK.playGeneration then return end
SNEK.isPlaying = false
print("|cff00ff00S.N.E.K.:|r Playback finished.")
end
local function nextStep()
if gen ~= SNEK.playGeneration then return end
if i > #snapshot then
finish()
return
end
local text = snapshot[i]
i = i + 1
if useSay then
-- Queue the SAY message; continue the chain from the callback
-- (after the message has actually been sent via hardware event)
MessageQueue.SendChatMessage(text, "SAY", nil, nil, function()
if gen ~= SNEK.playGeneration then return end
if i <= #snapshot then
C_Timer.After(delay, nextStep)
else
finish()
end
end)
else
-- Classic local print path
print(text)
if i <= #snapshot then
C_Timer.After(delay, nextStep)
else
finish()
end
end
end
C_Timer.After(initialDelay, nextStep)
end
function SNEK_Reset()
SNEK.playGeneration = SNEK.playGeneration + 1
SNEK.isPlaying = false
wipe(SNEK.sequence)
local db = SNEK.DB.Get()
db.isRecording = false
print("|cff00ff00S.N.E.K.:|r Sequence cleared & playback stopped.")
end
-------------------------------------------------
-- Initialization
-------------------------------------------------
local frame = CreateFrame("Frame")
frame:RegisterEvent("ADDON_LOADED")
frame:SetScript("OnEvent", function(self, event, name)
if name ~= addonName then return end
SNEK.DB.Init()
SNEK.Minimap.Create()
SNEK.Options.Register()
local status = SNEK.DB.Get().enabled and "|cff00ff00enabled|r" or "|cffff9900disabled|r"
print("|cff00ff00S.N.E.K.|r v" .. SNEK.VERSION .. " loaded (" .. status .. ").")
print(" Type |cffffff00/snek|r for commands.")
self:UnregisterEvent("ADDON_LOADED")
end)