Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Mediamonkey

Hey all,
I&039;ve added 2 lines to the core impact.js file at line 548

Class.parentId = prototype.parentId = (!!parent) ? parent.classId : [lastClassId];
Class.inheritance = prototype.inheritance = (!!parent && !!parent.inheritance) ? parent.inheritance.concat(parent.classId) : [];

This makes it possible to check the inheritance of two uninstantiated classes, like so:

console.log( ig.MyGame.inheritance.indexOf(ig.Game.classId) > -1 );

This works like instanceof, but on a class level. If you output a class's inheritance array you'll see all the inherited class id's as a sort of breadcrumbs.

I've needed this for a level change manager where I did not want to instantiate a level yet, but did want to check if the type was allowed into the manager. I guess in AS3 this would be checked by using the "is" operator.

1 decade ago by Mediamonkey

Alright, maybe I needed to add an example :)

In ActionScript I'd write:
function addScreen(screenClass) {
    // validate on type
    if (screenClass is ig.Game) {
        this.manager.push(screenClass);
    
    } else {
        throw new Error("argument must be of type ig.Game");
    }
}

In JavaScript this becomes:
function addScreen(screenClass) {
    // validate on type
    if (screenClass.inheritance.indexOf(ig.Game.classId) > -1) {
        this.manager.push(screenClass);
    
    } else {
        throw new Error("argument must be of type ig.Game");
    }
}
Page 1 of 1
« first « previous next › last »