Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support Aseprite export format (.json) for animations #379

Closed
wants to merge 67 commits into from

Conversation

nwessman
Copy link
Contributor

Adds support for importing/exporting animations as json

This adds the functionality of importing and exporting Aseprite formatted .json files.

Import

In the Resources menu there are now the option to Import Animation, which lets you select a .json file and it will import the corresponding spritesheet that is specified in that json import it to the engine with its data set (duration and so forth).

The import searches for the json like this:

  1. import searches 'image' element in .json,
  2. filename as the 'image' spritesheet but in same folder as .json,
  3. finally also searches same folder as .json for same name as .json with suffix from 'image' element
    so if 'image'=/animation.png and json=/anim.json, also searches /animation.png and /anim.png

ResourceMenuAfter

Export

There is also now the option to export an animation as a json in the Aseprite format.
exportSpritesheetAfter

Code coverage

codecoverage

resolve #321

Daniel Halvarsson and others added 30 commits March 4, 2021 17:37
Version: gson 2.8.6
This file is intended to handle importing and exporting of Aseprite JSON files for animations.
This changes the access modifiers of the fields keyframes, name and spritesheet in Animation-class so it can be used in the export process.
This adds the basic structure of Json format aseprite uses.
This adds a function that creates the aseprite json as a string representation. it currently only works for the frames object and does not include the meta-data object.
This fixes the broken index when creating the frame objects in aseprite json.
This adds a test for exportAnimation. It prints the constructed json to screen so it can be visualy asserted that it looks like it is supposed too.
This adds so that the meta object is created in the json. The app, version, format, scale and layers are now hardcoded.
Added function AsepriteHandler.importAnimation takes a path to the Aseprite .json file and returns an internal Animation object.
Added a new folder intended to contain test animations that can be used for testing the Aseprite import functionality.
Verifies that the import works as expected when given valid input.
This changes so it is the tests that prints the json not the export function.
Implemented import functionality for Aseprite animations
Added two functions for importing animations.
They work much like importspritesheet
Changed imports
Added UI elements to resourcemenu for import
Integration for export. Changed if else statements to switch
@nightm4re94
Copy link
Member

Amazing, thank you! Please allow us some more time to inspect and assess these changes in detail.

Fixes a build error. The error was:
```
/home/gamebuster/Desktop/Modding/LitiEngine/src/de/gurkenlabs/litiengine/graphics/animation/AsepriteHandler.java:270:
error: cannot infer type arguments for HashMap<K,V>
        Map<String, Integer> frame = new HashMap<>() {{
                                                ^
  reason: cannot use '<>' with anonymous inner classes
  where K,V are type-variables:
    K extends Object declared in class HashMap
    V extends Object declared in class HashMap
```
@Gamebuster19901
Copy link
Contributor

I've made a PR (DD2480-Group-11#30) to address some issues

Removed unnecessary catch block. Any exceptions are caught by the overarching catch-block instead.
* @param spritesheetResource the animation object to export
* @throws ExportAnimationException if the export fails
*/
public static String exportAnimation(SpritesheetResource spritesheetResource) throws ExportAnimationException {
Copy link
Contributor

@Gamebuster19901 Gamebuster19901 Mar 20, 2021

Choose a reason for hiding this comment

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

A sprite sheet can have multiple Animations. This method should be taking an Animation, or another method added should be added specifically for Animation objects.

Copy link
Member

Choose a reason for hiding this comment

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

I agree! Don't confuse Animations (->keyframes) and Spritesheets (-> dimensions).

Copy link
Contributor

Choose a reason for hiding this comment

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

I've tried to work on this PR myself (https://github.com/Gamebuster19901/litiengine/tree/gson), but stopped as it requires changes to UtiLITI, as there is no way to select an Animation. You can only select a SpriteSheetResource.

As far as I know, AssetPanelItem.origin cannot be an Animation.

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO I think animations should be considered a resource themselves, because a spritesheet could have multiple animations, and an animation could be played on multiple spritesheets.

Copy link
Contributor

Choose a reason for hiding this comment

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

I've tried to work on this PR myself (https://github.com/Gamebuster19901/litiengine/tree/gson), but stopped as it requires changes to UtiLITI, as there is no way to select an Animation. You can only select a SpriteSheetResource.

As far as I know, AssetPanelItem.origin cannot be an Animation.

I think I'll make another attempt with this PR soon, since UtiLITI is in this repository now, and that makes development a lot easier.

}};
String spritesheetName = spritesheet.getName();
Layer[] layers = {new Layer("Layer", 255, "normal")};
Meta meta = new Meta("http://www.aseprite.org/",
Copy link
Member

Choose a reason for hiding this comment

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

Please use links.properties for external links. Also, I don't really like the in-line version information here. Maybe make that reusable.

Copy link
Member

@nightm4re94 nightm4re94 left a comment

Choose a reason for hiding this comment

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

These are some welcome and important changes, thank you! Sorry for taking our time with this review. I have noticed some issues that need fixing before I can retest - please address the comments.

* @param spritesheetResource the animation object to export
* @throws ExportAnimationException if the export fails
*/
public static String exportAnimation(SpritesheetResource spritesheetResource) throws ExportAnimationException {
Copy link
Member

Choose a reason for hiding this comment

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

I agree! Don't confuse Animations (->keyframes) and Spritesheets (-> dimensions).

@@ -77,6 +79,7 @@
private static final String TEXTUREATLAS_FILE_NAME = "Texture Atlas XML (generic)";

private static final String IMPORT_DIALOGUE = "import_something";
private static final String ANIMATION_FILE_NAME = "Animation file";
Copy link
Member

Choose a reason for hiding this comment

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

This string should also be localizable.

@nightm4re94
Copy link
Member

Closing this due to inactivity. Thank you and feel free to resume at a later point :)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Aseprite export format (.json) for animations
6 participants