Merge with master

This commit is contained in:
Felipe Alfonso 2018-01-17 18:30:39 -03:00
commit 4983b393e3
93 changed files with 782 additions and 600 deletions

9
src/animations/index.js Normal file
View file

@ -0,0 +1,9 @@
// Phaser.Animations
module.exports = {
Animation: require('./Animation'),
AnimationFrame: require('./AnimationFrame'),
AnimationManager: require('./AnimationManager'),
};

8
src/cache/index.js vendored Normal file
View file

@ -0,0 +1,8 @@
// Phaser.Cache
module.exports = {
BaseCache: require('./BaseCache'),
CacheManager: require('./CacheManager')
};

View file

@ -116,25 +116,6 @@ var CameraManager = new Class({
},
*/
destroy: function ()
{
this.main = undefined;
for (var i = 0; i < this.cameras.length; i++)
{
this.cameras[i].destroy();
}
for (i = 0; i < this.cameraPool.length; i++)
{
this.cameraPool[i].destroy();
}
this.cameras = [];
this.cameraPool = [];
this.scene = undefined;
},
/*
{
cameras: [
@ -246,7 +227,7 @@ var CameraManager = new Class({
}
},
removeCamera: function (camera)
remove: function (camera)
{
var cameraIndex = this.cameras.indexOf(camera);
@ -298,6 +279,25 @@ var CameraManager = new Class({
shutdown: function ()
{
},
destroy: function ()
{
this.main = undefined;
for (var i = 0; i < this.cameras.length; i++)
{
this.cameras[i].destroy();
}
for (i = 0; i < this.cameraPool.length; i++)
{
this.cameraPool[i].destroy();
}
this.cameras = [];
this.cameraPool = [];
this.scene = undefined;
}
});

View file

@ -3,7 +3,7 @@
var Class = require('../../utils/Class');
var CubicBezierCurve = require('../cubicbezier/CubicBezierCurve');
var EllipseCurve = require('../ellipse/EllipseCurve');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../../gameobjects/GameObjectFactory');
var LineCurve = require('../line/LineCurve');
var MovePathTo = require('./MoveTo');
var Rectangle = require('../../geom/rectangle/Rectangle');

View file

@ -1,6 +1,6 @@
var Class = require('../../utils/Class');
var StableSort = require('../../utils/array/StableSort');
var PluginManager = require('../../plugins/PluginManager');
var Class = require('../utils/Class');
var StableSort = require('../utils/array/StableSort');
var PluginManager = require('../plugins/PluginManager');
var DisplayList = new Class({
@ -13,7 +13,7 @@ var DisplayList = new Class({
this.systems = scene.sys;
this.mapping = 'add';
this.mapping = 'children';
this.systems.events.on('boot', this.boot, this);

View file

@ -226,7 +226,7 @@ var GameObject = new Class({
*/
setInteractive: function (shape, callback)
{
this.scene.sys.inputManager.enable(this, shape, callback);
this.scene.sys.input.enable(this, shape, callback);
return this;
},
@ -282,25 +282,27 @@ var GameObject = new Class({
this.preDestroy.call(this);
}
this.scene.sys.displayList.remove(this);
this.scene.sys.updateList.remove(this);
var sys = this.scene.sys;
sys.displayList.remove(this);
sys.updateList.remove(this);
if (this.input)
{
this.scene.sys.inputManager.clear(this);
sys.input.clear(this);
this.input = undefined;
}
// TODO Keep a reference to the manager in Body, so body can remove itself, not via System
if (this.body)
{
this.scene.sys.physicsManager.remove(this);
sys.physicsManager.remove(this);
this.body = undefined;
}
// Tell the Scene to re-sort the children
this.scene.sys.queueDepthSort();
sys.queueDepthSort();
this.active = false;
this.visible = false;

View file

@ -1,5 +1,5 @@
var Class = require('../../utils/Class');
var PluginManager = require('../../plugins/PluginManager');
var Class = require('../utils/Class');
var PluginManager = require('../plugins/PluginManager');
var GameObjectCreator = new Class({

View file

@ -1,5 +1,5 @@
var Class = require('../../utils/Class');
var PluginManager = require('../../plugins/PluginManager');
var Class = require('../utils/Class');
var PluginManager = require('../plugins/PluginManager');
var GameObjectFactory = new Class({
@ -12,7 +12,7 @@ var GameObjectFactory = new Class({
this.systems = scene.sys;
this.mapping = 'time';
this.mapping = 'add';
this.systems.events.on('boot', this.boot, this);

View file

@ -1,7 +1,6 @@
var Class = require('../../utils/Class');
var PluginManager = require('../../plugins/PluginManager');
var Class = require('../utils/Class');
var PluginManager = require('../plugins/PluginManager');
// TODO - Extend from ProcessQueue
var UpdateList = new Class({
initialize:
@ -12,7 +11,7 @@ var UpdateList = new Class({
this.systems = scene.sys;
this.mapping = 'children';
this.mapping = null;
this.systems.events.on('boot', this.boot, this);

View file

@ -1,6 +1,6 @@
var BitmapText = require('./DynamicBitmapText');
var BuildGameObject = require('../../BuildGameObject');
var GameObjectCreator = require('../../../scene/plugins/GameObjectCreator');
var GameObjectCreator = require('../../GameObjectCreator');
var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue');
// When registering a factory function 'this' refers to the GameObjectCreator context.

View file

@ -1,5 +1,5 @@
var DynamicBitmapText = require('./DynamicBitmapText');
var GameObjectFactory = require('../../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context.
//

View file

@ -1,6 +1,6 @@
var BitmapText = require('./BitmapText');
var BuildGameObject = require('../../BuildGameObject');
var GameObjectCreator = require('../../../scene/plugins/GameObjectCreator');
var GameObjectCreator = require('../../GameObjectCreator');
var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue');
var GetValue = require('../../../utils/object/GetValue');

View file

@ -1,5 +1,5 @@
var BitmapText = require('./BitmapText');
var GameObjectFactory = require('../../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context.
//

View file

@ -2,7 +2,7 @@ var BlitterRender = require('./BlitterRender');
var Bob = require('./Bob');
var Class = require('../../utils/Class');
var Components = require('../components');
var DisplayList = require('../../scene/plugins/DisplayList');
var DisplayList = require('../DisplayList');
var GameObject = require('../GameObject');
/**

View file

@ -1,6 +1,6 @@
var Blitter = require('./Blitter');
var BuildGameObject = require('../BuildGameObject');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator');
var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
// When registering a factory function 'this' refers to the GameObjectCreator context.

View file

@ -1,5 +1,5 @@
var Blitter = require('./Blitter');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context.
//

View file

@ -1,13 +1,10 @@
var Class = require('../../utils/Class');
var Components = require('../components');
var DataProxy = require('../components/DataProxy');
var DisplayList = require('../../scene/plugins/DisplayList');
var TransformMatrix = require('../components/TransformMatrix');
var Container = new Class({
// Extends: DisplayList,
// Mixins: [
// Components.Visible,
// SpriteRender
@ -17,9 +14,6 @@ var Container = new Class({
function Container (scene, x, y)
{
// this.list = children
// DisplayList.call(this, scene);
this.scene = scene;
this.type = 'Container';

View file

@ -1,5 +1,5 @@
var Container = require('./Container');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator');
var GameObjectCreator = require('../GameObjectCreator');
// When registering a factory function 'this' refers to the GameObjectCreator context.

View file

@ -1,5 +1,5 @@
var Container = require('./Container');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context.
//

View file

@ -261,6 +261,16 @@ var Graphics = new Class({
fillPoint: function (x, y, size)
{
if (!size || size < 1)
{
size = 1;
}
else
{
x -= (size / 2);
y -= (size / 2);
}
this.commandBuffer.push(
Commands.FILL_RECT,
x, y, size, size
@ -430,6 +440,26 @@ var Graphics = new Class({
return this.strokePoints(points, true);
},
fillEllipseShape: function (ellipse, smoothness)
{
if (smoothness === undefined) { smoothness = 32; }
var points = ellipse.getPoints(smoothness);
return this.fillPoints(points, true);
},
fillEllipse: function (x, y, width, height, smoothness)
{
if (smoothness === undefined) { smoothness = 32; }
var ellipse = new Ellipse(x, y, width, height);
var points = ellipse.getPoints(smoothness);
return this.fillPoints(points, true);
},
// ARC
arc: function (x, y, radius, startAngle, endAngle, anticlockwise)

View file

@ -1,4 +1,4 @@
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator');
var GameObjectCreator = require('../GameObjectCreator');
var Graphics = require('./Graphics');
// When registering a factory function 'this' refers to the GameObjectCreator context.

View file

@ -1,5 +1,5 @@
var Graphics = require('./Graphics');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context.
//

View file

@ -1,4 +1,4 @@
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator');
var GameObjectCreator = require('../GameObjectCreator');
var Group = require('./Group');
// When registering a factory function 'this' refers to the GameObjectCreator context.

View file

@ -1,5 +1,5 @@
var Group = require('./Group');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context.
//

View file

@ -1,5 +1,5 @@
var BuildGameObject = require('../BuildGameObject');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator');
var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var Image = require('./Image');

View file

@ -1,5 +1,5 @@
var Image = require('./Image');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context.
//

View file

@ -2,6 +2,11 @@
var GameObjects = {
DisplayList: require('./DisplayList'),
UpdateList: require('./UpdateList'),
GameObjectCreator: require('./GameObjectCreator'),
GameObjectFactory: require('./GameObjectFactory'),
Components: require('./components'),
BitmapText: require('./bitmaptext/static/BitmapText'),

View file

@ -1,5 +1,5 @@
var BuildGameObject = require('../BuildGameObject');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator');
var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var LightLayer = require('./LightLayer');

View file

@ -1,5 +1,5 @@
var LightLayer = require('./LightLayer');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context.
//

View file

@ -1,5 +1,5 @@
var BuildGameObject = require('../BuildGameObject');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator');
var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var GetValue = require('../../utils/object/GetValue');
var Mesh = require('./Mesh');

View file

@ -1,5 +1,5 @@
var Mesh = require('./Mesh');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context.
//

View file

@ -1,4 +1,4 @@
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator');
var GameObjectCreator = require('../GameObjectCreator');
var GetFastValue = require('../../utils/object/GetFastValue');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var ParticleEmitterManager = require('./ParticleEmitterManager');

View file

@ -1,5 +1,5 @@
var ParticleEmitterManager = require('./ParticleEmitterManager');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context.
//

View file

@ -1,5 +1,5 @@
var PathFollower = require('./PathFollower');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context.
//

View file

@ -1,5 +1,5 @@
var BuildGameObject = require('../BuildGameObject');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator');
var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var Quad = require('./Quad');

View file

@ -1,5 +1,5 @@
var Quad = require('./Quad');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context.
//

View file

@ -1,6 +1,6 @@
var BuildGameObject = require('../BuildGameObject');
var BuildGameObjectAnimation = require('../BuildGameObjectAnimation');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator');
var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var Sprite = require('./Sprite');

View file

@ -1,5 +1,5 @@
var Sprite = require('./Sprite');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context.
//

View file

@ -1,6 +1,6 @@
var BuildGameObject = require('../BuildGameObject');
var BuildGameObjectAnimation = require('../BuildGameObjectAnimation');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator');
var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var Sprite3D = require('./Sprite3D');

View file

@ -1,5 +1,5 @@
var Sprite3D = require('./Sprite3D');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context.
//

View file

@ -1,5 +1,5 @@
var BuildGameObject = require('../../BuildGameObject');
var GameObjectCreator = require('../../../scene/plugins/GameObjectCreator');
var GameObjectCreator = require('../../GameObjectCreator');
var GetAdvancedValue = require('../../../utils/object/GetAdvancedValue');
var Text = require('./Text');

View file

@ -1,5 +1,5 @@
var Text = require('./Text');
var GameObjectFactory = require('../../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context.
//

View file

@ -1,4 +1,4 @@
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator');
var GameObjectCreator = require('../GameObjectCreator');
var ParseToTilemap = require('./ParseToTilemap');
// When registering a factory function 'this' refers to the GameObjectCreator context.

View file

@ -1,4 +1,4 @@
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../GameObjectFactory');
var ParseToTilemap = require('./ParseToTilemap');
// When registering a factory function 'this' refers to the GameObjectFactory context.

View file

@ -17,7 +17,6 @@ var DynamicTilemapLayer = new Class({
Components.RenderTarget,
Components.ScaleMode,
Components.Size,
Components.Texture,
Components.Transform,
Components.Visible,
Components.ScrollFactor,
@ -90,9 +89,7 @@ var DynamicTilemapLayer = new Class({
this.culledTiles = [];
this.setAlpha(this.layer.alpha);
this.setTexture(tileset.image.key);
this.setPosition(x, y);
this.setSizeToFrame();
this.setOrigin();
this.setSize(this.layer.tileWidth * this.layer.width, this.layer.tileHeight * this.layer.height);
},

View file

@ -11,7 +11,7 @@ var DynamicTilemapLayerCanvasRenderer = function (renderer, gameObject, interpol
var renderTiles = gameObject.culledTiles;
var length = renderTiles.length;
var image = gameObject.frame.source.image;
var image = gameObject.tileset.image.getSourceImage();
var tileset = this.tileset;
var tx = gameObject.x - camera.scrollX * gameObject.scrollFactorX;

View file

@ -12,7 +12,7 @@ var DynamicTilemapLayerWebGLRenderer = function (renderer, gameObject, interpola
var renderTiles = gameObject.culledTiles;
var length = renderTiles.length;
var batch = renderer.spriteBatch;
var texture = gameObject.texture.source[0].glTexture;
var texture = gameObject.tileset.image.get().source.glTexture;
var textureWidth = texture.width;
var textureHeight = texture.height;
var tileset = this.tileset;

View file

@ -18,7 +18,6 @@ var StaticTilemapLayer = new Class({
Components.RenderTarget,
Components.ScaleMode,
Components.Size,
Components.Texture,
Components.Transform,
Components.Visible,
Components.ScrollFactor,
@ -99,9 +98,7 @@ var StaticTilemapLayer = new Class({
this.vertexCount = 0;
this.setAlpha(this.layer.alpha);
this.setTexture(tileset.image.key);
this.setPosition(x, y);
this.setSizeToFrame();
this.setOrigin();
this.setSize(this.layer.tileWidth * this.layer.width, this.layer.tileHeight * this.layer.height);
@ -113,7 +110,6 @@ var StaticTilemapLayer = new Class({
*/
contextRestore: function (renderer)
{
this.tileTexture = null;
this.dirty = true;
this.vbo = null;
this.gl = renderer.gl;
@ -131,8 +127,8 @@ var StaticTilemapLayer = new Class({
var tileset = this.tileset;
var mapWidth = this.layer.width;
var mapHeight = this.layer.height;
var width = this.texture.source[0].width;
var height = this.texture.source[0].height;
var width = tileset.image.get().width;
var height = tileset.image.get().height;
var mapData = this.layer.data;
var tile;

View file

@ -12,10 +12,9 @@ var StaticTilemapLayerCanvasRenderer = function (renderer, gameObject, interpola
var renderTiles = gameObject.culledTiles;
var tileset = this.tileset;
var frame = gameObject.frame;
var ctx = renderer.gameContext;
var tileCount = renderTiles.length;
var image = frame.source.image;
var image = tileset.image.getSourceImage();
var tx = gameObject.x - camera.scrollX * gameObject.scrollFactorX;
var ty = gameObject.y - camera.scrollY * gameObject.scrollFactorY;

View file

@ -8,10 +8,10 @@ var StaticTilemapLayerWebGLRenderer = function (renderer, src, interpolationPerc
}
var gameObject = src;
var frame = gameObject.frame;
var gl = gameObject.gl;
var frame = gameObject.tileset.image.get();
renderer.setRenderer(gameObject.tilemapRenderer, frame.texture.source[frame.sourceIndex].glTexture, gameObject.renderTarget);
renderer.setRenderer(gameObject.tilemapRenderer, frame.source.glTexture, gameObject.renderTarget);
gameObject.tilemapRenderer.bind();
gameObject.upload(camera);

View file

@ -1,5 +1,5 @@
var BuildGameObject = require('../BuildGameObject');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator');
var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var TileSprite = require('./TileSprite');

View file

@ -1,5 +1,5 @@
var TileSprite = require('./TileSprite');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context.
//

View file

@ -1,4 +1,4 @@
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator');
var GameObjectCreator = require('../GameObjectCreator');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var Zone = require('./Zone');

View file

@ -1,5 +1,5 @@
var Zone = require('./Zone');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
var GameObjectFactory = require('../GameObjectFactory');
// When registering a factory function 'this' refers to the GameObjectFactory context.
//

View file

@ -10,8 +10,8 @@
*/
var Circumference = function (ellipse)
{
var rx = ellipse.width;
var ry = ellipse.height;
var rx = ellipse.width / 2;
var ry = ellipse.height / 2;
var h = Math.pow((rx - ry), 2) / Math.pow((rx + ry), 2);
return (Math.PI * (rx + ry)) * (1 + ((3 * h) / (10 + Math.sqrt(4 - (3 * h)))));

View file

@ -18,8 +18,8 @@ var Contains = function (ellipse, x, y)
}
// Normalize the coords to an ellipse with center 0,0 and a radius of 0.5
var normx = ((x - ellipse.x) / ellipse.width) - 0.5;
var normy = ((y - ellipse.y) / ellipse.height) - 0.5;
var normx = ((x - ellipse.x) / ellipse.width);
var normy = ((y - ellipse.y) / ellipse.height);
normx *= normx;
normy *= normy;

View file

@ -15,8 +15,8 @@ var GetBounds = function (ellipse, out)
{
if (out === undefined) { out = new Rectangle(); }
out.x = ellipse.x - ellipse.width;
out.y = ellipse.y - ellipse.height;
out.x = ellipse.left;
out.y = ellipse.top;
out.width = ellipse.width;
out.height = ellipse.height;

View file

@ -10,6 +10,7 @@ var Rectangle = require('../geom/rectangle/Rectangle');
var RectangleContains = require('../geom/rectangle/Contains');
var Triangle = require('../geom/triangle/Triangle');
var TriangleContains = require('../geom/triangle/Contains');
var PluginManager = require('../plugins/PluginManager');
// Drag Events
// https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API
@ -29,6 +30,12 @@ var InputPlugin = new Class({
// The Scene that owns this plugin
this.scene = scene;
this.systems = scene.sys;
this.mapping = 'input';
this.systems.events.on('boot', this.boot, this);
// InputManager
this.manager = scene.sys.game.input;
@ -87,36 +94,21 @@ var InputPlugin = new Class({
this._validTypes = [ 'onDown', 'onUp', 'onOver', 'onOut', 'onMove', 'onDragStart', 'onDrag', 'onDragEnd', 'onDragEnter', 'onDragLeave', 'onDragOver', 'onDrop' ];
},
activePointer: {
boot: function ()
{
this.systems.inject(this);
get: function ()
{
return this.manager.activePointer;
}
this.systems.events.on('preupdate', this.preUpdate, this);
this.systems.events.on('update', this.update, this);
this.systems.events.on('shutdown', this.shutdown, this);
this.systems.events.on('destroy', this.destroy, this);
this.cameras = this.systems.cameras;
this.displayList = this.systems.displayList;
},
// The x/y coordinates of the ActivePointer based on the first camera in the camera list.
// This is only safe to use if your game has just 1 non-transformed camera and doesn't use multi-touch.
x: {
get: function ()
{
return this.manager.activePointer.x;
}
},
y: {
get: function ()
{
return this.manager.activePointer.y;
}
},
begin: function ()
preUpdate: function ()
{
var removeList = this._pendingRemoval;
var insertList = this._pendingInsertion;
@ -156,13 +148,6 @@ var InputPlugin = new Class({
this._list = current.concat(insertList.splice(0));
},
boot: function ()
{
this.cameras = this.scene.sys.cameras;
this.displayList = this.scene.sys.displayList;
},
clear: function (gameObject)
{
var input = gameObject.input;
@ -209,7 +194,7 @@ var InputPlugin = new Class({
// Get a list of all objects that can be seen by the camera below the pointer in the scene and store in 'output' array.
// All objects in this array are input enabled, as checked by the hitTest method, so we don't need to check later on as well.
return this.manager.hitTest(this._list, pointer.x, pointer.y, camera);
return this.manager.hitTest(pointer.x, pointer.y, this._list, camera);
}
else
{
@ -988,8 +973,39 @@ var InputPlugin = new Class({
this.keyboard = undefined;
this.mouse = undefined;
this.gamepad = undefined;
}
},
activePointer: {
get: function ()
{
return this.manager.activePointer;
}
},
// The x/y coordinates of the ActivePointer based on the first camera in the camera list.
// This is only safe to use if your game has just 1 non-transformed camera and doesn't use multi-touch.
x: {
get: function ()
{
return this.manager.activePointer.x;
}
},
y: {
get: function ()
{
return this.manager.activePointer.y;
}
},
});
PluginManager.register('input', InputPlugin);
module.exports = InputPlugin;

View file

@ -3,6 +3,8 @@
module.exports = {
Gamepad: require('./gamepad'),
InputManager: require('./InputManager'),
InputPlugin: require('./InputPlugin'),
InteractiveObject: require('./InteractiveObject'),
Keyboard: require('./keyboard'),
Mouse: require('./mouse'),

View file

@ -1,26 +1,28 @@
var BaseLoader = require('../../loader/BaseLoader');
var Class = require('../../utils/Class');
var CONST = require('../../loader/const');
var NumberArray = require('../../utils/array/NumberArray');
var BaseLoader = require('./BaseLoader');
var Class = require('../utils/Class');
var CONST = require('./const');
var NumberArray = require('../utils/array/NumberArray');
var PluginManager = require('../plugins/PluginManager');
var AnimationJSONFile = require('../../loader/filetypes/AnimationJSONFile');
var AtlasJSONFile = require('../../loader/filetypes/AtlasJSONFile');
var AudioFile = require('../../loader/filetypes/AudioFile');
var BinaryFile = require('../../loader/filetypes/BinaryFile');
var BitmapFontFile = require('../../loader/filetypes/BitmapFontFile');
var GLSLFile = require('../../loader/filetypes/GLSLFile');
var HTMLFile = require('../../loader/filetypes/HTMLFile');
var ImageFile = require('../../loader/filetypes/ImageFile');
var JSONFile = require('../../loader/filetypes/JSONFile');
var ScriptFile = require('../../loader/filetypes/ScriptFile');
var SpriteSheet = require('../../loader/filetypes/SpriteSheet');
var SVGFile = require('../../loader/filetypes/SVGFile');
var TextFile = require('../../loader/filetypes/TextFile');
var TilemapCSVFile = require('../../loader/filetypes/TilemapCSVFile');
var TilemapJSONFile = require('../../loader/filetypes/TilemapJSONFile');
var UnityAtlasFile = require('../../loader/filetypes/UnityAtlasFile');
var WavefrontFile = require('../../loader/filetypes/WavefrontFile');
var XMLFile = require('../../loader/filetypes/XMLFile');
// TODO - Injection mapped
var AnimationJSONFile = require('./filetypes/AnimationJSONFile');
var AtlasJSONFile = require('./filetypes/AtlasJSONFile');
var AudioFile = require('./filetypes/AudioFile');
var BinaryFile = require('./filetypes/BinaryFile');
var BitmapFontFile = require('./filetypes/BitmapFontFile');
var GLSLFile = require('./filetypes/GLSLFile');
var HTMLFile = require('./filetypes/HTMLFile');
var ImageFile = require('./filetypes/ImageFile');
var JSONFile = require('./filetypes/JSONFile');
var ScriptFile = require('./filetypes/ScriptFile');
var SpriteSheet = require('./filetypes/SpriteSheet');
var SVGFile = require('./filetypes/SVGFile');
var TextFile = require('./filetypes/TextFile');
var TilemapCSVFile = require('./filetypes/TilemapCSVFile');
var TilemapJSONFile = require('./filetypes/TilemapJSONFile');
var UnityAtlasFile = require('./filetypes/UnityAtlasFile');
var WavefrontFile = require('./filetypes/WavefrontFile');
var XMLFile = require('./filetypes/XMLFile');
var Loader = new Class({
@ -32,9 +34,23 @@ var Loader = new Class({
{
BaseLoader.call(this, scene);
this.systems = scene.sys;
this.mapping = 'load';
this.systems.events.on('boot', this.boot, this);
this._multilist = {};
},
boot: function ()
{
this.systems.inject(this);
this.systems.events.on('shutdown', this.shutdown, this);
this.systems.events.on('destroy', this.destroy, this);
},
// key can be either a string, an object or an array of objects
image: function (key, url, xhrSettings)
@ -294,8 +310,15 @@ var Loader = new Class({
}
return entry;
},
shutdown: function ()
{
}
});
PluginManager.register('load', Loader);
module.exports = Loader;

9
src/loader/index.js Normal file
View file

@ -0,0 +1,9 @@
// Phaser.Loader
module.exports = {
BaseLoader: require('./BaseLoader'),
File: require('./File'),
LoaderPlugin: require('./Loader')
};

View file

@ -8,46 +8,29 @@ var Extend = require('./utils/object/Extend');
var Phaser = {
Actions: require('./actions/'),
Create: require('./create/'),
Animation: require('./animations/'),
Cache: require('./cache/'),
Cameras: require('./cameras/'),
DOM: require('./dom/'),
EventEmitter: require('./events/EventEmitter'),
Game: require('./boot/Game'),
Math: require('./math'),
Geom: require('./geom'),
Display: require('./display'),
Input: require('./input'),
GameObjects: require('./gameobjects'),
Scene: require('./scene/local/Scene'),
Loader: {
ImageFile: require('./loader/filetypes/ImageFile')
},
Sound: require('./sound'),
Structs: require('./structs'),
Curves: require('./curves'),
Physics: require('./physics'),
Class: require('./utils/Class'),
Utils: require('./utils')
Create: require('./create/'),
Curves: require('./curves/'),
Display: require('./display/'),
DOM: require('./dom/'),
EventEmitter: require('./events/EventEmitter'),
Game: require('./boot/Game'),
GameObjects: require('./gameobjects/'),
Geom: require('./geom/'),
Input: require('./input/'),
Loader: require('./loader/'),
Math: require('./math/'),
Physics: require('./physics/'),
Scene: require('./scene/Scene'),
Sound: require('./sound/'),
Structs: require('./structs/'),
Textures: require('./textures/'),
Time: require('./time/'),
Tweens: require('./tweens/'),
Utils: require('./utils/')
};

View file

@ -1,20 +0,0 @@
var Class = require('../../utils/Class');
var Factory = require('./Factory');
var World = require('./World');
var Arcade = new Class({
initialize:
function Arcade (physicsManager, config)
{
this.config = config;
physicsManager.world = new World(physicsManager.scene, config);
physicsManager.add = new Factory(physicsManager.world);
}
});
module.exports = Arcade;

View file

@ -0,0 +1,100 @@
var Class = require('../../utils/Class');
var Factory = require('./Factory');
var GetFastValue = require('../../utils/object/GetFastValue');
var Merge = require('../../utils/object/Merge');
var PluginManager = require('../../plugins/PluginManager');
var World = require('./World');
// Phaser.Physics.Arcade.ArcadePhysics
var ArcadePhysics = new Class({
initialize:
function ArcadePhysics (scene)
{
// The Scene that owns this plugin
this.scene = scene;
this.systems = scene.sys;
this.mapping = 'physics';
this.systems.events.on('boot', this.boot, this);
this.config = this.getConfig();
this.world;
this.add;
},
getConfig: function ()
{
var gameConfig = this.systems.game.config.physics;
var sceneConfig = this.systems.settings.physics;
var config = Merge(
GetFastValue(sceneConfig, 'arcade', {}),
GetFastValue(gameConfig, 'arcade', {})
);
return config;
},
boot: function ()
{
this.world = new World(this.scene, this.config);
this.add = new Factory(this.world);
this.systems.inject(this);
this.systems.events.on('update', this.world.update, this.world);
this.systems.events.on('postupdate', this.world.postUpdate, this.world);
this.systems.events.on('shutdown', this.shutdown, this);
this.systems.events.on('destroy', this.destroy, this);
},
overlap: function (object1, object2, overlapCallback, processCallback, callbackContext)
{
if (overlapCallback === undefined) { overlapCallback = null; }
if (processCallback === undefined) { processCallback = null; }
if (callbackContext === undefined) { callbackContext = overlapCallback; }
return this.world.collideObjects(object1, object2, overlapCallback, processCallback, callbackContext, true);
},
collide: function (object1, object2, collideCallback, processCallback, callbackContext)
{
if (collideCallback === undefined) { collideCallback = null; }
if (processCallback === undefined) { processCallback = null; }
if (callbackContext === undefined) { callbackContext = collideCallback; }
return this.world.collideObjects(object1, object2, collideCallback, processCallback, callbackContext, false);
},
// Utils
accelerateTo: require('./utils/AccelerateTo'),
accelerateToObject: require('./utils/AccelerateToObject'),
closest: require('./utils/Closest'),
furthest: require('./utils/Furthest'),
moveTo: require('./utils/MoveTo'),
moveToObject: require('./utils/MoveToObject'),
velocityFromAngle: require('./utils/VelocityFromAngle'),
velocityFromRotation: require('./utils/VelocityFromRotation'),
shutdown: function ()
{
this.world.shutdown();
},
destroy: function ()
{
this.world.destroy();
}
});
PluginManager.register('arcadePhysics', ArcadePhysics);
module.exports = ArcadePhysics;

View file

@ -1,5 +1,3 @@
// Phaser.Physics.Arcade.World
var Body = require('./Body');
var Class = require('../../utils/Class');
var Collider = require('./Collider');
@ -13,6 +11,8 @@ var Set = require('../../structs/Set');
var StaticBody = require('./StaticBody');
var Vector2 = require('../../math/Vector2');
// Phaser.Physics.Arcade.World
var World = new Class({
Extends: EventEmitter,
@ -399,16 +399,6 @@ var World = new Class({
collideGroupVsTilemapLayer: require('./inc/CollideGroupVsTilemapLayer'),
collideSpriteVsTilemapLayer: require('./inc/CollideSpriteVsTilemapLayer'),
// Utils
accelerateTo: require('./utils/AccelerateTo'),
accelerateToObject: require('./utils/AccelerateToObject'),
closest: require('./utils/Closest'),
furthest: require('./utils/Furthest'),
moveTo: require('./utils/MoveTo'),
moveToObject: require('./utils/MoveToObject'),
velocityFromAngle: require('./utils/VelocityFromAngle'),
velocityFromRotation: require('./utils/VelocityFromRotation'),
// TODO
collideGroupVsGroup: function (group1, group2, collideCallback, processCallback, callbackContext, overlapOnly)
{

View file

@ -11,10 +11,30 @@ var CollideSpriteVsTilemapLayer = function (sprite, tilemapLayer, collideCallbac
return false;
}
var mapData = tilemapLayer.getTilesWithinWorldXY(
body.position.x, body.position.y,
body.width, body.height
);
var x = body.position.x;
var y = body.position.y;
var w = body.width;
var h = body.height;
// TODO: this logic should be encapsulated within the Tilemap API at some point.
// If the map's base tile size differs from the layer's tile size, we need to adjust the
// selection area by the difference between the two.
var layerData = tilemapLayer.layer;
if (layerData.tileWidth > layerData.baseTileWidth)
{
// The x origin of a tile is the left side, so x and width need to be adjusted.
let xDiff = (layerData.tileWidth - layerData.baseTileWidth) * tilemapLayer.scaleX;
x -= xDiff;
w += xDiff;
}
if (layerData.tileHeight > layerData.baseTileHeight)
{
// The y origin of a tile is the bottom side, so just the height needs to be adjusted.
let yDiff = (layerData.tileHeight - layerData.baseTileHeight) * tilemapLayer.scaleY;
h += yDiff;
}
var mapData = tilemapLayer.getTilesWithinWorldXY(x, y, w, h);
if (mapData.length === 0)
{
@ -29,6 +49,14 @@ var CollideSpriteVsTilemapLayer = function (sprite, tilemapLayer, collideCallbac
tile = mapData[i];
tileWorldRect.left = tilemapLayer.tileToWorldX(tile.x);
tileWorldRect.top = tilemapLayer.tileToWorldY(tile.y);
// If the map's base tile size differs from the layer's tile size, only the top of the rect
// needs to be adjusted since it's origin is (0, 1).
if (tile.baseHeight !== tile.height)
{
tileWorldRect.top -= (tile.height - tile.baseHeight) * tilemapLayer.scaleY;
}
tileWorldRect.right = tileWorldRect.left + tile.width * tilemapLayer.scaleX;
tileWorldRect.bottom = tileWorldRect.top + tile.height * tilemapLayer.scaleY;

View file

@ -55,7 +55,7 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer, tileBia
{
if (faceHorizontal)
{
ox = TileCheckX(body, tile, tilemapLayer, tileBias);
ox = TileCheckX(body, tile, tileLeft, tileRight, tileBias);
// That's horizontal done, check if we still intersects? If not then we can return now
if (ox !== 0 && !TileIntersectsBody(tileWorldRect, body))
@ -66,14 +66,14 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer, tileBia
if (faceVertical)
{
oy = TileCheckY(body, tile, tilemapLayer, tileBias);
oy = TileCheckY(body, tile, tileTop, tileBottom, tileBias);
}
}
else
{
if (faceVertical)
{
oy = TileCheckY(body, tile, tilemapLayer, tileBias);
oy = TileCheckY(body, tile, tileTop, tileBottom, tileBias);
// That's vertical done, check if we still intersects? If not then we can return now
if (oy !== 0 && !TileIntersectsBody(tileWorldRect, body))
@ -84,7 +84,7 @@ var SeparateTile = function (i, body, tile, tileWorldRect, tilemapLayer, tileBia
if (faceHorizontal)
{
ox = TileCheckX(body, tile, tilemapLayer, tileBias);
ox = TileCheckX(body, tile, tileLeft, tileRight, tileBias);
}
}

View file

@ -10,12 +10,9 @@ var ProcessTileSeparationX = require('./ProcessTileSeparationX');
* @param {Phaser.TilemapLayer} tilemapLayer - The tilemapLayer to collide against.
* @return {number} The amount of separation that occurred.
*/
var TileCheckX = function (body, tile, tilemapLayer, tileBias)
var TileCheckX = function (body, tile, tileLeft, tileRight, tileBias)
{
var ox = 0;
var tileLeft = tilemapLayer.tileToWorldX(tile.x);
var tileWidth = tile.width * tilemapLayer.scaleX;
var tileRight = tileLeft + tileWidth;
if (body.deltaX() < 0 && !body.blocked.left && tile.collideRight && body.checkCollision.left)
{

View file

@ -10,12 +10,9 @@ var ProcessTileSeparationY = require('./ProcessTileSeparationY');
* @param {Phaser.TilemapLayer} tilemapLayer - The tilemapLayer to collide against.
* @return {number} The amount of separation that occurred.
*/
var TileCheckY = function (body, tile, tilemapLayer, tileBias)
var TileCheckY = function (body, tile, tileTop, tileBottom, tileBias)
{
var oy = 0;
var tileTop = tilemapLayer.tileToWorldX(tile.y);
var tileHeight = tile.height * tilemapLayer.scaleY;
var tileBottom = tileTop + tileHeight;
if (body.deltaY() < 0 && !body.blocked.up && tile.collideDown && body.checkCollision.up)
{

View file

@ -1,15 +1,16 @@
// Phaser.Physics.Arcade
// World updated to run off the Phaser main loop.
// Body extended to support additional setter functions.
module.exports = {
ArcadePhysics: require('./ArcadePhysics'),
Body: require('./Body'),
Collider: require('./Collider'),
Factory: require('./Factory'),
Group: require('./PhysicsGroup'),
Image: require('./ArcadeImage'),
Sprite: require('./ArcadeSprite'),
StaticBody: require('./StaticBody'),
StaticGroup: require('./StaticPhysicsGroup'),
World: require('./World')
};

View file

@ -1,20 +0,0 @@
var Class = require('../../utils/Class');
var Factory = require('./Factory');
var World = require('./World');
var Impact = new Class({
initialize:
function Impact (physicsManager, config)
{
this.config = config;
physicsManager.world = new World(physicsManager.scene, config);
physicsManager.add = new Factory(physicsManager.world);
}
});
module.exports = Impact;

View file

@ -0,0 +1,71 @@
var Class = require('../../utils/Class');
var Factory = require('./Factory');
var GetFastValue = require('../../utils/object/GetFastValue');
var Merge = require('../../utils/object/Merge');
var PluginManager = require('../../plugins/PluginManager');
var World = require('./World');
// Phaser.Physics.Impact.ImpactPhysics
var ImpactPhysics = new Class({
initialize:
function ImpactPhysics (scene)
{
// The Scene that owns this plugin
this.scene = scene;
this.systems = scene.sys;
this.mapping = 'impact';
this.systems.events.on('boot', this.boot, this);
this.config = this.getConfig();
this.world;
this.add;
},
getConfig: function ()
{
var gameConfig = this.systems.game.config.physics;
var sceneConfig = this.systems.settings.physics;
var config = Merge(
GetFastValue(sceneConfig, 'impact', {}),
GetFastValue(gameConfig, 'impact', {})
);
return config;
},
boot: function ()
{
this.world = new World(this.scene, this.config);
this.add = new Factory(this.world);
this.systems.inject(this);
this.systems.events.on('update', this.world.update, this.world);
this.systems.events.on('shutdown', this.shutdown, this);
this.systems.events.on('destroy', this.destroy, this);
},
shutdown: function ()
{
this.world.shutdown();
},
destroy: function ()
{
this.world.destroy();
}
});
PluginManager.register('impactPhysics', ImpactPhysics);
module.exports = ImpactPhysics;

View file

@ -216,11 +216,6 @@ var World = new Class({
return this;
},
postUpdate: function ()
{
// NOOP
},
update: function (time, delta)
{
if (!this.enabled || this.bodies.size === 0)

View file

@ -15,10 +15,14 @@
module.exports = {
Body: require('./Body'),
Body: require('./ImpactBody'),
COLLIDES: require('./COLLIDES'),
CollisionMap: require('./CollisionMap'),
Factory: require('./Factory'),
Image: require('./ImpactImage'),
ImpactPhysics: require('./ImpactPhysics'),
Sprite: require('./ImpactSprite'),
TYPE: require('./TYPE'),
World: require('./World'),
Factory: require('./Factory')
World: require('./World')
};

View file

@ -1,8 +1,10 @@
// Phaser.Physics
module.exports = {
Arcade: require('./arcade'),
Impact: require('./impact'),
Matter: require('./matter-js/CustomMain'),
Matter: require('./matter-js'),
PolyDecomp: require('./poly-decomp')
};

View file

@ -1,57 +0,0 @@
var Class = require('../../utils/Class');
var Factory = require('./Factory');
var GetValue = require('../../utils/object/GetValue');
var MatterAttractors = require('./lib/plugins/MatterAttractors');
var MatterLib = require('./lib/core/Matter');
var MatterWrap = require('./lib/plugins/MatterWrap');
var Plugin = require('./lib/core/Plugin');
var World = require('./World');
var Matter = new Class({
initialize:
// Referenced from the Scene PhysicsManager as `system`
function Matter (physicsManager, config)
{
this.config = config;
physicsManager.world = new World(physicsManager.scene, config);
physicsManager.add = new Factory(physicsManager.world);
// Matter plugins
if (GetValue(config, 'plugins.attractors', false))
{
Plugin.register(MatterAttractors);
Plugin.use(MatterLib, MatterAttractors);
}
if (GetValue(config, 'plugins.wrap', false))
{
Plugin.register(MatterWrap);
Plugin.use(MatterLib, MatterWrap);
}
},
enableAttractorPlugin: function ()
{
Plugin.register(MatterAttractors);
Plugin.use(MatterLib, MatterAttractors);
return this;
},
enableWrapPlugin: function ()
{
Plugin.register(MatterWrap);
Plugin.use(MatterLib, MatterWrap);
return this;
}
});
module.exports = Matter;

View file

@ -0,0 +1,111 @@
var Class = require('../../utils/Class');
var Factory = require('./Factory');
var GetFastValue = require('../../utils/object/GetFastValue');
var GetValue = require('../../utils/object/GetValue');
var MatterAttractors = require('./lib/plugins/MatterAttractors');
var MatterLib = require('./lib/core/Matter');
var MatterWrap = require('./lib/plugins/MatterWrap');
var Merge = require('../../utils/object/Merge');
var Plugin = require('./lib/core/Plugin');
var PluginManager = require('../../plugins/PluginManager');
var World = require('./World');
// Phaser.Physics.Matter.MatterPhysics
var MatterPhysics = new Class({
initialize:
// Referenced from the Scene PhysicsManager as `system`
function MatterPhysics (scene)
{
// The Scene that owns this plugin
this.scene = scene;
this.systems = scene.sys;
this.mapping = 'matter';
this.systems.events.on('boot', this.boot, this);
this.config = this.getConfig();
this.world;
this.add;
},
getConfig: function ()
{
var gameConfig = this.systems.game.config.physics;
var sceneConfig = this.systems.settings.physics;
var config = Merge(
GetFastValue(sceneConfig, 'matter', {}),
GetFastValue(gameConfig, 'matter', {})
);
return config;
},
boot: function ()
{
var config = this.config;
this.world = new World(this.scene, config);
this.add = new Factory(this.world);
// Matter plugins
if (GetValue(config, 'plugins.attractors', false))
{
Plugin.register(MatterAttractors);
Plugin.use(MatterLib, MatterAttractors);
}
if (GetValue(config, 'plugins.wrap', false))
{
Plugin.register(MatterWrap);
Plugin.use(MatterLib, MatterWrap);
}
this.systems.inject(this);
this.systems.events.on('update', this.world.update, this.world);
this.systems.events.on('postupdate', this.world.postUpdate, this.world);
this.systems.events.on('shutdown', this.shutdown, this);
this.systems.events.on('destroy', this.destroy, this);
},
enableAttractorPlugin: function ()
{
Plugin.register(MatterAttractors);
Plugin.use(MatterLib, MatterAttractors);
return this;
},
enableWrapPlugin: function ()
{
Plugin.register(MatterWrap);
Plugin.use(MatterLib, MatterWrap);
return this;
},
shutdown: function ()
{
this.world.shutdown();
},
destroy: function ()
{
this.world.destroy();
}
});
PluginManager.register('matterPhysics', MatterPhysics);
module.exports = MatterPhysics;

View file

@ -307,36 +307,38 @@ var World = new Class({
postUpdate: function ()
{
if (this.drawDebug)
if (!this.drawDebug)
{
var graphics = this.debugGraphic;
var bodies = Composite.allBodies(this.localWorld);
return;
}
graphics.clear();
graphics.lineStyle(1, this.defaults.bodyDebugColor);
var graphics = this.debugGraphic;
var bodies = Composite.allBodies(this.localWorld);
for (var i = 0; i < bodies.length; i++)
graphics.clear();
graphics.lineStyle(1, this.defaults.bodyDebugColor);
for (var i = 0; i < bodies.length; i++)
{
var body = bodies[i];
if (!body.render.visible)
{
var body = bodies[i];
if (!body.render.visible)
{
continue;
}
var vertices = body.vertices;
graphics.moveTo(vertices[0].x, vertices[0].y);
for (var j = 1; j < vertices.length; j++)
{
graphics.lineTo(vertices[j].x, vertices[j].y);
}
graphics.lineTo(vertices[0].x, vertices[0].y);
graphics.strokePath();
continue;
}
var vertices = body.vertices;
graphics.moveTo(vertices[0].x, vertices[0].y);
for (var j = 1; j < vertices.length; j++)
{
graphics.lineTo(vertices[j].x, vertices[j].y);
}
graphics.lineTo(vertices[0].x, vertices[0].y);
graphics.strokePath();
}
},
@ -362,7 +364,6 @@ var World = new Class({
destroy: function ()
{
// TODO
this.shutdown();
}

View file

@ -0,0 +1,12 @@
// Phaser.Physics.Matter
module.exports = {
Factory: require('./Factory'),
Image: require('./MatterImage'),
Matter: require('./CustomMain'),
MatterPhysics: require('./MatterPhysics'),
Sprite: require('./MatterSprite'),
World: require('./World')
};

View file

@ -16,20 +16,29 @@ var PluginManager = new Class({
{
},
install: function (scene, config)
install: function (scene, globalPlugins, localPlugins)
{
var i;
var pluginKey;
var sys = scene.sys;
for (var i = 0; i < config.length; i++)
for (var i = 0; i < globalPlugins.length; i++)
{
var p = config[i];
pluginKey = globalPlugins[i];
console.log('installing', p);
sys.scene[pluginKey] = sys[pluginKey];
}
if (plugins[p])
for (var i = 0; i < localPlugins.length; i++)
{
pluginKey = localPlugins[i];
if (plugins[pluginKey])
{
// console.log('installing', pluginKey);
// Install a local reference inside of Systems
sys[p] = new plugins[p](scene);
sys[pluginKey] = new plugins[pluginKey](scene);
}
}
},
@ -52,7 +61,7 @@ PluginManager.register = function (key, plugin)
{
plugins[key] = plugin;
console.log('PluginManager.register', key);
// console.log('PluginManager.register', key);
};
module.exports = PluginManager;

View file

@ -1,5 +1,5 @@
// These properties get injected into the Scene and map to local systems
// The map key is the local system reference, the value is the property that is added to the Scene
// The map key is the property that is added to the Scene, the value is the Scene.Systems reference
// These defaults can be modified via the Scene config object
var InjectionMap = {
@ -14,14 +14,16 @@ var InjectionMap = {
add: 'add',
cameras: 'cameras',
children: 'displayList',
data: 'data',
displayList: 'children',
events: 'events',
inputManager: 'input',
impact: 'impactPhysics',
input: 'input',
load: 'load',
make: 'make',
physicsManager: 'physics',
sceneManager: 'scene',
matter: 'matterPhysics',
physics: 'arcadePhysics',
scene: 'sceneManager',
time: 'time',
tweens: 'tweens'

View file

@ -1,5 +1,4 @@
var Class = require('../../utils/Class');
var Class = require('../utils/Class');
var Systems = require('./Systems');
var Scene = new Class({

View file

@ -4,8 +4,8 @@ var Class = require('../utils/Class');
var CONST = require('../const');
var GetValue = require('../utils/object/GetValue');
var NOOP = require('../utils/NOOP');
var Scene = require('./local/Scene');
var Systems = require('./local/Systems');
var Scene = require('./Scene');
var Systems = require('./Systems');
var SceneManager = new Class({

View file

@ -1,5 +1,5 @@
var Class = require('../../utils/Class');
var PluginManager = require('../../plugins/PluginManager');
var Class = require('../utils/Class');
var PluginManager = require('../plugins/PluginManager');
// A proxy class to the Global Scene Manager
var SceneManager = new Class({
@ -32,11 +32,12 @@ var SceneManager = new Class({
{
this.systems.inject(this);
this.systems.events.on('preupdate', this.preUpdate, this);
this.systems.events.on('shutdown', this.shutdown, this);
this.systems.events.on('destroy', this.destroy, this);
},
update: function ()
preUpdate: function ()
{
var len = this._queue.length;

View file

@ -1,6 +1,6 @@
var CONST = require('../const');
var ScaleModes = require('../../renderer/ScaleModes');
var GetValue = require('../../utils/object/GetValue');
var CONST = require('./const');
var ScaleModes = require('../renderer/ScaleModes');
var GetValue = require('../utils/object/GetValue');
var InjectionMap = require('./InjectionMap');
var Settings = {

View file

@ -1,21 +1,8 @@
// var CameraManager = require('../../camera/local/CameraManager');
var Class = require('../../utils/Class');
var Clock = require('../../time/Clock');
var Data = require('../../data/Data');
var DataStore = require('../../data/DataStore');
var DisplayList = require('../plugins/DisplayList');
var Class = require('../utils/Class');
var EventEmitter = require('eventemitter3');
var GameObjectCreator = require('../plugins/GameObjectCreator');
var GameObjectFactory = require('../plugins/GameObjectFactory');
var InputManager = require('../../input/InputPlugin');
var Loader = require('../plugins/Loader');
var PhysicsManager = require('../plugins/PhysicsManager');
var SceneManager = require('../plugins/SceneManager');
var GetFastValue = require('../utils/object/GetFastValue');
var ScenePlugin = require('./ScenePlugin');
var Settings = require('./Settings');
var TweenManager = require('../../tweens/manager/TweenManager');
var UpdateList = require('../plugins/UpdateList');
var TestPlugin = require('../../plugins/TestPlugin');
var Systems = new Class({
@ -31,7 +18,7 @@ var Systems = new Class({
this.settings = Settings.create(config);
// Set by the GlobalSceneManager - a reference to the Scene canvas / context
// Set by the SceneManager - a reference to the Scene canvas / context
this.canvas;
this.context;
@ -74,27 +61,55 @@ var Systems = new Class({
this.events = new EventEmitter();
game.plugins.install(scene, [ 'displayList', 'updateList', 'sceneManager', 'time', 'cameras', 'add', 'make' ]);
game.plugins.install(scene,
[ 'anims', 'cache', 'registry', 'sound', 'textures' ],
[ 'displayList', 'updateList', 'sceneManager', 'time', 'cameras', 'add', 'make', 'load', 'tweens', 'input' ]
);
// Optional Scene plugins - not referenced by core systems, can be overridden with user code
var physics = this.getPhysicsSystem();
// game.plugins.install(scene, [ , 'test' ]);
this.data = new Data(scene);
this.dataStore = new DataStore(scene);
this.inputManager = new InputManager(scene);
this.load = new Loader(scene);
this.physicsManager = new PhysicsManager(scene);
this.tweens = new TweenManager(scene);
// Sometimes the managers need access to a system created after them
if (physics)
{
game.plugins.install(scene, [], physics);
}
this.events.emit('boot', this);
},
this.inputManager.boot();
this.physicsManager.boot();
getPhysicsSystem: function ()
{
var defaultSystem = this.game.config.defaultPhysicsSystem;
var sceneSystems = GetFastValue(this.settings, 'physics', false);
this.inject2();
if (!defaultSystem && !sceneSystems)
{
// No default physics system or systems in this scene
return;
}
// Let's build the systems array
var output = [];
if (defaultSystem)
{
output.push(defaultSystem + 'Physics');
}
if (sceneSystems)
{
for (var key in sceneSystems)
{
key = key.concat('Physics');
if (output.indexOf(key) === -1)
{
output.push(key);
}
}
}
// An array of Physics systems to start for this Scene
return output;
},
inject: function (plugin)
@ -107,49 +122,20 @@ var Systems = new Class({
}
},
inject2: function ()
{
var map = this.settings.map;
for (var key in map)
{
if (key === 'sys')
{
continue;
}
this.scene[map[key]] = this[key];
}
},
step: function (time, delta)
{
// Are there any pending SceneManager actions?
// This plugin is a special case, as it can literally modify this Scene, so we update it directly.
this.sceneManager.update();
this.events.emit('preupdate', time, delta);
if (!this.settings.active)
{
return;
}
this.events.emit('preupdate', time, delta);
this.tweens.begin(time);
this.inputManager.begin(time);
this.events.emit('update', time, delta);
this.physicsManager.update(time, delta);
this.tweens.update(time, delta);
this.inputManager.update(time, delta);
this.scene.update.call(this.scene, time, delta);
this.events.emit('postupdate', time, delta);
this.physicsManager.postUpdate();
},
render: function (interpolation, renderer)
@ -181,100 +167,67 @@ var Systems = new Class({
// A paused Scene still renders, it just doesn't run ANY of its update handlers or systems
pause: function ()
{
// Was paused by the GlobalSceneManager
// Was paused by the SceneManager
this.settings.active = false;
if (this.scene.pause)
{
this.scene.pause.call(this.scene);
}
this.events.emit('pause', this);
},
resume: function ()
{
// Was resumed by the GlobalSceneManager
// Was resumed by the SceneManager
this.settings.active = true;
if (this.scene.resume)
{
this.scene.resume.call(this.scene);
}
this.events.emit('resume', this);
},
sleep: function ()
{
// Was sent to sleep by the GlobalSceneManager
// Was sent to sleep by the SceneManager
this.settings.active = false;
this.settings.visible = false;
if (this.scene.sleep)
{
this.scene.sleep.call(this.scene);
}
this.events.emit('sleep', this);
},
wake: function ()
{
// Was woken up by the GlobalSceneManager
// Was woken up by the SceneManager
this.settings.active = true;
this.settings.visible = true;
if (this.scene.wake)
{
this.scene.wake.call(this.scene);
}
this.events.emit('wake', this);
},
start: function (data)
{
// Was started by the GlobalSceneManager
// Was started by the SceneManager
this.settings.data = data;
this.settings.active = true;
this.settings.visible = true;
this.events.emit('start', this);
},
shutdown: function ()
{
// Was stopped by the GlobalSceneManager
// Was stopped by the SceneManager
this.settings.active = false;
this.settings.visible = false;
this.events.emit('shutdown', this);
// this.displayList.shutdown();
// this.updateList.shutdown();
// this.time.shutdown();
this.tweens.shutdown();
this.physicsManager.shutdown();
if (this.scene.shutdown)
{
this.scene.shutdown.call(this.scene);
}
},
// TODO: Game level nuke
destroy: function ()
{
this.events.emit('destroy', this);
this.add.destroy();
// this.time.destroy();
this.tweens.destroy();
this.physicsManager.destroy();
// etc
if (this.scene.destroy)
{
this.scene.destroy.call(this.scene);
}
}
});

View file

@ -1,92 +0,0 @@
var Class = require('../../utils/Class');
var GetValue = require('../../utils/object/GetValue');
var Merge = require('../../utils/object/Merge');
var NOOP = require('../../utils/NOOP');
// Physics Systems (TODO: Remove from here)
var Arcade = require('../../physics/arcade/Arcade');
var Impact = require('../../physics/impact/Impact');
var Matter = require('../../physics/matter-js/Matter');
var PhysicsManager = new Class({
initialize:
function PhysicsManager (scene)
{
this.scene = scene;
this.gameConfig = scene.sys.game.config.physics;
this.defaultSystem = scene.sys.game.config.defaultPhysicsSystem;
this.sceneConfig = scene.sys.settings.physics;
// This gets set to an instance of the physics system during boot
this.system;
// This gets set by the physics system during boot
this.world = { update: NOOP, postUpdate: NOOP, shutdown: NOOP, destroy: NOOP };
// This gets set by the physics system during boot
this.add;
},
boot: function ()
{
var sceneSystem = GetValue(this.sceneConfig, 'system', false);
if (!this.defaultSystem && !sceneSystem)
{
// No default physics system or system in this scene, so abort
return;
}
// Which physics system are we using in this Scene?
var system = (sceneSystem !== false) ? sceneSystem : this.defaultSystem;
// Create the config for it
var config = Merge(this.sceneConfig, GetValue(this.gameConfig, system, {}));
switch (system)
{
case 'arcade':
this.system = new Arcade(this, config);
break;
case 'impact':
this.system = new Impact(this, config);
break;
case 'matter':
this.system = new Matter(this, config);
break;
}
},
remove: function (object)
{
this.world.remove(object);
},
update: function (time, delta)
{
this.world.update(time, delta);
},
postUpdate: function ()
{
this.world.postUpdate();
},
shutdown: function ()
{
this.world.shutdown();
},
destroy: function ()
{
this.world.destroy();
}
});
module.exports = PhysicsManager;

11
src/textures/index.js Normal file
View file

@ -0,0 +1,11 @@
// Phaser.Textures
module.exports = {
FilterMode: require('./FilterMode'),
Frame: require('./Frame'),
Texture: require('./Texture'),
TextureManager: require('./TextureManager'),
TextureSource: require('./TextureSource')
};

View file

@ -1,6 +1,6 @@
var Class = require('../../utils/Class');
var TweenBuilder = require('../builder/TweenBuilder');
var TWEEN_CONST = require('../tween/const');
var Class = require('../utils/Class');
var TweenBuilder = require('./builder/TweenBuilder');
var TWEEN_CONST = require('./tween/const');
// Phaser.Tweens.Timeline

View file

@ -1,8 +1,9 @@
var Class = require('../../utils/Class');
var TimelineBuilder = require('../builder/TimelineBuilder');
var TweenBuilder = require('../builder/TweenBuilder');
var NumberTweenBuilder = require('../builder/NumberTweenBuilder');
var TWEEN_CONST = require('../tween/const');
var Class = require('../utils/Class');
var NumberTweenBuilder = require('./builder/NumberTweenBuilder');
var PluginManager = require('../plugins/PluginManager');
var TimelineBuilder = require('./builder/TimelineBuilder');
var TWEEN_CONST = require('./tween/const');
var TweenBuilder = require('./builder/TweenBuilder');
// Phaser.Tweens.TweenManager
@ -12,9 +13,15 @@ var TweenManager = new Class({
function TweenManager (scene)
{
// The Scene the Tween Manager belongs to (tweens are Scene specific, not Game global)
// The Scene that owns this plugin
this.scene = scene;
this.systems = scene.sys;
this.mapping = 'tweens';
this.systems.events.on('boot', this.boot, this);
this.timeScale = 1;
this._add = [];
@ -25,9 +32,15 @@ var TweenManager = new Class({
this._toProcess = 0;
},
// Scene is starting up
boot: function ()
{
this.systems.inject(this);
this.systems.events.on('preupdate', this.preUpdate, this);
this.systems.events.on('update', this.update, this);
this.systems.events.on('shutdown', this.shutdown, this);
this.systems.events.on('destroy', this.destroy, this);
this.timeScale = 1;
},
@ -92,7 +105,7 @@ var TweenManager = new Class({
return tween;
},
begin: function ()
preUpdate: function ()
{
if (this._toProcess === 0)
{
@ -466,4 +479,6 @@ var TweenManager = new Class({
});
PluginManager.register('tweens', TweenManager);
module.exports = TweenManager;

View file

@ -7,7 +7,7 @@ var GetTargets = require('./GetTargets');
var GetTweens = require('./GetTweens');
var GetValue = require('../../utils/object/GetValue');
var GetAdvancedValue = require('../../utils/object/GetAdvancedValue');
var Timeline = require('../timeline/Timeline');
var Timeline = require('../Timeline');
var TweenBuilder = require('./TweenBuilder');
// Phaser.Tweens.TimelineBuilder

View file

@ -2,9 +2,9 @@
module.exports = {
TweenManager: require('./manager/TweenManager'),
TweenManager: require('./TweenManager'),
Tween: require('./tween/Tween'),
TweenData: require('./tween/TweenData'),
Timeline: require('./timeline/Timeline')
Timeline: require('./Timeline')
};

View file

@ -1,6 +1,6 @@
var Class = require('../../utils/Class');
var GameObjectCreator = require('../../scene/plugins/GameObjectCreator');
var GameObjectFactory = require('../../scene/plugins/GameObjectFactory');
var GameObjectCreator = require('../../gameobjects/GameObjectCreator');
var GameObjectFactory = require('../../gameobjects/GameObjectFactory');
var TWEEN_CONST = require('./const');
// Phaser.Tweens.Tween