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

??????

Diabolical Codemaster
Veteran
Joined
May 11, 2012
Messages
6,548
Reaction score
3,304
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,958
Reaction score
2,100
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,965
Reaction score
3,072
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,548
Reaction score
3,304
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.
 

Latest Threads

Latest Posts

Latest Profile Posts

So, as i finish setting up my items for part 1 of my game, I realized I forgot to finalize an ENTIRE category of items. Know which ones? The Fallen Feathers....BTW my game is called "Fallen Feather"
and_remember_tomorrow_exploding_puzzle_logo.jpg

Made some new friends, and blew up a puzzle... Happens. :LZSwink:
A new RPG Maker music pack is coming out soon! Below is a demo of one of the compositions in the pack, Heroic Battle. More details coming soon!

Trying to build a child-size body. Mostly happy with it except the sideview arms - can't get them to move quite right yet. Anyway, here's the work-in-progress, with an adult for size comparison.
ChildTest-01.gif

I started in VXAce and I liked how the kids flapped their arms so that's why it's just flapping.
A character theme... finally posted some of the music tonight as celebration for 500 followers. I really like how this song came out.

Forum statistics

Threads
111,135
Messages
1,058,602
Members
144,364
Latest member
D_MOB0704
Top