How to Extends / Alias / Overwrite existing class in MZ/ ES6 [Tutorial]

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,532
Reaction score
3,683
First Language
Java's Crypt
Primarily Uses
RMMZ
I'm making a core plugin for all of my plugins, but it'll also be available for anyone else who wants to use the same core.
 

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
1,076
Reaction score
848
First Language
English
Primarily Uses
RMMV
@Hudell Aah, neatness. Kind of curious as to how the core plugin looks. :o
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,839
First Language
English
Lol imagine everyone's projects looking like

HudellCore
OssraCore
DoubleCore
NioCore
SolarCore
HimeCore

cause we all have our own preference for aliasing classes using class syntax
 

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
1,076
Reaction score
848
First Language
English
Primarily Uses
RMMV
Yeah, basically, heh. I have whittled the framework plugin I have been tinkering on down to around a hundred lines of code, or even a bit smaller should I not need a few features. So I could cram all the code I need into each plugin, or I could toss out a framework plugin. Not certain which direction I will go. I kind of feel like cramming the code -- of any length -- into each plugin is a waste, but I am also not entirely sure I want to go the framework route ... blarg.
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,040
First Language
French
Primarily Uses
RMMV
afterseing the Cyclone engine that Hudell was working on. I was like : wow his plugins does everything my core do but better. So my idea will be to use the Cyclone Engine for those technical aspect but also add my own Core engine.

Gemstone engine have mostly Common function I reuse often such as :
Code:
    /**
     * Convert a value to a percent.
     *
     * @export
     * @param {number} a
     * @param {number} b
     * @return {number}
     */
    export function PercentOf(a: number, b: number, large: boolean = false): number {
        return a / b * (large ? 100 : 1);
    }

    /**
     * Convert a value to a rounded percent.
     *
     * @export
     * @param {number} a The value to convert
     * @param {number} b The target max value
     * @param {boolean} large convert the percent to a small value (0 ~ 1) or a large value (0 ~ 100)
     * @return {number}
     */
    export function RoundedPercentOf(a: number, b: number, large: boolean = false): number {
        return Math.round(PercentOf(a, b, large));
    }

// ...
I think having a common framework for those thing is fine but also having our own framework for our own useful common method is always nice.
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,532
Reaction score
3,683
First Language
Java's Crypt
Primarily Uses
RMMZ
I'm usually against cores too, but this time I gave up the fight and joined the enemy. At least the core is doing a little more than just adding a way to patch classes.

I wrote a small documentation of it here:
 

DoubleX

Just a nameless weakling
Veteran
Joined
Jan 2, 2014
Messages
1,757
Reaction score
923
First Language
Chinese
Primarily Uses
N/A
My consideration on this is the size of the duplicated codes, the number of duplication, and their rate of changes.
In general, the larger they are, the more duplication are there and the more frequently they change, the more reasons for me to extract those codes into something like a core plugin.
Also, if the core plugin doesn't have any breaking change, it'd be a great bonus for me :)
 

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
1,076
Reaction score
848
First Language
English
Primarily Uses
RMMV
Dah, Cyclone does look rather neat. Makes the framework I had been working on look silly.
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,532
Reaction score
3,683
First Language
Java's Crypt
Primarily Uses
RMMZ
The code for the `patchClass` function would be super simple if all you want to support is methods. It got a bit more complex to include support for properties, then a little more to automatically copy old properties to the $super object and then even more to copy inherited old properties to the $super object.
I don't know if anyone has ever needed to alias an object property though, so I may be overkilling it there. Just wanted to ensure it was compatible with anything. I can make a simple `patchClass` function without property aliasing if anyone wants to copy it into their own plugins.
 

Solar_Flare

Veteran
Veteran
Joined
Jun 6, 2020
Messages
531
Reaction score
232
First Language
English
Primarily Uses
RMMV
Lol imagine everyone's projects looking like

HudellCore
OssraCore
DoubleCore
NioCore
SolarCore
HimeCore
There won't be a SolarCore anytime soon, as I currently have no plans to buy MZ. Even in MV the SFG_Utils plugin isn't anything so elaborate as a core plugin - it's literally what it says, just a few utility plugins.

cause we all have our own preference for aliasing classes using class syntax
My preference is, don't do that and just alias functions in the ES5 way. I basically just don't use the class syntax for anything.
 

Nekohime1989

Nekohime
Veteran
Joined
May 31, 2014
Messages
495
Reaction score
223
First Language
English
Primarily Uses
RMMZ
Now I just need to figure out how to load the meta... -_-
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Little early but to all of you that celebrate it :

Tomorrow is Halloween! I can't wait to go to Boxi Park and show off my costume! Also one of Dad's friends is staying the night, so he might get to see the show.
Here's the title-screen for the game I'm working on: :LZSgrin:
Oh man I've been struggling with event spawners and Qmovement compatibility for quite a while- went as far as to use a tool just to pick crops :kaocry: but Ritter got their spawner to work with Qmove and I'm screeing! It's still in testing period but just- the feeling of getting over a large gameplay hurdle is a HUGE relief, I'm so thankful to Ritter! It's a cheap paid plugin but totally worth it!
Welp, I just finished my favorite part of RPG making which is creating skills, now onto the tasks I like less so the motivation is lower. At least I'll get to create new ones while designing enemies!

Forum statistics

Threads
104,657
Messages
1,007,906
Members
136,147
Latest member
Kandoras
Top