From 9409f93d1059c5f942f120392ebd3e444797b252 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Fri, 19 Oct 2012 01:38:22 +0000 Subject: [PATCH] Add a debugging module to Ovale to selectively print debugging messages. Add a new public method Ovale:debugPrint(flag, ...) that prints the message if the debugging flag has been set. The flag can be any string. Flags may be toggled with: /ovale toggledebug . Flags may be listed with: /ovale debugflags. Add some debugging print statements for when a script compilation is requested using a "compile" flag. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@607 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- Ovale.lua | 24 ++++++++++++++++++++---- OvaleData.lua | 10 ++++++++-- OvaleOptions.lua | 39 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 66 insertions(+), 7 deletions(-) diff --git a/Ovale.lua b/Ovale.lua index 1b91834..42f9633 100644 --- a/Ovale.lua +++ b/Ovale.lua @@ -53,6 +53,8 @@ Ovale.combatStartTime = nil --needCompile is true, false, or "quick" Ovale.needCompile = false Ovale.listes = {} +--debug flags +Ovale.debugFlags = {} -- --Key bindings @@ -64,6 +66,12 @@ BINDING_NAME_OVALE_CHECKBOX3 = L["Inverser la boîte à cocher "].."(4)" BINDING_NAME_OVALE_CHECKBOX4 = L["Inverser la boîte à cocher "].."(5)" -- +function Ovale:debugPrint(flag, ...) + if self.debugFlags[flag] then + self:Print("[" .. flag .. "]", ...) + end +end + function Ovale:Debug() self:Print(OvaleCompile:DebugNode(self.masterNodes[1])) end @@ -84,9 +92,11 @@ function Ovale:CompileAll() local code = OvaleOptions:GetProfile().code if code then if self.needCompile == "quick" then + self.debugPrint("compile", "quick compile") code = OvaleCompile:CompileDeclarations(code) code = OvaleCompile:CompileInputs(code) elseif self.needCompile then + self.debugPrint("compile", "FULL compile") self.masterNodes = OvaleCompile:Compile(code) end OvaleCompile:UpdateNodesEnabled(self.masterNodes, self.masterNodesEnabled) @@ -144,19 +154,21 @@ function Ovale:OnDisable() self.frame:Hide() end -function Ovale:UNIT_INVENTORY_CHANGED() +function Ovale:UNIT_INVENTORY_CHANGED(event) if self.compileOnItems then + self:debugPrint("compile", event) self.needCompile = self.needCompile or "quick" else self.refreshNeeded.player = true end end -function Ovale:Ovale_UpdateShapeshiftForm() +function Ovale:Ovale_UpdateShapeshiftForm(event) if Ovale.compileOnStances then - Ovale.needCompile = self.needCompile or "quick" + self:debugPrint("compile", event) + self.needCompile = self.needCompile or "quick" else - Ovale.refreshNeeded.player = true + self.refreshNeeded.player = true end end @@ -171,12 +183,14 @@ end --Called when a glyph has been added --The script needs to be compiled function Ovale:GLYPH_ADDED(event) + self:debugPrint("compile", event) self.needCompile = self.needCompile or "quick" end --Called when a glyph has been updated --The script needs to be compiled function Ovale:GLYPH_UPDATED(event) + self:debugPrint("compile", event) self.needCompile = self.needCompile or "quick" end @@ -238,6 +252,7 @@ end local function OnCheckBoxValueChanged(widget) OvaleOptions:GetProfile().check[widget.userdata.k] = widget:GetValue() if Ovale.casesACocher[widget.userdata.k].compile then + Ovale.debugPrint("compile", "checkbox value changed: " .. widget.userdata.k) Ovale.needCompile = Ovale.needCompile or "quick" end end @@ -245,6 +260,7 @@ end local function OnDropDownValueChanged(widget) OvaleOptions:GetProfile().list[widget.userdata.k] = widget.value if Ovale.listes[widget.userdata.k].compile then + Ovale.debugPrint("compile", "list value changed: " .. widget.userdata.k) Ovale.needCompile = Ovale.needCompile or "quick" end end diff --git a/OvaleData.lua b/OvaleData.lua index ba3d0a8..34e2184 100644 --- a/OvaleData.lua +++ b/OvaleData.lua @@ -282,7 +282,8 @@ function OvaleData:UNIT_PET() end --The user learnt a new spell -function OvaleData:SPELLS_CHANGED() +function OvaleData:SPELLS_CHANGED(event) + Ovale.debugPrint("compile", event) self:FillSpellList() Ovale.needCompile = Ovale.needCompile or "quick" end @@ -379,6 +380,7 @@ end function OvaleData:RemplirListeTalents() local talentId = 1 + local needCompile = false while true do local name, texture, tier, column, selected, available = GetTalentInfo(talentId) if not name then @@ -393,9 +395,13 @@ function OvaleData:RemplirListeTalents() self.pointsTalent[talentId] = 0 end self.listeTalentsRemplie = true - Ovale.needCompile = Ovale.needCompile or "quick" + needCompile = Ovale.needCompile or "quick" talentId = talentId + 1 end + if needCompile then + Ovale.debugPrint("compile", "filling talent list") + Ovale.needCompile = needCompile + end end function OvaleData:FirstInit() diff --git a/OvaleOptions.lua b/OvaleOptions.lua index a81764e..456d46d 100644 --- a/OvaleOptions.lua +++ b/OvaleOptions.lua @@ -12,7 +12,7 @@ OvaleOptions = LibStub("AceAddon-3.0"):NewAddon("OvaleOptions", "AceEvent-3.0", "AceConsole-3.0") -- -local strgsub = string.gsub +local strgmatch, strgsub, tostring = string.gmatch, string.gsub, tostring -- -- @@ -286,6 +286,7 @@ local options = end, set = function(info,v) OvaleOptions.db.profile.code = v + Ovale.debugPrint("compile", "accepting script") Ovale.needCompile = true end, width = "full" @@ -300,6 +301,7 @@ local options = end, func = function() OvaleOptions.db.profile.code = OvaleOptions.db.defaults.profile.code + Ovale.debugPrint("compile", "restoring default script") Ovale.needCompile = true end, } @@ -355,6 +357,39 @@ local options = Ovale:Print(OvaleState.state.eclipse) end }, + debugflags = + { + name = "List debug flags", + type = "execute", + func = function() + local flags + for flag in pairs(Ovale.debugFlags) do + if flags then + flags = flags .. ", " .. flag + else + flags = flag + end + end + if flags then + Ovale:Print(flags) + end + end + }, + toggledebug = + { + name = "Toggle debug flag", + type = "input", + set = function(info, value) + for flag in strgmatch(value, "[%w_]+") do + if Ovale.debugFlags[flag] then + Ovale.debugFlags[flag] = nil + else + Ovale.debugFlags[flag] = true + end + end + end, + get = nil, + }, talent = { order = -4, @@ -462,6 +497,7 @@ function OvaleOptions:FirstInit() self.db.RegisterCallback( self, "OnProfileCopied", "HandleProfileChanges" ) if self.db.profile.code then + Ovale.debugPrint("compile", "setting script during addon initialization") Ovale.needCompile = true end end @@ -469,6 +505,7 @@ end function OvaleOptions:HandleProfileChanges() if self.firstInit then if (self.db.profile.code) then + Ovale.debugPrint("compile", "changing profiles") Ovale.needCompile = true end end -- 1.7.9.5