Files

47 lines
2.3 KiB
Lua

-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
-- Commands use the existing owned self-addon envelope. The gateway consumes
-- them privately and waits for authoritative source flags before presentation.
local waiting={}
local function say(text)
if DEFAULT_CHAT_FRAME then DEFAULT_CHAT_FRAME:AddMessage('Equipment visibility: '..text) end
end
local function command(part,text)
local action=type(text)=='string' and text:match('^%s*(.-)%s*$'):lower() or ''
if action=='' then action='toggle' end
if action~='on' and action~='off' and action~='toggle' and action~='status' then
say('/gw'..part..' on|off|toggle|status');return
end
local self=UnitName and UnitName('player')
if not self or not C_ChatInfo or not C_ChatInfo.SendAddonMessage then
say('source control unavailable');return
end
waiting[part]=true
C_ChatInfo.SendAddonMessage('GWTURTLE','visibility '..part..' '..action,'WHISPER',self)
end
SLASH_GWHELM1='/gwhelm'
SLASH_GWCLOAK1='/gwcloak'
SlashCmdList.GWHELM=function(text)command('helm',text)end
SlashCmdList.GWCLOAK=function(text)command('cloak',text)end
local frame=CreateFrame('Frame')
frame:RegisterEvent('CHAT_MSG_SYSTEM')
frame:RegisterEvent('PLAYER_LEAVING_WORLD')
frame:SetScript('OnEvent',function(_,event,message)
if event=='PLAYER_LEAVING_WORLD' then waiting={};return end
if type(message)~='string' then return end
if message=='GWTURTLE1 VISIBILITY unavailable' then
if waiting.helm or waiting.cloak then say('source visibility state unavailable')end
waiting={};return
end
local part,state,phase=message:match('^GWTURTLE1 VISIBILITY (helm) (o[nf]+) (%a+)$')
if not part then part,state,phase=message:match('^GWTURTLE1 VISIBILITY (cloak) (o[nf]+) (%a+)$')end
if not part or not waiting[part] or (state~='on' and state~='off') then return end
if phase=='pending' then say(part..' is '..state..'; waiting for server confirmation')
elseif phase=='confirmed' then waiting[part]=nil;say(part..' '..state..' (server confirmed)')end
end)
if ChatFrame_AddMessageEventFilter then
ChatFrame_AddMessageEventFilter('CHAT_MSG_SYSTEM',function(_,_,message)
return type(message)=='string' and message:match('^GWTURTLE1 VISIBILITY ')~=nil
end)
end