Created
September 27, 2019 13:35
-
-
Save triacontane/f3be9079657bd4e8fcee13cc39048aff to your computer and use it in GitHub Desktop.
パラメータで指定した名称のイベントを呼び出すサンプル
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*:ja | |
* @plugindesc サンプル | |
* @author | |
* | |
* @param 呼び出すイベント名 | |
* @desc 呼び出されるイベントの名称 | |
* @default Called_Event | |
* | |
* @help | |
* パラメータで指定した名称のイベントをプラグインコマンドから呼び出します。 | |
* | |
* パラメータで指定した名称のイベントのページ[1]を呼び出します。 | |
* Call_Event_from_this_map 1 | |
* | |
*/ | |
(function() { | |
'use strict'; | |
// プラグインパラメータを取ります。 | |
var parameter = PluginManager.parameters('Call_to_each_map'); | |
var eventName = String(parameter['呼び出すイベント名']) || 'Called_Event'; | |
// プラグインコマンドの実行 | |
var _Game_Interpreter_pluginCommand = Game_Interpreter.prototype.pluginCommand; | |
Game_Interpreter.prototype.pluginCommand = function(command, args) { | |
_Game_Interpreter_pluginCommand.apply(this, arguments); | |
if (command === 'Call_Event_from_this_map') { | |
var pageIndex = parseInt(args[0]); | |
console.log(eventName); | |
this.callMapEventByName(pageIndex, eventName); | |
} | |
}; | |
// 指定された名前に一致するイベントの呼び出し | |
Game_Interpreter.prototype.callMapEventByName = function(pageIndex, eventName) { | |
var event = DataManager.searchDataItem($dataMap.events, 'name', eventName); | |
if (event) { | |
this.setupAnotherList(event.id, event.pages, pageIndex); | |
} | |
}; | |
// イベント実行内容のセットアップ | |
Game_Interpreter.prototype.setupAnotherList = function(eventId, pages, pageIndex) { | |
var page = pages[pageIndex - 1 || this._pageIndex] || pages[0]; | |
if (!eventId) eventId = this.isOnCurrentMap() ? this._eventId : 0; | |
this.setupChild(page.list, eventId); | |
}; | |
// データベースから条件に一致するデータを検索 | |
DataManager.searchDataItem = function(dataArray, columnName, columnValue) { | |
var result = 0; | |
dataArray.some(function(dataItem) { | |
if (dataItem && dataItem[columnName] === columnValue) { | |
result = dataItem; | |
return true; | |
} | |
return false; | |
}); | |
return result; | |
}; | |
})(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment