Skip to content

Instantly share code, notes, and snippets.

@goofmint
Created October 6, 2017 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goofmint/5c8c1ed63c1f8bd49d46e1ae6d508dbb to your computer and use it in GitHub Desktop.
Save goofmint/5c8c1ed63c1f8bd49d46e1ae6d508dbb to your computer and use it in GitHub Desktop.
RPGツクールMVでNCMBを扱うプラグインデモです。
/*:ja
* @plugindesc ニフクラ mobile backendを簡易的に実行するデモです
* @author Atsushi Nakatsugawa
*
* @help
*
* プラグインコマンド:
* NCMB save # データを保存する
* NCMB load # データを取得する
*
*
* @param applicationKey
* @desc アプリケーションキーを指定してください
*
* @param clientKey
* @desc クライアントキーを指定してください
* @default
*
*/
(function() {
var parameters = PluginManager.parameters('SimpleNCMBDemo');
console.log(parameters);
var ncmb = null;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'js/plugins/ncmb.min.js';
script.async = false;
global._babelPolyfill = null;
script.onload = function() {
ncmb = new NCMB(parameters.applicationKey, parameters.clientKey);
};
script.onerror = function(e) {
throw new Error('NCMB JavaScript SDKの読み込みに失敗しました。');
};
document.body.appendChild(script);
var _Game_Interpreter_pluginCommand =
Game_Interpreter.prototype.pluginCommand;
Game_Interpreter.prototype.pluginCommand = function(command, args) {
_Game_Interpreter_pluginCommand.call(this, command, args);
if (command === 'NCMB') {
switch (args[0]) {
case 'save':
$gameSystem.saveToNCMB();
break;
case 'load':
$gameSystem.loadFromNCMB();
break;
}
}
}
Game_System.prototype.saveToNCMB = function() {
var SaveData = ncmb.DataStore('SaveData');
var saveData = new SaveData;
saveData
.set('message', 'Hello from RPG Maker.')
.save()
.then(function(obj) {
console.log('Saved');
})
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment