@@ -21,7 +21,7 @@ std::string EventBlocks::name() const
2121void EventBlocks::registerBlocks (IEngine *engine)
2222{
2323 // Blocks
24- engine->addHatBlock (this , " event_whenflagclicked" );
24+ engine->addCompileFunction (this , " event_whenflagclicked" , &compileWhenFlagClicked );
2525 engine->addCompileFunction (this , " event_broadcast" , &compileBroadcast);
2626 engine->addCompileFunction (this , " event_broadcastandwait" , &compileBroadcastAndWait);
2727 engine->addCompileFunction (this , " event_whenbroadcastreceived" , &compileWhenBroadcastReceived);
@@ -37,6 +37,11 @@ void EventBlocks::registerBlocks(IEngine *engine)
3737 engine->addField (this , " KEY_OPTION" , KEY_OPTION);
3838}
3939
40+ void EventBlocks::compileWhenFlagClicked (Compiler *compiler)
41+ {
42+ compiler->engine ()->addGreenFlagScript (compiler->block ());
43+ }
44+
4045void EventBlocks::compileBroadcast (Compiler *compiler)
4146{
4247 auto input = compiler->input (BROADCAST_INPUT);
@@ -72,60 +77,54 @@ void EventBlocks::compileWhenBroadcastReceived(Compiler *compiler)
7277{
7378 auto broadcast = std::static_pointer_cast<Broadcast>(compiler->field (BROADCAST_OPTION)->valuePtr ());
7479
75- compiler->engine ()->addBroadcastScript (compiler->block (), broadcast.get ());
80+ compiler->engine ()->addBroadcastScript (compiler->block (), BROADCAST_OPTION, broadcast.get ());
7681}
7782
7883void EventBlocks::compileWhenBackdropSwitchesTo (Compiler *compiler)
7984{
80- if (Stage *stage = compiler->engine ()->stage ()) {
81- std::string backdropName = compiler->field (BACKDROP)->value ().toString ();
82- int index = stage->findCostume (backdropName);
83-
84- if (index != -1 )
85- compiler->engine ()->addBroadcastScript (compiler->block (), stage->costumeAt (index)->broadcast ());
86- }
85+ compiler->engine ()->addBackdropChangeScript (compiler->block (), BACKDROP);
8786}
8887
8988void EventBlocks::compileWhenKeyPressed (Compiler *compiler)
9089{
9190 // NOTE: Field values don't have to be registered because keys are referenced by their names
92- compiler->engine ()->addKeyPressScript (compiler->block (), compiler-> field ( KEY_OPTION)-> value (). toString () );
91+ compiler->engine ()->addKeyPressScript (compiler->block (), KEY_OPTION);
9392}
9493
9594unsigned int EventBlocks::broadcast (VirtualMachine *vm)
9695{
97- vm->engine ()->broadcast (vm->engine ()->findBroadcast (vm->getInput (0 , 1 )->toString ()), vm );
96+ vm->engine ()->broadcast (vm->engine ()->findBroadcast (vm->getInput (0 , 1 )->toString ()));
9897 return 1 ;
9998}
10099
101100unsigned int EventBlocks::broadcastByIndex (VirtualMachine *vm)
102101{
103- vm->engine ()->broadcast (vm->getInput (0 , 1 )->toLong (), vm );
102+ vm->engine ()->broadcast (vm->getInput (0 , 1 )->toLong ());
104103 return 1 ;
105104}
106105
107106unsigned int EventBlocks::broadcastAndWait (VirtualMachine *vm)
108107{
109- vm->engine ()->broadcast (vm->engine ()->findBroadcast (vm->getInput (0 , 1 )->toString ()), vm, true );
108+ vm->engine ()->broadcast (vm->engine ()->findBroadcast (vm->getInput (0 , 1 )->toString ()));
110109 return 1 ;
111110}
112111
113112unsigned int EventBlocks::broadcastByIndexAndWait (VirtualMachine *vm)
114113{
115- vm->engine ()->broadcast (vm->getInput (0 , 1 )->toLong (), vm, true );
114+ vm->engine ()->broadcast (vm->getInput (0 , 1 )->toLong ());
116115 return 1 ;
117116}
118117
119118unsigned int EventBlocks::checkBroadcast (VirtualMachine *vm)
120119{
121- if (vm->engine ()->broadcastRunning (vm->engine ()->findBroadcast (vm->getInput (0 , 1 )->toString ()), vm ))
120+ if (vm->engine ()->broadcastRunning (vm->engine ()->findBroadcast (vm->getInput (0 , 1 )->toString ())))
122121 vm->stop (true , true , true );
123122 return 1 ;
124123}
125124
126125unsigned int EventBlocks::checkBroadcastByIndex (VirtualMachine *vm)
127126{
128- if (vm->engine ()->broadcastRunning (vm->getInput (0 , 1 )->toLong (), vm ))
127+ if (vm->engine ()->broadcastRunning (vm->getInput (0 , 1 )->toLong ()))
129128 vm->stop (true , true , true );
130129 return 1 ;
131130}
0 commit comments