﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

namespace Tap.Tilt
{
    public class PlayerCanvasController : MonoBehaviour
    {
        // The object to draw the player symbol
        public Text playerSymbol;

        // The player point total
        public Text playerPoints;

        // The total number of points
        public int totalPoints = 0;
        
        // The identity of the player
        public string playerId;

        // Enable / Disable haptic response on points and multiplier
        public float hapticMultiplier = 10f;

        // Set the Id
        public void SetId(string newId)
        {
            playerId = newId;
        }

        // Set the symbol
        public void SetSymbol(string symbol)
        {
            playerSymbol.text = symbol;
        }

        // Set the color
        public void SetColor(Color color)
        {
            ColorThings ct = GetComponent<ColorThings>();
            if (ct != null)
                ct.DoColor(color);
        }

        // timeout the player
        public void SendTimeout()
        {
            GameController.instance.UserTimeout(playerId, "");
        }

        // Add points to the player
        public void SendPoints(int points)
        {
            totalPoints += points;
            UpdateCounter();

            // apply the haptic modifier to a haptic call back to the player
            GameController.instance.UserVibe(playerId, points * hapticMultiplier);
        }
        public void Reset()
        {
            totalPoints = 0;
            UpdateCounter();
        }

        private void UpdateCounter()
        {
            // update the counter
            if (playerPoints != null)
                playerPoints.text = totalPoints.ToString();
        }

    }
}
