using InControl;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CatController : MonoBehaviour
{
	[Header("Runtime")]
    [SerializeField, ReadOnly] private CharacterAppearance appearance;
    [SerializeField, ReadOnly] private new CharacterAudio audio;
    [SerializeField, ReadOnly] private CharacterInfo info;
    [SerializeField, ReadOnly] private CharacterInput input;
    [SerializeField, ReadOnly] private CharacterPhysics physics;

    public CharacterAppearance Appearance { get { return appearance; } }
    public CharacterAudio Audio { get { return audio; } }
    public CharacterInfo Info { get { return info; } }
    public CharacterInput Input { get { return input; } }
    public CharacterPhysics Physics { get { return physics; } }

    public int ID;

    private void Awake ()
    {
        appearance = GetComponent<CharacterAppearance>();
        audio = GetComponent<CharacterAudio>();
        info = GetComponent<CharacterInfo>();
        input = GetComponent<CharacterInput>();
        physics = GetComponent<CharacterPhysics>();
        appearance.Player = input.Player = physics.Player = this;
    }

    private void Update()
    {
        // Update input
        input.Tick();

        // Update Physics
        physics.Tick(Time.deltaTime);

        // Update Audio
        audio.Tick(Time.deltaTime);

        // Update animation
        appearance.UpdateAnimation(input.MovementDirection);
    }

    private void FixedUpdate()
    {
        // Update physics
        physics.FixedTick(input.MovementDirection);
    }

    public void Init(int controllerID, InputDevice device)
    {
        // Bind input device to player
        input.BindController(device);

        // Assign id
        info.AssignControllerID(controllerID);

        Info.AssignCat(controllerID);
    }
}
