/*
Copyright 2019 Dr. Thomas Benjamin Senior, Michael Zoeller 

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;

namespace EyeSkills
{
    /// <summary>
    /// Conflict zone model. Add or remove a source of retinal conflict.
    /// </summary>
    public class ConflictZoneModel : MonoBehaviour
    {
        private float brightnessRatio;

        /// <summary>
        /// A container for something you wish to display and alter the luminance of.
        /// </summary>
        public GameObject leftConflictItem, rightConflictItem;

        public GameObject blinkerLeft, blinkerRight;

        /// <summary>
        /// Show or hide the conflict background.
        /// </summary>
        /// <returns>The show.</returns>
        /// <param name="showing">If set to <c>true</c> showing.</param>
        public void Show(bool showing)
        {           
            GameObject[] conflictObjects = GameObject.FindGameObjectsWithTag("Conflict");
            if( conflictObjects.Length > 0 ) {
              foreach(GameObject go in conflictObjects)
                go.SetActive(showing);
            } else {
              leftConflictItem.SetActive(showing);
              rightConflictItem.SetActive(showing);
            }
        }

        public void SetLuminanceRatio(float brightnessRatio){
            FindObjectOfType<EyeSkillsCameraRig>().SetBinocularSuppressionRatio(brightnessRatio);
        }

        /// <summary>
        /// Moves the left and right (eye) items into conflict
        /// </summary>
        public void IntoConflict()
        {
            blinkerLeft.SetActive(false);
            blinkerRight.SetActive(false);
        }

        /// <summary>
        /// Moves the left and right (eye) items out of conflict
        /// </summary>
        public void OutOfConflict()
        {
          blinkerLeft.SetActive(true);
          blinkerRight.SetActive(true);
        }

    }
}
