Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=======================================================================
- // JGSS Function Add-Ons Plugin (RMMV) v1.0
- //=======================================================================
- // * While looking through various MV functions, notably "String" and
- // "Number", I noticed a distinct lack of them. So I created some of
- // my own and thought I'd share them.
- //
- // It took me AGES to figure out how to do some of these routines! No
- // doubt there are better methods for doing these too, but these are
- // presented "as is" and they work!
- //
- // Some are simple, some are well-known, and some aren't. Several of
- // these arose out of necessity for "Otherworld", where I needed some
- // extra functions - such as reverse text for messages that can only
- // be read in a mirror - and these aren't present in the "String"
- // class.
- //
- // These were intended for personal use only and I put them into a
- // single plugin to use them in future projects as needed. I released
- // this publicly so that others may benefit from any or all of them,
- // which can be easily integrated into a game's code.
- //
- // * © 2016, Companion Wulf
- //
- //========================================================================
- // CW_FunctonAddons.js
- //========================================================================
- var Imported = Imported || {}; Imported.CW_FunctonAddons = true;
- var CWT = CWT || {}
- CWT.Version = 1.0;
- CWT.Build = 8.0;
- /*:
- @plugindesc Adds several useful JS/JGSS functions missing in RMMV.
- @author Companion Wulf
- @help
- --------------------------------------------------------------
- Usage
- --------------------------------------------------------------
- You can use these in your code as:
- variable.function
- So, for example, with the Capitalize All Letters function, you'd use the
- following in your code:
- var string = "Convert to caps";
- string.toCapitalizeAllLetters();
- And the result would be:
- CONVERT TO CAPS
- --------------------------------------------------------------
- Terms & Conditions of Use
- --------------------------------------------------------------
- This plugin is free to use under CC BY-SA 4.0, but please refer to the
- RPG Maker Times blogsite for other details, including commercial use.
- Credit "Companion Wulf" or "RPG Maker Times" if used in your projects.
- */
- (function(){
- // ** Below are console logs for testing purposes. These have been remarked
- // out, but can be unremarked to see how they work.
- // ** Strings **
- // Capitalize First Letter
- String.prototype.capitalizeFirstLetter = function() {
- return this.charAt(0).toUpperCase() + this.slice(1).toLowerCase();
- };
- // console.log('Capitalize first letter:','hello'.capitalizeFirstLetter());
- // Capitalize Each Word
- String.prototype.capitalizeEachWord = function() {
- return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
- };
- // console.log('Capitalize Each Word:','capitalize each word'.capitalizeEachWord());
- // Capitalize All Letters
- String.prototype.capitalizeAllLetters = function() {
- return this.toUpperCase();
- };
- // console.log('Capitalize All Letters:','capitalize all letters'.capitalizeAllLetters());
- // Convert to Leet
- String.prototype.toLeet = function() {
- // Credit: Javascript One Liners
- return this.replace(/[a-z]/g,function f(a){return "4BCD3F6H1JKLMN0PQR57"[parseInt(a, 36)-10] || a.replace(/[a-t]/gi,f)});
- };
- // console.log('Convert This To Leet','Convert this to leet'.toLeet());
- // Reverse Text
- String.prototype.toReverseText = function() {
- return this.split('').reverse().join('');
- };
- // console.log('Reverse text:','Reverse this text'.toReverseText());
- // Reverse Words
- String.prototype.toReverseWords = function() {
- return this.split(" ").reverse().join(" ");
- };
- // console.log('Reverse words:','Reverse these words'.toReverseWords());
- // ** Numbers **
- // Convert to Decimal
- Number.prototype.toDecimal = function() {
- return this.toFixed(2);
- };
- // console.log('\nConvert number to decimal',2345.69483.toDecimal());
- // Round Up
- Number.prototype.toRoundUp = function(decimals) {
- return parseFloat(this.toFixed(decimals));
- };
- // console.log('Round numbers up',23487.49384.toRoundUp(3));
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement