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,101
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,073
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

For a long time I always consider XP soundtracks as the best one.
Just listened to some of MZ tracks from the free version.
It's... Quite mindblowing. xD
Only listened to the battles, towns, and fields.
But I'm sure the rest are equally good. :D
What do you guys want to see for the new Jump into Javascript? A continuation of the rpg_objects, or would you prefer a "lesson 0" where I go back to the absolute basics of Javascript and cover the fundamentals of the language and its construction?
Hey RPG members!!

How do you finish projects? Some new game developers start off strong but end up losing momentum. What keeps you motivated while working on new projects?
Feeling wee sleepy.. ZzzZ
So many threads to move to the right place. My post count is awesome, but 95% of it is due to moving things.

Forum statistics

Threads
112,452
Messages
1,068,383
Members
146,107
Latest member
kenjum
Top