Load the entry state machine and access it via the public artboard api.
diff --git a/dev/defs/artboard.json b/dev/defs/artboard.json index 05782ba..935d8d0 100644 --- a/dev/defs/artboard.json +++ b/dev/defs/artboard.json
@@ -79,6 +79,17 @@ "description": "Id of the last open animation.", "runtime": false, "coop": false + }, + "defaultStateMachineId": { + "type": "Id", + "typeRuntime": "uint", + "initialValue": "Core.missingId", + "initialValueRuntime": "-1", + "key": { + "int": 236, + "string": "defaultStateMachineId" + }, + "description": "The default StateMachine attached to this artboard automatically when it is initialized." } } } \ No newline at end of file
diff --git a/include/rive/artboard.hpp b/include/rive/artboard.hpp index 68effa7..3c52a68 100644 --- a/include/rive/artboard.hpp +++ b/include/rive/artboard.hpp
@@ -68,7 +68,6 @@ Core* resolve(uint32_t id) const override; - /// Find the id of a component in the artboard the object in the artboard. The artboard /// itself has id 0 so we use that as a flag for not found. uint32_t idOf(Core* object) const; @@ -129,6 +128,10 @@ StateMachine* stateMachine(const std::string& name) const; StateMachine* stateMachine(size_t index) const; + /// When provided, the designer has specified that this artboard should + /// always autoplay this StateMachine. + StateMachine* defaultStateMachine() const; + /// Make an instance of this artboard, must be explictly deleted when no /// longer needed. // Deprecated...
diff --git a/include/rive/generated/artboard_base.hpp b/include/rive/generated/artboard_base.hpp index 786b5df..f548975 100644 --- a/include/rive/generated/artboard_base.hpp +++ b/include/rive/generated/artboard_base.hpp
@@ -2,6 +2,7 @@ #define _RIVE_ARTBOARD_BASE_HPP_ #include "rive/core/field_types/core_bool_type.hpp" #include "rive/core/field_types/core_double_type.hpp" +#include "rive/core/field_types/core_uint_type.hpp" #include "rive/world_transform_component.hpp" namespace rive { class ArtboardBase : public WorldTransformComponent { @@ -34,6 +35,7 @@ static const uint16_t yPropertyKey = 10; static const uint16_t originXPropertyKey = 11; static const uint16_t originYPropertyKey = 12; + static const uint16_t defaultStateMachineIdPropertyKey = 236; private: bool m_Clip = true; @@ -43,6 +45,7 @@ float m_Y = 0.0f; float m_OriginX = 0.0f; float m_OriginY = 0.0f; + uint32_t m_DefaultStateMachineId = -1; public: inline bool clip() const { return m_Clip; } @@ -108,6 +111,15 @@ originYChanged(); } + inline uint32_t defaultStateMachineId() const { return m_DefaultStateMachineId; } + void defaultStateMachineId(uint32_t value) { + if (m_DefaultStateMachineId == value) { + return; + } + m_DefaultStateMachineId = value; + defaultStateMachineIdChanged(); + } + Core* clone() const override; void copy(const ArtboardBase& object) { m_Clip = object.m_Clip; @@ -117,6 +129,7 @@ m_Y = object.m_Y; m_OriginX = object.m_OriginX; m_OriginY = object.m_OriginY; + m_DefaultStateMachineId = object.m_DefaultStateMachineId; WorldTransformComponent::copy(object); } @@ -143,6 +156,9 @@ case originYPropertyKey: m_OriginY = CoreDoubleType::deserialize(reader); return true; + case defaultStateMachineIdPropertyKey: + m_DefaultStateMachineId = CoreUintType::deserialize(reader); + return true; } return WorldTransformComponent::deserialize(propertyKey, reader); } @@ -155,6 +171,7 @@ virtual void yChanged() {} virtual void originXChanged() {} virtual void originYChanged() {} + virtual void defaultStateMachineIdChanged() {} }; } // namespace rive
diff --git a/include/rive/generated/core_registry.hpp b/include/rive/generated/core_registry.hpp index 918498f..bf06626 100644 --- a/include/rive/generated/core_registry.hpp +++ b/include/rive/generated/core_registry.hpp
@@ -439,6 +439,9 @@ case DrawRulesBase::drawTargetIdPropertyKey: object->as<DrawRulesBase>()->drawTargetId(value); break; + case ArtboardBase::defaultStateMachineIdPropertyKey: + object->as<ArtboardBase>()->defaultStateMachineId(value); + break; case WeightBase::valuesPropertyKey: object->as<WeightBase>()->values(value); break; @@ -905,6 +908,8 @@ return object->as<ImageBase>()->assetId(); case DrawRulesBase::drawTargetIdPropertyKey: return object->as<DrawRulesBase>()->drawTargetId(); + case ArtboardBase::defaultStateMachineIdPropertyKey: + return object->as<ArtboardBase>()->defaultStateMachineId(); case WeightBase::valuesPropertyKey: return object->as<WeightBase>()->values(); case WeightBase::indicesPropertyKey: @@ -1205,6 +1210,7 @@ case PolygonBase::pointsPropertyKey: case ImageBase::assetIdPropertyKey: case DrawRulesBase::drawTargetIdPropertyKey: + case ArtboardBase::defaultStateMachineIdPropertyKey: case WeightBase::valuesPropertyKey: case WeightBase::indicesPropertyKey: case TendonBase::boneIdPropertyKey:
diff --git a/src/artboard.cpp b/src/artboard.cpp index 56f1e6d..1d862b7 100644 --- a/src/artboard.cpp +++ b/src/artboard.cpp
@@ -527,6 +527,13 @@ return m_StateMachines[index]; } +StateMachine* Artboard::defaultStateMachine() const { + if (defaultStateMachineId() > m_StateMachines.size()) { + return nullptr; + } + return m_StateMachines[defaultStateMachineId()]; +} + std::unique_ptr<ArtboardInstance> Artboard::instance() const { std::unique_ptr<ArtboardInstance> artboardClone(new ArtboardInstance); artboardClone->copy(*this);