@@ -107,8 +107,8 @@ void Engine::resolveIds()
107
107
const auto &blocks = target->blocks ();
108
108
for (auto block : blocks) {
109
109
auto container = blockSectionContainer (block->opcode ());
110
- block->setNext (getBlock (block->nextId ()));
111
- block->setParent (getBlock (block->parentId ()));
110
+ block->setNext (getBlock (block->nextId (), target. get () ));
111
+ block->setParent (getBlock (block->parentId (), target. get () ));
112
112
113
113
if (container) {
114
114
block->setCompileFunction (container->resolveBlockCompileFunc (block->opcode ()));
@@ -117,16 +117,16 @@ void Engine::resolveIds()
117
117
118
118
const auto &inputs = block->inputs ();
119
119
for (const auto &input : inputs) {
120
- input->setValueBlock (getBlock (input->valueBlockId ()));
120
+ input->setValueBlock (getBlock (input->valueBlockId (), target. get () ));
121
121
122
122
if (container)
123
123
input->setInputId (container->resolveInput (input->name ()));
124
124
125
125
InputValue *value = input->primaryValue ();
126
126
std::string id = value->valueId (); // no reference!
127
- value->setValuePtr (getEntity (id));
127
+ value->setValuePtr (getEntity (id, target. get () ));
128
128
assert (input->secondaryValue ()->type () != InputValue::Type::Variable && input->secondaryValue ()->type () != InputValue::Type::List); // secondary values never have a variable or list
129
- input->secondaryValue ()->setValuePtr (getEntity (input->secondaryValue ()->valueId ()));
129
+ input->secondaryValue ()->setValuePtr (getEntity (input->secondaryValue ()->valueId (), target. get () ));
130
130
131
131
// Add missing variables and lists
132
132
if (!value->valuePtr ()) {
@@ -149,7 +149,7 @@ void Engine::resolveIds()
149
149
const auto &fields = block->fields ();
150
150
for (auto field : fields) {
151
151
std::string id = field->valueId (); // no reference!
152
- field->setValuePtr (getEntity (id));
152
+ field->setValuePtr (getEntity (id, target. get () ));
153
153
154
154
if (container) {
155
155
field->setFieldId (container->resolveField (field->name ()));
@@ -179,7 +179,7 @@ void Engine::resolveIds()
179
179
block->updateInputMap ();
180
180
block->updateFieldMap ();
181
181
182
- auto comment = getComment (block->commentId ());
182
+ auto comment = getComment (block->commentId (), target. get () );
183
183
block->setComment (comment);
184
184
185
185
if (comment) {
@@ -209,7 +209,7 @@ void Engine::resolveIds()
209
209
assert (target);
210
210
211
211
for (auto field : fields) {
212
- field->setValuePtr (getEntity (field->valueId ()));
212
+ field->setValuePtr (getEntity (field->valueId (), target ));
213
213
214
214
if (container) {
215
215
field->setFieldId (container->resolveField (field->name ()));
@@ -1411,17 +1411,27 @@ const std::unordered_map<std::shared_ptr<Block>, std::shared_ptr<Script>> &Engin
1411
1411
}
1412
1412
1413
1413
// Returns the block with the given ID.
1414
- std::shared_ptr<Block> Engine::getBlock (const std::string &id)
1414
+ std::shared_ptr<Block> Engine::getBlock (const std::string &id, Target *target )
1415
1415
{
1416
1416
if (id.empty ())
1417
1417
return nullptr ;
1418
1418
1419
- for (auto target : m_targets) {
1420
- int index = target->findBlock (id);
1419
+ int index;
1420
+
1421
+ if (target) {
1422
+ index = target->findBlock (id);
1423
+
1421
1424
if (index != -1 )
1422
1425
return target->blockAt (index);
1423
1426
}
1424
1427
1428
+ for (auto t : m_targets) {
1429
+ index = t->findBlock (id);
1430
+
1431
+ if (index != -1 )
1432
+ return t->blockAt (index);
1433
+ }
1434
+
1425
1435
return nullptr ;
1426
1436
}
1427
1437
@@ -1469,22 +1479,32 @@ std::shared_ptr<Broadcast> Engine::getBroadcast(const std::string &id)
1469
1479
}
1470
1480
1471
1481
// Returns the comment with the given ID.
1472
- std::shared_ptr<Comment> Engine::getComment (const std::string &id)
1482
+ std::shared_ptr<Comment> Engine::getComment (const std::string &id, Target *target )
1473
1483
{
1474
1484
if (id.empty ())
1475
1485
return nullptr ;
1476
1486
1477
- for (auto target : m_targets) {
1478
- int index = target->findComment (id);
1487
+ int index;
1488
+
1489
+ if (target) {
1490
+ index = target->findComment (id);
1491
+
1479
1492
if (index != -1 )
1480
1493
return target->commentAt (index);
1481
1494
}
1482
1495
1496
+ for (auto t : m_targets) {
1497
+ index = t->findComment (id);
1498
+
1499
+ if (index != -1 )
1500
+ return t->commentAt (index);
1501
+ }
1502
+
1483
1503
return nullptr ;
1484
1504
}
1485
1505
1486
1506
// Returns the entity with the given ID. \see IEntity
1487
- std::shared_ptr<Entity> Engine::getEntity (const std::string &id)
1507
+ std::shared_ptr<Entity> Engine::getEntity (const std::string &id, Target *target )
1488
1508
{
1489
1509
// Variables
1490
1510
auto variable = getVariable (id);
@@ -1502,12 +1522,12 @@ std::shared_ptr<Entity> Engine::getEntity(const std::string &id)
1502
1522
return std::static_pointer_cast<Entity>(broadcast);
1503
1523
1504
1524
// Blocks
1505
- auto block = getBlock (id);
1525
+ auto block = getBlock (id, target );
1506
1526
if (block)
1507
1527
return std::static_pointer_cast<Entity>(block);
1508
1528
1509
1529
// Comments
1510
- auto comment = getComment (id);
1530
+ auto comment = getComment (id, target );
1511
1531
if (comment)
1512
1532
return std::static_pointer_cast<Entity>(comment);
1513
1533
0 commit comments