2017-07-20 16:10:12 +00:00
|
|
|
var Class = require('../../utils/Class');
|
|
|
|
|
|
|
|
// Drag Events
|
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API
|
|
|
|
|
|
|
|
var SceneInputManager = new Class({
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
|
|
|
function SceneInputManager (scene, game)
|
|
|
|
{
|
|
|
|
// The Scene that owns this plugin
|
|
|
|
this.scene = scene;
|
|
|
|
|
|
|
|
// GlobalInputManager
|
|
|
|
this.manager = game.input;
|
|
|
|
|
|
|
|
// A reference to this.scene.sys.displayList (set in boot)
|
|
|
|
this.displayList;
|
|
|
|
|
|
|
|
// A reference to the this.scene.sys.cameras.cameras array (set in boot)
|
|
|
|
this.cameras;
|
|
|
|
|
|
|
|
// Should use Scene event dispatcher?
|
|
|
|
this.events = this.manager.events;
|
|
|
|
|
2017-07-21 02:39:55 +00:00
|
|
|
// Proxy references available via the Scene
|
|
|
|
this.keyboard = this.manager.keyboard;
|
|
|
|
this.mouse = this.manager.mouse;
|
2017-07-20 16:10:12 +00:00
|
|
|
|
2017-07-21 02:39:55 +00:00
|
|
|
// Only fire callbacks and events on the top-most Game Object in the display list (emulating DOM behavior)
|
|
|
|
// and ignore any GOs below it, or call them all?
|
2017-07-20 16:10:12 +00:00
|
|
|
this.topOnly = true;
|
|
|
|
|
|
|
|
// How often should the pointer input be checked?
|
|
|
|
// Time given in ms
|
|
|
|
// Pointer will *always* be checked if it has been moved by the user.
|
|
|
|
// This controls how often it will be polled if it hasn't been moved.
|
|
|
|
// Set to 0 to poll constantly. Set to -1 to only poll on user movement.
|
|
|
|
this.pollRate = -1;
|
|
|
|
|
2017-07-21 02:39:55 +00:00
|
|
|
// Internal counter
|
2017-07-20 16:10:12 +00:00
|
|
|
this._pollTimer = 0;
|
|
|
|
|
2017-07-21 02:39:55 +00:00
|
|
|
// An object containing the various lists of Interactive Objects
|
|
|
|
// list: A list of all Interactive Objects
|
|
|
|
// pendingInsertion: Objects waiting to be inserted to the list on the next call to 'begin'
|
|
|
|
// pendingRemoval: Objects waiting to be removed from the list on the next call to 'begin'
|
|
|
|
// draggable: A list of all Interactive Objects that are set to be draggable (a subset of list)
|
|
|
|
// over: A list of all Interactive Objects currently considered as being 'over' by any pointer, indexed by pointer ID
|
|
|
|
// down: A list of all Interactive Objects currently considered as being 'down' by any pointer, indexed by pointer ID
|
|
|
|
this.children = {
|
|
|
|
size: 0,
|
|
|
|
list: [],
|
|
|
|
pendingInsertion: [],
|
|
|
|
pendingRemoval: [],
|
|
|
|
draggable: [],
|
|
|
|
over: { 0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [] },
|
|
|
|
down: { 0: [], 1: [], 2: [], 3: [], 4: [], 5: [], 6: [], 7: [], 8: [], 9: [] }
|
|
|
|
};
|
2017-07-20 16:10:12 +00:00
|
|
|
|
2017-07-21 12:59:22 +00:00
|
|
|
this._validTypes = [ 'onDown', 'onUp', 'onOver', 'onOut', 'onMove' ];
|
2017-07-20 16:10:12 +00:00
|
|
|
},
|
|
|
|
|
2017-07-21 02:39:55 +00:00
|
|
|
// Add option to get all IOs within a Rect or Circle
|
|
|
|
|
2017-07-20 16:10:12 +00:00
|
|
|
boot: require('./components/Boot'),
|
|
|
|
begin: require('./components/Begin'),
|
|
|
|
update: require('./components/Update'),
|
|
|
|
hitTestPointer: require('./components/HitTestPointer'),
|
2017-07-21 02:39:55 +00:00
|
|
|
disable: require('./components/Disable'),
|
|
|
|
enable: require('./components/Enable'),
|
|
|
|
queueForInsertion: require('./components/QueueForInsertion'),
|
|
|
|
queueForRemoval: require('./components/QueueForRemoval'),
|
2017-07-20 16:10:12 +00:00
|
|
|
|
|
|
|
setpollRate: require('./components/SetPollRate'),
|
|
|
|
setpollAlways: require('./components/SetPollAlways'),
|
|
|
|
setpollOnMove: require('./components/SetPollOnMove'),
|
|
|
|
|
|
|
|
setHitArea: require('./components/SetHitArea'),
|
|
|
|
setHitAreaCircle: require('./components/SetHitAreaCircle'),
|
|
|
|
setHitAreaEllipse: require('./components/SetHitAreaEllipse'),
|
|
|
|
setHitAreaFromTexture: require('./components/SetHitAreaFromTexture'),
|
|
|
|
setHitAreaRectangle: require('./components/SetHitAreaRectangle'),
|
|
|
|
setHitAreaTriangle: require('./components/SetHitAreaTriangle'),
|
|
|
|
|
|
|
|
setCallback: require('./components/SetCallback'),
|
|
|
|
setCallbacks: require('./components/SetCallbacks'),
|
|
|
|
setOnDownCallback: require('./components/SetOnDownCallback'),
|
|
|
|
setOnOutCallback: require('./components/SetOnOutCallback'),
|
|
|
|
setOnOverCallback: require('./components/SetOnOverCallback'),
|
|
|
|
setOnUpCallback: require('./components/SetOnUpCallback'),
|
2017-07-21 12:59:22 +00:00
|
|
|
setOnMoveCallback: require('./components/SetOnMoveCallback'),
|
2017-07-20 16:10:12 +00:00
|
|
|
|
2017-07-21 02:39:55 +00:00
|
|
|
processOverOutEvents: require('./components/ProcessOverOutEvents'),
|
2017-07-21 03:11:40 +00:00
|
|
|
processDownEvents: require('./components/ProcessDownEvents'),
|
|
|
|
processUpEvents: require('./components/ProcessUpEvents'),
|
2017-07-21 13:05:04 +00:00
|
|
|
processMoveEvents: require('./components/ProcessMoveEvents'),
|
2017-07-21 02:39:55 +00:00
|
|
|
childOnOut: require('./components/ChildOnOut'),
|
|
|
|
childOnOver: require('./components/ChildOnOver'),
|
2017-07-21 03:11:40 +00:00
|
|
|
childOnDown: require('./components/ChildOnDown'),
|
|
|
|
childOnUp: require('./components/ChildOnUp'),
|
2017-07-21 02:39:55 +00:00
|
|
|
sortInteractiveObjects: require('./components/SortInteractiveObjects'),
|
|
|
|
sortIndexHandler: require('./components/SortIndexHandler'),
|
2017-07-20 16:10:12 +00:00
|
|
|
|
|
|
|
// Scene that owns this is shutting down
|
|
|
|
shutdown: function ()
|
|
|
|
{
|
|
|
|
this._list = [];
|
|
|
|
this._over = [];
|
|
|
|
this._draggable = [];
|
|
|
|
this._pendingRemoval = [];
|
|
|
|
this._pendingInsertion = [];
|
|
|
|
},
|
|
|
|
|
|
|
|
// Game level nuke
|
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
this.shutdown();
|
|
|
|
|
|
|
|
this.scene = undefined;
|
|
|
|
this.cameras = undefined;
|
|
|
|
this.manager = undefined;
|
|
|
|
this.events = undefined;
|
|
|
|
this.keyboard = undefined;
|
|
|
|
this.mouse = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = SceneInputManager;
|