Skip to content

Gamelab: SerializedAnimationProps does not need source size#9535

Merged
islemaster merged 3 commits into
stagingfrom
gamelab-does-not-need-sourceSize
Jul 15, 2016
Merged

Gamelab: SerializedAnimationProps does not need source size#9535
islemaster merged 3 commits into
stagingfrom
gamelab-does-not-need-sourceSize

Conversation

@islemaster

Copy link
Copy Markdown
Contributor

There's no need to specify the sourceSize property in the level's animation data (or to serialize it out, for that matter) so this PR moves sourceSize from the SerializedAnimationProps type to its ephemeral superset the AnimationProps type, and extends the loadAnimationFromSource process to read the spritesheet dimensions and populate sourceSize at that time.

A brief overview of how animations are loaded:

  1. On page load, we receive a SerializedAnimationList (a collection of SerializedAnimationProps objects) from either the level definition or from the student's saved project. This contains the animation properties (name, frame size, framerate, etc) but not the spritesheet images themselves.
  2. We push those properties into Redux as an AnimationList of AnimationProps (which are like SerializedAnimationProps but they have more fields), and in the process we call loadAnimationFromSource for every animation.
  3. loadAnimationFromSource makes an asynchronous request for the animation's spritesheet image. When it's done downloading as a Blob we convert it to a data URI and (as of this change) get its dimensions, add a loadedFromSource flag, and put all of those on the AnimationProps in Redux.

And how they're used:

  • Pretty much every place we use the animation now, we are reading its data URI from the AnimationProps in Redux - this saves us from making a web request for the spritesheet image again. That includes loading the animation into p5.play and sending the image to Piskel to load for editing.
  • Whenever an edit is made in Piskel we update the corresponding Blob and data URI in Redux so that every place the image is used gets updated.
  • When the project gets saved, we upload the image Blob as a PNG image to our animations API, and then we convert the AnimationList back into a SerializedAnimationList and save that with the project.

Make the sourceSize animation property ephemeral, not part of the SerializedAnimationProps type, because we can always infer it once the asset is loaded.  Instead we add a step to our loadfromsource process to determine the dimensions of the asset right before we are done loading.
@islemaster islemaster force-pushed the gamelab-does-not-need-sourceSize branch from 6b24bf6 to 4df67d6 Compare July 15, 2016 01:26
@islemaster

Copy link
Copy Markdown
Contributor Author

Note: After this is deployed to levelbuilder, I will go update existing gamelab levels to remove sourceSize from their JSON. This is non-urgent though; the sourceSize field in that JSON will just be ignored after this change.

import {createStore} from '@cdo/apps/redux';
import {expect} from '../../util/configuredChai';

// var testUtils = require('../../util/testUtils');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need these if they are commented out? or are they related to the todos?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nope, just forgot to remove them. Nice catch.

@caleybrock

Copy link
Copy Markdown
Contributor

👍

thank you for the explanations!

@islemaster islemaster merged commit d4d2126 into staging Jul 15, 2016
@islemaster islemaster deleted the gamelab-does-not-need-sourceSize branch July 15, 2016 19:18
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.

2 participants