Skip to content

Commit 49f60c9

Browse files
author
Walter Bender
committed
fix regression with fill; catch null label case
1 parent b9f2235 commit 49f60c9

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

js/palette.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ function PaletteModel(palette, palettes, name) {
641641
}
642642
}
643643

644-
if (['do', 'nameddo', 'namedbox', 'namedcalc', 'doArg', 'calcArg', 'nameddoArg', 'namedcalcArg'].indexOf(protoBlock.name) != -1 && label.length > 8) {
644+
if (['do', 'nameddo', 'namedbox', 'namedcalc', 'doArg', 'calcArg', 'nameddoArg', 'namedcalcArg'].indexOf(protoBlock.name) != -1 && label != null && label.length > 8) {
645645
label = label.substr(0, 7) + '...';
646646
}
647647

@@ -1711,7 +1711,7 @@ function Palette(palettes, name) {
17111711
};
17121712

17131713
this._makeBlockFromPalette = function(protoblk, blkname, callback) {
1714-
const BUILTINMACROS= ['setturtlename', 'fill', 'hollowline', 'status'];
1714+
const BUILTINMACROS= ['setturtlename', 'fill', 'hollowline', 'status', 'xturtle', 'yturtle'];
17151715
if (protoblk == null) {
17161716
console.log('null protoblk?');
17171717
return;
@@ -1831,12 +1831,16 @@ function Palette(palettes, name) {
18311831
const SETTURTLENAMEOBJ = [[0, 'setturtlename', this.protoContainers[blkname].x - paletteBlocks.stage.x, this.protoContainers[blkname].y - paletteBlocks.stage.y, [null, 1, 2, null]], [1, 'turtlename', 0, 0, [0]], [2, ['text', {'value': 'Yertle'}], 0, 0, [0]]];
18321832
const FILLOBJ = [[0, 'fill', this.protoContainers[blkname].x - paletteBlocks.stage.x, this.protoContainers[blkname].y - paletteBlocks.stage.y, [null, null, 1]], [1, 'hidden', 0, 0, [0, null]]];
18331833
const HOLLOWOBJ = [[0, 'hollowline', this.protoContainers[blkname].x - paletteBlocks.stage.x, this.protoContainers[blkname].y - paletteBlocks.stage.y, [null, null, 1]], [1, 'hidden', 0, 0, [0, null]]];
1834+
const XTURTLEOBJ = [[0, 'xturtle', this.protoContainers[blkname].x - paletteBlocks.stage.x, this.protoContainers[blkname].y - paletteBlocks.stage.y, [null, 1, null]], [1, 'turtlename', 0, 0, [0]]];
1835+
const YTURTLEOBJ = [[0, 'yturtle', this.protoContainers[blkname].x - paletteBlocks.stage.x, this.protoContainers[blkname].y - paletteBlocks.stage.y, [null, 1, null]], [1, 'turtlename', 0, 0, [0]]];
18341836

18351837
const BUILTINMACROS = {
18361838
'status': STATUSOBJ,
18371839
'setturtlename': SETTURTLENAMEOBJ,
18381840
'fill': FILLOBJ,
18391841
'hollowline': HOLLOWOBJ,
1842+
'xturtle': XTURTLEOBJ,
1843+
'yturtle': YTURTLEOBJ,
18401844
};
18411845

18421846
function __myCallback (newBlock) {

js/turtle.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ function Turtle (name, turtles, drum) {
195195
this.closeSVG();
196196

197197
ctx.stroke();
198-
ctx.closePath();
198+
if (!this.fillState) {
199+
ctx.closePath();
200+
}
199201
// restore stroke.
200202
this.stroke = savedStroke;
201203
ctx.lineWidth = this.stroke;
@@ -244,7 +246,9 @@ function Turtle (name, turtles, drum) {
244246
this.x = x2;
245247
this.y = y2;
246248
ctx.stroke();
247-
ctx.closePath();
249+
if (!this.fillState) {
250+
ctx.closePath();
251+
}
248252

249253
} else {
250254
this.x = x2;
@@ -357,7 +361,9 @@ function Turtle (name, turtles, drum) {
357361
this.closeSVG();
358362

359363
ctx.stroke();
360-
ctx.closePath();
364+
if (!this.fillState) {
365+
ctx.closePath();
366+
}
361367
// restore stroke.
362368
this.stroke = savedStroke;
363369
ctx.lineWidth = this.stroke;
@@ -375,7 +381,9 @@ function Turtle (name, turtles, drum) {
375381
var nyScaled = ny * this.turtles.scale;
376382
this.svgOutput += nxScaled + ',' + nyScaled + ' ';
377383
ctx.stroke();
378-
ctx.closePath();
384+
if (!this.fillState) {
385+
ctx.closePath();
386+
}
379387
} else {
380388
ctx.moveTo(nx, ny);
381389
}
@@ -488,7 +496,9 @@ function Turtle (name, turtles, drum) {
488496
this.closeSVG();
489497

490498
ctx.stroke();
491-
ctx.closePath();
499+
if (!this.fillState) {
500+
ctx.closePath();
501+
}
492502
// restore stroke.
493503
this.stroke = savedStroke;
494504
ctx.lineWidth = this.stroke;
@@ -513,7 +523,9 @@ function Turtle (name, turtles, drum) {
513523
var radiusScaled = radius * this.turtles.scale;
514524
this.svgOutput += 'A ' + radiusScaled + ',' + radiusScaled + ' 0 0 ' + sweep + ' ' + nxScaled + ',' + nyScaled + ' ';
515525
ctx.stroke();
516-
ctx.closePath();
526+
if (!this.fillState) {
527+
ctx.closePath();
528+
}
517529
} else {
518530
ctx.moveTo(nx, ny);
519531
}
@@ -978,6 +990,7 @@ function Turtle (name, turtles, drum) {
978990
this.doEndFill = function() {
979991
/// redraw the points with fill enabled
980992
ctx.fill();
993+
ctx.closePath();
981994
this.closeSVG();
982995
this.fillState = false;
983996
};

0 commit comments

Comments
 (0)