mirror of
https://github.com/IllusionMan1212/adventures-of-kuroneko.git
synced 2026-10-24 18:12:36 +00:00
61 lines
1.0 KiB
JavaScript
61 lines
1.0 KiB
JavaScript
ig.module(
|
|||
|
|
'impact.entity-pool'
|
||
|
|
)
|
||
|
|
.requires(
|
||
|
|
'impact.game'
|
||
|
|
)
|
||
|
|
.defines(function(){ "use strict";
|
||
|
|
|
||
|
|
ig.EntityPool = {
|
||
|
|
pools: {},
|
||
|
|
|
||
|
|
mixin: {
|
||
|
|
staticInstantiate: function( x, y, settings ) {
|
||
|
|
return ig.EntityPool.getFromPool( this.classId, x, y, settings );
|
||
|
|
},
|
||
|
|
|
||
|
|
erase: function() {
|
||
|
|
ig.EntityPool.putInPool( this );
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
enableFor: function( Class ) {
|
||
|
|
Class.inject(this.mixin);
|
||
|
|
},
|
||
|
|
|
||
|
|
getFromPool: function( classId, x, y, settings ) {
|
||
|
|
var pool = this.pools[classId];
|
||
|
|
if( !pool || !pool.length ) { return null; }
|
||
|
|
|
||
|
|
var instance = pool.pop();
|
||
|
|
instance.reset(x, y, settings);
|
||
|
|
return instance;
|
||
|
|
},
|
||
|
|
|
||
|
|
putInPool: function( instance ) {
|
||
|
|
if( !this.pools[instance.classId] ) {
|
||
|
|
this.pools[instance.classId] = [instance];
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
this.pools[instance.classId].push(instance);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
drainPool: function( classId ) {
|
||
|
|
delete this.pools[classId];
|
||
|
|
},
|
||
|
|
|
||
|
|
drainAllPools: function() {
|
||
|
|
this.pools = {};
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
ig.Game.inject({
|
||
|
|
loadLevel: function( data ) {
|
||
|
|
ig.EntityPool.drainAllPools();
|
||
|
|
this.parent(data);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
});
|