Skip to content

Instantly share code, notes, and snippets.

@marblejenka
Created January 2, 2018 17:05
Show Gist options
  • Save marblejenka/82c8c69ef6afbc32a8eb1a29fc5e7516 to your computer and use it in GitHub Desktop.
Save marblejenka/82c8c69ef6afbc32a8eb1a29fc5e7516 to your computer and use it in GitHub Desktop.
//=============================================================================
// MoveCount.js
//=============================================================================
/*:
* @plugindesc A plugin for counting moves.
* @author marblejenka
*
* @help
* A plugin for counting moves.
*
* MoveCount log # emit the count to console
* MoveCount show # add on the count to the message window
* MoveCount clear # clear the count
*/
/*:ja
* @plugindesc 歩数計測用のプラグイン
* @author marblejenka
*
* @help
* 歩数計測用のプラグインです。
*
* MoveCount log # コンソールにカウントを出力します
* MoveCount show # メッセージウィンドウにカウントを表示します
* MoveCount clear # カウントを消去します
*/
(function() {
function Game_MoveCount() {
this.count = 0;
}
var _createGameObjects = DataManager.createGameObjects;
DataManager.createGameObjects = function() {
_createGameObjects.call(this);
$gameMoveCount = new Game_MoveCount();
console.log("createGameObjects: " + $gameMoveCount.count);
};
var _makeSaveContents = DataManager.makeSaveContents;
DataManager.makeSaveContents = function() {
var contents = _makeSaveContents.call(this);
contents.gameMoveCount = $gameMoveCount;
console.log("makeSaveContents: " + $gameMoveCount.count);
return contents;
};
var _extractSaveContents = DataManager.extractSaveContents;
DataManager.extractSaveContents = function(contents) {
_extractSaveContents.call(this, contents);
if (contents.gameMoveCount) {
$gameMoveCount = contents.gameMoveCount;
}
console.log("extractSaveContents: " + $gameMoveCount.count);
};
var _Game_Player_prototype_executeMove = Game_Player.prototype.executeMove;
Game_Player.prototype.executeMove = function(direction) {
_Game_Player_prototype_executeMove.call(this, direction);
if (this.canPass(this.x, this.y, direction)) { // TODO 判定がダメっぽい?
$gameMoveCount.count++;
}
};
var _Game_Interpreter_pluginCommand =
Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === 'MoveCount') {
switch (args[0]) {
case 'log':
console.log("MoveCount log: " + $gameMoveCount.count);
break;
case 'show':
$gameMessage.add($gameMoveCount.count);
break;
case 'clear':
$gameMoveCount = new Game_MoveCount();
break;
}
}
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment