using Godot;
using Godot.Collections;
using System.Collections.Generic;
using Newlon.Components;
using Newlon.Systems.Effects;

public partial class EffectBasedPlayer : Node
{
	[Export] public Array<Effect> effectsToMap;
	[Export] public Array<AudioStream> streamsToMapTo;
	[Export] public Array<ChannelSettings> streamSettings;
	private System.Collections.Generic.Dictionary<Effect, (AudioStream,ChannelSettings)> effectToAudioMap = new();
	public override void _Ready()
	{
		GetParent<Entity>().EffectStarted += OnEffectStarted;

		for (int i = 0; i < effectsToMap.Count; i++)
		{
			effectToAudioMap.Add(effectsToMap[i], (streamsToMapTo[i],streamSettings[i]));
		}
	}

	public void OnEffectStarted(Effect what)
	{
		if (effectToAudioMap.ContainsKey(what) == false) return;
		AudioSequencer.Play(what.Slot, effectToAudioMap[what].Item1);
		AudioSequencer.ChangeSettings(what.Slot, effectToAudioMap[what].Item2);
	}
}
