Skip to content

Commit 16999e7

Browse files
committed
Engine: Add backdrop broadcast map
1 parent 77e0a7e commit 16999e7

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/engine/internal/engine.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,30 @@ void Engine::addBroadcastScript(std::shared_ptr<Block> whenReceivedBlock, int fi
11601160

11611161
void Engine::addBackdropChangeScript(std::shared_ptr<Block> hatBlock, int fieldId)
11621162
{
1163+
Stage *stage = this->stage();
1164+
1165+
if (!stage)
1166+
return;
1167+
1168+
// TODO: This assumes the first field holds the broadcast pointer, maybe this is not the best way (e. g. if an extension uses this method)
1169+
assert(hatBlock->fieldAt(0));
1170+
const std::string &backdropName = hatBlock->fieldAt(0)->value().toString();
1171+
auto backdrop = stage->costumeAt(stage->findCostume(backdropName));
1172+
Broadcast *broadcast = backdrop->broadcast();
1173+
assert(broadcast->isBackdropBroadcast());
1174+
11631175
Script *script = m_scripts[hatBlock].get();
1176+
auto it = m_backdropBroadcastMap.find(broadcast);
1177+
1178+
if (it != m_backdropBroadcastMap.cend()) {
1179+
auto &scripts = it->second;
1180+
auto scriptIt = std::find(scripts.begin(), scripts.end(), script);
1181+
1182+
if (scriptIt == scripts.end())
1183+
scripts.push_back(script);
1184+
} else
1185+
m_backdropBroadcastMap[broadcast] = { script };
1186+
11641187
addHatToMap(m_backdropChangeHats, script);
11651188
addHatField(script, HatField::Backdrop, fieldId);
11661189
}

src/engine/internal/engine.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ class Engine : public IEngine
237237
std::vector<std::shared_ptr<Target>> m_targets;
238238
std::vector<std::shared_ptr<Broadcast>> m_broadcasts;
239239
std::unordered_map<Broadcast *, std::vector<Script *>> m_broadcastMap;
240+
std::unordered_map<Broadcast *, std::vector<Script *>> m_backdropBroadcastMap;
240241
std::vector<std::shared_ptr<Monitor>> m_monitors;
241242
std::vector<std::string> m_extensions;
242243
std::vector<Target *> m_executableTargets; // sorted by layer (reverse order of execution)

0 commit comments

Comments
 (0)