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 dungeonmaster

Is it legit to define a .js file just to use for injecting some code, without any class declerations like this:
ig.module(
	'plugins.explorable-background-map'
)
.requires(
	'impact.background-map',
	'impact.image'
)
.defines(function(){ "use strict";

ig.BackgroundMap.inject({	

    explored: [[]],
    
    masterData: [[]],
    
    init: function( tilesize, data, tileset ) {
		console.log('start of injection: BackgroundMap')
		this.parent( tilesize, data );
		this.setTileset( tileset );
        this.explored = this.data.slice(0);
        var i,i = 0;

        this.masterData = this.data;
        this.data = [[]];
        for (var i = 0;i<this.explored.length;i++) {
            this.data[i] =[];
            for (var j = 0; j<this.explored[0].length;j++) {
                this.explored[i][j] = false;
                this.data[i][j] = 0;
            };
        };
	},
});
});

1 decade ago by dungeonmaster

Hey, I just solved it after 3-4 hours of pain. (Answer: yes but carefully)

Which is not clear about injecting but VERY important is:

Class1
Class2 (extending class1)

...then somewhere
.inject.someMethod (of class2)

now, if you call this.parent() in this.someMethod it actually calls .someMethod of Class 2!!! (and not Class1)

So in my example, when I call this.parent(tilesize,data) in hopes to call the init of ig.Map, it actually calls the overriden/overinjected method of ig.BackgroundMap, with the missing 'tileset' parameter of course. Which also gives errors all over the place.

Now I can sleep.
Page 1 of 1
« first « previous next › last »