File tree Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Expand file tree Collapse file tree 4 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 99namespace libscratchcpp
1010{
1111
12+ class Target ;
1213class VariablePrivate ;
1314
1415/* ! \brief The Variable class represents a Scratch variable. */
@@ -29,6 +30,9 @@ class LIBSCRATCHCPP_EXPORT Variable : public Entity
2930 bool isCloudVariable () const ;
3031 void setIsCloudVariable (bool isCloudVariable);
3132
33+ Target *target () const ;
34+ void setTarget (Target *target);
35+
3236 std::shared_ptr<Variable> clone ();
3337
3438 private:
Original file line number Diff line number Diff line change @@ -49,6 +49,18 @@ void Variable::setIsCloudVariable(bool isCloudVariable)
4949 impl->isCloudVariable = isCloudVariable;
5050}
5151
52+ /* ! Returns the sprite or stage this variable belongs to. */
53+ Target *Variable::target () const
54+ {
55+ return impl->target ;
56+ }
57+
58+ /* ! Sets the sprite or stage this variable belongs to. */
59+ void Variable::setTarget (Target *target)
60+ {
61+ impl->target = target;
62+ }
63+
5264/* ! Creates a copy of the variable. */
5365std::shared_ptr<Variable> Variable::clone ()
5466{
Original file line number Diff line number Diff line change 77namespace libscratchcpp
88{
99
10+ class Target ;
11+
1012struct VariablePrivate
1113{
1214 VariablePrivate (const std::string &name, const Value &value = Value(), bool isCloudVariable = false );
@@ -15,6 +17,7 @@ struct VariablePrivate
1517 std::string name;
1618 Value value;
1719 bool isCloudVariable;
20+ Target *target = nullptr ;
1821};
1922
2023} // namespace libscratchcpp
Original file line number Diff line number Diff line change 11#include < scratchcpp/variable.h>
2+ #include < scratchcpp/target.h>
23
34#include " ../common.h"
45
@@ -57,6 +58,16 @@ TEST(VariableTest, IsCloudVariable)
5758 ASSERT_TRUE (var.isCloudVariable ());
5859}
5960
61+ TEST (VariableTest, Target)
62+ {
63+ Variable var (" " , " " );
64+ ASSERT_EQ (var.target (), nullptr );
65+
66+ Target target;
67+ var.setTarget (&target);
68+ ASSERT_EQ (var.target (), &target);
69+ }
70+
6071TEST (VariableTest, Clone)
6172{
6273 std::shared_ptr<Variable> clone;
You can’t perform that action at this time.
0 commit comments