#include "../Fusion/RuFusion_AudioLibrary.h"

#pragma unmanaged

// ************************************************************************************************************************************************************

ruRTTI_DEFINE_SUBCLASS(CRuFusion_AudioRegistry, IRuObject)
ruHEAP_DEFINE_SUBCLASS(CRuFusion_AudioRegistry, "CRuFusion_AudioRegistry", "IRuObject")
ruCLASSGUID_DEFINE(CRuFusion_AudioRegistry, 0xD0AE6B60, 0x3A4840bc, 0xB7E63E07, 0x8A5BD167)

ruRTTI_DEFINE_SUBCLASS(CRuFusion_AudioLibrary, IRuObject)
ruHEAP_DEFINE_SUBCLASS(CRuFusion_AudioLibrary, "CRuFusion_AudioLibrary", "IRuObject")
ruCLASSGUID_DEFINE(CRuFusion_AudioLibrary, 0x7EB54FEC, 0xE74947d1, 0x9796F019, 0xB6803AAE)

// ************************************************************************************************************************************************************

CRuFusion_AudioRegistry::CRuFusion_AudioRegistry()
{
}

CRuFusion_AudioRegistry::~CRuFusion_AudioRegistry()
{
	// Clear off the tree...
}

BOOL CRuFusion_AudioRegistry::AssociateAudio(const char *tag, const char *audioResource)
{
	TagDescriptor *tagDesc = NULL;

	// If the specified tag does not exist, create it
	if(m_tagDescriptors.ContainsKey(tag) == FALSE)
	{
		tagDesc = ruNEW TagDescriptor();
		m_tagDescriptors.Add(tag, tagDesc);
	}
	else
	{
		tagDesc = m_tagDescriptors.Get(tag);
	}

	tagDesc->m_associatedAudio.Add(ruNEW CRuString(audioResource));

	return TRUE;
}

const char *CRuFusion_AudioRegistry::GetAssociatedAudio(const char *tag)
{
	if(m_tagDescriptors.ContainsKey(tag))
	{
		TagDescriptor *tagDesc = m_tagDescriptors.Get(tag);

		if(tagDesc->m_associatedAudio.Count() > 0)
		{
			INT32 audioIndex = g_mtRand.GenerateUINT32() % tagDesc->m_associatedAudio.Count();

			return *(tagDesc->m_associatedAudio[audioIndex]);
		}
	}

	return NULL;
}

// ************************************************************************************************************************************************************

CRuFusion_AudioLibrary::CRuFusion_AudioLibrary()
{
	CRuFusion_AudioRegistry *audioRegistry = ruNEW CRuFusion_AudioRegistry();

	audioRegistry->AssociateAudio("attack", "sound\\sample\\Character\\PlayerExertions\\NightElfFemaleFinal\\NightElfFemaleMainAttackA.wav");
	audioRegistry->AssociateAudio("attack", "sound\\sample\\Character\\PlayerExertions\\NightElfFemaleFinal\\NightElfFemaleMainAttackB.wav");
	audioRegistry->AssociateAudio("attack", "sound\\sample\\Character\\PlayerExertions\\NightElfFemaleFinal\\NightElfFemaleMainAttackC.wav");
	audioRegistry->AssociateAudio("attack", "sound\\sample\\Character\\PlayerExertions\\NightElfFemaleFinal\\NightElfFemaleMainAttackD.wav");

	m_audioRegistries.Add("hm_female", audioRegistry);
}

CRuFusion_AudioLibrary::~CRuFusion_AudioLibrary()
{
	// Clear off registries
}

const char *CRuFusion_AudioLibrary::GetAssociatedAudio(const char *audioClass, const char *audioTag)
{
	if(m_audioRegistries.ContainsKey(audioClass))
	{
		CRuFusion_AudioRegistry *audioRegistry = m_audioRegistries.Get(audioClass);
		return audioRegistry->GetAssociatedAudio(audioTag);
	}

	return NULL;
}

// ************************************************************************************************************************************************************

#pragma managed
