/*
<copyright file="BGNCLoad.cs" company="BansheeGz">
    Copyright (c) 2018-2021 All Rights Reserved
</copyright>
*/

using System.IO;
using ParadoxNotion.Design;

namespace BansheeGz.BGDatabase
{
    [Category("BansheeGz")]
    [Name("BGDatabase: Load game")]
    [Description("Load game using SaveLoad addon. Set useArray to true if you want to use array instead of file. If you want to use file- provide fileName without extension and path, for example MySave")]
    public class BGNCLoad : BGNCSaveLoadA
    {
        protected override void FileAction()
        {
            var filePath = FilePath;
            if (!File.Exists(filePath))
            {
                Log("Unable to load game, cause file " + filePath + " does not exist!");
                return;
            }

            BGRepo.I.Addons.Get<BGAddonSaveLoad>().Load(File.ReadAllBytes(filePath));
            Log("Game is loaded from file " + filePath);
        }

        protected override void ArrayAction()
        {
            BGRepo.I.Addons.Get<BGAddonSaveLoad>().Load(array.value);
            Log("Game is loaded from array");
        }
    }
}