using System.Collections;
using System.Linq;
using UnityEngine;

[RequireComponent(typeof(DanMachiAssetLibrary), typeof(DanMachiModelBuilder), typeof(DanMachiInterface))]
public class DanMachiMain : ModelViewerMain
{
    public static DanMachiMain Instance => GetInstance<DanMachiMain>();

    protected DanMachiAssetLibrary _assets => DanMachiAssetLibrary.Instance;
    protected DanMachiModelBuilder _modelBuilder => DanMachiModelBuilder.Instance;

    protected override void Awake()
    {
        CurrentScene = SceneContainer.Create<SceneContainer>(this);
        base.Awake();
    }

    private IEnumerator Start()
    {
        Application.targetFrameRate = 30;
        Error.Log(Color.green, "Viewer version: " + Application.version);

        float warningTimer = 0;
        while (DanMachiAssetLibrary.Instance == null || DanMachiModelBuilder.Instance == null || DanMachiInterface.Instance == null || SharedResources.Instance == null)
        {
            warningTimer += Time.deltaTime;
            if(warningTimer > 2)
            {
                warningTimer = 0;
                string report = $"AssetLibrary: {DanMachiAssetLibrary.Instance != null}\nModelBuilder: {DanMachiModelBuilder.Instance != null}\nInterface: {DanMachiInterface.Instance != null}\nResources: {SharedResources.Instance != null}";
                Error.Log(report, Color.red);
            }
            yield return 0;
        }
    }

    private void Update()
    {
        //AutoSaveUpdate();
    }
}