﻿// uScript Action Node
// (C) 2015 Detox Studios LLC

using UnityEngine;
using System.Collections;
using Yarn.Unity;

[NodePath("Actions/Audio")]

[NodeCopyright("Copyright 2020 by Austin Yarger")]
[NodeToolTip("Launch an audio track (within a Resources folder) or adjust its volume. Useful for layering of music.")]
[NodeAuthor("Austin Yarger", "umich.edu")]
[NodeHelp("http://docs.uscript.net/#3-Working_With_uScript/3.4-Nodes.htm")]

[FriendlyName("Play Audio Track", "Launch an audio track (within a Resources folder) or adjust its volume. Useful for layering of music.")]
public class uScriptNodePlayAudioTrack : uScriptLogic
{
    public bool Out { get { return true; } }

    public void In(
       [FriendlyName("audio_file_name", "The name of the audio file we wish to play (residing in a Resources folder) without file extension. we wish to start dialogue with."), AutoLinkType(typeof(string))]
      string audio_file_name,
              [FriendlyName("volume", "The volume the requested audio file should assume. This should be between 0.0 and 1.0"), AutoLinkType(typeof(float))]
      float volume
       )
    {
        GameObject command_go = GameObject.Find("command");
        if(command_go == null)
        {
            Debug.LogError("[PlayAudioTrack Node] The current scene doesn't have a command gameobject. Please find one from another scene and copy it in to this one.");
            return;
        }

        YarnCommands command = command_go.GetComponent<YarnCommands>();
        if(command == null)
        {
            Debug.LogError("[PlayAudioTrack Node] The current scene's command gameobject does not have a YarnCommands component. Please add it.");
            return;
        }

        command.play_audio_track(audio_file_name, volume.ToString());
    }
}
