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

● ARCHIVED · READ-ONLY
Started by nio kasgami 113 posts Page 6 of 6 View original ↗
  1. 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.
  2. @Hudell Aah, neatness. Kind of curious as to how the core plugin looks. :o
  3. 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
  4. 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.
  5. 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.
  6. 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:
  7. 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 :)
  8. Dah, Cyclone does look rather neat. Makes the framework I had been working on look silly.
  9. 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.
  10. Tsukihime said:
    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.

    Tsukihime said:
    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.
  11. Do the whole engine in a single js file, problem solved :rheh:
  12. Now I just need to figure out how to load the meta... -_-
  13. Lol wait ! be sure your are using at least Babel to compile code to ES5 if your use `super` !
    `super` work fine and are support by all browser now, but have terrible performance :mad:.
    I made for your a bench to see why you should never use super without Babel to transpile to es5.
    Sure ,for a app or webpage is fine, but for a game engine is not good idea!
    Or at least avoid placing '.super' in the game loop.

    JSBench.me - JavaScript performance benchmarking playground and we are not talking about a small difference!

    1609158989216.png
    Babel is over there:

    Babel