Skip to content
Antarka edited this page Jul 29, 2016 · 6 revisions

Addons

Addons are modules that are automatically updated by the engine. It's not necessary to update a class extended by United.Addon ! The abstract class addons is extended by EventEmitter which allows to manage events on each extended class.

For exemple, i make a new building class for my game :

class Building extends United.Addon {
    
    public mineral: number;

    private timer: United.Timer;
    private day: number;
    private delay: number;
    
    constructor(public name: string,day: number,delay: number) {
        super({
            defaultName: "Building"
        });
        this.mineral = 0;
        this.day = day;
        this.delay = delay;
        this.timer = new United.Timer();
    }
    
    update() : void {
        if(this.timer.walk(this.delay)) {
            this.mineral += this.day;
            this.emit("receivingMineral",this.mineral);
        }
    }
}

const MineralFactory : Building = new Building("MineralFactory",150,U.FPS * 15);
const GazFactory : Building = new Building("GazFactory",30,U.FPS * 17);
const PlasmaFactory : Building = new Building("PlasmaFactory",200,U.FPS * 60);

MineralFactory.on("receivingMineral",(mineral) => {
    // Catch event and update the interface ! 
    UIText.textRenderer.setText(`${mineral}`);
});

No need to update these buildings... The engine do it for you ! That simplify many process where you need behavior. That doesn't means you dont need a real behavior with an actor when you make a graphical game ! But that can separate the update process properly and save the update component for renderer events.

Addon constructor interface

interface AddonConstructor {
    defaultName: string;
    global?: boolean;
    lockingScene?: string;
    parentAddon ?: United.Addon;
}

You can set the addon to global true. That's mean your addon is not linked to a scene but to the engine. It's still continue to update between scenes (usefull for playlist plugin for example).

lockingScene is usefull is you want to lock the addon to a specific scene of your game. parentAddon have the same behavior with addon. This two arguments are in alpha stage.

Roadmap

  • Log support.
  • Multi-threading native support.
Clone this wiki locally