﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HutongGames.PlayMaker.Actions;
using HutongGames.PlayMaker;
using Tooltip = HutongGames.PlayMaker.TooltipAttribute;

namespace Bayat.SaveSystem.PlayMaker
{

    [ActionCategory(SaveSystemAction.ActionCategoryName)]
    [Tooltip("Loads the image from the storage as Texture2D.")]
    public class SaveSystemLoadImageAction : SaveSystemSettingsAction
    {

        [Tooltip("The unique identifier for the image.")]
        public FsmString identifier;
        [Tooltip("The variable to load the texture to.")]
        [ObjectType(typeof(Texture2D))]
        public FsmTexture texture2D;

        public override void OnReset()
        {
            this.identifier = "hello-world.png";
            this.texture2D = null;
        }

        public override async void Enter()
        {
            if (this.settingsPreset)
            {
                this.texture2D.Value = await SaveSystemAPI.LoadImageAsync(this.identifier.Value, this.settingsPreset.CustomSettings);
            }
            else
            {
                this.texture2D.Value = await SaveSystemAPI.LoadImageAsync(this.identifier.Value);
            }
            Finish();
        }

    }

}