Mercurial > wow > degaine
changeset 5:66640a8f1cbd
Started reworking code ordering in files, comments and vars are in english
author | contrebasse |
---|---|
date | Fri, 10 Dec 2010 16:04:55 +0100 |
parents | 388b12209e6c |
children | 120f29645e34 |
files | Degaine.lua Degaine.toc |
diffstat | 2 files changed, 149 insertions(+), 83 deletions(-) [+] |
line wrap: on
line diff
--- a/Degaine.lua Fri Dec 10 13:12:06 2010 +0100 +++ b/Degaine.lua Fri Dec 10 16:04:55 2010 +0100 @@ -1,146 +1,194 @@ local AddonName = ... --- Dégaine auto des armes +-- Draw your weapons automagically --- BUGS connus : --- le camouflage du voleur ne rentre pas l'arme +-- Known bugs : -- si on se lève en sautant ça ne sort pas l'arme (impossible de savoir si on était assis avant) --- DEBUG +--@debug@ local debug = false; +--@end-debug@ --- Fonctions globales en local --- GLOBALS: ToggleAutoDegaine, isDegaineAuto, BINDING_HEADER_DEGAINE -local GossipFrame = GossipFrame; -local DEFAULT_CHAT_FRAME = DEFAULT_CHAT_FRAME; -local InCombatLockdown = InCombatLockdown; -local ToggleSheath = ToggleSheath; +--------------------------------------------------------------- +-- Globals to local +--------------------------------------------------------------- +-- These need to be globals +-- GLOBALS: ToggleAutoDegaine, Degaine_isAuto, BINDING_HEADER_DEGAINE +-- It doesn't matter if they are globals +-- GLOBALS: DEFAULT_CHAT_FRAME, GossipFrame + +-- Lua functions local pairs = pairs; local type = type; --- Pour les raccourcis --- Cf Bindings.xml pour les raccourcis eux-mêmes -BINDING_HEADER_DEGAINE = "Dégainer automatiquement"; +-- Wow functions +local InCombatLockdown = InCombatLockdown +local ToggleSheath = ToggleSheath --- Variables locales -local DegaineFrame = CreateFrame("Frame"); -local playername = UnitName("player"); -local done = true; -local t_restant = -1; --- Configuration des events à regarder -local events = { -- events sans arguments à voir +--------------------------------------------------------------- +-- Some stuff... +--------------------------------------------------------------- +-- Bindings +BINDING_HEADER_DEGAINE = "Dégainer automatiquement" + +-- Print status +local printState = function() + DEFAULT_CHAT_FRAME:AddMessage(Degaine_isAuto and "Dégainage automatique |cFF00FF00activé|r" or "Dégainage automatique |cFFFF0000désactivé|r"); +end + + +--------------------------------------------------------------- +-- Local vars +--------------------------------------------------------------- +-- const +local DegaineFrame = CreateFrame("Frame") +local playername = UnitName("player") + +-- vars +local done = true +local t_left = -1 + +--------------------------------------------------------------- +-- Events config +--------------------------------------------------------------- +-- Events to watch +local events = { -- no args to watch GOSSIP_SHOW = true, MERCHANT_SHOW = function() return GossipFrame:IsShown(); end, - BANKFRAME_OPENED = true; --function() return GossipFrame:IsShown(); end, + BANKFRAME_OPENED = true, --function() return GossipFrame:IsShown(); end, AUCTION_HOUSE_SHOW = true, -}; -local events1player = { -- events dont le 1er argument doit être le joueur - UNIT_SPELLCAST_FAILED = true; - UNIT_SPELLCAST_INTERRUPTED = true; - UNIT_SPELLCAST_SUCCEEDED = true; -}; -local events2playername = { -- events dont le 2e argument doit être le joueur - CHAT_MSG_SAY = true; - CHAT_MSG_YELL = true; - CHAT_MSG_TEXT_EMOTE = true; -}; +} +local SpellBlacklist = { + [1784] = true, -- Stealth (Rogue) + [58984] = true, -- Shadowmeld (Nightelf stealth) +} +local events1player = { -- the first arg is "player" + UNIT_SPELLCAST_FAILED = true, + UNIT_SPELLCAST_INTERRUPTED = true, + UNIT_SPELLCAST_SUCCEEDED = true, +} +local events2playername = { -- the 2nd arg is playername + CHAT_MSG_SAY = true, + CHAT_MSG_YELL = true, + CHAT_MSG_TEXT_EMOTE = true, +} --- Fonctions d'activation/désactivation des events -local registerEvents = function() - --if debug then - -- DEBUG - -- DegaineFrame:RegisterAllEvents(); - --else - for k,v in pairs(events) do DegaineFrame:RegisterEvent(k); end - for k,v in pairs(events1player) do DegaineFrame:RegisterEvent(k); end - for k,v in pairs(events2playername) do DegaineFrame:RegisterEvent(k); end - --end -end -- function -local unregisterEvents = function() - if not debug then - for k,v in pairs(events) do DegaineFrame:UnregisterEvent(k); end - for k,v in pairs(events1player) do DegaineFrame:UnregisterEvent(k); end - for k,v in pairs(events2playername) do DegaineFrame:UnregisterEvent(k); end - end -end -- function --- Fonction de timer --- On attend un petit délai avant de dégainer, pour voir l'animation et éviter que ça bug -local OnUpdate = function(self,t_ecoule) +--------------------------------------------------------------- +-- Events registering +--------------------------------------------------------------- + + +--------------------------------------------------------------- +-- Timer +--------------------------------------------------------------- +-- Wait a few seconds before drawing, to be able to see the curren animation (and avoid bugs) +local Degaine_OnUpdate = function(self,t_elapsed) if not done then - t_restant = t_restant - t_ecoule; - if t_restant<=0 then + t_left = t_left - t_elapsed; + if t_left<=0 then done = true; ToggleSheath(); end end end --- Fonctions d'activation/désactivation -local activer = function() - if (not isDegaineAuto) or InCombatLockdown() then return end - - DegaineFrame:SetScript("OnUpdate", OnUpdate); - registerEvents(); + +--------------------------------------------------------------- +-- Activation functions +--------------------------------------------------------------- +local activate = function() + if (not Degaine_isAuto) or InCombatLockdown() then return end + + DegaineFrame:SetScript("OnUpdate", Degaine_OnUpdate); + --@debug@ + if debug then + DegaineFrame:RegisterAllEvents(); + else + --@end-debug@ + for k,v in pairs(events) do DegaineFrame:RegisterEvent(k); end + for k,v in pairs(events1player) do DegaineFrame:RegisterEvent(k); end + for k,v in pairs(events2playername) do DegaineFrame:RegisterEvent(k); end + --@end-debug@ + end + --@end-debug@ end -local desactiver = function() - -- Désactivation - unregisterEvents(); +local desactivate = function() + for k,v in pairs(events) do DegaineFrame:UnregisterEvent(k); end + for k,v in pairs(events1player) do DegaineFrame:UnregisterEvent(k); end + for k,v in pairs(events2playername) do DegaineFrame:UnregisterEvent(k); end DegaineFrame:SetScript("OnUpdate", nil); done = true; end +ToggleAutoDegaine = function() + if Degaine_isAuto then + Degaine_isAuto = false + desactivate() + else + Degaine_isAuto = true + activate() + end + printState() +end --- Fonctions -local printState = function() - DEFAULT_CHAT_FRAME:AddMessage(isDegaineAuto and "Dégainage automatique |cFF00FF00activé|r" or "Dégainage automatique |cFFFF0000désactivé|r"); -end -local OnEvent = function(self,event, arg1, arg2, ...) + +--------------------------------------------------------------- +-- Event/hooks functions +--------------------------------------------------------------- +local Degaine_OnEvent = function(self,event, arg1, arg2, ...) + --@debug@ if debug then - DEFAULT_CHAT_FRAME:AddMessage(event); + DEFAULT_CHAT_FRAME:AddMessage(event) if arg1 then DEFAULT_CHAT_FRAME:AddMessage("arg1 = "..arg1); end if arg2 then DEFAULT_CHAT_FRAME:AddMessage("arg2 = "..arg2); end end - + --@end-debug@ + if ((events[event] and (type(events[event])~="function" or events[event]())) or (events1player[event] and arg1=="player") or (events2playername[event] and arg2==playername)) then - t_restant = 2; - done = false; + t_left = 2 + done = false + elseif event == "PLAYER_REGEN_ENABLED" then - desactiver(); + desactivate() elseif event == "PLAYER_REGEN_DISABLED" then - activer(); + activate() + elseif event == "ADDON_LOADED" and arg1==AddonName then - if isDegaineAuto==nil then - isDegaineAuto = true; + if Degaine_isAuto==nil then + Degaine_isAuto = true end - if isDegaineAuto then - activer(); + if Degaine_isAuto then + activate() else - desactiver(); + desactivate() end - printState(); + printState() + + -- Not needed anymore + DegaineFrame:UnregisterEvent("ADDON_LOADED") end end +-- Hook when standing up +-- (Didn't work, see http://forums.wowace.com/showthread.php?p=310547#post310547) +hooksecurefunc("SitStandOrDescendStart",function() + if Degaine_isAuto and not InCombatLockdown() then + t_left = 2 + done = false + end +end) --- Pour mettre le dégainage auto on/off TODO -ToggleAutoDegaine = function() - if isDegaineAuto then - isDegaineAuto = false; - desactiver(); - else - isDegaineAuto = true; - activer(); - end - printState(); -end --- Enregistrement des events et activation -DegaineFrame:RegisterEvent("PLAYER_REGEN_ENABLED"); -DegaineFrame:RegisterEvent("PLAYER_REGEN_DISABLED"); -DegaineFrame:RegisterEvent("ADDON_LOADED"); -DegaineFrame:SetScript("OnEvent",OnEvent); --- ça ne marche pas... question posée sur http://forums.wowace.com/showthread.php?p=310547#post310547 -hooksecurefunc("SitStandOrDescendStart",function() if isDegaineAuto and not InCombatLockdown() then t_restant = 2; done = false; end; end); -activer(); + +--------------------------------------------------------------- +-- Initialization +--------------------------------------------------------------- +DegaineFrame:SetScript("OnEvent",Degaine_OnEvent) + +-- Global events +DegaineFrame:RegisterEvent("PLAYER_REGEN_ENABLED") +DegaineFrame:RegisterEvent("PLAYER_REGEN_DISABLED") +DegaineFrame:RegisterEvent("ADDON_LOADED") +activate()