DYNAMIC INHERITANCE FRAMEWORK


Description

This framework adds an easy way to create classes which can be reflected dynamically by any object in GameMaker Studio 2.3+. The aim of this system is to provide developers a simple way to maximise code reuse and simplicity within their GameMaker Studio 2 projects.

Creating a new PseudoClass

Any object can be inherited from dynamically if it is a child of the PseudoClass object. To create a new PseudoClass object, simply create a new object and change its parent to be PseudoClass. Once this is completed, any object which inherits the PseudoClassUser can implement from this new PseudoClass dynamically.

Implementing a PseudoClass Dynamically

Once you have created a new object to inherit from, the next step is to implement that object. To do this, create an object and set its parent to be PseudoClassUser. With your new PseudoClassUser, you can now implement and stop implementing classes with the following methods.


        // Inherit the parent event:

        event_inherited();

        // Implement from the NewPseudoClass object:

        implements(NewPseudoClass);

        // Check if we are implementing the NewPseudoClass object:

        if (isImplementing(NewPseudoClass))
        {
            // Stop implementing the NewPseudoClass object:

            stopImplementing(NewPseudoClass);
        }
        


Finding Each Instance of a PseudoClass

One of the benefits of having dynamic inheritance is being able to categorise each object which is implementing a desirable behaviour. In this framework, this can be done in the following way.


        var mapSize, key, map, instance;

        // Get a map of each object implementing NewPseudoClass:

        map = PseudoClassTracker.getImplementing(NewPseudoClass);

        // Iterate through the map:

        mapSize = ds_map_size(map);
        key = ds_map_find_first(map);

        repeat (mapSize)
        {
            instance = ds_map_find_value(map, key);

            key = ds_map_find_next(map, key);
        }

        // Remove reference to map ID:

        map = undefined;
        


Dependencies

The framework currently requires that the PseudoClassTracker object is present in any room you are using the framework. I recommend that you use an object which will help manage your dependencies for each room, and include the PseudoClassTracker for simplicity.

Additionally, this framework was made for GameMaker Studio 2.3 and above, it will not work on older versions of GameMaker Studio 2 or any version of GameMaker Studio 1 or below.