A dirty way to split up the rmmz js files!!

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,477
Reaction score
3,079
First Language
Binary
Primarily Uses
RMMZ
@nio kasgami recently asked if I had an easy way to split the default rm codebase into separate files for each class, so I wrote up a quick and dirty js file to do such a thing... I figured I would share it here in case anyone else has a use for it. It certainly makes browsing default classes much easier.

This assumes you have node js installed on your machine. Although it could most likely be converted to a plugin to be triggered by script call fairly easily (and then would use the nwjs env your game uses).


To separate the files just save this code into a file (called splits.js) in your rmmz projects js folder. Then create a new folder (also in the js folder) called 'splits'. Lastly, open a command terminal and run 'node splits.js' from the js directory. The code will then scan for the rmmz code files, and split them up into separate files - each with the name of their class...

1599780749169.png
Due to how this splits things, a few files cannot be named after a class (because they have no real data). These files are called 'unknown-class-N' where n is an iteration number to ensure no duplicates are made/overwrite one another. The only unknown class file worth anything is 'unknown-class-1(rmmz_core)' which is the 'JsExtensions' 'namespace' that rm uses for adding some functions to the default js classes like array and number.

Once the process is complete, you will should have 170 files within the splits folder. Each of them a specific rm class. This process should also work with mv if you change the way the commandFiles are filtered.

The code:
Code:
/*: ==========================================================================
* ############################################################################
*
* Plugin: Split RMMZ.js files
* Author: DekitaRPG [dekitarpg.com] (dekitarpg@gmail.com)
*
* ############################################################################
* ============================================================================
* 1- save this code into the /.js folder of your rpg maker mz project.
*  - call it 'splits.js'.
* 2- create a folder called 'splits'.
* 3 - run 'node splits.js'
*/
const splitter = "//-----------------------------------------------------------------------------";
const fs = require('fs');
const path = require('path');
console.log('#scanning-all-files:..')
const cdirectoryFiles = fs.readdirSync('.');
const commandFiles = cdirectoryFiles.filter(f => {
    return f.startsWith('rmmz_') && f.endsWith('.js')
});
console.log('#scanning-rmmz-files:', commandFiles)
for (const filename of commandFiles) {
    fs.readFile(path.join('.', filename), 'utf8', (err, data) => {
        if (err) throw err;
        const split_classes = data.split(splitter);
        for (const [i, maybeclass]  of split_classes.entries()) {
            const tempname = filename.replace('.js','');
            const matches = maybeclass.match(/(function) \w+/);
            const classname = matches ? matches[0].replace('function','').trim() : `unknown-class-${i}`;
            const newpath = `/splits/${classname}(${tempname}).js`;
            const newfilepath = path.join('.', newpath);
            fs.writeFile(newfilepath, maybeclass, (werr, wdata) =>{
                if (werr) throw werr;
                console.log('wrote', newfilepath);
            })
        }
    });
}
Anyway. Happy Coding :*
 

Kupotepo

Fantasy realist/Advocatus Diaboli
Veteran
Joined
Jul 5, 2017
Messages
1,917
Reaction score
2,014
First Language
Thai
Primarily Uses
RMMV
Hahaha, it is anyone here learn another lesson: you can ask @?????? about coding. Just playing with you. I do not understand why @nio kasgami wants to split the files. Is it going to sometime complex that I do not understand?
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,040
First Language
French
Primarily Uses
RMMV
Hahaha, it is anyone here learn another lesson: you can ask @?????? about coding. Just playing with you. I do not understand why @nio kasgami wants to split the files. Is it going to sometime complex that I do not understand?
Its for the the typescript typing process where we can splits the files easily and convert them to typescript definition files
 

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,477
Reaction score
3,079
First Language
Binary
Primarily Uses
RMMZ
There could be many reasons for splitting up the default code files. In Nio's case, its for easier management of files for the typescript definitions. Others might just find it easier to have each class as its own file. A lot of folks have mentioned here and there about the files being bundled and so large its hard to navigate through them.

Personally, I'm using it as a way to test what the minimum amount of mz code required to run a game is. Like, lets say you had no need for the game map scene, that allows at least like 5 different classes to be totally removed.

I'm sure there are other use cases as well.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

I made my own pizza. First critique, more chicken next time.
My pumpkin! Anyone like Fallout?

It's not terrible, but could be better. This thing took me over an hour to carve. :kaophew:

Dad's watching a WWII documentary while I work on some cool assets for my games. I just love RPG Maker!
Also Happy Halloween! Dad's friend won't be coming unfortunately, but Dad will still be taking me to Boxi Park to have some fun tonight! I'll be posting a video on my YouTube channel of the show, and I'll be sure to post a link here.
"Nightmares exist outside of logic and there's little fun to be had in explanations. They're antithetical to the poetry of fear. In a horror story the victim keeps asking why, but there can be no explanation and there shouldn't be one..." - Stephen King
I feel people seek explanation and demand it sometimes in games, but in the horror genre, well, maybe you shouldn't have one. Silent Hill 1 comes to mind...
Managed to implement QSprite.

Always double check your plugin order.

Forum statistics

Threads
104,686
Messages
1,008,102
Members
136,177
Latest member
SGXNinetyNine
Top