mirror of
https://github.com/rive-app/rive-cpp.git
synced 2026-01-18 21:21:17 +01:00
Bunch of changes, i think its at the point where it will be helpful to get a review, there is a *lot* of outstanding work to do here, but i'm hoping that much of it can be done while this is in master but not enabled for uat yet. so @susan101566 and I can work through that set together, with smaller more targeted fixes and changes.
There are a couple of things i want to figure out to make sure we can merge this:
- is the Resolver approach going to work (library components resolve to real components)
- writing library assets into the parent needs a bit more love, it should not cause problems unless you're using libraries
- I want to do a small refactor on the exporter before merge to keep asset writing and asset index updates together as suggested by @susan101566. there's a larger refactor here but i think that can be done in due course.
- re-check editor-only deliniation
After refactoring those i also need to re-check that all these things still work, because chances are i've broken something in the meantime.
for
using a library in as a nested artboard &
using a library as part of using a nested artboard that contains a library
check
using a library animation
using a library stateMachine
using a library stateMachineInputs
we can key state machine input changes
we can trigger nested state machine input changes from teh state machine editor
using a library with assets
exporting all the above and view in cpp viewer
exporting all the above and view in dart viewer
There is a large list of items that need to be worked on beyond this. but hopefully we can do that more incrementally. this includes but is not limited to:
- object validations make sense
- the asset panel is interacting as we want
- right click menus make sense
- out of band loading works
- library api failures are handled
- refactor how we add library assets
- refactor asset exporting
- tracking
- smi paths'
Diffs=
9d8a7e81fa Libraries (#9255)
Co-authored-by: Arthur Vivian <arthur@rive.app>
Co-authored-by: Maxwell Talbot <talbot.maxwell@gmail.com>
Co-authored-by: Susan Wang <susan@rive.app>
151 lines
5.3 KiB
C++
151 lines
5.3 KiB
C++
#include <rive/file.hpp>
|
|
#include <rive/node.hpp>
|
|
#include <rive/nested_artboard.hpp>
|
|
#include <rive/shapes/clipping_shape.hpp>
|
|
#include <rive/shapes/rectangle.hpp>
|
|
#include <rive/assets/image_asset.hpp>
|
|
#include <rive/assets/font_asset.hpp>
|
|
#include <rive/animation/nested_simple_animation.hpp>
|
|
#include <rive/animation/nested_state_machine.hpp>
|
|
#include <rive/relative_local_asset_loader.hpp>
|
|
#include <utils/no_op_factory.hpp>
|
|
#include <utils/no_op_renderer.hpp>
|
|
#include "rive_file_reader.hpp"
|
|
#include <catch.hpp>
|
|
#include <cstdio>
|
|
|
|
TEST_CASE("File with library artboard loads", "[libraries]")
|
|
{
|
|
// created by test in rive_core.
|
|
auto file = ReadRiveFile("assets/library_export_test.riv");
|
|
|
|
auto nestedArtboard =
|
|
file->artboard()->find<rive::NestedArtboard>("The nested artboard");
|
|
REQUIRE(nestedArtboard != nullptr);
|
|
REQUIRE(nestedArtboard->name() == "The nested artboard");
|
|
REQUIRE(nestedArtboard->x() == 1);
|
|
REQUIRE(nestedArtboard->y() == 2);
|
|
REQUIRE(nestedArtboard->artboardId() == -1);
|
|
|
|
// time to find the library asset somewhere
|
|
auto assets = file->assets();
|
|
REQUIRE(assets.size() == 0);
|
|
// todo assert nested artboard structure
|
|
}
|
|
|
|
TEST_CASE("File with library animation loads", "[libraries]")
|
|
{
|
|
// created by test in rive_core.
|
|
auto file = ReadRiveFile("assets/library_export_animation_test.riv");
|
|
|
|
auto nestedArtboard =
|
|
file->artboard()->find<rive::NestedArtboard>("The nested artboard");
|
|
REQUIRE(nestedArtboard != nullptr);
|
|
REQUIRE(nestedArtboard->name() == "The nested artboard");
|
|
REQUIRE(nestedArtboard->x() == 1);
|
|
REQUIRE(nestedArtboard->y() == 2);
|
|
REQUIRE(nestedArtboard->artboardId() == -1);
|
|
|
|
auto nestedSimpleAnimation =
|
|
file->artboard()->find<rive::NestedSimpleAnimation>("");
|
|
REQUIRE(nestedSimpleAnimation != nullptr);
|
|
REQUIRE(nestedSimpleAnimation->name() == "");
|
|
REQUIRE(nestedSimpleAnimation->isPlaying() == true);
|
|
// // TODO: figure out what the id should be?
|
|
REQUIRE(nestedSimpleAnimation->animationId() == -1);
|
|
|
|
// // time to find the library asset somewhere
|
|
auto assets = file->assets();
|
|
REQUIRE(assets.size() == 0);
|
|
|
|
REQUIRE(nestedArtboard->nestedAnimations().size() == 1);
|
|
// todo assert nested artboard has animation structure
|
|
}
|
|
|
|
TEST_CASE("File with library state machine loads", "[libraries]")
|
|
{
|
|
// created by test in rive_core.
|
|
auto file = ReadRiveFile("assets/library_export_state_machine_test.riv");
|
|
|
|
auto nestedArtboard =
|
|
file->artboard()->find<rive::NestedArtboard>("The nested artboard");
|
|
REQUIRE(nestedArtboard != nullptr);
|
|
REQUIRE(nestedArtboard->name() == "The nested artboard");
|
|
REQUIRE(nestedArtboard->x() == 1);
|
|
REQUIRE(nestedArtboard->y() == 2);
|
|
REQUIRE(nestedArtboard->artboardId() == -1);
|
|
|
|
auto nestedSimpleAnimation =
|
|
file->artboard()->find<rive::NestedStateMachine>("");
|
|
REQUIRE(nestedSimpleAnimation != nullptr);
|
|
REQUIRE(nestedSimpleAnimation->name() == "");
|
|
REQUIRE(nestedSimpleAnimation->animationId() == -1);
|
|
|
|
// time to find the library asset somewhere
|
|
// make sure its loaded?
|
|
auto assets = file->assets();
|
|
REQUIRE(assets.size() == 0);
|
|
|
|
REQUIRE(nestedArtboard->nestedAnimations().size() == 1);
|
|
// todo assert nested artboard has state machine structure
|
|
}
|
|
|
|
// TODO reinstate, but right now we're missing fonts locally, need to get
|
|
// backend to uat to recreate this test. we are literally just loading files
|
|
// here. TEST_CASE("File with library", "[libraries]")
|
|
// {
|
|
// TODO: create this file in the editor tests.
|
|
// auto file = ReadRiveFile("assets/library_with_text_and_image.riv");
|
|
|
|
// // library, image and text
|
|
// auto assets = file->assets();
|
|
// REQUIRE(assets.size() == 3);
|
|
// auto libraryAsset = assets[0];
|
|
// REQUIRE(libraryAsset->is<rive::LibraryAsset>());
|
|
// REQUIRE(libraryAsset->name() == "library - Version 1");
|
|
|
|
// auto fontAsset = assets[1];
|
|
// REQUIRE(fontAsset->is<rive::FontAsset>());
|
|
// REQUIRE(fontAsset->name() == "Inter");
|
|
|
|
// auto imageAsset = assets[2];
|
|
// REQUIRE(imageAsset->is<rive::ImageAsset>());
|
|
// REQUIRE(imageAsset->name() == "tree");
|
|
|
|
// // library, image and text
|
|
// auto libraryAssets =
|
|
// static_cast<rive::LibraryAsset*>(libraryAsset)->riveFile()->assets();
|
|
// REQUIRE(libraryAssets.size() == 2);
|
|
|
|
// auto librayFontAsset = libraryAssets[0];
|
|
// REQUIRE(librayFontAsset->is<rive::FontAsset>());
|
|
// REQUIRE(librayFontAsset->name() == "Inter");
|
|
|
|
// auto libraryImageAsset = libraryAssets[1];
|
|
// REQUIRE(libraryImageAsset->is<rive::ImageAsset>());
|
|
// REQUIRE(libraryImageAsset->name() == "tree");
|
|
// }
|
|
|
|
// we are literally just loading files here.
|
|
TEST_CASE("File with library including image", "[libraries]")
|
|
{
|
|
// TODO: create this file in the editor tests.
|
|
auto file = ReadRiveFile("assets/library_with_image.riv");
|
|
|
|
// library, image and text
|
|
auto assets = file->assets();
|
|
REQUIRE(assets.size() == 0);
|
|
// TODO: asset image
|
|
}
|
|
|
|
TEST_CASE("File with multiple libraries including image", "[libraries]")
|
|
{
|
|
// TODO: create this file in the editor tests.
|
|
auto file = ReadRiveFile("assets/double_library_with_image.riv");
|
|
|
|
// library, image and text
|
|
auto assets = file->assets();
|
|
REQUIRE(assets.size() == 0);
|
|
// TODO: asset multiple images
|
|
}
|