Skip to content
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

Merged
merged 4 commits into from
Feb 1, 2017

Conversation

caleybrock
Copy link

@caleybrock caleybrock commented Jan 25, 2017

Used by: code-dot-org/code-dot-org#12866

PiskelApi changes

  • loadAdditionalFrames - used to append an animation to an existing animation
  • addBlankFrame - used to add a blank frame
  • onAddFrame - register a callback for when the user clicks "Add new frame" button

I 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.

@caleybrock caleybrock force-pushed the add-custom-frame branch 2 times, most recently from 32a2301 to bf74f50 Compare January 26, 2017 00:27
@caleybrock caleybrock force-pushed the add-custom-frame branch 3 times, most recently from a016c53 to fcff069 Compare January 27, 2017 19:05
$.publish(Events.ADD_NEW_FRAME_CLICKED);
// Disable adding a blank frame and idead use the PiskelApi
// to cause an action.
//this.piskelController.addFrame();
Copy link
Author

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?

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.

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.

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;
Copy link
Author

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.

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.

@caleybrock caleybrock changed the title WIP: Add custom frame API updates to allow for custom frame additions Jan 27, 2017
@caleybrock
Copy link
Author

@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

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

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);

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);

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?

Copy link
Author

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)

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);

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();

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.

Copy link

@islemaster islemaster left a 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

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?)

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.

@caleybrock
Copy link
Author

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?

@caleybrock caleybrock merged commit af834f1 into master Feb 1, 2017
@caleybrock caleybrock deleted the add-custom-frame branch February 1, 2017 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants