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

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,477
Reaction score
3,072
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,915
Reaction score
1,997
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,072
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

There are only a few days left in our Spooktober Spooktacular Game Jam! Hope you are working hard to get your game in!
Where do i have to play Heisei Pistol Show the same creator that made Re: Kinder Parun
I really get the feeling I should be doing regular YouTube videos whenever I make something cool in my game, instead of waiting for massive changes. But not going to lie... I always feel like it's never quite enough to merit an update, until it's a drastic change. :kaoswt:
Going to submit to this game jam...struggling with the time crunch...
Have to keep compromising...
Just released a new OST for my game and a new place to purchase it!

Ah, things to do when you finish a game.

Forum statistics

Threads
104,548
Messages
1,007,043
Members
136,032
Latest member
WhatisGachi
Top