Quantcast

Merge branch 'master' into mop

F16Gaming (Laptop) [04-02-12 - 09:47]
Merge branch 'master' into mop
Filename
AddonComm.lua
ChatManager.lua
Command.lua
CommandManager.lua
EventHandler.lua
Events.lua
LocaleManager.lua
Logger.lua
LootManager.lua
PlayerManager.lua
QueueManager.lua
RollManager.lua
diff --git a/AddonComm.lua b/AddonComm.lua
index f7477e9..6aca5bc 100644
--- a/AddonComm.lua
+++ b/AddonComm.lua
@@ -19,10 +19,7 @@

 local C = Command

-local function L(k)
-	return C.LocaleManager:GetActive()[k]
-end
-
+local L = C.LocaleManager
 local GT = C.GroupTools
 local CES = C.Extensions.String
 local CET = C.Extensions.Table
diff --git a/ChatManager.lua b/ChatManager.lua
index faeb7bc..a631d0b 100644
--- a/ChatManager.lua
+++ b/ChatManager.lua
@@ -181,7 +181,7 @@ function CM:HandleMessage(msg, sender, channel, target, sourceChannel, isBN, pID
 	local cmd = self:ParseCommand(args[1])
 	if not CCM:HasCommand(cmd) then return end
 	if not AC:IsController(sourceChannel) then
-		C.Logger:Normal(L:GetActive()["CHAT_HANDLE_NOTCONTROLLER"]:format(sourceChannel:lower()))
+		C.Logger:Normal(L("CHAT_HANDLE_NOTCONTROLLER"):format(sourceChannel:lower()))
 		return
 	end
 	local t = {}
@@ -191,7 +191,6 @@ function CM:HandleMessage(msg, sender, channel, target, sourceChannel, isBN, pID
 		end
 	end
 	local player = PM:GetOrCreatePlayer(sender)
-	--local result, err = CCM:HandleCommand(cmd, t, true, player)
 	local result, arg, errArg = CCM:HandleCommand(cmd, t, sourceChannel, player)
 	if isBN then
 		target = pID
@@ -207,7 +206,7 @@ function CM:HandleMessage(msg, sender, channel, target, sourceChannel, isBN, pID
 		if type(result) == "table" then
 			for _,v in ipairs(result) do
 				if type(v) == "table" then
-					local s = v[1]
+					local s = l[v[1]]
 					if type(v[2]) == "table" then
 						s = s:format(unpack(v[2]))
 					end
diff --git a/Command.lua b/Command.lua
index 04992a1..f89a81a 100644
--- a/Command.lua
+++ b/Command.lua
@@ -44,7 +44,6 @@ Command = {

 local C = Command
 local L
-local GetL
 local Cmd
 local CM
 local PM
@@ -66,8 +65,7 @@ function C:Init()
 	AC = self.AddonComm
 	log = self.Logger
 	self:LoadSavedVars()
-	GetL = function(k) return L:GetActive()[k] end
-	log:Normal(GetL("ADDON_LOAD"))
+	log:Normal(L("ADDON_LOAD"))
 	self.Loaded = true
 end

@@ -79,7 +77,7 @@ function C:LoadSavedVars()
 		_G["COMMAND"] = {}
 	elseif type(_G["COMMAND"]["VERSION"]) == "number" then
 		if _G["COMMAND"]["VERSION"] < self.VarVersion then
-			log:Normal(GetL("SVARS_OUTDATED"))
+			log:Normal(L("SVARS_OUTDATED"))
 			wipe(_G["COMMAND"])
 			_G["COMMAND"] = {}
 		end
@@ -115,7 +113,7 @@ function C:CheckVersion(ver)
 	if self.VersionChecked then return end
 	ver = ver or 0
 	if ver > self.VersionNum then
-		log:Normal(GetL("NEWVERSION_NOTICE"):format(self.Name))
+		log:Normal(L("NEWVERSION_NOTICE"):format(self.Name))
 		self.VersionChecked = true
 	end
 end
diff --git a/CommandManager.lua b/CommandManager.lua
index 26af309..8649d3b 100644
--- a/CommandManager.lua
+++ b/CommandManager.lua
@@ -135,7 +135,7 @@ end
 -- @return Error message if not successful, otherwise nil.
 --
 function CM:HandleCommand(command, args, isChat, player)
-	command = command:lower()
+	command = tostring(command):lower()
 	local cmd = self:GetCommand(command)
 	if cmd then
 		if isChat then
@@ -747,7 +747,6 @@ SlashCmdList[C.Name:upper()] = function(msg, editBox)
 			table.insert(t, args[i])
 		end
 	end
-	--local result, err = CM:HandleCommand(cmd, t, false, PM:GetOrCreatePlayer(UnitName("player")))
 	local result, arg, errArg = CM:HandleCommand(cmd, t, false, PM:GetOrCreatePlayer(UnitName("player")))
 	local l = L:GetActive()
 	if result then
@@ -775,17 +774,4 @@ SlashCmdList[C.Name:upper()] = function(msg, editBox)
 	else
 		C.Logger:Error(tostring(err))
 	end
-	--[[ PRE-Locale code
-	if result then
-		if type(result) == "table" then
-			for _,v in ipairs(result) do
-				C.Logger:Normal(tostring(v))
-			end
-		else
-			C.Logger:Normal(tostring(result))
-		end
-	else
-		C.Logger:Error(tostring(err))
-	end
-	-- END PRE-Locale code ]]
 end
diff --git a/EventHandler.lua b/EventHandler.lua
index c88e81e..a28c2e9 100644
--- a/EventHandler.lua
+++ b/EventHandler.lua
@@ -18,7 +18,6 @@
 --]]

 local C = Command
-local L = C.LocaleManager
 local CES = C.Extensions.String

 --- Handles events.
diff --git a/Events.lua b/Events.lua
index 60cc013..4ae0f1b 100644
--- a/Events.lua
+++ b/Events.lua
@@ -19,7 +19,7 @@

 local C = Command

-local L = function(k) return C.LocaleManager:GetActive()[k] end
+local L = C.LocaleManager
 local CM = C.ChatManager
 local QM = C.QueueManager
 local AC = C.AddonComm
diff --git a/LocaleManager.lua b/LocaleManager.lua
index ee0aff6..8be3937 100644
--- a/LocaleManager.lua
+++ b/LocaleManager.lua
@@ -31,16 +31,31 @@ C.LocaleManager = {

 local LM = C.LocaleManager

-local function l_index(t, k) -- Wait with metatable stuff til we know everything else works properly :P
-	local master = LM:GetMaster()[k]
-	if master then return master end
-	return ("%%%s%%"):format(k)
+local function l_index(self, k)
+	k = tostring(k):upper()
+	master = LM:GetMaster()
+	if self == master then -- Prevent recursion
+		return ("%%%s%%"):format(k)
+	end
+	local val = master[k]
+	if val then return val end
 end

+local s_meta = {
+	__call = function(self, arg1, arg2, isPlr)
+		if not arg1 then return nil end
+		if arg2 then -- (locale, key)
+			return self:GetLocale(tostring(arg1), isPlr)[tostring(arg2):upper()]
+		end
+		arg1 = tostring(arg1):upper()
+		return self:GetActive()[arg1]
+	end
+}
+
 -- Initialize LocaleManager
 function LM:Init()
 	if self.Active == "enGB" then self.Active = "enUS" end
-	--setmetatable(self.Locales, {__index = function(t, k) error("FATAL: __index meta LocaleManager.Locales report to addon author.") end})
+	setmetatable(self, s_meta)
 	self:LoadSavedVars()
 end

@@ -72,7 +87,7 @@ function LM:Register(locale, localeTable)
 			self.Locales[locale][k] = v
 		end
 	end
-	--setmetatable(self.Locales[locale], {__index = l_index})
+	setmetatable(self.Locales[locale], {__index = l_index})
 end

 -- Check if a locale has been loaded/registered
diff --git a/Logger.lua b/Logger.lua
index f2647f4..ba14fe2 100644
--- a/Logger.lua
+++ b/Logger.lua
@@ -1 +1 @@
---[[
	* Copyright (c) 2011-2012 by Adam Hellberg.
	* 
	* This file is part of Command.
	* 
	* Command is free software: you can redistribute it and/or modify
	* it under the terms of the GNU General Public License as published by
	* the Free Software Foundation, either version 3 of the License, or
	* (at your option) any later version.
	* 
	* Command is distributed in the hope that it will be useful,
	* but WITHOUT ANY WARRANTY; without even the implied warranty of
	* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	* GNU General Public License for more details.
	* 
	* You should have received a copy of the GNU General Public License
	* along with Command. If not, see <http://www.gnu.org/licenses/>.
--]]

local C = Command

--- Table containing all Logger methods.
-- This is referenced "Logger" in Logger.lua.
-- @name Command.Logger
-- @class table
-- @field Level Table containing all logger levels.
-- @field Settings Table containing all settings specific to Logger.
--
C.Logger = {
	Level = {
		Debug = 0,
		Normal = 1,
		Warning = 2,
		Error = 3
	},
	Settings = {
		Debug = false,
		Format = "%s%s: %s",
	}
}

local Logger = C.Logger
local L = function(k) return C.LocaleManager:GetActive()[k] end

------------------------
-- MAIN LOGGER MODULE --
------------------------

--- Print a log message at the specified level.
-- @param msg Message to pring.
-- @param level One of the levels defined in Logger.Level.
--
function Logger:Print(msg, level)
	local prefix
	if level == self.Level.Debug then
		if not self.Settings.Debug then return end
		prefix = L("LOGGER_PREFIX_DEBUG")
	elseif level == self.Level.Normal then
		prefix = L("LOGGER_PREFIX_NORMAL")
	elseif level == self.Level.Warning then
		prefix = L("LOGGER_PREFIX_WARNING")
	elseif level == self.Level.Error then
		prefix = L("LOGGER_PREFIX_ERROR")
	else
		error(L("LOGGER_ERR_UNDEFINED"):format(tostring(level)))
		return
	end
	DEFAULT_CHAT_FRAME:AddMessage(self.Settings.Format:format(L("LOGGER_PREFIX_MAIN"):format(C.Name), prefix, msg))
end

--- Print a debug message.
-- @param msg Message to print.
--
function Logger:Debug(msg)
	self:Print(msg, self.Level.Debug)
end

--- Print a normal message
-- @param msg Message to print.
--
function Logger:Normal(msg)
	self:Print(msg, self.Level.Normal)
end

--- Print a warning message.
-- @param msg Message to pring.
--
function Logger:Warning(msg)
	self:Print(msg, self.Level.Warning)
end

--- Print an error message.
-- @param msg Message to print.
--
function Logger:Error(msg)
	self:Print(msg, self.Level.Error)
end


--- Control the debug state.
-- Setting debugging to enabled will enable debug messages to be printed.
-- @param enabled Boolean indicating enabled or disabled state.
--
function Logger:SetDebug(enabled)
	self.Settings.Debug = enabled
end

--- Enable debugging.
--
function Logger:EnableDebug()
	self:SetDebug(true)
end

--- Disable debugging.
--
function Logger:DisableDebug()
	self:SetDebug(false)
end

--- Toggle debugging.
--
function Logger:ToggleDebug()
	self:SetDebug(not self.Settings.Debug)
end
\ No newline at end of file
+--[[
	* Copyright (c) 2011-2012 by Adam Hellberg.
	* 
	* This file is part of Command.
	* 
	* Command is free software: you can redistribute it and/or modify
	* it under the terms of the GNU General Public License as published by
	* the Free Software Foundation, either version 3 of the License, or
	* (at your option) any later version.
	* 
	* Command is distributed in the hope that it will be useful,
	* but WITHOUT ANY WARRANTY; without even the implied warranty of
	* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	* GNU General Public License for more details.
	* 
	* You should have received a copy of the GNU General Public License
	* along with Command. If not, see <http://www.gnu.org/licenses/>.
--]]

local C = Command

--- Table containing all Logger methods.
-- This is referenced "Logger" in Logger.lua.
-- @name Command.Logger
-- @class table
-- @field Level Table containing all logger levels.
-- @field Settings Table containing all settings specific to Logger.
--
C.Logger = {
	Level = {
		Debug = 0,
		Normal = 1,
		Warning = 2,
		Error = 3
	},
	Settings = {
		Debug = false,
		Format = "%s%s: %s",
	}
}

local Logger = C.Logger
local L = C.LocaleManager

------------------------
-- MAIN LOGGER MODULE --
------------------------

--- Print a log message at the specified level.
-- @param msg Message to pring.
-- @param level One of the levels defined in Logger.Level.
--
function Logger:Print(msg, level)
	local prefix
	if level == self.Level.Debug then
		if not self.Settings.Debug then return end
		prefix = L("LOGGER_PREFIX_DEBUG")
	elseif level == self.Level.Normal then
		prefix = L("LOGGER_PREFIX_NORMAL")
	elseif level == self.Level.Warning then
		prefix = L("LOGGER_PREFIX_WARNING")
	elseif level == self.Level.Error then
		prefix = L("LOGGER_PREFIX_ERROR")
	else
		error(L("LOGGER_ERR_UNDEFINED"):format(tostring(level)))
		return
	end
	DEFAULT_CHAT_FRAME:AddMessage(self.Settings.Format:format(L("LOGGER_PREFIX_MAIN"):format(C.Name), prefix, msg))
end

--- Print a debug message.
-- @param msg Message to print.
--
function Logger:Debug(msg)
	self:Print(msg, self.Level.Debug)
end

--- Print a normal message
-- @param msg Message to print.
--
function Logger:Normal(msg)
	self:Print(msg, self.Level.Normal)
end

--- Print a warning message.
-- @param msg Message to pring.
--
function Logger:Warning(msg)
	self:Print(msg, self.Level.Warning)
end

--- Print an error message.
-- @param msg Message to print.
--
function Logger:Error(msg)
	self:Print(msg, self.Level.Error)
end


--- Control the debug state.
-- Setting debugging to enabled will enable debug messages to be printed.
-- @param enabled Boolean indicating enabled or disabled state.
--
function Logger:SetDebug(enabled)
	self.Settings.Debug = enabled
end

--- Enable debugging.
--
function Logger:EnableDebug()
	self:SetDebug(true)
end

--- Disable debugging.
--
function Logger:DisableDebug()
	self:SetDebug(false)
end

--- Toggle debugging.
--
function Logger:ToggleDebug()
	self:SetDebug(not self.Settings.Debug)
end
\ No newline at end of file
diff --git a/LootManager.lua b/LootManager.lua
index 1404b8b..29ccedd 100644
--- a/LootManager.lua
+++ b/LootManager.lua
@@ -27,7 +27,7 @@ local C = Command
 C.LootManager = {
 }

-local L = function(k) return C.LocaleManager:GetActive()[k] end
+local L = C.LocaleManager
 local LM = C.LootManager
 local GT = C.GroupTools

diff --git a/PlayerManager.lua b/PlayerManager.lua
index d72b1b6..ea405ac 100644
--- a/PlayerManager.lua
+++ b/PlayerManager.lua
@@ -22,7 +22,6 @@ local MODE_WHITELIST = 1

 local C = Command
 local L = C.LocaleManager
-local GetL = function(k) return L:GetActive()[k] end
 local CM
 local GT = C.GroupTools
 local BNT = C.BattleNetTools
@@ -107,34 +106,34 @@ local function Kick(name, sender, reason)
 		if type(reason) == "string" then
 			local msg
 			if CM.LastChannel == "WHISPER" or CM.LastChannel == "BNET" then
-				msg = L:GetLocale(PM:GetOrCreatePlayer(sender).Settings.Locale, true)["PM_KICK_REASON"]:format(name, sender, reason)
+				msg = L(PM:GetOrCreatePlayer(sender).Settings.Locale, "PM_KICK_REASON", true):format(name, sender, reason)
 			else
-				msg = GetL("PM_KICK_REASON"):format(name, sender, reason)
+				msg = L("PM_KICK_REASON"):format(name, sender, reason)
 			end
 			CM:SendMessage(msg, CM.LastChannel, CM.LastTarget)
 		else
 			local msg
 			if CM.LastChannel == "WHISPER" or CM.LastChannel == "BNET" then
-				msg = L:GetLocale(PM:GetOrCreatePlayer(sender).Settings.Locale, true)["PM_KICK"]:format(name, sender)
+				msg = L(PM:GetOrCreatePlayer(sender).Settings.Locale, "PM_KICK", true):format(name, sender)
 			else
-				msg = GetL("PM_KICK"):format(name, sender)
+				msg = L("PM_KICK"):format(name, sender)
 			end
 			CM:SendMessage(msg, CM.LastChannel, CM.LastTarget)
 		end
 	else
-		local msg = L:GetLocale(PM:GetOrCreatePlayer(sender).Settings.Locale, true)["PM_KICK_NOTIFY"]:format(name)
+		local msg = L(PM:GetOrCreatePlayer(sender).Settings.Locale, "PM_KICK_NOTIFY", true):format(name)
 		CM:SendMessage(msg, "WHISPER", sender)
 	end
-	local msg = L:GetLocale(PM:GetOrCreatePlayer(name).Settings.Locale, true)["PM_KICK_TARGET"]:format(sender)
+	local msg = L(PM:GetOrCreatePlayer(name).Settings.Locale, "PM_KICK_TARGET", true):format(sender)
 	CM:SendMessage(msg, "WHISPER", name)
 end

 local function KickCancelled(name, sender)
 	local msg
 	if CM.LastTarget and (CM.LastChannel == "WHISPER" or CM.LastChannel == "BNET") then
-		msg = L:GetLocale(PM:GetOrCreatePlayer(CM.LastTarget).Settings.Locale, true)["PM_KICK_DENIED"]:format(sender, name)
+		msg = L(PM:GetOrCreatePlayer(CM.LastTarget).Settings.Locale, "PM_KICK_DENIED", true):format(sender, name)
 	else
-		msg = GetL("PM_KICK_DENIED"):format(sender, name)
+		msg = L("PM_KICK_DENIED"):format(sender, name)
 	end
 	CM:SendMessage(msg, CM.LastChannel, CM.LastTarget)
 end
@@ -224,7 +223,7 @@ function PM:GetOrCreatePlayer(name)
 			player.Info.Group = self.Access.Groups.User.Name
 		end
 		Players[player.Info.Name] = player
-		log:Normal(GetL("PM_PLAYER_CREATE"):format(player.Info.Name))
+		log:Normal(L("PM_PLAYER_CREATE"):format(player.Info.Name))
 		return player
 	end
 end
@@ -234,7 +233,7 @@ end
 --
 function PM:UpdatePlayer(player)
 	Players[player.Info.Name] = player
-	log:Normal(GetL("PM_PLAYER_UPDATE"):format(player.Info.Name))
+	log:Normal(L("PM_PLAYER_UPDATE"):format(player.Info.Name))
 end

 --- Completely remove a command from a group's access list.
@@ -564,7 +563,7 @@ function PM:Invite(player, sender)
 			return "PM_INVITE_NOTIFYTARGET"
 		elseif player.Settings.Invite then
 			InviteUnit(player.Info.Name)
-			local msg = L:GetLocale(player.Settings.Locale, true)["PM_INVITE_NOTIFY"]:format(sender.Info.Name, player.Info.Name)
+			local msg = L(player.Settings.Locale, "PM_INVITE_NOTIFY", true):format(sender.Info.Name, player.Info.Name)
 			CM:SendMessage(msg, "WHISPER", player.Info.Name)
 			return "PM_INVITE_SUCCESS", {player.Info.Name}
 		else
@@ -586,7 +585,7 @@ function PM:DenyInvites(player, isWhisper)
 		if isWhisper then
 			return "PM_DI_BLOCKING"
 		end
-		local msg = L:GetLocale(player.Settings.Locale, true)["PM_DI_BLOCKING"]
+		local msg = L(player.Settings.Locale, "PM_DI_BLOCKING", true)
 		CM:SendMessage(msg, "WHISPER", player.Info.Name)
 		return "PM_DI_SUCCESS", {player.Info.Name}
 	end
@@ -607,7 +606,7 @@ function PM:AllowInvites(player, isWhisper)
 	if isWhisper then
 		return "PM_AI_ALLOWING"
 	end
-	local msg = L:GetLocale(player.Settings.Locale, true)["PM_AI_ALLOWING"]
+	local msg = L(player.Settings.Locale, "PM_AI_ALLOWING", true)
 	CM:SendMessage(msg, "WHISPER", player.Info.Name)
 	return "PM_AI_SUCCESS", {player.Info.Name}
 end
@@ -629,10 +628,10 @@ function PM:Kick(player, sender, reason)
 	if GT:IsGroupLeader() or GT:IsRaidLeaderOrAssistant() then
 		KickName = player.Info.Name
 		KickSender = sender.Info.Name
-		KickReason = reason or GetL("PM_KICK_DEFAULTREASON"):format(KickSender)
-		StaticPopupDialogs.COMMAND_CONFIRMKICK.text = GetL("PM_KICK_POPUP")
-		StaticPopupDialogs.COMMAND_CONFIRMKICK.button1 = GetL("YES")
-		StaticPopupDialogs.COMMAND_CONFIRMKICK.button2 = GetL("NO")
+		KickReason = reason or L("PM_KICK_DEFAULTREASON"):format(KickSender)
+		StaticPopupDialogs.COMMAND_CONFIRMKICK.text = L("PM_KICK_POPUP")
+		StaticPopupDialogs.COMMAND_CONFIRMKICK.button1 = L("YES")
+		StaticPopupDialogs.COMMAND_CONFIRMKICK.button2 = L("NO")
 		StaticPopup_Show("COMMAND_CONFIRMKICK", KickSender, KickName)
 		return "PM_KICK_WAIT", {KickName}
 	end
diff --git a/QueueManager.lua b/QueueManager.lua
index 73e849b..0ba3fd5 100644
--- a/QueueManager.lua
+++ b/QueueManager.lua
@@ -38,7 +38,7 @@ C.QueueManager = {
 	Announced = false
 }

-local L = function(k) return C.LocaleManager:GetActive()[k] end
+local L = C.LocaleManager
 local QM = C.QueueManager

 --- Contains information about various dungeon types.
diff --git a/RollManager.lua b/RollManager.lua
index f69b0ef..3b58be5 100644
--- a/RollManager.lua
+++ b/RollManager.lua
@@ -18,7 +18,7 @@
 --]]

 local C = Command
-local L = function(k) return C.LocaleManager:GetActive()[k] end
+local L = C.LocaleManager
 local GT = C.GroupTools
 local CM
 local CES = C.Extensions.String