Advertisement
nio_kasgami

EEMV::EmojiBase

Nov 12th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*:
  2. //==============================================================================
  3. // ■ Emoji Engine MV - Origin "EmojiBase"
  4. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  5. // * @plugindesc Base for EMM. It's store params and permit to extract plugin
  6.      parrameters easily and faster then the default manner.
  7. // * id: EEMV::Base
  8. // * @author Nio Kasgami.
  9. // * @Data : 2015/10/05
  10. // * @Version : 1.0.0
  11. // * @Require : NA
  12. //==============================================================================
  13.  
  14. //==============================================================================
  15. // ■ History
  16. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  17. //  * 2015/10/29 - Begin and finish the plugin.
  18. //==============================================================================
  19.  
  20. //==============================================================================
  21. // ■ Introduction
  22. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  23. //  * it's serve for store params
  24. //==============================================================================
  25.  
  26.  
  27. //==============================================================================
  28. // ■ Plugin Parameter
  29. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  30. // this section handle the plugin parameter. Please do not edit unless you
  31. // want to add extra plugin command.
  32. //------------------------------------------------------------------------------
  33.    * it's a base so this not handle any param commands
  34. //==============================================================================
  35.  
  36. //==============================================================================
  37. // ■ Help File
  38. // =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  39. // This section serve for input the help file in the engine don't touch this
  40. // unless you want to input more information
  41. //------------------------------------------------------------------------------
  42.    * @help
  43.    * This plugin base serve for handles datas so it's not provide plugin command
  44.    * though it's serve for store my other plugin commands via the alias of
  45.    * the method "get_pluginname" and "get_params".
  46.    *
  47.    * be sure please to input this above all my EEMV plugin for avoid any issues.
  48.    *
  49.    * ====================================================================
  50.    *  ■ Internal Method call
  51.    * ====================================================================
  52.    * /var/ = this.set_PluginName(plugin); : set the plugin name.
  53.    * /var/ = this.set_PluginID(plugin); : set the plugin ID.
  54.    * /var/ = this.setString(pluginVar,ParamName); : set the param as a string.
  55.    * /var/ = this.setBoolean(pluginVar,ParamName); : set the param as a boolean.
  56.    * /var/ = this.setNumber(PluginVar,ParamName,type,max_number); : set the
  57.    * params as number and permit to proceed maths conversion.
  58.    * /var/ = this.setArray(PluginVar,ParamName); : transform a list of number in
  59.    * array.
  60. */
  61.  
  62. //==============================================================================
  63. // ■ Emoji_Engine
  64. //------------------------------------------------------------------------------
  65. // the class who handle all the base of my plugins. Can be access via $emoji.
  66. //==============================================================================
  67.  
  68. //==============================================================================
  69. // ■ Emoji_Engine {Core}
  70. //------------------------------------------------------------------------------
  71. // this section serve for handle the param getting and initialize it.
  72. //==============================================================================
  73.  
  74. var EmojiAlias = EmojiAlias || {};
  75.  
  76. function Emoji_Engine() {this.initialize.apply(this,arguments);}
  77.   Emoji_Engine.prototype.constructor = Emoji_Engine;
  78.  
  79. //----------------------------------------------------------------------------
  80. // ○ new function: initialize
  81. //----------------------------------------------------------------------------
  82. // * This method serve for initialize. It's not necessary to touch this method.
  83. //
  84. Emoji_Engine.prototype.initialize = function() {
  85.   this.get_pluginname();
  86.   this.get_params();
  87. };
  88.  
  89. //----------------------------------------------------------------------------
  90. // ○ new function: Get_pluginName
  91. //----------------------------------------------------------------------------
  92. // * This the function who serve for hold all your plugin name.
  93. // * Do a alias for your plugin name or you gonna overwrite the previous.
  94. // * and you don't want this because overwrite = breaking.
  95. //
  96. Emoji_Engine.prototype.get_pluginname = function() {
  97.   this.emojibase = this.set_PluginID("EEMV::Base");
  98. };
  99.  
  100. //----------------------------------------------------------------------------
  101. // ○ new function: get_params
  102. //----------------------------------------------------------------------------
  103. // * This the function where you hold all your plugin parameter.
  104. // * Do a alias for store your param or you gonna overwrite the previous.
  105. // * and you don't want this because overwrite = breaking.
  106. //
  107. Emoji_Engine.prototype.get_params = function() {};
  108.  
  109. //===============================================================================
  110. // => END : Emoji_Engine {Core}
  111. //===============================================================================
  112.  
  113. //==============================================================================
  114. // ■ Emoji_Engine {PluginName}
  115. //------------------------------------------------------------------------------
  116. // this section serve for get everything's related to Plugin Name. It's
  117. // contain method for permit to extract the name.
  118. //==============================================================================
  119.  
  120. //----------------------------------------------------------------------------
  121. // ○ new function: set_PluginName
  122. //----------------------------------------------------------------------------
  123. // * Special command who permit to get your  plugin name more easily without having
  124. // * repeat the code "PluginManager.parameters('yourpluginname')".
  125. // * you can use "this.set_PluginName('plugin name');"
  126. // * or $Emoji.get_PluginName('plugin'); for get your param_name if you
  127. // * do your params outside of the Core functions.
  128. //
  129. Emoji_Engine.prototype.set_PluginName = function(plugin){
  130.     return PluginManager.parameters(plugin);
  131. };
  132.  
  133. //----------------------------------------------------------------------------
  134. // ○ new function: set_PluginID
  135. //----------------------------------------------------------------------------
  136. // * Originally Lavra Method for permit to remove the dependancie of the
  137. // * original PluginManager who was Heavy name focussed. I just decide to
  138. // * transfert is method into a function so it's avoid to have to repeat the
  139. // * whole code in in your plugin. Can be acesses like the other function.
  140. // * the id: have to be in the description method. Please check Lavra
  141. // * original method here :
  142. // * (http://forums.rpgmakerweb.com/index.php?/topic/47591-how-to-get-plugin-parameters-without-knowing-your-filename/)
  143. //
  144. Emoji_Engine.prototype.set_PluginID = function(plugin) {
  145.  return $plugins.filter(function(p){return p.description.contains("id: " + plugin )})[0].parameters;
  146. };
  147. //===============================================================================
  148. // => END : Emoji_engine {PluginName}
  149. //===============================================================================
  150.  
  151.  
  152. //==============================================================================
  153. // ■ Emoji_Engine {Param}
  154. //------------------------------------------------------------------------------
  155. // this section serve for get everything's related to Plugin params. It's
  156. // contain methods for permit to extract the params and to use them.
  157. //==============================================================================
  158.  
  159. //----------------------------------------------------------------------------
  160. // ○ new function: setString
  161. //----------------------------------------------------------------------------
  162. // * Convert the params in a string. Even if it's still a string in a ways,
  163. // * it's better to implement string for being sure the system will read this
  164. // * only as a string and nothing else!
  165. //
  166. Emoji_Engine.prototype.setString = function(Plugin_var,ParamName) {
  167.     return String(Plugin_var[ParamName]);
  168. };
  169.  
  170. //----------------------------------------------------------------------------
  171. // ○ new function: setBoolean
  172. //----------------------------------------------------------------------------
  173. // * By default the Boolean can't recognize string's correctly. Pure example,
  174. // * if you input Boolean(param); it's will not work. Why? Because boolean()
  175. // * auto recognize a string as true. it's not eval the string content.
  176. // * and sadly Plugin parameters are strings. So this method will
  177. // * consider your param as a boolean and return a true or a false.
  178. //
  179. Emoji_Engine.prototype.setBoolean = function(PluginVar,ParamName) {
  180.   var n = PluginVar[ParamName];
  181.   var s = undefined;
  182.   if(n === 'true' || n === 'false'){
  183.     if(n === 'true'){
  184.       s = true;
  185.     } else {
  186.       s = false;
  187.     }
  188.   } else {
  189.     throw new Error(ParamName + ' is a boolean please set it to true or false.');
  190.   }
  191.   return s;
  192. };
  193.  
  194. //----------------------------------------------------------------------------
  195. // ○ new function: setNumber
  196. //----------------------------------------------------------------------------
  197. // * It's create the plugin command into number but also permit to add maths
  198. // * conversion.
  199. // * They have multiple options who permit to quick convert your number in
  200. // * math process. Process who are :
  201. // * 'default' or "" : transform the param string in a regular number.
  202. // * 'floor' : round your number to the lowest round. E.g : 3.9 -> 3
  203. // * 'ceil'  : round your number to the highest round. E.g : 3.9 -> 4
  204. // * 'round' : round your number to the nearest values. E.g : 5.35 -> 5
  205. // * 'topercent' : convert your number in a Percentage value.
  206. // * 'todecimal' : convert your percent in a decimal value.
  207. // * 'topi' : convert your number in a PI value.
  208. // * 'abs'  : return the absolute value of your number
  209. // *
  210. // * You can use this method by doing this.setNumber or $emoji.setNumber.
  211. // * the function works like this :
  212. // * this.setNumber(Plugin_var,ParamName,type,max_number);
  213. // * The definition of these arguments are :
  214. // * Plugin_var : The variable you stored your plugin name.
  215. // * ParamName  : The Name of your Param command.
  216. // * Type       : Set the Number process you want to do (set to 'default' for reg number).
  217. // * max_number : set the limit of your number (use only for topercent and todecimal).
  218. // * (PS : you can setup a varaible for max_number. E.g : this.maxHP)
  219. //
  220. Emoji_Engine.prototype.setNumber = function(Plugin_var,ParamName,type,max_number) {
  221.     var number = Number(Plugin_var[ParamName]);
  222.     var final_result = null;
  223.     switch (type.toLowerCase()){
  224.     // get the regular number.
  225.         default :
  226.         final_result = number;
  227.         break;
  228.     // get the low round
  229.         case 'floor' :
  230.          final_result = Math.floor(number);
  231.         break;
  232.     // get the uppest round.
  233.         case 'ceil' :
  234.         final_result = Math.ceil(number);
  235.         break;
  236.         case 'round' :
  237.     // round to the nearest value.
  238.         final_result = Math.round(number);
  239.         break;
  240.         case 'topercent' :
  241.     // convert number to percent.
  242.         final_result = (number / max_number) * 100;
  243.         break;
  244.     // convert the percent in float number.
  245.         case 'todecimal' :
  246.         final_result = (number / 100) * max_number;
  247.         break;
  248.     // convert your number into a PI math value.
  249.         case 'topi' :
  250.         final_result = Math.PI(number);
  251.         break;
  252.     // return the absolute values of the number.
  253.         case 'abs' :
  254.         final_result = Math.abs(number);
  255.     }
  256. return final_result;
  257. };
  258.  
  259. //----------------------------------------------------------------------------
  260. // ○ new function: setArray
  261. //----------------------------------------------------------------------------
  262. // * Convert a list of number in a Array. It's transform the string into a
  263. // * number for after convert the chain into a Array.
  264. // * it's look like this in the pluginManager :
  265. // * Paramcommand = 1,2,3,4
  266. // * in the system it's will return this [1,2,3,4];
  267. // * so after you can access the array easily by doing this.varname[0];
  268. //
  269.  Emoji_Engine.prototype.setArray = function (Plugin_var,ParamName) {
  270.     return Plugin_var[ParamName].split(',').map( function (i) { return Number(i || 0);  } );
  271. };
  272.  
  273. //----------------------------------------------------------------------------
  274. // ○ new function: loadJSON
  275. //----------------------------------------------------------------------------
  276. // * Load JSON files when asked.
  277. // * Though when input in get_misc, it's will load the JSON file on startup.
  278. // * you can get the file via this.loadJSON(pathofile,jsonfile);
  279. // * pathofile = the JSON folder.
  280. // * jsonfile = the JSON file.
  281. //
  282. Emoji_Engine.prototype.loadJSON = function(pathofile,jsonfile) {};
  283.  
  284. //----------------------------------------------------------------------------
  285. // ○ new function: getLinear
  286. //----------------------------------------------------------------------------
  287. // * Permit to create a dynamic lineart movement of a sprite easily.
  288. // * You have although need to create a if method for stop the sprite to update.
  289. // * if(t < 0 || b < c){}
  290. // * please be sure to input true variable and not the c,t,d because this not var
  291. // * t = Current time (frame)
  292. // * b = Start value
  293. // * c = Target value
  294. // * d = Duration total (frames)
  295. // * Returns: Value modified by t
  296. //
  297. Emoji_Engine.prototype.getLinear = function(t,b,c,d) {
  298.   return c*t/d + b;
  299. };
  300. //===============================================================================
  301. // => END : Emoji_engine {PluginName}
  302. //===============================================================================
  303.  
  304. //===============================================================================
  305. // => END : Emoji_Engine
  306. //===============================================================================
  307.  
  308. //==============================================================================
  309. // ■ DataManager
  310. //------------------------------------------------------------------------------
  311. // The static class that manages the database and game objects.
  312. //==============================================================================
  313.  
  314. //----------------------------------------------------------------------------
  315. // ★ new global variables : $emoji
  316. //----------------------------------------------------------------------------
  317.  var $emoji = null;
  318.  
  319. //----------------------------------------------------------------------------
  320. // ● alias function: createGameObjects
  321. //----------------------------------------------------------------------------
  322. var emoji_basealias = DataManager.createGameObjects;
  323. DataManager.createGameObjects = function() {
  324.   emoji_basealias.call(this);
  325.     $emoji                      = new Emoji_Engine();
  326. };
  327.  
  328. //----------------------------------------------------------------------------
  329. // ● overwrite function: loadDataFileSync
  330. //----------------------------------------------------------------------------  
  331. DataManager.loadDataFileSync = function(name, src) {
  332.     var xhr = new XMLHttpRequest();
  333.     var url = 'data/' + src;
  334.     xhr.open('GET', url, true);
  335.     xhr.overrideMimeType('application/json');
  336.     xhr.onload = function() {
  337.         if (xhr.status < 400) {
  338.             window[name] = JSON.parse(xhr.responseText);
  339.             DataManager.onLoad(window[name]);
  340.         }
  341.     };
  342.     xhr.onerror = function() {
  343.         DataManager._errorUrl = DataManager._errorUrl || url;
  344.     };
  345.     window[name] = null;
  346.     xhr.send();
  347. };
  348. //===============================================================================
  349. // => END : DataManager
  350. //===============================================================================
  351.  
  352. //==============================================================================
  353. // ■ ExSprite
  354. //------------------------------------------------------------------------------
  355. // Extended version of Sprite for add more "Ace-like" options.
  356. // Call it by using this.varname = new Sprite();
  357. //==============================================================================
  358.  
  359. //----------------------------------------------------------------------------
  360. // ○ new function: mirror
  361. //----------------------------------------------------------------------------
  362. // * This function serve for flip the picture from horizontal and vertical.
  363. // * Just use sprite.mirror(true or false,true or false); and it's will flip
  364. // * the picture. Though be sure to fix the anchor if it's really needed.
  365. // * The first argument will flip the picture horizontaly.
  366. // * The second argument will flip the picture vertically
  367.  Sprite.prototype.mirror = function(hori,verti) {
  368.     if(hori) {
  369.         this.scale.x = -1;
  370.     }else{
  371.         this.scale.x = 1;
  372.     }
  373.     if(verti){
  374.         this.scale.y = -1;
  375.     }else{
  376.         this.scale.y = 1;
  377.     }
  378.  };
  379.  
  380. //----------------------------------------------------------------------------
  381. // ○ new function: setOrigin
  382. //----------------------------------------------------------------------------
  383. // * This function serve for set anchor in a more lazy ways or Ace way.
  384. // * Totally just a extra code for convenience.
  385. // * call it like this sprite.setOrigin(ox,oy);
  386. //
  387.  Sprite.prototype.setOrigin = function(ox,oy) {
  388.     this.anchor.x = ox;
  389.     this.anchor.y = oy;
  390.  };
  391.  
  392. //----------------------------------------------------------------------------
  393. // ○ new function: linear
  394. //----------------------------------------------------------------------------
  395. // * This function serve for help easy linear sprite movement based on
  396. // * the time. this method need to be called like this in a update method
  397. // * this.sprite = this.sprite.linear(t,b,c,d);
  398. // * t = Current time (frame)
  399. // * b = Start value
  400. // * c = Target value
  401. // * d = Duration total (frames)
  402. // * Returns: Value modified by t
  403. //
  404.  Sprite.prototype.linear = function(t, b, c, d) {
  405.   return c * t / d + b;
  406.  };
  407.  
  408. //----------------------------------------------------------------------------
  409. // ○ new function: radius
  410. //----------------------------------------------------------------------------
  411. // * this method permit easier circle sprite movement. it's take the sprite x
  412. // * coordinate as the center.
  413. // * Also work with time value
  414. // * t = current time (frame)
  415. // * b = start angle
  416. // * c = target angle
  417. // * d = duration total (frames)
  418. // * Returns: Value modified by t
  419. //
  420.  Sprite.prototype.radius = function(t, b, c, d) {
  421.   var circle = Maths.PI * 2 / 180;
  422.   var center = this.x;
  423.   var maths = "";
  424.  };
  425.  
  426. //===============================================================================
  427. // => END : ExSprite
  428. //===============================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement