-
Notifications
You must be signed in to change notification settings - Fork 1
Continuous right click plot #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -332,6 +332,8 @@ Pointer.prototype = { | |
| while(i--) { | ||
| input.moveCallbacks[i].callback.call(input.moveCallbacks[i].context, this, this.x, this.y, fromClick); | ||
| } | ||
|
|
||
| input.interactiveItems.callAll('_pointerMoveHandler', this); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't actually need to call move on all the interactive objects, that's more for click down and up events (like draggin) |
||
|
|
||
| // Easy out if we're dragging something and it still exists | ||
| if(this.targetObject !== null && this.targetObject.isDragged === true) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,32 +12,47 @@ function Selection(game) { | |
| return true; | ||
| }; | ||
|
|
||
| this.world.on('inputUp', this._onInput, this); | ||
| this.world.on('inputDown', this._onInput, this); | ||
| }; | ||
| this.world.on('inputDown', this._onInputDown, this); | ||
| this.world.on('inputUp', this._onInputUp, this); | ||
| this.world.on('inputMove', this._onInputMove, this); | ||
| } | ||
|
|
||
| Selection.prototype.constructor = Selection; | ||
|
|
||
| Selection.prototype._onInput = function(world, pointer) { | ||
| Selection.prototype._emitInputAction = function(dataType, pointer, emitPrimary, emitSecondary) { | ||
| var data = { | ||
| type: pointer.isDown ? 'start' : 'stop', | ||
| type: dataType, | ||
| target: { | ||
| x: pointer.x, | ||
| y: pointer.y | ||
| } | ||
| }; | ||
| if(pointer.button === engine.Mouse.LEFT_BUTTON) { | ||
| if (emitPrimary) { | ||
| this.game.emit('ship/primary', data); | ||
| } else if(pointer.button === engine.Mouse.RIGHT_BUTTON) { | ||
| } | ||
| if (emitSecondary) { | ||
| this.game.emit('ship/secondary', data); | ||
| } | ||
| }; | ||
|
|
||
| Selection.prototype._onInputDown = function(world, pointer) { | ||
| this._emitInputAction('start', pointer, pointer.button === engine.Mouse.LEFT_BUTTON, pointer.button === engine.Mouse.RIGHT_BUTTON); | ||
| }; | ||
|
|
||
| Selection.prototype._onInputUp = function(world, pointer) { | ||
| this._emitInputAction('stop', pointer, pointer.button === engine.Mouse.LEFT_BUTTON, pointer.button === engine.Mouse.RIGHT_BUTTON); | ||
| }; | ||
|
|
||
| Selection.prototype._onInputMove = function(world, pointer) { | ||
| this._emitInputAction('move', pointer, pointer.leftButton.isDown, pointer.rightButton.isDown); | ||
| }; | ||
|
|
||
| Selection.prototype.destroy = function() { | ||
| this.input.destroy(); | ||
|
|
||
| this.world.removeListener('onDown', this._onInput); | ||
| this.world.removeListener('onUp', this._onInput); | ||
| this.world.removeListener('inputDown', this._onInputDown); | ||
| this.world.removeListener('inputUp', this._onInputUp); | ||
| this.world.removeListener('inputMove', this._onInputMove); | ||
|
|
||
| this.game = | ||
| this.input = undefined; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See: Movement.prototype.move = function() { You could probably do something similar here, in fact, that is what that function use to do, but it needs to be fixed and updated. |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,9 @@ function ShipManager(game) { | |
| this.glowEmitter = new GlowEmitter(this.game); | ||
| this.shockwaveEmitter = new ShockwaveEmitter(this.game); | ||
| this.fireEmitter = new FireEmitter(this.game); | ||
|
|
||
| // throttled function to plot ship course | ||
| this._throttledPlot = null; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can throttle using |
||
|
|
||
| this.game.particles.add(this.explosionEmitter); | ||
| this.game.particles.add(this.flashEmitter); | ||
|
|
@@ -217,14 +220,15 @@ ShipManager.prototype._primary = function(data) { | |
| y: input.mousePointer.y | ||
| }); | ||
| }); | ||
| } else { | ||
| } else if (data.type === 'stop') { | ||
| this.autofire && clock.events.remove(this.autofire); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| ShipManager.prototype._secondary = function(data) { | ||
| var game = this.game, | ||
| clock = this.clock, | ||
| ship = this.player, | ||
| socket = this.socket, | ||
| indicator = this.indicator, | ||
|
|
@@ -239,6 +243,14 @@ ShipManager.prototype._secondary = function(data) { | |
| uuid: ship.uuid, | ||
| destination: destination | ||
| }); | ||
| } else if (data.type === 'move') { | ||
| this._throttledPlot = this._throttledPlot || clock.throttle(function (data) { | ||
| socket.emit('ship/plot', data); | ||
| }, 250); // throttle threshold | ||
| this._throttledPlot({ | ||
| uuid: ship.uuid, | ||
| destination: destination | ||
| }); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Take a look at src/client/objects/sector/Movement.js - an old version of how to detect mouse movement without events is commented out...
You probably don't need to edit InputHandler.js