-
Notifications
You must be signed in to change notification settings - Fork 186
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
feat(improvement): restJoystick now accepts an object #162
Conversation
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.
Some formatting issues and I don't understand why you had to duplicate the transformation logic.
Although, I wouldn't keep that logic randomly placed in the code, I'd just do it where we actually use the option.
src/nipple.js
Outdated
if(typeof restJoystick === 'boolean'){ | ||
this.options.restJoystick = { | ||
x: restJoystick, | ||
y: restJoystick, | ||
}; | ||
}else if(typeof restJoystick === 'object'){ | ||
this.options.restJoystick = u.safeExtend({x:true,y:true},restJoystick); | ||
} |
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.
if(typeof restJoystick === 'boolean'){ | |
this.options.restJoystick = { | |
x: restJoystick, | |
y: restJoystick, | |
}; | |
}else if(typeof restJoystick === 'object'){ | |
this.options.restJoystick = u.safeExtend({x:true,y:true},restJoystick); | |
} | |
if (typeof restJoystick === 'boolean'){ | |
this.options.restJoystick = { | |
x: restJoystick, | |
y: restJoystick, | |
}; | |
} else if (typeof restJoystick === 'object') { | |
this.options.restJoystick = u.safeExtend({x:true, y:true}, restJoystick); | |
} |
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.
fixed.. (removed this duplicated logic)
src/collection.js
Outdated
const restJoystick = this.options.restJoystick; | ||
|
||
if(typeof restJoystick === 'boolean'){ | ||
this.options.restJoystick = { | ||
x: restJoystick, | ||
y: restJoystick, | ||
}; | ||
}else if(typeof restJoystick === 'object'){ | ||
this.options.restJoystick = u.safeExtend({x:true,y:true},restJoystick); | ||
} |
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.
const restJoystick = this.options.restJoystick; | |
if(typeof restJoystick === 'boolean'){ | |
this.options.restJoystick = { | |
x: restJoystick, | |
y: restJoystick, | |
}; | |
}else if(typeof restJoystick === 'object'){ | |
this.options.restJoystick = u.safeExtend({x:true,y:true},restJoystick); | |
} | |
const restJoystick = this.options.restJoystick; | |
if (typeof restJoystick === 'boolean') { | |
this.options.restJoystick = { | |
x: restJoystick, | |
y: restJoystick, | |
}; | |
} else if (typeof restJoystick === 'object') { | |
this.options.restJoystick = u.safeExtend({x:true, y:true}, restJoystick); | |
} |
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.
fixed.. (removed this duplicated logic)
src/nipple.js
Outdated
self.setPosition(cb, { | ||
x: self.options.restJoystick.x ?0 :self.instance.frontPosition.x, | ||
y: self.options.restJoystick.y ?0 :self.instance.frontPosition.y | ||
}); |
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.
I think it's best to have this logic just once where we do actually use it.
You can remove the other logics that you duplicated.
self.setPosition(cb, { | |
x: self.options.restJoystick.x ?0 :self.instance.frontPosition.x, | |
y: self.options.restJoystick.y ?0 :self.instance.frontPosition.y | |
}); | |
if (self.options.restJoystick) { | |
const rest = self.options.restJoystick; | |
const newPosition = {}; | |
newPosition.x = rest === true || rest.x ? 0 : self.instance.frontPosition.x; | |
newPosition.y = rest === true || rest.y ? 0 : self.instance.frontPosition.y; | |
self.setPosition(cb, newPosition); | |
} |
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.
refactored it as you request..
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.
Awesome, LGTM.
Sorry for the delay, I'll make a release later today.
Currently the
restJoystick
option only acceptsboolean
values. This means that I can't specify which axis should be re-centered on rest state. For example, in my use case I only want the Y-axis to be reset on rest state while the X-axis should remain in the same position.This improvement will add this capability to the library. This is how we'll be able to use
restJoystick
option:Although a small improvement, it'll be useful of many of us.