Iavra

Iavra Text Eval

Feb 23rd, 2016 (edited)
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*:
  2.  * @plugindesc v1.00 Adds a new escape code, that allows to insert arbitrary script calls inside text (for example messages).
  3.  * <Iavra Text Eval>
  4.  * @author Iavra
  5.  *
  6.  * @param Escape Code
  7.  * @desc Code to be used to insert evaluated expressions. "code" serves as a placeholder for the expression.
  8.  * @default #{code}
  9.  *
  10.  * @help
  11.  * After activating the plugin, you can use javascript inside text by surrounding it with the escape code defined in
  12.  * the plugin parameter "Escape Code". So the following example:
  13.  *
  14.  * "Actor 1 has #{$gameActors.actors(1).atk} attack."
  15.  *
  16.  * Would show the attack value of actor number 1. The escape code has been made configurable, since it might already be
  17.  * used by a different plugin and, depending on the javascript code used, some characters might not be usable.
  18.  */
  19. (function ($, undefined) {
  20.     "use strict";
  21.    
  22.     var _params = $plugins.filter(function (p) { return p.description.contains('<Iavra Text Eval>'); })[0].parameters;
  23.     var _param_escapeCode = _params['Escape Code'];
  24.    
  25.     var _regex = new RegExp(_param_escapeCode.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&").replace('code', '([\\S\\s]+?)'), 'g');
  26.    
  27.     var alias_windowBase_convertEscapeCharacters = $.prototype.convertEscapeCharacters;
  28.    
  29.     Window_Base.prototype.convertEscapeCharacters = function (text) {
  30.         return alias_windowBase_convertEscapeCharacters.call(this, text.replace(_regex, function (m, c) { return eval(c); }));
  31.     };
  32.    
  33. })(this.IAVRA || (this.IAVRA = {}));
Add Comment
Please, Sign In to add comment