KillingBlowAnnouncer = LibStub("AceAddon-3.0"):NewAddon("KillingBlowAnnouncer", "AceConsole-3.0", "AceEvent-3.0")


Media = LibStub("LibSharedMedia-3.0")
------------------------------------------------------------------ADD SOUND FILES HERE--------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------
--------HOW TO ADD SOUND FILES----------------------------------------------------------------------------------
---1. Make sure that the sound file is either a mp3 file or ogg file. This is important because WoW doesn't support any other soundfiles.
---2. Add the file to the Sounds map. Found at Interface\AddOns\Killing Blow Announcer\Sounds
---3. Add the following line to this lua file with your own soundname and the path to the sound file: 
---   Media:Register("sound", "HOW YOU WANT THE SOUND FILE TO BE NAMED", [[Interface\AddOns\Killing Blow Announcer\Sounds\FILENAME.mp3]]);
---4. Save changes to the Killing Blow Announcer file and  Restart WoW in case it was already open.
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
---Make sure to backup any changes to this file and of the files added to the sounds map when updating this addon. Any changes will be overwritten
---when updating so just a heads up.
----------------------------------------------------------------------------------------------------------------

--QUAKE FEMALE SOUNDS
Media:Register("sound", "Quake female: bottomfeeder", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\bottomfeeder.mp3]]);
Media:Register("sound", "Quake female: dominating", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\dominating.mp3]]);
Media:Register("sound", "Quake female: firstblood", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\firstblood.mp3]]);
Media:Register("sound", "Quake female: godlike", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\godlike.mp3]]);
Media:Register("sound", "Quake female: headshot", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\headshot.mp3]]);
Media:Register("sound", "Quake female: humiliation", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\humiliation.mp3]]);
Media:Register("sound", "Quake female: killingspree", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\killingspree.mp3]]);
Media:Register("sound", "Quake female: monsterkill", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\monsterkill.mp3]]);
Media:Register("sound", "Quake female: multikill", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\multikill.mp3]]);
Media:Register("sound", "Quake female: play", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\prepare.mp3]]);
Media:Register("sound", "Quake female: rampage", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\rampage.mp3]]);
Media:Register("sound", "Quake female: ultrakill", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\ultrakill.mp3]]);
Media:Register("sound", "Quake female: unstoppable", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\unstoppable.mp3]]);
Media:Register("sound", "Quake female: wickedsick", [[Interface\AddOns\Killing Blow Announcer\Sounds\female\wickedsick.mp3]]);

--QUAKE MALE SOUNDS
Media:Register("sound", "Quake male: wickedsick", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\wickedsick.mp3]]);
Media:Register("sound", "Quake male: unstoppable", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\unstoppable.mp3]])
Media:Register("sound", "Quake male: ultrakill", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\ultrakill.mp3]]);
Media:Register("sound", "Quake male: triplekill", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\triplekill.mp3]]);
Media:Register("sound", "Quake male: teamkiller", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\teamkiller.mp3]]);
Media:Register("sound", "Quake male: rampage", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\rampage.mp3]]);
Media:Register("sound", "Quake male: prepare", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\prepare.mp3]]);
Media:Register("sound", "Quake male: perfect", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\perfect.mp3]]);
Media:Register("sound", "Quake male: multikill", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\multikill.mp3]]);
Media:Register("sound", "Quake male: monsterkill", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\monsterkill.mp3]]);
Media:Register("sound", "Quake male: megakill", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\megakill.mp3]]);
Media:Register("sound", "Quake male: ludicrouskill", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\ludicrouskill.mp3]]);
Media:Register("sound", "Quake male: killingspree", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\killingspree.mp3]]);
Media:Register("sound", "Quake male: impressive", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\impressive.mp3]]);
Media:Register("sound", "Quake male: humiliation", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\humiliation.mp3]]);
Media:Register("sound", "Quake male: holyshit", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\holyshit.mp3]]);
Media:Register("sound", "Quake male: headshot", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\headshot.mp3]]);
Media:Register("sound", "Quake male: godlike", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\godlike.mp3]]);
Media:Register("sound", "Quake male: firstblood", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\firstblood.mp3]]);
Media:Register("sound", "Quake male: doublekill", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\doublekill.mp3]]);
Media:Register("sound", "Quake male: dominating", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\dominating.mp3]]);
Media:Register("sound", "Quake male: combowhore", [[Interface\AddOns\Killing Blow Announcer\Sounds\male\combowhore.mp3]]);

----------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------END OF SOUND FILE LIST------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------


------------------------------------------------------------------ADD IMAGE FILES HERE--------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------
--------HOW TO ADD IMAGE FILES----------------------------------------------------------------------------------
---1. Make sure that the image file is either a  BLP image or TGA  image. This is important because WoW doesn't support any other image types.
---2. Make sure that the image contains a power of two dimension. Basically this means that both the width and height of an image needs to be one of the following dimensions
--    "8", "16", "32", "64", "128", "256", "512", "1024", "2048". http://wowpedia.org/API_Texture_SetTexture
---3. Add the file to the Images map. Found at Interface\AddOns\Killing Blow Announcer\Images
---4. Add the following line exactly as the example below with FILENAME being the image name:
---   Media:Register("images", "Interface\\AddOns\\Killing Blow Announcer\\Images\\FILENAME", [[Interface\AddOns\Killing Blow Announcer\Images\FILENAME.tga]]);
---5. Save changes to the Killing Blow Announcer file and  Restart WoW in case it was already open.
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------
---Make sure to backup any changes to this file and of the files added to the images map when updating this addon. Any changes will be overwritten
---when updating so just a heads up.
----------------------------------------------------------------------------------------------------------------

Media:Register("images", "Interface\\AddOns\\Killing Blow Announcer\\Images\\imageBlue", [[Interface\AddOns\Killing Blow Announcer\Images\imageBlue.tga]]);
Media:Register("images", "Interface\\AddOns\\Killing Blow Announcer\\Images\\imageFrost", [[Interface\AddOns\Killing Blow Announcer\Images\imageFrost.tga]]);
Media:Register("images", "Interface\\AddOns\\Killing Blow Announcer\\Images\\imageYellow", [[Interface\AddOns\Killing Blow Announcer\Images\imageYellow.tga]]);
Media:Register("images", "Interface\\AddOns\\Killing Blow Announcer\\Images\\alliance1", [[Interface\AddOns\Killing Blow Announcer\Images\alliance1.tga]]);
Media:Register("images", "Interface\\AddOns\\Killing Blow Announcer\\Images\\horde1", [[Interface\AddOns\Killing Blow Announcer\Images\horde1.tga]]);
Media:Register("images", "Interface\\AddOns\\Killing Blow Announcer\\Images\\alliance2", [[Interface\AddOns\Killing Blow Announcer\Images\alliance2.tga]]);
Media:Register("images", "Interface\\AddOns\\Killing Blow Announcer\\Images\\horde2", [[Interface\AddOns\Killing Blow Announcer\Images\horde2.tga]]);

----------------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------END OF IMAGE FILES LIST-----------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------

--create minimap icon data
kbaLDB = LibStub("LibDataBroker-1.1"):NewDataObject("Killing blow announcer", {
	type = "data source",
	text = "Killing Blow Announcer",
	icon = "Interface\\Icons\\Trade_Archaeology_Orc_BloodText",
	OnClick = function() KillingBlowAnnouncer:KillingBlowAnnouncerSlash() end,
	OnTooltipShow = function(tooltip)
		tooltip:AddLine("|cffecf0f1Killing Blow Announcer|r\nClick to open");
	end
})

--create Libstub variable for minimap icon and prefix
icon = LibStub("LibDBIcon-1.0")
KBADK = "KBADK-#c58821c0"


--intitialize chatcommand(/kba) and dependencies
function KillingBlowAnnouncer:OnInitialize()
	KillingBlowAnnouncer:RegisterChatCommand("kba", "KillingBlowAnnouncerSlash")
	
	self.db = LibStub("AceDB-3.0"):New("kbaDB", defaults, "Default")	
	options.args.profile = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
	
	LibStub("AceConfig-3.0"):RegisterOptionsTable("KillingBlowAnnouncer", options)	
	LibStub("AceConfig-3.0"):RegisterOptionsTable("killingBlowAnnouncerProfiles", options.args.profile)
	
	self.KillingBlowAnnouncerOptions = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("KillingBlowAnnouncer", "KillingBlowAnnouncer")
	
	icon:Register("Killing blow announcer", kbaLDB, self.db.profile.minimap)
end;


-- open ingame options menu when /kba gets called
function KillingBlowAnnouncer:KillingBlowAnnouncerSlash(input)
	InterfaceOptionsFrame_OpenToCategory("KillingBlowAnnouncer");
	InterfaceOptionsFrame_OpenToCategory("KillingBlowAnnouncer");
end;

function interp(s, tab)
	return (s:gsub('($%b{})', function(w) return tab[w:sub(3, -2)] or w end))
end

function table.map_length(t)
    local c = 0
    for k,v in pairs(t) do
         c = c+1
    end
    return c
end