@@ -220,7 +220,7 @@ unsigned int PenBlocks::stamp(libscratchcpp::VirtualMachine *vm)
220220
221221unsigned int PenBlocks::penDown (VirtualMachine *vm)
222222{
223- SpriteModel *model = getSpriteModel (vm);
223+ TargetModel *model = getTargetModel (vm);
224224
225225 if (model)
226226 model->setPenDown (true );
@@ -230,7 +230,7 @@ unsigned int PenBlocks::penDown(VirtualMachine *vm)
230230
231231unsigned int PenBlocks::penUp (libscratchcpp::VirtualMachine *vm)
232232{
233- SpriteModel *model = getSpriteModel (vm);
233+ TargetModel *model = getTargetModel (vm);
234234
235235 if (model)
236236 model->setPenDown (false );
@@ -240,7 +240,7 @@ unsigned int PenBlocks::penUp(libscratchcpp::VirtualMachine *vm)
240240
241241unsigned int PenBlocks::changePenSizeBy (libscratchcpp::VirtualMachine *vm)
242242{
243- SpriteModel *model = getSpriteModel (vm);
243+ TargetModel *model = getTargetModel (vm);
244244
245245 if (model)
246246 model->penAttributes ().diameter = std::clamp (model->penAttributes ().diameter + vm->getInput (0 , 1 )->toDouble (), PEN_SIZE_MIN, PEN_SIZE_MAX);
@@ -250,7 +250,7 @@ unsigned int PenBlocks::changePenSizeBy(libscratchcpp::VirtualMachine *vm)
250250
251251unsigned int PenBlocks::setPenSizeTo (libscratchcpp::VirtualMachine *vm)
252252{
253- SpriteModel *model = getSpriteModel (vm);
253+ TargetModel *model = getTargetModel (vm);
254254
255255 if (model)
256256 model->penAttributes ().diameter = std::clamp (vm->getInput (0 , 1 )->toDouble (), PEN_SIZE_MIN, PEN_SIZE_MAX);
@@ -260,7 +260,7 @@ unsigned int PenBlocks::setPenSizeTo(libscratchcpp::VirtualMachine *vm)
260260
261261unsigned int PenBlocks::changePenShadeBy (libscratchcpp::VirtualMachine *vm)
262262{
263- SpriteModel *model = getSpriteModel (vm);
263+ TargetModel *model = getTargetModel (vm);
264264
265265 if (model) {
266266 PenState &penState = model->penState ();
@@ -272,7 +272,7 @@ unsigned int PenBlocks::changePenShadeBy(libscratchcpp::VirtualMachine *vm)
272272
273273unsigned int PenBlocks::setPenShadeToNumber (libscratchcpp::VirtualMachine *vm)
274274{
275- SpriteModel *model = getSpriteModel (vm);
275+ TargetModel *model = getTargetModel (vm);
276276
277277 if (model)
278278 setPenShade (vm->getInput (0 , 1 )->toInt (), model->penState ());
@@ -282,7 +282,7 @@ unsigned int PenBlocks::setPenShadeToNumber(libscratchcpp::VirtualMachine *vm)
282282
283283unsigned int PenBlocks::changePenHueBy (libscratchcpp::VirtualMachine *vm)
284284{
285- SpriteModel *model = getSpriteModel (vm);
285+ TargetModel *model = getTargetModel (vm);
286286
287287 if (model) {
288288 PenState &penState = model->penState ();
@@ -296,7 +296,7 @@ unsigned int PenBlocks::changePenHueBy(libscratchcpp::VirtualMachine *vm)
296296
297297unsigned int PenBlocks::setPenHueToNumber (libscratchcpp::VirtualMachine *vm)
298298{
299- SpriteModel *model = getSpriteModel (vm);
299+ TargetModel *model = getTargetModel (vm);
300300
301301 if (model) {
302302 PenState &penState = model->penState ();
@@ -311,7 +311,7 @@ unsigned int PenBlocks::setPenHueToNumber(libscratchcpp::VirtualMachine *vm)
311311
312312unsigned int PenBlocks::setPenColorToColor (libscratchcpp::VirtualMachine *vm)
313313{
314- SpriteModel *model = getSpriteModel (vm);
314+ TargetModel *model = getTargetModel (vm);
315315
316316 if (model) {
317317 const Value *value = vm->getInput (0 , 1 );
@@ -358,7 +358,7 @@ unsigned int PenBlocks::setPenColorToColor(libscratchcpp::VirtualMachine *vm)
358358
359359unsigned int PenBlocks::changePenColorParamBy (VirtualMachine *vm)
360360{
361- SpriteModel *model = getSpriteModel (vm);
361+ TargetModel *model = getTargetModel (vm);
362362
363363 if (model) {
364364 const auto it = COLOR_PARAM_MAP.find (vm->getInput (0 , 2 )->toString ());
@@ -374,7 +374,7 @@ unsigned int PenBlocks::changePenColorParamBy(VirtualMachine *vm)
374374
375375unsigned int PenBlocks::changePenColorBy (VirtualMachine *vm)
376376{
377- SpriteModel *model = getSpriteModel (vm);
377+ TargetModel *model = getTargetModel (vm);
378378
379379 if (model)
380380 setOrChangeColorParam (ColorParam::COLOR, vm->getInput (0 , 1 )->toDouble (), model->penState (), true );
@@ -384,7 +384,7 @@ unsigned int PenBlocks::changePenColorBy(VirtualMachine *vm)
384384
385385unsigned int PenBlocks::changePenSaturationBy (VirtualMachine *vm)
386386{
387- SpriteModel *model = getSpriteModel (vm);
387+ TargetModel *model = getTargetModel (vm);
388388
389389 if (model)
390390 setOrChangeColorParam (ColorParam::SATURATION, vm->getInput (0 , 1 )->toDouble (), model->penState (), true );
@@ -394,7 +394,7 @@ unsigned int PenBlocks::changePenSaturationBy(VirtualMachine *vm)
394394
395395unsigned int PenBlocks::changePenBrightnessBy (VirtualMachine *vm)
396396{
397- SpriteModel *model = getSpriteModel (vm);
397+ TargetModel *model = getTargetModel (vm);
398398
399399 if (model)
400400 setOrChangeColorParam (ColorParam::BRIGHTNESS, vm->getInput (0 , 1 )->toDouble (), model->penState (), true );
@@ -404,7 +404,7 @@ unsigned int PenBlocks::changePenBrightnessBy(VirtualMachine *vm)
404404
405405unsigned int PenBlocks::changePenTransparencyBy (VirtualMachine *vm)
406406{
407- SpriteModel *model = getSpriteModel (vm);
407+ TargetModel *model = getTargetModel (vm);
408408
409409 if (model)
410410 setOrChangeColorParam (ColorParam::TRANSPARENCY, vm->getInput (0 , 1 )->toDouble (), model->penState (), true );
@@ -414,7 +414,7 @@ unsigned int PenBlocks::changePenTransparencyBy(VirtualMachine *vm)
414414
415415unsigned int PenBlocks::setPenColorParamTo (VirtualMachine *vm)
416416{
417- SpriteModel *model = getSpriteModel (vm);
417+ TargetModel *model = getTargetModel (vm);
418418
419419 if (model) {
420420 const auto it = COLOR_PARAM_MAP.find (vm->getInput (0 , 2 )->toString ());
@@ -430,7 +430,7 @@ unsigned int PenBlocks::setPenColorParamTo(VirtualMachine *vm)
430430
431431unsigned int PenBlocks::setPenColorTo (VirtualMachine *vm)
432432{
433- SpriteModel *model = getSpriteModel (vm);
433+ TargetModel *model = getTargetModel (vm);
434434
435435 if (model)
436436 setOrChangeColorParam (ColorParam::COLOR, vm->getInput (0 , 1 )->toDouble (), model->penState (), false );
@@ -440,7 +440,7 @@ unsigned int PenBlocks::setPenColorTo(VirtualMachine *vm)
440440
441441unsigned int PenBlocks::setPenSaturationTo (VirtualMachine *vm)
442442{
443- SpriteModel *model = getSpriteModel (vm);
443+ TargetModel *model = getTargetModel (vm);
444444
445445 if (model)
446446 setOrChangeColorParam (ColorParam::SATURATION, vm->getInput (0 , 1 )->toDouble (), model->penState (), false );
@@ -450,7 +450,7 @@ unsigned int PenBlocks::setPenSaturationTo(VirtualMachine *vm)
450450
451451unsigned int PenBlocks::setPenBrightnessTo (VirtualMachine *vm)
452452{
453- SpriteModel *model = getSpriteModel (vm);
453+ TargetModel *model = getTargetModel (vm);
454454
455455 if (model)
456456 setOrChangeColorParam (ColorParam::BRIGHTNESS, vm->getInput (0 , 1 )->toDouble (), model->penState (), false );
@@ -460,24 +460,28 @@ unsigned int PenBlocks::setPenBrightnessTo(VirtualMachine *vm)
460460
461461unsigned int PenBlocks::setPenTransparencyTo (VirtualMachine *vm)
462462{
463- SpriteModel *model = getSpriteModel (vm);
463+ TargetModel *model = getTargetModel (vm);
464464
465465 if (model)
466466 setOrChangeColorParam (ColorParam::TRANSPARENCY, vm->getInput (0 , 1 )->toDouble (), model->penState (), false );
467467
468468 return 1 ;
469469}
470470
471- SpriteModel *PenBlocks::getSpriteModel (libscratchcpp::VirtualMachine *vm)
471+ TargetModel *PenBlocks::getTargetModel (libscratchcpp::VirtualMachine *vm)
472472{
473473 Target *target = vm->target ();
474474
475- if (!target || target-> isStage () )
475+ if (!target)
476476 return nullptr ;
477477
478- Sprite *sprite = static_cast <Sprite *>(target);
479- SpriteModel *model = static_cast <SpriteModel *>(sprite->getInterface ());
480- return model;
478+ if (target->isStage ()) {
479+ Stage *stage = static_cast <Stage *>(target);
480+ return static_cast <StageModel *>(stage->getInterface ());
481+ } else {
482+ Sprite *sprite = static_cast <Sprite *>(target);
483+ return static_cast <SpriteModel *>(sprite->getInterface ());
484+ }
481485}
482486
483487void PenBlocks::setOrChangeColorParam (ColorParam param, double value, PenState &penState, bool change)
0 commit comments