Advertisement
CompanionWulf

JGSS Function Add-Ons Plugin (RMMV)

Mar 24th, 2016
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=======================================================================
  2. // JGSS Function Add-Ons Plugin (RMMV) v1.0
  3. //=======================================================================
  4. // * While looking  through various MV functions,  notably "String" and
  5. //   "Number", I noticed a distinct lack of them.  So I created some of
  6. //   my own and thought I'd share them.
  7. //
  8. //   It took me AGES to figure out how to do some of these routines! No
  9. //   doubt there are better methods  for doing these too, but these are
  10. //   presented "as is" and they work!
  11. //
  12. //   Some are simple, some are  well-known, and some aren't. Several of
  13. //   these arose out of necessity for "Otherworld", where I needed some
  14. //   extra functions - such as reverse text  for messages that can only
  15. //   be read  in a mirror - and  these aren't  present in  the "String"
  16. //   class.
  17. //
  18. //   These were  intended for personal  use only and I put  them into a
  19. //   single plugin to use them in future projects as needed. I released
  20. //   this publicly so that others  may benefit from any or all of them,
  21. //   which can be easily integrated into a game's code.
  22. //
  23. //       * © 2016, Companion Wulf
  24. //
  25. //========================================================================
  26. // CW_FunctonAddons.js
  27. //========================================================================
  28.  
  29. var Imported = Imported || {}; Imported.CW_FunctonAddons = true;
  30. var CWT = CWT || {}
  31.  
  32. CWT.Version = 1.0;
  33. CWT.Build = 8.0;
  34.  
  35. /*:
  36.  @plugindesc Adds several useful JS/JGSS functions missing in RMMV.
  37.  @author Companion Wulf
  38.  
  39.  @help
  40.  --------------------------------------------------------------
  41.   Usage
  42.  --------------------------------------------------------------
  43.  You can use these in your code as:
  44.  
  45.     variable.function
  46.    
  47.  So, for example, with the Capitalize All Letters function, you'd use the
  48.  following in your code:
  49.  
  50.     var string = "Convert to caps";
  51.     string.toCapitalizeAllLetters();
  52.    
  53.  And the result would be:
  54.  
  55.     CONVERT TO CAPS
  56.  
  57.  --------------------------------------------------------------
  58.   Terms & Conditions of Use
  59.  --------------------------------------------------------------
  60.  This plugin is free to use under CC BY-SA 4.0, but please refer to the
  61.  RPG Maker Times blogsite for other details, including commercial use.
  62.  
  63.  Credit "Companion Wulf" or "RPG Maker Times" if used in your projects.
  64.  
  65.  */
  66.  
  67.  
  68. (function(){
  69.    
  70.     // ** Below are console logs for testing purposes. These have been remarked
  71.     //    out, but can be unremarked to see how they work.
  72.    
  73.     // ** Strings **
  74.     // Capitalize First Letter
  75.     String.prototype.capitalizeFirstLetter = function() {
  76.         return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
  77.     };
  78.         // console.log('Capitalize first letter:','hello'.capitalizeFirstLetter());
  79.    
  80.     // Capitalize Each Word
  81.     String.prototype.capitalizeEachWord = function() {
  82.         return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
  83.     };
  84.         // console.log('Capitalize Each Word:','capitalize each word'.capitalizeEachWord());
  85.    
  86.     // Capitalize All Letters
  87.     String.prototype.capitalizeAllLetters = function() {
  88.         return this.toUpperCase();
  89.     };
  90.         // console.log('Capitalize All Letters:','capitalize all letters'.capitalizeAllLetters());
  91.    
  92.     // Convert to Leet
  93.     String.prototype.toLeet = function() {
  94.         // Credit: Javascript One Liners
  95.         return this.replace(/[a-z]/g,function f(a){return "4BCD3F6H1JKLMN0PQR57"[parseInt(a, 36)-10] || a.replace(/[a-t]/gi,f)});
  96.     };
  97.         // console.log('Convert This To Leet','Convert this to leet'.toLeet());
  98.    
  99.     // Reverse Text
  100.     String.prototype.toReverseText = function() {
  101.         return this.split('').reverse().join('');
  102.     };
  103.         // console.log('Reverse text:','Reverse this text'.toReverseText());
  104.    
  105.     // Reverse Words
  106.     String.prototype.toReverseWords = function() {
  107.         return this.split(" ").reverse().join(" ");
  108.     };
  109.         // console.log('Reverse words:','Reverse these words'.toReverseWords());
  110.    
  111.    
  112.     // ** Numbers **
  113.     // Convert to Decimal
  114.     Number.prototype.toDecimal = function() {
  115.         return this.toFixed(2);
  116.     };
  117.         // console.log('\nConvert number to decimal',2345.69483.toDecimal());
  118.    
  119.     // Round Up
  120.     Number.prototype.toRoundUp = function(decimals) {
  121.         return parseFloat(this.toFixed(decimals));
  122.     };
  123.         // console.log('Round numbers up',23487.49384.toRoundUp(3));
  124.        
  125. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement