Mercurial > wow > breuesk
changeset 43:4109683c3172
Kept AceConsole embedded - it handily disables the chat commands when the addon is disabled
Did a little passthrough to properly set the self param for commands like Print()
author | John@Yosemite-PC |
---|---|
date | Thu, 15 Mar 2012 22:27:51 -0400 |
parents | 72055fc7e115 |
children | 8913e7d79cad |
files | Core.lua Gui.lua Lists.lua Options.lua |
diffstat | 4 files changed, 60 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/Core.lua Thu Mar 15 08:47:41 2012 -0400 +++ b/Core.lua Thu Mar 15 22:27:51 2012 -0400 @@ -22,7 +22,8 @@ local strsplit=strsplit local string=string local sformat=string.format -local bsk = LibStub("AceAddon-3.0"):NewAddon("bsk","AceConsole-3.0", "AceHook-3.0", "AceComm-3.0", "AceSerializer-3.0") +local bsk = LibStub("AceAddon-3.0"):NewAddon("bsk","AceConsole-3.0") +-- "AceHook-3.0", "AceComm-3.0", "AceSerializer-3.0" _G.bsk=bsk local L = LibStub("AceLocale-3.0"):GetLocale("bsk", false) setfenv(1,bsk) @@ -37,12 +38,22 @@ -- 4) table.remove() works ok if reverse iterating, terrible at anything else -- 5) pairs() does not have a guaranteed iteration order +-- These two functions properly format the call to AceConsole:Print(), which +-- needs a full object. Calling "Print" will call the mixed-in console functions +-- but without a self parameter because of the namespacing. I would disembed +-- console, except that it has handy OnDisable behavior to disable chat +-- commands. +function print(...) + bsk:Print(...) +end +function printf(...) + bsk:Printf(...) +end function OnInitialize() db = _G.LibStub("AceDB-3.0"):New("BskDB", defaults, "Default") - bsk:Print("Totally libstubbed a db") options.args.profile = _G.LibStub("AceDBOptions-3.0"):GetOptionsTable(db) _G.LibStub("AceConfig-3.0"):RegisterOptionsTable("bsk", options) @@ -54,7 +65,7 @@ function OnEnable() CreateWorkingStateFromChanges(db.profile.changes) - CreateGUI() + --CreateGUI() end function HandleCommand(paramIn) @@ -67,7 +78,7 @@ end if param[1] == nil or param[1] == "" then - bsk:Print("need args") + print("need args") return end if param[1] == "persons" then @@ -92,7 +103,7 @@ local person = FixPersonName(param[3]) RemovePerson(person) else - bsk:Print(sformat("Deleting anything of type %s is not supported",param[2])) + printf("Deleting anything of type %s is not supported",param[2]) end elseif param[1] == "nuke" then if param[2] == nil or param[2] == "" then
--- a/Gui.lua Thu Mar 15 08:47:41 2012 -0400 +++ b/Gui.lua Thu Mar 15 22:27:51 2012 -0400 @@ -143,10 +143,10 @@ --pulldown:SetFullHeight(true) --pulldown:SetAutoAdjustHeight(false) - --pulldown:SetCallback("OnGroupSelected", function(widget,_,uniquevalue) bsk:Print("OGS: uniquevalue: "..uniquevalue) + --pulldown:SetCallback("OnGroupSelected", function(widget,_,uniquevalue) print("OGS: uniquevalue: "..uniquevalue) --end) - --pulldown:SetCallback("OnClick", function(widget,_,uniquevalue) bsk:Print("Onclick: uniquevalue: " .. uniquevalue) end) - --pulldown:SetCallback("OnButtonEnter", function(widget,_,value) bsk:Print("OnButtonEnter: value: " .. value) end) + --pulldown:SetCallback("OnClick", function(widget,_,uniquevalue) print("Onclick: uniquevalue: " .. uniquevalue) end) + --pulldown:SetCallback("OnButtonEnter", function(widget,_,value) print("OnButtonEnter: value: " .. value) end) end @@ -217,7 +217,7 @@ --local btn = AceGUI:Create("Button") --btn:SetWidth(170) --btn:SetText("Button !") - --btn:SetCallback("OnClick", function() bsk:print("Click!") end) + --btn:SetCallback("OnClick", function() Print("Click!") end) -- Add the button to the container --frame:AddChild(btn) end
--- a/Lists.lua Thu Mar 15 08:47:41 2012 -0400 +++ b/Lists.lua Thu Mar 15 22:27:51 2012 -0400 @@ -124,9 +124,9 @@ -- Debugging {{{ function PrettyPrintList(listIndex) local list = lists[listIndex] - bsk:Print("List: " .. list.name .. " (" .. listIndex .. ") - last modified " .. date("%m/%d/%y %H:%M:%S", list.time) .. " (",list.time,")" ) + print("List: " .. list.name .. " (" .. listIndex .. ") - last modified " .. date("%m/%d/%y %H:%M:%S", list.time) .. " (",list.time,")" ) for i = 1,#list do - bsk:Print(" " .. i .. " - " .. persons[list[i].id].main) + print(" " .. i .. " - " .. persons[list[i].id].main) end end function PrettyPrintLists() @@ -146,40 +146,40 @@ function PrintAPI(object) for i,v in pairs(object) do if type(v) == "function" then - bsk:Print("function "..i.."()") + print("function "..i.."()") end end end function PrintTable(table, depth) depth = depth or "" if not table then return end - if #depth > 3*5 then bsk:Print(depth.."Recursion too deep - stopping"); return end + if #depth > 3*5 then print(depth.."Recursion too deep - stopping"); return end for i,v in pairs(table) do if( type(v) == "string" ) then - bsk:Print(depth .. i .. " - " .. v) + print(depth .. i .. " - " .. v) elseif( type(v) == "number" ) then - bsk:Print(depth .. i .. " - " .. tostring(v)) + print(depth .. i .. " - " .. tostring(v)) elseif( type(v) == "table" ) then - bsk:Print(depth .. i .." - ") + print(depth .. i .." - ") PrintTable(v,depth.." ") elseif( type(v) == "boolean" ) then - bsk:Print(depth .. i .. " - " .. tostring(v)) + print(depth .. i .. " - " .. tostring(v)) elseif( type(v) == "function" ) then - bsk:Print(depth .. "function " .. i .. "()") + print(depth .. "function " .. i .. "()") else - bsk:Print(depth .. i .. " - not sure how to print type: " .. type(v) ) + print(depth .. i .. " - not sure how to print type: " .. type(v) ) end end end function PrintRaidAndReserve() - bsk:Print("RaidNameP") + print("RaidNameP") PrintTable(raidNameP) - bsk:Print("RaidIdP") + print("RaidIdP") PrintTable(raidIdP) - bsk:Print("ReserveP") + print("ReserveP") PrintTable(reserveIdP) - bsk:Print("personName2id") + print("personName2id") PrintTable(personName2id) end --}}} @@ -192,7 +192,7 @@ end end --- Czohange processing {{{ +-- Change processing {{{ function CreateWorkingStateFromChanges(changes) local personsBase = db.profile.persons local lists = db.profile.lists @@ -261,7 +261,7 @@ elseif change.action == "SuicidePerson" then DoSuicidePerson(change) else - bsk:Print("Unknown message encountered") + print("Unknown message encountered") PrintTable(change) assert(false) end @@ -335,20 +335,20 @@ local guid = _G.UnitGUID(name) -- TODO: check guid to be sure it's a player if not guid then - bsk:Print(sformat("Could not add player %s - they must be in range or group",name)) + printf("Could not add player %s - they must be in range or group",name) return end local _,englishClass = _G.UnitClass(name) - --bsk:Print("Person " .. name .. " is class " .. englishClass) + --print("Person " .. name .. " is class " .. englishClass) local id = string.sub(guid,6) -- skip at least 0x0580 ... id = id:gsub("^0*(.*)","%1") -- nom all leading zeroes remaining if persons[id] and persons[id] ~= name then - bsk:Print(sformat("Namechange detected for %s - new is %s, please rename the existing entry", persons[id].main, name)) + printf("Namechange detected for %s - new is %s, please rename the existing entry", persons[id].main, name) return end if persons[id] ~= nil then - bsk:Print(sformat("%s is already in the persons list; disregarding", name)) + printf("%s is already in the persons list; disregarding", name) return end local change = {action="AddPerson",arg={name=name,id=id,class=englishClass}} @@ -358,7 +358,7 @@ end--}}} function DoCreateList(change)--{{{ --if GetListIndex(change.arg.name) then - -- bsk:Print(sformat("List %s already exists",v.name)) + -- rintf(("List %s already exists",v.name) -- return false --end lists[change.arg.id]={name=change.arg.name,time=change.time} @@ -369,7 +369,7 @@ local change={action="CreateList",arg={name=name}} StartChange(change) change.arg.id=change.time -- use the creation timestamp as the list's index. it's as unique as anything... - bsk:Print("Creating ... " .. name) + print("Creating ... " .. name) if DoCreateList(change) then CommitChange(change) end @@ -395,10 +395,10 @@ local listIndex = GetListIndex(listName) local id = personName2id[name] if IdIsInList(id,lists[listIndex]) then - bsk:Print(sformat("Person %s is already on the reqeuested list",name)) + printf("Person %s is already on the reqeuested list",name) return false end - bsk:Print(sformat("Adding %s (%s) to list %s (%s)", name, id, listName, listIndex)) + printf("Adding %s (%s) to list %s (%s)", name, id, listName, listIndex) local change = {action="AddToListEnd",arg={id=id,listIndex=listIndex}} StartChange(change) if DoAddPersonToListEnd(change) then @@ -419,16 +419,16 @@ -- require admin local listIndex = GetListIndex(listName) if lists[listIndex].closedRandom then - bsk:Print("Cannot add person to list by random roll because an add-to-end operation has already occurred") + print("Cannot add person to list by random roll because an add-to-end operation has already occurred") return false end local id = personName2id[name] if IdIsInList(id,lists[listIndex]) then - bsk:Print(sformat("Person %s is already on the reqeuested list",name)) + printf("Person %s is already on the reqeuested list",name) return false end local roll = math.random() - bsk:Print(sformat("Adding %s (%s) to list %s (%s) with roll (%f)", name, id, listName, listIndex, roll)) + printf("Adding %s (%s) to list %s (%s) with roll (%f)", name, id, listName, listIndex, roll) local change = {action="AddToListRand",arg={id=id,listIndex=listIndex,roll=roll}} StartChange(change) if DoAddPersonToListRandom(change) then @@ -445,7 +445,7 @@ function RemovePerson(name)--{{{ local id = personName2id[name] if not id then - bsk:Print(sformat("%s is not in the persons list, please check your spelling", name)) + printf("%s is not in the persons list, please check your spelling", name) return false end local listsTheyreOn = {} @@ -457,7 +457,7 @@ end end if getn(listsTheyreOn) > 0 then - bsk:Print(sformat("Cannot remove person %s because they are on one or more lists (%s)",name,table.concat(listsTheyreOn,", "))) + printf("Cannot remove person %s because they are on one or more lists (%s)",name,table.concat(listsTheyreOn,", ")) return false end local change = {action="RemovePerson",arg={id=id}} @@ -476,7 +476,7 @@ local replacement = shallowCopy(change.arg.affect) local temp = table.remove(replacement,1) -- pop tinsert(replacement,temp) -- push_back - --bsk:Print(sformat("Before suicide of %s on list %s",slist[1],list.name)) + --rintf(("Before suicide of %s on list %s",slist[1],list.name) --PrintTable(list) for i = 1, #list do if list[i].id == affected[1] then @@ -555,7 +555,7 @@ function TrimLists(time) if not CheckListCausality() then - bsk:Print("Unable to trim changelist due to violated causality") + print("Unable to trim changelist due to violated causality") return false end @@ -595,7 +595,7 @@ end for name,_ in pairs(raidNameP) do if personName2id[name] == nil then - bsk:Print(sformat("Person %s is missing from the persons list - adding",name)) + printf("Person %s is missing from the persons list - adding",name) AddPerson(name) end end @@ -644,7 +644,7 @@ -- reserves function AddReserve(name) - bsk:Print("Reserving" .. name) + print("Reserving" .. name) reserveIdP[personName2id[name]]=true -- TODO: communicate to others. don't store this in any way. end @@ -711,7 +711,7 @@ function GetSuicideList(id,list) - --bsk:Print("Calculating changeset for "..name.." from list -") + --print("Calculating changeset for "..name.." from list -") --PrintTable(list) local t = {} local ret = {} @@ -724,9 +724,9 @@ tinsert(ret,list[i].id) end end - --bsk:Print("GSL") + --print("GSL") --PrintTable(ret) - --bsk:Print("GSL") + --print("GSL") return ret end
--- a/Options.lua Thu Mar 15 08:47:41 2012 -0400 +++ b/Options.lua Thu Mar 15 22:27:51 2012 -0400 @@ -1,3 +1,5 @@ +--local bsk = bsk +--local _G=_G setfenv(1,bsk) options = { name= 'bsk', @@ -9,7 +11,7 @@ type = "execute", name = "Version query", desc = "Check others' versions", - func = function(self) bsk:Print("TODO") end - } + func = function(self) print("TODO") end + } } }