Last active
March 26, 2017 11:10
-
-
Save Narazaka/c707e869808863ecb5cfbb6a91ea2ba8 to your computer and use it in GitHub Desktop.
ツクールMVプラグイン $gameVariables, $gameSwitchesを名前参照できるようにする be_named.js
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
//=========================================================================== | |
// be_named.js | |
//=========================================================================== | |
/*: | |
* @plugindesc $gameVariables, $gameSwitchesを名前参照できる$namedVariables, $namedSwitchesを定義します。 | |
* @author Narazaka | |
* | |
* @help | |
* ONにするだけで下記のように使えます。 | |
* 変数やスイッチの名前設定で設定した名前のみ使えます。 | |
* | |
* var plusHp = $namedVariables.隠しパラメーター * 2; | |
* $namedVariables.なんとか = 1; | |
* if ($namedSwitches.flag1) $namedSwitches.flag1 = false; | |
* etc... | |
* | |
* [ 利用規約 ] ................................................................ | |
* ・CC0とかなんかそういうやつで。 | |
* ・商用、非商用、有償、無償、一般向け、成人向けを問わず、利用可能です。 | |
* ・利用の際、連絡や報告は必要ありません。また、製作者名の記載等も不要です。 | |
* ・プラグインを導入した作品に同梱する形以外での再配布、転載を許可します。 | |
* ・本プラグインにより生じたいかなる問題についても、一切の責任を負いかねます。 | |
* -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+- | |
* Web Site: https://narazaka.net/ | |
* Twitter : https://twitter.com/narazaka | |
* Copylight (C) 2017 Narazaka | |
*/ | |
var $namedVariables = {}; | |
var $namedSwitches = {}; | |
(function() { | |
var onLoad = DataManager.onLoad; | |
DataManager.onLoad = function(object) { | |
onLoad.apply(DataManager, arguments); | |
if (object === $dataSystem) { | |
for (var id = 0; id < $dataSystem.variables.length; ++id) { | |
var name = $dataSystem.variables[id]; | |
if (name == null || name.length === 0) continue; | |
(function(_id) { | |
Object.defineProperty($namedVariables, name, { | |
enumerable: true, | |
configurable: true, | |
get: function() { return $gameVariables.value(_id) }, | |
set: function(value) { $gameVariables.setValue(_id, value) }, | |
}); | |
})(id); | |
} | |
for (var id = 0; id < $dataSystem.switches.length; ++id) { | |
var name = $dataSystem.switches[id]; | |
if (name == null || name.length === 0) continue; | |
(function(_id) { | |
Object.defineProperty($namedSwitches, name, { | |
enumerable: true, | |
configurable: true, | |
get: function() { return $gameSwitches.value(_id) }, | |
set: function(value) { $gameSwitches.setValue(_id, value) }, | |
}); | |
})(id); | |
} | |
} | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment