From f7f1a58f411927af6b0ea1bf7a3224a91428ba94 Mon Sep 17 00:00:00 2001 From: "Johnny C. Lam" Date: Sat, 2 Mar 2013 22:15:56 +0000 Subject: [PATCH] Add new module OvaleScripts to manage scripts from multiple sources. Move the existing default scripts into OvaleScripts and decorate them with a description that allows a user to see what class specializations are supported by the default script. Teach Ovale to use the script ``source'' to find the code for the current script. Custom code can be copied from an existing script to a blank custom template that may be modified and saved into the SavedVariables file. The script ``source'' may be selected from a dropdown menu, with the default menu containing the Ovale default script and either a blank custom script or the custom script loaded from the SavedVariables file. git-svn-id: svn://svn.curseforge.net/wow/ovale/mainline/trunk@715 d5049fe3-3747-40f7-a4b5-f36d6801af5f --- Ovale.lua | 2 -- Ovale.toc | 36 +++++++++++++++------------ OvaleCompile.lua | 12 ++++----- OvaleData.lua | 2 +- OvaleOptions.lua | 66 +++++++++++++++++++++++++++++++++++++------------- OvaleScripts.lua | 60 +++++++++++++++++++++++++++++++++++++++++++++ defaut/Chaman.lua | 7 ++++-- defaut/Chasseur.lua | 7 ++++-- defaut/Chevalier.lua | 7 ++++-- defaut/Demoniste.lua | 7 ++++-- defaut/Druide.lua | 7 ++++-- defaut/Guerrier.lua | 7 ++++-- defaut/Mage.lua | 7 ++++-- defaut/Moine.lua | 7 ++++-- defaut/Paladin.lua | 7 ++++-- defaut/Pretre.lua | 7 ++++-- defaut/Voleur.lua | 7 ++++-- 17 files changed, 191 insertions(+), 64 deletions(-) create mode 100644 OvaleScripts.lua diff --git a/Ovale.lua b/Ovale.lua index da9cda0..3a3da19 100644 --- a/Ovale.lua +++ b/Ovale.lua @@ -22,8 +22,6 @@ local damageMeterModules = {} -- Ovale.L = L ---Default scripts (see "defaut" directory) -Ovale.defaut = {} --The table of check boxes definition Ovale.casesACocher = {} --the frame with the icons diff --git a/Ovale.toc b/Ovale.toc index d9bb70f..18a5e48 100644 --- a/Ovale.toc +++ b/Ovale.toc @@ -23,29 +23,19 @@ Locale-ptBR.lua Locale-ruRU.lua Locale-zhCN.lua Locale-zhTW.lua + Ovale.lua + OvaleActionBar.lua -OvaleAura.lua -OvaleBestAction.lua -OvaleComboPoints.lua -OvaleCompile.lua -OvaleCondition.lua -OvaleData.lua -OvaleEquipement.lua OvaleEnemies.lua -OvaleFrame.lua -OvaleFuture.lua +OvaleEquipement.lua OvaleGUID.lua -OvaleIcone.lua -OvaleIcone.xml -OvaleOptions.lua OvalePaperDoll.lua -OvaleRecount.lua -OvaleSkada.lua OvaleSpellDamage.lua OvaleStance.lua -OvaleState.lua -OvaleSwing.lua +OvaleData.lua +OvaleComboPoints.lua +OvaleScripts.lua defaut\Chaman.lua defaut\Chasseur.lua defaut\Demoniste.lua @@ -57,3 +47,17 @@ defaut\Pretre.lua defaut\Voleur.lua defaut\Moine.lua defaut\Chevalier.lua + +OvaleAura.lua +OvaleBestAction.lua +OvaleCompile.lua +OvaleCondition.lua +OvaleFrame.lua +OvaleFuture.lua +OvaleIcone.lua +OvaleIcone.xml +OvaleOptions.lua +OvaleRecount.lua +OvaleSkada.lua +OvaleState.lua +OvaleSwing.lua diff --git a/OvaleCompile.lua b/OvaleCompile.lua index 2587c5e..2ddd8ef 100644 --- a/OvaleCompile.lua +++ b/OvaleCompile.lua @@ -684,12 +684,12 @@ function OvaleCompile:Ovale_StanceChanged(event) end function OvaleCompile:Compile() - local code = OvaleOptions:GetProfile().code - if code then - CompileScript(code) - Ovale.refreshNeeded.player = true - Ovale:UpdateFrame() - end + local profile = OvaleOptions:GetProfile() + local source = profile.source + local code = OvaleScripts.script[OvaleData.className][source].code + CompileScript(code) + Ovale.refreshNeeded.player = true + Ovale:UpdateFrame() end function OvaleCompile:DebugNode(node) diff --git a/OvaleData.lua b/OvaleData.lua index a3d7289..255e235 100644 --- a/OvaleData.lua +++ b/OvaleData.lua @@ -291,13 +291,13 @@ local rootSpellList = nil -- function OvaleData:OnInitialize() + self.className = select(2, UnitClass("player")) for k,v in pairs(self.power) do self.powerType[v.id] = k end end function OvaleData:OnEnable() - self.className = select(2, UnitClass("player")) self.level = UnitLevel("player") self:RegisterEvent("CHARACTER_POINTS_CHANGED", "RemplirListeTalents") diff --git a/OvaleOptions.lua b/OvaleOptions.lua index 4f842d7..6b56446 100644 --- a/OvaleOptions.lua +++ b/OvaleOptions.lua @@ -275,32 +275,65 @@ local options = type = "group", args = { + source = { + order = 0, + type = "select", + name = L["Script"], + width = "double", + values = function(info) + return OvaleScripts:GetDescriptions() + end, + get = function(info) + return OvaleOptions.db.profile.source + end, + set = function(info, v) + local oldSource = OvaleOptions.db.profile.source + if oldSource ~= v then + OvaleOptions.db.profile.source = v + OvaleOptions:SendMessage("Ovale_ScriptChanged") + end + end, + }, code = { order = 1, type = "input", multiline = 15, name = L["Code"], + width = "full", + disabled = function() + return OvaleOptions.db.profile.source ~= "custom" + end, get = function(info) - return strgsub(OvaleOptions.db.profile.code, "\t", " ") + local source = OvaleOptions.db.profile.source + local code = OvaleScripts.script[OvaleData.className][source].code + return strgsub(code, "\t", " ") end, - set = function(info,v) + set = function(info, v) + OvaleScripts:RegisterScript(OvaleData.className, "custom", "Custom script", v) OvaleOptions.db.profile.code = v - self:SendMessage("Ovale_ScriptChanged") + OvaleOptions:SendMessage("Ovale_ScriptChanged") end, - width = "full" }, - restore = + copy = { order = 2, type = "execute", - name = L["Restaurer le défaut"], + name = "Copy to Custom script", disabled = function() - return OvaleOptions.db.profile.code == OvaleOptions.db.defaults.profile.code + return OvaleOptions.db.profile.source == "custom" + end, + confirm = function() + return "Overwrite existing Custom script?" end, func = function() - OvaleOptions.db.profile.code = OvaleOptions.db.defaults.profile.code - self:SendMessage("Ovale_ScriptChanged") + local class = OvaleData.className + local source = OvaleOptions.db.profile.source + local code = OvaleScripts.script[class][source].code + OvaleScripts.script[class]["custom"].code = code + OvaleOptions.db.profile.source = "custom" + OvaleOptions.db.profile.code = code + OvaleOptions:SendMessage("Ovale_ScriptChanged") end, } } @@ -480,13 +513,13 @@ local options = -- function OvaleOptions:OnInitialize() - local localizedClass, englishClass = UnitClass("player") self.db = LibStub("AceDB-3.0"):New("OvaleDB", { profile = { display = true, - code = Ovale.defaut[englishClass], + source = "Ovale", + code = "", left = 500, top = 500, check = {}, @@ -499,7 +532,7 @@ function OvaleOptions:OnInitialize() optionsAlpha = 1, updateInterval=0.1} } }) - + options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db) AceConfig:RegisterOptionsTable("Ovale", options.args.code) AceConfig:RegisterOptionsTable("Ovale Actions", options.args.actions, "Ovale") @@ -511,19 +544,18 @@ function OvaleOptions:OnInitialize() AceConfigDialog:AddToBlizOptions("Ovale Profile", "Profile", "Ovale") AceConfigDialog:AddToBlizOptions("Ovale Apparence", "Apparence", "Ovale") AceConfigDialog:AddToBlizOptions("Ovale Debug", "Debug", "Ovale") - + self.db.RegisterCallback( self, "OnNewProfile", "HandleProfileChanges" ) self.db.RegisterCallback( self, "OnProfileReset", "HandleProfileChanges" ) self.db.RegisterCallback( self, "OnProfileChanged", "HandleProfileChanges" ) self.db.RegisterCallback( self, "OnProfileCopied", "HandleProfileChanges" ) - + + OvaleScripts:RegisterScript(OvaleData.className, "custom", "Custom script", self.db.profile.code) self:HandleProfileChanges() end function OvaleOptions:HandleProfileChanges() - if self.db.profile.code then - self:SendMessage("Ovale_ScriptChanged") - end + self:SendMessage("Ovale_ScriptChanged") end function OvaleOptions:GetProfile() diff --git a/OvaleScripts.lua b/OvaleScripts.lua new file mode 100644 index 0000000..5515190 --- /dev/null +++ b/OvaleScripts.lua @@ -0,0 +1,60 @@ +--[[-------------------------------------------------------------------- + Ovale Spell Priority + Copyright (C) 2013 Johnny C. Lam + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License in the LICENSE + file accompanying this program. +--]]-------------------------------------------------------------------- + +-- This addon is a script repository. + +local _, Ovale = ... +OvaleScripts = Ovale:NewModule("OvaleScripts") + +-- +-- + +-- +-- Table of default class scripts, indexed by class tokens. +OvaleScripts.script = { + DEATHKNIGHT = {}, + DRUID = {}, + HUNTER = {}, + MAGE = {}, + MONK = {}, + PALADIN = {}, + PRIEST = {}, + ROGUE = {}, + SHAMAN = {}, + WARLOCK = {}, + WARRIOR = {}, +} +-- + +-- +-- Return a table of script descriptions indexed by source. +function OvaleScripts:GetDescriptions() + local descriptionsTable = {} + for src, tbl in pairs(self.script[OvaleData.className]) do + descriptionsTable[src] = tbl.desc + end + return descriptionsTable +end + +function OvaleScripts:RegisterScript(class, source, description, code) + -- Default values for description and code. + description = description or source + code = code or "" + + if not self.script[class][source] then + self.script[class][source] = {} + end + self.script[class][source].desc = description + self.script[class][source].code = code +end + +function OvaleScripts:UnregisterScript(class, source) + self.script[class][source] = nil +end +-- \ No newline at end of file diff --git a/defaut/Chaman.lua b/defaut/Chaman.lua index 1b68fe8..0e0a38f 100644 --- a/defaut/Chaman.lua +++ b/defaut/Chaman.lua @@ -1,4 +1,5 @@ -Ovale.defaut["SHAMAN"] = [[Define(ancestral_swiftness 16188) +local code = [[ +Define(ancestral_swiftness 16188) SpellInfo(ancestral_swiftness cd=90 ) SpellAddBuff(ancestral_swiftness ancestral_swiftness=1) Define(ascendance 114049) @@ -210,4 +211,6 @@ AddIcon mastery=2 help=cd Spell(spiritwalkers_grace) } -]] \ No newline at end of file +]] + +OvaleScripts:RegisterScript("SHAMAN", "Ovale", "[5.1] Ovale: Elemental, Enhancement", code) diff --git a/defaut/Chasseur.lua b/defaut/Chasseur.lua index c9a78e2..3404424 100644 --- a/defaut/Chasseur.lua +++ b/defaut/Chasseur.lua @@ -1,4 +1,5 @@ -Ovale.defaut["HUNTER"] = [[Define(a_murder_of_crows 131900) +local code = [[ +Define(a_murder_of_crows 131900) Define(aimed_shot 19434) SpellInfo(aimed_shot focus=50 ) Define(arcane_shot 3044) @@ -237,4 +238,6 @@ AddIcon mastery=3 help=cd if not BuffPresent(rapid_fire) Spell(rapid_fire) if BuffPresent(rapid_fire) Spell(readiness) } -]] \ No newline at end of file +]] + +OvaleScripts:RegisterScript("HUNTER", "Ovale", "[5.1] Ovale: Beast Mastery, Marksmanship, Survival", code) diff --git a/defaut/Chevalier.lua b/defaut/Chevalier.lua index df57625..39576b8 100644 --- a/defaut/Chevalier.lua +++ b/defaut/Chevalier.lua @@ -1,4 +1,5 @@ -Ovale.defaut["DEATHKNIGHT"] = [[Define(army_of_the_dead 42650) +local code = [[ +Define(army_of_the_dead 42650) SpellInfo(army_of_the_dead duration=4 frost=1 blood=1 unholy=1 runicpower=-300 cd=600 ) SpellAddBuff(army_of_the_dead army_of_the_dead=1) Define(blood_charge 114851) @@ -184,4 +185,6 @@ AddIcon mastery=3 help=cd Spell(summon_gargoyle) Spell(empower_rune_weapon) } -]] \ No newline at end of file +]] + +OvaleScripts:RegisterScript("DEATHKNIGHT", "Ovale", "[5.1] Ovale: Frost, Unholy", code) diff --git a/defaut/Demoniste.lua b/defaut/Demoniste.lua index 83fbfc4..2eaf384 100644 --- a/defaut/Demoniste.lua +++ b/defaut/Demoniste.lua @@ -1,4 +1,5 @@ -Ovale.defaut["WARLOCK"] = [[Define(agony 980) +local code = [[ +Define(agony 980) SpellInfo(agony duration=24 tick=2 ) SpellAddTargetDebuff(agony agony=1) Define(backdraft 117896) @@ -286,4 +287,6 @@ AddIcon mastery=3 help=cd Spell(dark_soul) Spell(summon_doomguard) } -]] \ No newline at end of file +]] + +OvaleScripts:RegisterScript("WARLOCK", "Ovale", "[5.1] Ovale: Affliction, Demonology, Destruction", code) diff --git a/defaut/Druide.lua b/defaut/Druide.lua index 829c11a..ef3823e 100644 --- a/defaut/Druide.lua +++ b/defaut/Druide.lua @@ -1,4 +1,5 @@ -Ovale.defaut["DRUID"] = [[Define(berserk 50334) +local code = [[ +Define(berserk 50334) SpellInfo(berserk duration=10 cd=180 ) SpellAddBuff(berserk berserk=1) Define(berserking 26297) @@ -270,4 +271,6 @@ AddIcon mastery=2 help=cd { Item(Trinket0Slot usable=1) Item(Trinket1Slot usable=1) } if BuffPresent(tigers_fury) or {target.DeadIn() <18 and SpellCooldown(tigers_fury) >6 } Spell(berserk) } -]] \ No newline at end of file +]] + +OvaleScripts:RegisterScript("DRUID", "Ovale", "[5.1] Ovale: Balance, Feral", code) diff --git a/defaut/Guerrier.lua b/defaut/Guerrier.lua index 44ac578..4724759 100644 --- a/defaut/Guerrier.lua +++ b/defaut/Guerrier.lua @@ -1,4 +1,5 @@ -Ovale.defaut["WARRIOR"] = [[Define(avatar 107574) +local code = [[ +Define(avatar 107574) SpellInfo(avatar duration=24 cd=180 ) SpellAddBuff(avatar avatar=1) Define(battle_shout 6673) @@ -272,4 +273,6 @@ AddIcon mastery=3 help=cd if BuffExpires(shield_block_aura) Spell(shield_wall) { Item(Trinket0Slot usable=1) Item(Trinket1Slot usable=1) } } -]] \ No newline at end of file +]] + +OvaleScripts:RegisterScript("WARRIOR", "Ovale", "[5.1] Ovale: Arms, Fury, Protection", code) diff --git a/defaut/Mage.lua b/defaut/Mage.lua index 52dcc43..5887fa1 100644 --- a/defaut/Mage.lua +++ b/defaut/Mage.lua @@ -1,4 +1,5 @@ -Ovale.defaut["MAGE"] = [[Define(alter_time 110909) +local code = [[ +Define(alter_time 110909) SpellInfo(alter_time duration=6 ) SpellAddBuff(alter_time alter_time=1) Define(alter_time_activate 108978) @@ -246,4 +247,6 @@ AddIcon mastery=3 help=cd if BuffExpires(invokers_energy) and BuffExpires(alter_time) Spell(evocation) if BuffRemains(invokers_energy) >10 and BuffExpires(alter_time) and ManaPercent() >28 Spell(berserking) } -]] \ No newline at end of file +]] + +OvaleScripts:RegisterScript("MAGE", "Ovale", "[5.1] Ovale: Arcane, Fire, Frost", code) diff --git a/defaut/Moine.lua b/defaut/Moine.lua index 25a2ce4..b634413 100644 --- a/defaut/Moine.lua +++ b/defaut/Moine.lua @@ -1,4 +1,5 @@ -Ovale.defaut["MONK"] = [[Define(berserking 26297) +local code = [[ +Define(berserking 26297) SpellInfo(berserking duration=10 cd=180 ) SpellAddBuff(berserking berserking=1) Define(blackout_kick 100784) @@ -89,4 +90,6 @@ AddIcon mastery=3 help=cd if TalentPoints(chi_brew_talent) and Chi() ==0 Spell(chi_brew) if TalentPoints(invoke_xuen_talent) Spell(invoke_xuen) } -]] \ No newline at end of file +]] + +OvaleScripts:RegisterScript("MONK", "Ovale", "[5.1] Ovale: Windwalker", code) diff --git a/defaut/Paladin.lua b/defaut/Paladin.lua index 4f5e562..36de9d6 100644 --- a/defaut/Paladin.lua +++ b/defaut/Paladin.lua @@ -1,4 +1,5 @@ -Ovale.defaut["PALADIN"] = [[Define(avenging_wrath 31884) +local code = [[ +Define(avenging_wrath 31884) SpellInfo(avenging_wrath duration=20 cd=180 ) SpellAddBuff(avenging_wrath avenging_wrath=1) Define(blessing_of_kings 20217) @@ -68,4 +69,6 @@ AddIcon mastery=3 help=cd if BuffPresent(avenging_wrath) Spell(guardian_of_ancient_kings) if BuffPresent(inquisition) { Item(Trinket0Slot usable=1) Item(Trinket1Slot usable=1) } } -]] \ No newline at end of file +]] + +OvaleScripts:RegisterScript("PALADIN", "Ovale", "[5.1] Ovale: Retribution", code) diff --git a/defaut/Pretre.lua b/defaut/Pretre.lua index 728ef5a..2a95728 100644 --- a/defaut/Pretre.lua +++ b/defaut/Pretre.lua @@ -1,4 +1,5 @@ -Ovale.defaut["PRIEST"] = [[Define(berserking 26297) +local code = [[ +Define(berserking 26297) SpellInfo(berserking duration=10 cd=180 ) SpellAddBuff(berserking berserking=1) Define(cascade 120785) @@ -115,4 +116,6 @@ AddIcon mastery=3 help=cd if ShadowOrbs() ==3 and Health() <=40 Spell(vampiric_embrace) Spell(dispersion) } -]] \ No newline at end of file +]] + +OvaleScripts:RegisterScript("PRIEST", "Ovale", "[5.1] Ovale: Shadow", code) diff --git a/defaut/Voleur.lua b/defaut/Voleur.lua index b3bc6b4..16bf67b 100644 --- a/defaut/Voleur.lua +++ b/defaut/Voleur.lua @@ -1,4 +1,5 @@ -Ovale.defaut["ROGUE"] = [[Define(adrenaline_rush 13750) +local code = [[ +Define(adrenaline_rush 13750) SpellInfo(adrenaline_rush duration=15 cd=180 ) SpellAddBuff(adrenaline_rush adrenaline_rush=1) Define(ambush 8676) @@ -197,4 +198,6 @@ AddIcon mastery=3 help=cd if BuffPresent(shadow_dance) Spell(berserking) if TimeInCombat() >10 and Energy() >=45 and Energy() <=75 and ComboPoints() <=3 and not BuffPresent(shadow_dance) and not BuffPresent(master_of_subtlety) and not target.DebuffPresent(find_weakness) Spell(vanish) } -]] \ No newline at end of file +]] + +OvaleScripts:RegisterScript("ROGUE", "Ovale", "[5.1] Ovale: Assassination, Combat, Subtlety", code) -- 1.7.9.5