-
Notifications
You must be signed in to change notification settings - Fork 3
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
API updates to allow for custom frame additions #24
Conversation
32a2301
to
bf74f50
Compare
bf74f50
to
d2c1ff2
Compare
a016c53
to
fcff069
Compare
fcff069
to
53d91b6
Compare
$.publish(Events.ADD_NEW_FRAME_CLICKED); | ||
// Disable adding a blank frame and idead use the PiskelApi | ||
// to cause an action. | ||
//this.piskelController.addFrame(); |
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.
This means that code-dot-org/piskel isn't super usable unless it's connected with gamelab. Does this matter?
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 fine for now - we already have a set of changes we don't merge upstream. 👍 leaving comment in so we know in the future that this change is intentional and should be preserved.
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.
A couple of alternatives:
- This could do the old behavior if no custom
newFrameClicked
handler has been attached. - We could do more refactoring here to make the behavior more configurable - perhaps have a default controller that normally listens for and handles
ADD_NEW_FRAME_CLICKED
and then skip loading that controller and have our own controller handle it in our particular use case.
Both are probably overkill for now though.
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.
The more I think about this, the more I'd like to see it be more flexible; as if the service should offer each attached client an opportunity to handle "new frame" and proceed to its own logic if all clients refuse. The 'old behavior if no custom handler' version is probably the MVP for this, and would be cheap-ish to implement now. Thoughts?
* @param {function} [onComplete] | ||
*/ | ||
ns.ImportService.prototype.importFramesFromImage = function (image, options, onComplete) { | ||
onComplete = onComplete || Constants.EMPTY_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.
This logic is mostly borrowed from ns.ImportService.prototype.newPiskelFromImage
Wasn't sure, since we try not to make piskel too hard to upgrade in the future, if I should refactor out some of the logic, or just copy and add my own new function. In the past I've been trying to only add code to piskel, in hopes that merging might be easier.
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.
ImportService.js was added by us - refactor away. I'd strongly consider submitting a generic version of this change upstream too.
@islemaster you're welcome to take a look at these two PRs too. Added Brent as a reviewer, since we spent a bunch of time discussing, but you probably have more context within Piskel. |
ADD_NEW_FRAME_CLICKED: 'ADD_NEW_FRAME_CLICKED', | ||
|
||
// Add a set of new frames to the current piskel | ||
// Arguments: uri, frameSizeX, frameSizeY, frameRate |
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.
Does frameRate
make sense as an argument for this event? How does it interact with the existing animation frameRate?
@@ -133,6 +145,50 @@ var PiskelApi = (function (module) { | |||
}; | |||
|
|||
/** | |||
* Tell Piskel to load an spritesheet for editing, merging with whatever document |
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.
s/an/a
, and maybe 'appending to' would be more specific than 'merging with'.
frameSizeY, smoothing); | ||
var mergedPiskel = this.mergePiskels(this.piskelController_.getPiskel(), piskel); | ||
this.piskelController_.setPiskel(mergedPiskel); | ||
this.previewController_.setFPS(frameRate); |
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.
Looks like the new framerate clobbers the old framerate - and from Piskel's point of view I suppose this is fine since it's only a preview setting. Still, it seems like an odd choice for this API that adds frames to an existing animation.
var piskel = this.createPiskelFromImages_(frameImages, frameSizeX, | ||
frameSizeY, smoothing); | ||
var mergedPiskel = this.mergePiskels(this.piskelController_.getPiskel(), piskel); | ||
this.piskelController_.setPiskel(mergedPiskel); |
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 we've had undo issues in the past with operations that set a new piskel (like the built-in resize tools) - does that affect us here?
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'm able to upload a different size frame, change other things, then undo to before I added the frame and re-sized so I think it's okay. I'll keep an eye out though.
setPiskelFromFrameImages(frameImages); | ||
} | ||
onComplete(); | ||
}.bind(this) |
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.
Agreed, extracting an async getFrameImagesFromSpriteSheet
would be much cleaner here.
this.removeCallback_(PiskelApi.MessageType.FRAMES_LOADED, callback); | ||
onComplete(); | ||
}.bind(this); | ||
this.addCallback_(PiskelApi.MessageType.FRAMES_LOADED, callback); |
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.
It looks like this pattern is used in a couple places (add a callback that gets called once, then removed). I wonder if it's worth adding a helper for it, so that you can just do something like this.callBackOnce(FRAMES_LOADED, callback)
* Add a blank frame to the end of the current piskel. | ||
*/ | ||
ns.PiskelApiService.prototype.addBlankFrame = function () { | ||
this.piskelController_.addFrame(); |
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'd be fine to inline this method above.
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.
Nice work! I think a little refactoring would be good, but overall structure is great.
@@ -178,6 +185,41 @@ | |||
}; | |||
|
|||
/** | |||
* @param {!string} uri |
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.
Might be worth a function level comment saying what it means to load frames? (i.e. does it essentially just mean to download the frames?)
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 prefer append
to loadAdditional
here, would recommend a rename.
4457fa1
to
7dada8e
Compare
I think pushing this upstream will be my tech debt item for the sprint, which will include looking at the best way to handle how flexible "adding a frame" should be. It looks like almost none of this is currently is tested, including the PiskelApi and ImportService. For my last PR I added tests for the function that merges piskels, but that's it. Suggestions on what is reasonable to go about testing here? |
Used by: code-dot-org/code-dot-org#12866
PiskelApi changes
loadAdditionalFrames
- used to append an animation to an existing animationaddBlankFrame
- used to add a blank frameonAddFrame
- register a callback for when the user clicks "Add new frame" buttonI also disabled adding a blank frame when the user clicks add new frame and instead created an event that gets fired so that gamelab can control better what happens. I made a comment about this inline.