@@ -220,7 +220,7 @@ unsigned int PenBlocks::stamp(libscratchcpp::VirtualMachine *vm)
220
220
221
221
unsigned int PenBlocks::penDown (VirtualMachine *vm)
222
222
{
223
- SpriteModel *model = getSpriteModel (vm);
223
+ TargetModel *model = getTargetModel (vm);
224
224
225
225
if (model)
226
226
model->setPenDown (true );
@@ -230,7 +230,7 @@ unsigned int PenBlocks::penDown(VirtualMachine *vm)
230
230
231
231
unsigned int PenBlocks::penUp (libscratchcpp::VirtualMachine *vm)
232
232
{
233
- SpriteModel *model = getSpriteModel (vm);
233
+ TargetModel *model = getTargetModel (vm);
234
234
235
235
if (model)
236
236
model->setPenDown (false );
@@ -240,7 +240,7 @@ unsigned int PenBlocks::penUp(libscratchcpp::VirtualMachine *vm)
240
240
241
241
unsigned int PenBlocks::changePenSizeBy (libscratchcpp::VirtualMachine *vm)
242
242
{
243
- SpriteModel *model = getSpriteModel (vm);
243
+ TargetModel *model = getTargetModel (vm);
244
244
245
245
if (model)
246
246
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)
250
250
251
251
unsigned int PenBlocks::setPenSizeTo (libscratchcpp::VirtualMachine *vm)
252
252
{
253
- SpriteModel *model = getSpriteModel (vm);
253
+ TargetModel *model = getTargetModel (vm);
254
254
255
255
if (model)
256
256
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)
260
260
261
261
unsigned int PenBlocks::changePenShadeBy (libscratchcpp::VirtualMachine *vm)
262
262
{
263
- SpriteModel *model = getSpriteModel (vm);
263
+ TargetModel *model = getTargetModel (vm);
264
264
265
265
if (model) {
266
266
PenState &penState = model->penState ();
@@ -272,7 +272,7 @@ unsigned int PenBlocks::changePenShadeBy(libscratchcpp::VirtualMachine *vm)
272
272
273
273
unsigned int PenBlocks::setPenShadeToNumber (libscratchcpp::VirtualMachine *vm)
274
274
{
275
- SpriteModel *model = getSpriteModel (vm);
275
+ TargetModel *model = getTargetModel (vm);
276
276
277
277
if (model)
278
278
setPenShade (vm->getInput (0 , 1 )->toInt (), model->penState ());
@@ -282,7 +282,7 @@ unsigned int PenBlocks::setPenShadeToNumber(libscratchcpp::VirtualMachine *vm)
282
282
283
283
unsigned int PenBlocks::changePenHueBy (libscratchcpp::VirtualMachine *vm)
284
284
{
285
- SpriteModel *model = getSpriteModel (vm);
285
+ TargetModel *model = getTargetModel (vm);
286
286
287
287
if (model) {
288
288
PenState &penState = model->penState ();
@@ -296,7 +296,7 @@ unsigned int PenBlocks::changePenHueBy(libscratchcpp::VirtualMachine *vm)
296
296
297
297
unsigned int PenBlocks::setPenHueToNumber (libscratchcpp::VirtualMachine *vm)
298
298
{
299
- SpriteModel *model = getSpriteModel (vm);
299
+ TargetModel *model = getTargetModel (vm);
300
300
301
301
if (model) {
302
302
PenState &penState = model->penState ();
@@ -311,7 +311,7 @@ unsigned int PenBlocks::setPenHueToNumber(libscratchcpp::VirtualMachine *vm)
311
311
312
312
unsigned int PenBlocks::setPenColorToColor (libscratchcpp::VirtualMachine *vm)
313
313
{
314
- SpriteModel *model = getSpriteModel (vm);
314
+ TargetModel *model = getTargetModel (vm);
315
315
316
316
if (model) {
317
317
const Value *value = vm->getInput (0 , 1 );
@@ -358,7 +358,7 @@ unsigned int PenBlocks::setPenColorToColor(libscratchcpp::VirtualMachine *vm)
358
358
359
359
unsigned int PenBlocks::changePenColorParamBy (VirtualMachine *vm)
360
360
{
361
- SpriteModel *model = getSpriteModel (vm);
361
+ TargetModel *model = getTargetModel (vm);
362
362
363
363
if (model) {
364
364
const auto it = COLOR_PARAM_MAP.find (vm->getInput (0 , 2 )->toString ());
@@ -374,7 +374,7 @@ unsigned int PenBlocks::changePenColorParamBy(VirtualMachine *vm)
374
374
375
375
unsigned int PenBlocks::changePenColorBy (VirtualMachine *vm)
376
376
{
377
- SpriteModel *model = getSpriteModel (vm);
377
+ TargetModel *model = getTargetModel (vm);
378
378
379
379
if (model)
380
380
setOrChangeColorParam (ColorParam::COLOR, vm->getInput (0 , 1 )->toDouble (), model->penState (), true );
@@ -384,7 +384,7 @@ unsigned int PenBlocks::changePenColorBy(VirtualMachine *vm)
384
384
385
385
unsigned int PenBlocks::changePenSaturationBy (VirtualMachine *vm)
386
386
{
387
- SpriteModel *model = getSpriteModel (vm);
387
+ TargetModel *model = getTargetModel (vm);
388
388
389
389
if (model)
390
390
setOrChangeColorParam (ColorParam::SATURATION, vm->getInput (0 , 1 )->toDouble (), model->penState (), true );
@@ -394,7 +394,7 @@ unsigned int PenBlocks::changePenSaturationBy(VirtualMachine *vm)
394
394
395
395
unsigned int PenBlocks::changePenBrightnessBy (VirtualMachine *vm)
396
396
{
397
- SpriteModel *model = getSpriteModel (vm);
397
+ TargetModel *model = getTargetModel (vm);
398
398
399
399
if (model)
400
400
setOrChangeColorParam (ColorParam::BRIGHTNESS, vm->getInput (0 , 1 )->toDouble (), model->penState (), true );
@@ -404,7 +404,7 @@ unsigned int PenBlocks::changePenBrightnessBy(VirtualMachine *vm)
404
404
405
405
unsigned int PenBlocks::changePenTransparencyBy (VirtualMachine *vm)
406
406
{
407
- SpriteModel *model = getSpriteModel (vm);
407
+ TargetModel *model = getTargetModel (vm);
408
408
409
409
if (model)
410
410
setOrChangeColorParam (ColorParam::TRANSPARENCY, vm->getInput (0 , 1 )->toDouble (), model->penState (), true );
@@ -414,7 +414,7 @@ unsigned int PenBlocks::changePenTransparencyBy(VirtualMachine *vm)
414
414
415
415
unsigned int PenBlocks::setPenColorParamTo (VirtualMachine *vm)
416
416
{
417
- SpriteModel *model = getSpriteModel (vm);
417
+ TargetModel *model = getTargetModel (vm);
418
418
419
419
if (model) {
420
420
const auto it = COLOR_PARAM_MAP.find (vm->getInput (0 , 2 )->toString ());
@@ -430,7 +430,7 @@ unsigned int PenBlocks::setPenColorParamTo(VirtualMachine *vm)
430
430
431
431
unsigned int PenBlocks::setPenColorTo (VirtualMachine *vm)
432
432
{
433
- SpriteModel *model = getSpriteModel (vm);
433
+ TargetModel *model = getTargetModel (vm);
434
434
435
435
if (model)
436
436
setOrChangeColorParam (ColorParam::COLOR, vm->getInput (0 , 1 )->toDouble (), model->penState (), false );
@@ -440,7 +440,7 @@ unsigned int PenBlocks::setPenColorTo(VirtualMachine *vm)
440
440
441
441
unsigned int PenBlocks::setPenSaturationTo (VirtualMachine *vm)
442
442
{
443
- SpriteModel *model = getSpriteModel (vm);
443
+ TargetModel *model = getTargetModel (vm);
444
444
445
445
if (model)
446
446
setOrChangeColorParam (ColorParam::SATURATION, vm->getInput (0 , 1 )->toDouble (), model->penState (), false );
@@ -450,7 +450,7 @@ unsigned int PenBlocks::setPenSaturationTo(VirtualMachine *vm)
450
450
451
451
unsigned int PenBlocks::setPenBrightnessTo (VirtualMachine *vm)
452
452
{
453
- SpriteModel *model = getSpriteModel (vm);
453
+ TargetModel *model = getTargetModel (vm);
454
454
455
455
if (model)
456
456
setOrChangeColorParam (ColorParam::BRIGHTNESS, vm->getInput (0 , 1 )->toDouble (), model->penState (), false );
@@ -460,24 +460,28 @@ unsigned int PenBlocks::setPenBrightnessTo(VirtualMachine *vm)
460
460
461
461
unsigned int PenBlocks::setPenTransparencyTo (VirtualMachine *vm)
462
462
{
463
- SpriteModel *model = getSpriteModel (vm);
463
+ TargetModel *model = getTargetModel (vm);
464
464
465
465
if (model)
466
466
setOrChangeColorParam (ColorParam::TRANSPARENCY, vm->getInput (0 , 1 )->toDouble (), model->penState (), false );
467
467
468
468
return 1 ;
469
469
}
470
470
471
- SpriteModel *PenBlocks::getSpriteModel (libscratchcpp::VirtualMachine *vm)
471
+ TargetModel *PenBlocks::getTargetModel (libscratchcpp::VirtualMachine *vm)
472
472
{
473
473
Target *target = vm->target ();
474
474
475
- if (!target || target-> isStage () )
475
+ if (!target)
476
476
return nullptr ;
477
477
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
+ }
481
485
}
482
486
483
487
void PenBlocks::setOrChangeColorParam (ColorParam param, double value, PenState &penState, bool change)
0 commit comments