'use strict';

//=============================================================================
// EISChangeSavePath.js
//=============================================================================

/*:
* @author Kino
* @plugindesc Changes the default save path in RPGMakerMV <ChngSvPath>
*
* @param Use MV Directory
* @desc Use MV default directory
* @type boolean
* @default false
*
* @param Save Path
* @desc This will be placed in the users home directory; make sure it ends with '/'
* @default /MyGameName/save/
*
* @help
* Version 1.00
//=============================================================================
//  Introduction
//=============================================================================
*
* This plugin allows you to place your game in a folder seperate from the game
* launch directory on desktop. This means that the user's game data will be
* stored seperately in a folder within the home directory.
* Here are a few examples.
* Linux & Mac : /home/myusrname/MyGameName/save/
* Windows: C:/Users/MyUserName/MyGameName/save/
*
* With the above you have a lot of options on where to save your game data.
* You can also set it use MV directory to on for testing purposes.
*
* This plugin is DESKTOP ONLY. This will not work on browser.
*
*
//=============================================================================
//  Contact Information
//=============================================================================
*
* Contact me via twitter: EISKino, or on the rpg maker forums.
* Username on forums: Kino.
*
* Forum Link: http://forums.rpgmakerweb.com/index.php?/profile/75879-kino/
* Website Link: http://endlessillusoft.com/
* Twitter Link: https://twitter.com/EISKino
* Patreon Link: https://www.patreon.com/EISKino
*
* Hope this plugin helps, and enjoy!
* --Kino
*/

(function () {
  var params = $plugins.filter(function (plugin) {
    return (/<ChngSvPath>/ig.test(plugin.description)
    );
  })[0].parameters;
  var ChangePathParams = {
    useDefault: /true/ig.test(params['Use MV Directory'].trim()),
    path: params['Save Path'].trim()
  };
  function setup() {
    //=============================================================================
    //  StorageManager
    //=============================================================================
    StorageManager.localFileDirectoryPath = function () {
      var path = require('path');
      var base = path.dirname(process.mainModule.filename);
      var home = process.env.HOME || process.env.HOMEPATH;

      if (ChangePathParams.useDefault) return path.join(base, ChangePathParams.path);else return path.join(home, ChangePathParams.path);
    };
  }

  setup();
})();