Gamelab: Accept strings in addition to constants for mouse blocks#9647
Conversation
| if(buttonCode === undefined) | ||
| buttonCode = this.LEFT; | ||
|
|
||
| // Add other acceptable strings |
There was a problem hiding this comment.
Right now only constants are accepted for these blocks so I had to add support for strings (which I ended up mapping back to constants). Not sure if this is the right place for these though since I have to modify p5.play, but I couldn't find another place to do it.
There was a problem hiding this comment.
It would be nice to make this follow the pattern used with keys, with a mapping between the string names and the constants and a lookup.
|
@islemaster can you take a look at this one too when you get a chance? thanks! |
|
Is this something we intend to backport upstream? If not, can we wrap |
|
@islemaster Are these changes what you meant by your comment? (I don't think we are planning on putting these extra strings upstream into p5.play) |
| }; | ||
|
|
||
| // Overrride p5.play so we can use strings in addition to constants. | ||
| window.p5.prototype._isMouseButtonInState = function (buttonCode, state) { |
There was a problem hiding this comment.
I would go another step and implement this as a wrapper around the existing _isMouseButtonInState instead of copying the implementation over:
// Overrride p5.play so we can use strings in addition to constants.
const p5IsMouseButtonInState = window.p5.prototype._isMouseButtonInState;
window.p5.prototype._isMouseButtonInState = function (buttonCode, state) {
return p5IsMouseButtonInState(this._clickKeyFromString(buttonCode), state);
};|
@islemaster should be good to go now! thanks for your help :) |
|
LGTM! |
Remove constants as defaults for mouse blocks.