52 lines
2.5 KiB
Lua
52 lines
2.5 KiB
Lua
-- #125: saved key bindings must survive the 70334 Modern-preset reset that follows PLAYER_ENTERING_WORLD.
|
|
-- Simulates the engine sequence observed on LOCAL (ClaudeBindProbe, 2026-11-26): cache load (Q=TOGGLEWORLDMAP),
|
|
-- PLAYER_ENTERING_WORLD, then one UPDATE_BINDINGS after the engine re-applied the preset defaults (Q=TURNLEFT).
|
|
local root = assert(arg[1], 'gateway directory required')
|
|
local with_addon = arg[2] ~= 'without'
|
|
|
|
local defaults = {Q = 'TURNLEFT', A = 'STRAFELEFT', E = 'TURNRIGHT'}
|
|
local saved = {Q = 'TOGGLEWORLDMAP', Z = 'STRAFELEFT'}
|
|
local bindings, frames, timers, combat = {}, {}, {}, false
|
|
|
|
local function apply(t) for k, v in pairs(t) do bindings[k] = v end end
|
|
function GetBindingAction(key) return bindings[key] or '' end
|
|
function GetCurrentBindingSet() return 1 end
|
|
function LoadBindings(set) assert(set == 1) bindings = {} apply(defaults) apply(saved) end
|
|
function InCombatLockdown() return combat end
|
|
C_Timer = {After = function(_, fn) timers[#timers + 1] = fn end}
|
|
function CreateFrame()
|
|
local fr = {events = {}}
|
|
function fr:RegisterEvent(e) self.events[e] = true end
|
|
function fr:UnregisterEvent(e) self.events[e] = nil end
|
|
function fr:SetScript(_, fn) self.handler = fn end
|
|
frames[#frames + 1] = fr
|
|
return fr
|
|
end
|
|
local function fire(e) for _, fr in ipairs(frames) do if fr.events[e] then fr.handler(fr, e) end end end
|
|
|
|
if with_addon then dofile(root .. '/client_addons/OctoKeepBindings/OctoKeepBindings.lua') end
|
|
|
|
-- login: engine loads defaults + cache, enters world, then re-applies the preset defaults
|
|
LoadBindings(1)
|
|
fire('PLAYER_ENTERING_WORLD')
|
|
apply(defaults)
|
|
fire('UPDATE_BINDINGS')
|
|
assert(GetBindingAction('Q') == 'TOGGLEWORLDMAP', 'saved Q binding lost after world entry: ' .. GetBindingAction('Q'))
|
|
assert(GetBindingAction('A') == 'STRAFELEFT' and GetBindingAction('Z') == 'STRAFELEFT', 'other bindings changed')
|
|
|
|
-- later binding changes by the player are not undone
|
|
bindings.Q = 'TOGGLEBACKPACK'
|
|
fire('UPDATE_BINDINGS')
|
|
assert(GetBindingAction('Q') == 'TOGGLEBACKPACK', 'later UPDATE_BINDINGS reloaded bindings')
|
|
|
|
-- reset during combat: restore after combat ends
|
|
combat = true
|
|
fire('PLAYER_ENTERING_WORLD')
|
|
apply(defaults)
|
|
fire('UPDATE_BINDINGS')
|
|
assert(GetBindingAction('Q') == 'TURNLEFT', 'bindings reloaded in combat')
|
|
combat = false
|
|
fire('PLAYER_REGEN_ENABLED')
|
|
assert(GetBindingAction('Q') == 'TOGGLEWORLDMAP', 'not restored after combat')
|
|
print('keep bindings: saved Q survives the preset reset, later changes kept, combat deferred')
|