-
Notifications
You must be signed in to change notification settings - Fork 341
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
Add update drawable methods for each property #469
Changes from 1 commit
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 |
---|---|---|
|
@@ -1313,9 +1313,122 @@ class RenderWebGL extends EventEmitter { | |
}, null); | ||
} | ||
|
||
/** | ||
* Update a drawable's skin. | ||
* @param {number} drawableID The drawable's id. | ||
* @param {number} skinId The skin to update to. | ||
*/ | ||
updateDrawableSkinId (drawableID, skinId) { | ||
const drawable = this._allDrawables[drawableID]; | ||
// TODO: vm's requests to drawableID that do not have a Drawable object. | ||
if (!drawable) return; | ||
drawable.skin = this._allSkins[skinId]; | ||
} | ||
|
||
/** | ||
* Update a drawable's skin rotation center. | ||
* @param {number} drawableID The drawable's id. | ||
* @param {Array.<number>} rotationCenter The rotation center for the skin. | ||
*/ | ||
updateDrawableRotationCenter (drawableID, rotationCenter) { | ||
const drawable = this._allDrawables[drawableID]; | ||
// TODO: vm's requests to drawableID that do not have a Drawable object. | ||
if (!drawable) return; | ||
drawable.skin.setRotationCenter(rotationCenter[0], rotationCenter[1]); | ||
} | ||
|
||
/** | ||
* Update a drawable's skin and rotation center together. | ||
* @param {number} drawableID The drawable's id. | ||
* @param {number} skinId The skin to update to. | ||
* @param {Array.<number>} rotationCenter The rotation center for the skin. | ||
*/ | ||
updateDrawableSkinIdRotationCenter (drawableID, skinId, rotationCenter) { | ||
const drawable = this._allDrawables[drawableID]; | ||
// TODO: vm's requests to drawableID that do not have a Drawable object. | ||
if (!drawable) return; | ||
drawable.skin = this._allSkins[skinId]; | ||
drawable.skin.setRotationCenter(rotationCenter[0], rotationCenter[1]); | ||
} | ||
|
||
/** | ||
* Update a drawable's position. | ||
* @param {number} drawableID The drawable's id. | ||
* @param {Array.<number>} position The new position. | ||
*/ | ||
updateDrawablePosition (drawableID, position) { | ||
const drawable = this._allDrawables[drawableID]; | ||
// TODO: vm's requests to drawableID that do not have a Drawable object. | ||
if (!drawable) return; | ||
drawable.updatePosition(position); | ||
} | ||
|
||
/** | ||
* Update a drawable's direction. | ||
* @param {number} drawableID The drawable's id. | ||
* @param {number} direction A new direction. | ||
*/ | ||
updateDrawableDirection (drawableID, direction) { | ||
const drawable = this._allDrawables[drawableID]; | ||
// TODO: vm's requests to drawableID that do not have a Drawable object. | ||
if (!drawable) return; | ||
drawable.updateDirection(direction); | ||
} | ||
|
||
/** | ||
* Update a drawable's scale. | ||
* @param {number} drawableID The drawable's id. | ||
* @param {Array.<number>} scale A new scale. | ||
*/ | ||
updateDrawableScale (drawableID, scale) { | ||
const drawable = this._allDrawables[drawableID]; | ||
// TODO: vm's requests to drawableID that do not have a Drawable object. | ||
if (!drawable) return; | ||
drawable.updateScale(scale); | ||
} | ||
|
||
/** | ||
* Update a drawable's direction and scale together. | ||
* @param {number} drawableID The drawable's id. | ||
* @param {number} direction A new direction. | ||
* @param {Array.<number>} scale A new scale. | ||
*/ | ||
updateDrawableDirectionScale (drawableID, direction, scale) { | ||
const drawable = this._allDrawables[drawableID]; | ||
// TODO: vm's requests to drawableID that do not have a Drawable object. | ||
if (!drawable) return; | ||
drawable.updateDirection(direction); | ||
drawable.updateScale(scale); | ||
} | ||
|
||
/** | ||
* Update a drawable's visibility. | ||
* @param {number} drawableID The drawable's id. | ||
* @param {boolean} visible Will the drawable be visible? | ||
*/ | ||
updateDrawableVisible (drawableID, visible) { | ||
const drawable = this._allDrawables[drawableID]; | ||
// TODO: vm's requests to drawableID that do not have a Drawable object. | ||
if (!drawable) return; | ||
drawable.updateVisible(visible); | ||
} | ||
|
||
/** | ||
* Update a drawable's visual effect. | ||
* @param {number} drawableID The drawable's id. | ||
* @param {string} effectName The effect to change. | ||
* @param {number} value A new effect value. | ||
*/ | ||
updateDrawableEffect (drawableID, effectName, value) { | ||
const drawable = this._allDrawables[drawableID]; | ||
// TODO: vm's requests to drawableID that do not have a Drawable object. | ||
if (!drawable) return; | ||
drawable.updateEffect(effectName, value); | ||
} | ||
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. These are 9 methods which all do basically the same thing but on a different property. It would probably be more DRY to add a getDrawable method to RenderWebGL and then have the VM call the respective 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. Hmm. That's a fair thought. I think making such a change in this PR will be out of scope. We might be repeating ourselves some, but we are not changing the API in a large way.
This would be a pretty big change. RenderWebGL is essentially designed as a foreign function interface in case we need it to become one. Hmm. I think this code is DRY. As each method calls a different property, they are not doing the same thing. There is the drawable safety check but that's unavoidable. It's the nature of checking that a variable has value before operating on it. It doesn't look dry, but I think that's just the limits of the JS syntax. |
||
|
||
/** | ||
* Update the position, direction, scale, or effect properties of this Drawable. | ||
* @deprecated Use specific updateDrawable* methods instead. | ||
* @param {int} drawableID The ID of the Drawable to update. | ||
* @param {object.<string,*>} properties The new property values to set. | ||
*/ | ||
|
@@ -1329,11 +1442,10 @@ class RenderWebGL extends EventEmitter { | |
return; | ||
} | ||
if ('skinId' in properties) { | ||
drawable.skin = this._allSkins[properties.skinId]; | ||
this.updateDrawableSkinId(drawableID, properties.skinId); | ||
} | ||
if ('rotationCenter' in properties) { | ||
const newRotationCenter = properties.rotationCenter; | ||
drawable.skin.setRotationCenter(newRotationCenter[0], newRotationCenter[1]); | ||
this.updateDrawableRotationCenter(drawableID, properties.rotationCenter); | ||
} | ||
drawable.updateProperties(properties); | ||
} | ||
|
@@ -1627,14 +1739,14 @@ class RenderWebGL extends EventEmitter { | |
} | ||
|
||
twgl.setUniforms(currentShader, uniforms); | ||
|
||
/* adjust blend function for this skin */ | ||
if (drawable.skin.hasPremultipliedAlpha){ | ||
gl.blendFuncSeparate(gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); | ||
} else { | ||
gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); | ||
} | ||
|
||
twgl.drawBufferInfo(gl, this._bufferInfo, gl.TRIANGLES); | ||
} | ||
|
||
|
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.
Can we make this todo comment (and the associated ones below) clearer in terms of what actually needs to be done?
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.
Alternatively, we should file an issue either here or in VM and note it in these todo comments as well as the one in the now deprecated
updateDrawableProperties
function.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.
Sure.
For clarity: The text of this current comment is an abbreviation of the comment in updateDrawable. https://github.com/LLK/scratch-render/pull/469/files#diff-0e66131b35a2396bf8b007193ee7bc77R1437-R1442
This is a very old issue. And not one these new updateDrawable* methods are introducing.