//=============================================================================
// TransferingStack.js
//=============================================================================
/*:
* @plugindesc Storing location before transfering.
* @author hyrious
*
* @param Auto Push Location
* @desc Run 'TransferingStack push' automatically before any transfering.
* @type boolean
* @default true
*
* @param Fade Type
* @desc The fade effect type of transfering.
* 0 - black. 1 - white. any other number - none.
* @type number
* @default 0
*
* @help This plugin provides the following plugin commands.
*
* TransferingStack push # Save current location (push to stack)
* TransferingStack pop # Remove and transfer to the last location
* TransferingStack pop! # Remove the last location without transfering
* TransferingStack clear # Remove all things in the stack
* TransferingStack debug # Log the stack to console
*/
/*:zh
* @plugindesc “回到上一个位置”。
* @author hyrious
*
* @param Auto Push Location
* @text 自动保存位置
* @desc 在场所移动前自动执行一次 TransferingStack push 。
* @type boolean
* @default true
*
* @param Fade Type
* @text 渐变样式
* @desc 场所移动时的渐变(变黑、变白等)。
* 0 - 变黑. 1 - 变白. 任何其他数字 - 无渐变.
* @type number
* @default 0
*
* @help 这个插件提供了以下事件指令:
*
* TransferingStack push # 保存当前位置(入栈)
* TransferingStack pop # 返回到上一个位置(出栈)
* TransferingStack pop! # 出栈,但不执行场所移动
* TransferingStack clear # 清空位置栈
* TransferingStack debug # Log the stack to console
*/
(function() {
var parameters = PluginManager.parameters('TransferingStack');
var autoPushLocation = Boolean(parameters['Auto Push Location'] || 'true');
var fadeType = Number(parameters['Fade Type'] || '0');
var transferingStack = [];
function pushLocation() {
var mapId = $gameMap.mapId(),
x = $gamePlayer._realX,
y = $gamePlayer._realY,
d = $gamePlayer._direction;
transferingStack.push([mapId, x, y, d, fadeType]);
}
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand;
var _Game_Player_reserveTransfer = Game_Player.prototype.reserveTransfer;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === 'TransferingStack') {
switch (args[0]) {
case 'push':
pushLocation();
break;
case 'pop':
if (transferingStack.length) {
var last = transferingStack.length - 1;
var payload = transferingStack[last];
_Game_Player_reserveTransfer.apply($gamePlayer, payload);
}
case 'pop!':
transferingStack.pop();
break;
case 'clear':
transferingStack = [];
break;
case 'debug':
console.log("transferingStack: [(mapId, x, y, d, fadeType)]");
console.log(transferingStack);
break;
}
}
};
Game_Player.prototype.reserveTransfer = function(mapId, x, y, d, fadeType) {
if (!this._transferring && autoPushLocation) {
pushLocation();
}
_Game_Player_reserveTransfer.call(this, mapId, x, y, d, fadeType);
}
var _DataManager_setupNewGame = DataManager.setupNewGame;
DataManager.setupNewGame = function() {
_DataManager_setupNewGame.call(DataManager);
transferingStack = [];
}
})();