@@ -27,6 +27,7 @@ void LooksBlocks::registerBlocks(IEngine *engine)
2727 engine->addCompileFunction (this , " looks_show" , &compileShow);
2828 engine->addCompileFunction (this , " looks_hide" , &compileHide);
2929 engine->addCompileFunction (this , " looks_changeeffectby" , &compileChangeEffectBy);
30+ engine->addCompileFunction (this , " looks_seteffectto" , &compileSetEffectTo);
3031 engine->addCompileFunction (this , " looks_changesizeby" , &compileChangeSizeBy);
3132 engine->addCompileFunction (this , " looks_setsizeto" , &compileSetSizeTo);
3233 engine->addCompileFunction (this , " looks_size" , &compileSize);
@@ -43,6 +44,7 @@ void LooksBlocks::registerBlocks(IEngine *engine)
4344 engine->addInput (this , " SIZE" , SIZE);
4445 engine->addInput (this , " COSTUME" , COSTUME);
4546 engine->addInput (this , " BACKDROP" , BACKDROP);
47+ engine->addInput (this , " VALUE" , VALUE);
4648
4749 // Fields
4850 engine->addField (this , " NUMBER_NAME" , NUMBER_NAME);
@@ -153,6 +155,89 @@ void LooksBlocks::compileChangeEffectBy(Compiler *compiler)
153155 }
154156}
155157
158+ void LooksBlocks::compileSetEffectTo (Compiler *compiler)
159+ {
160+ int option = compiler->field (EFFECT)->specialValueId ();
161+
162+ switch (option) {
163+ case ColorEffect:
164+ if (!m_colorEffect)
165+ m_colorEffect = ScratchConfiguration::getGraphicsEffect (" color" );
166+
167+ compiler->addInput (CHANGE);
168+ compiler->addFunctionCall (&setColorEffectTo);
169+ break ;
170+
171+ case FisheyeEffect:
172+ if (!m_fisheyeEffect)
173+ m_fisheyeEffect = ScratchConfiguration::getGraphicsEffect (" fisheye" );
174+
175+ compiler->addInput (CHANGE);
176+ compiler->addFunctionCall (&setFisheyeEffectTo);
177+ break ;
178+
179+ case WhirlEffect:
180+ if (!m_whirlEffect)
181+ m_whirlEffect = ScratchConfiguration::getGraphicsEffect (" whirl" );
182+
183+ compiler->addInput (CHANGE);
184+ compiler->addFunctionCall (&setWhirlEffectTo);
185+ break ;
186+
187+ case PixelateEffect:
188+ if (!m_pixelateEffect)
189+ m_pixelateEffect = ScratchConfiguration::getGraphicsEffect (" pixelate" );
190+
191+ compiler->addInput (CHANGE);
192+ compiler->addFunctionCall (&setPixelateEffectTo);
193+ break ;
194+
195+ case MosaicEffect:
196+ if (!m_mosaicEffect)
197+ m_mosaicEffect = ScratchConfiguration::getGraphicsEffect (" mosaic" );
198+
199+ compiler->addInput (CHANGE);
200+ compiler->addFunctionCall (&setMosaicEffectTo);
201+ break ;
202+
203+ case BrightnessEffect:
204+ if (!m_brightnessEffect)
205+ m_brightnessEffect = ScratchConfiguration::getGraphicsEffect (" brightness" );
206+
207+ compiler->addInput (CHANGE);
208+ compiler->addFunctionCall (&setBrightnessEffectTo);
209+ break ;
210+
211+ case GhostEffect:
212+ if (!m_ghostEffect)
213+ m_ghostEffect = ScratchConfiguration::getGraphicsEffect (" ghost" );
214+
215+ compiler->addInput (CHANGE);
216+ compiler->addFunctionCall (&setGhostEffectTo);
217+ break ;
218+
219+ default :
220+ IGraphicsEffect *effect = ScratchConfiguration::getGraphicsEffect (compiler->field (EFFECT)->value ().toString ());
221+
222+ if (effect) {
223+ auto it = std::find (m_customGraphicsEffects.begin (), m_customGraphicsEffects.end (), effect);
224+ size_t index;
225+
226+ if (it == m_customGraphicsEffects.end ()) {
227+ index = m_customGraphicsEffects.size ();
228+ m_customGraphicsEffects.push_back (effect);
229+ } else
230+ index = it - m_customGraphicsEffects.begin ();
231+
232+ compiler->addConstValue (index);
233+ compiler->addInput (CHANGE);
234+ compiler->addFunctionCall (&setEffectTo);
235+ }
236+
237+ break ;
238+ }
239+ }
240+
156241void LooksBlocks::compileChangeSizeBy (Compiler *compiler)
157242{
158243 compiler->addInput (CHANGE);
@@ -429,6 +514,86 @@ unsigned int LooksBlocks::changeGhostEffectBy(VirtualMachine *vm)
429514 return 1 ;
430515}
431516
517+ unsigned int LooksBlocks::setEffectTo (VirtualMachine *vm)
518+ {
519+ Sprite *sprite = dynamic_cast <Sprite *>(vm->target ());
520+
521+ if (sprite)
522+ sprite->setGraphicsEffectValue (m_customGraphicsEffects[vm->getInput (0 , 2 )->toLong ()], vm->getInput (1 , 2 )->toDouble ());
523+
524+ return 2 ;
525+ }
526+
527+ unsigned int LooksBlocks::setColorEffectTo (VirtualMachine *vm)
528+ {
529+ Sprite *sprite = dynamic_cast <Sprite *>(vm->target ());
530+
531+ if (sprite)
532+ sprite->setGraphicsEffectValue (m_colorEffect, vm->getInput (0 , 1 )->toDouble ());
533+
534+ return 1 ;
535+ }
536+
537+ unsigned int LooksBlocks::setFisheyeEffectTo (VirtualMachine *vm)
538+ {
539+ Sprite *sprite = dynamic_cast <Sprite *>(vm->target ());
540+
541+ if (sprite)
542+ sprite->setGraphicsEffectValue (m_fisheyeEffect, vm->getInput (0 , 1 )->toDouble ());
543+
544+ return 1 ;
545+ }
546+
547+ unsigned int LooksBlocks::setWhirlEffectTo (VirtualMachine *vm)
548+ {
549+ Sprite *sprite = dynamic_cast <Sprite *>(vm->target ());
550+
551+ if (sprite)
552+ sprite->setGraphicsEffectValue (m_whirlEffect, vm->getInput (0 , 1 )->toDouble ());
553+
554+ return 1 ;
555+ }
556+
557+ unsigned int LooksBlocks::setPixelateEffectTo (VirtualMachine *vm)
558+ {
559+ Sprite *sprite = dynamic_cast <Sprite *>(vm->target ());
560+
561+ if (sprite)
562+ sprite->setGraphicsEffectValue (m_pixelateEffect, vm->getInput (0 , 1 )->toDouble ());
563+
564+ return 1 ;
565+ }
566+
567+ unsigned int LooksBlocks::setMosaicEffectTo (VirtualMachine *vm)
568+ {
569+ Sprite *sprite = dynamic_cast <Sprite *>(vm->target ());
570+
571+ if (sprite)
572+ sprite->setGraphicsEffectValue (m_mosaicEffect, vm->getInput (0 , 1 )->toDouble ());
573+
574+ return 1 ;
575+ }
576+
577+ unsigned int LooksBlocks::setBrightnessEffectTo (VirtualMachine *vm)
578+ {
579+ Sprite *sprite = dynamic_cast <Sprite *>(vm->target ());
580+
581+ if (sprite)
582+ sprite->setGraphicsEffectValue (m_brightnessEffect, vm->getInput (0 , 1 )->toDouble ());
583+
584+ return 1 ;
585+ }
586+
587+ unsigned int LooksBlocks::setGhostEffectTo (VirtualMachine *vm)
588+ {
589+ Sprite *sprite = dynamic_cast <Sprite *>(vm->target ());
590+
591+ if (sprite)
592+ sprite->setGraphicsEffectValue (m_ghostEffect, vm->getInput (0 , 1 )->toDouble ());
593+
594+ return 1 ;
595+ }
596+
432597unsigned int LooksBlocks::changeSizeBy (VirtualMachine *vm)
433598{
434599 Sprite *sprite = dynamic_cast <Sprite *>(vm->target ());
0 commit comments