From 6ff5dcd6bb8b1024897554b9a47800bb26347748 Mon Sep 17 00:00:00 2001 From: jmoenig Date: Fri, 11 Oct 2019 08:45:45 +0200 Subject: [PATCH] accept a list of pixels in the SWITCH TO COSTUME block thanks, @DyslexicAwe for the idea! --- HISTORY.md | 4 ++++ snap.html | 4 ++-- src/objects.js | 20 +++++++++++++++++++- src/threads.js | 6 +++--- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index a0413933..c114ce63 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -3,6 +3,7 @@ ## in development: * **New Features:** * new cloud-menu entry: "Open in Community Site", thanks, Michael! + * accept a list of pixels in the SWITCH TO COSTUME block * **Notable Changes:** * **Notable Fixes:** * morphic collision detection off-by-1 fix, thanks, Dariusz! @@ -14,6 +15,9 @@ * Galician, thanks, Bernat * Turkish, thanks, Turgut! +### 2019-10-11 +* objects, threads: accept a list of pixels in the SWITCH TO COSTUME block + ### 2019-10-09 * new dev version * morphic: collision detection off-by-1 fix, thanks, @DarDoro diff --git a/snap.html b/snap.html index 883e34c4..f2bbc581 100755 --- a/snap.html +++ b/snap.html @@ -7,8 +7,8 @@ - - + + diff --git a/src/objects.js b/src/objects.js index 251858b1..ab406c43 100644 --- a/src/objects.js +++ b/src/objects.js @@ -84,7 +84,7 @@ BlockEditorMorph, BlockDialogMorph, PrototypeHatBlockMorph, BooleanSlotMorph, localize, TableMorph, TableFrameMorph, normalizeCanvas, VectorPaintEditorMorph, HandleMorph, AlignmentMorph, Process, XML_Element, WorldMap*/ -modules.objects = '2019-August-08'; +modules.objects = '2019-October-11'; var SpriteMorph; var StageMorph; @@ -3516,6 +3516,24 @@ SpriteMorph.prototype.doWearPreviousCostume = function () { }; SpriteMorph.prototype.doSwitchToCostume = function (id, noShadow) { + var w, h; + if (id instanceof List) { // try to turn a list of pixels into a costume + if (this.costume) { + // recycle dimensions of current costume + w = this.costume.width(); + h = this.costume.height(); + } else { + // assume stage's dimensions + w = StageMorph.prototype.dimensions.x; + h = StageMorph.prototype.dimensions.y; + } + id = Process.prototype.reportNewCostume( + id, + w, + h, + this.newCostumeName(localize('snap')) + ); + } if (id instanceof Costume) { // allow first-class costumes this.wearCostume(id, noShadow); return; diff --git a/src/threads.js b/src/threads.js index bcfed5bc..853a361a 100644 --- a/src/threads.js +++ b/src/threads.js @@ -61,7 +61,7 @@ StageMorph, SpriteMorph, StagePrompterMorph, Note, modules, isString, copy, isNil, WatcherMorph, List, ListWatcherMorph, alert, console, TableMorph, Color, TableFrameMorph, ColorSlotMorph, isSnapObject, Map, newCanvas, Symbol*/ -modules.threads = '2019-August-07'; +modules.threads = '2019-October-11'; var ThreadManager; var Process; @@ -4933,7 +4933,7 @@ Process.prototype.costumeNamed = function (name) { ); }; -Process.prototype.reportNewCostume = function (pixels, width, height) { +Process.prototype.reportNewCostume = function (pixels, width, height, name) { // private width = Math.abs(Math.floor(+width)); height = Math.abs(Math.floor(+height)); @@ -4953,7 +4953,7 @@ Process.prototype.reportNewCostume = function (pixels, width, height) { ctx.putImageData(dta, 0, 0); return new Costume( canvas, - this.blockReceiver().newCostumeName(localize('snap')) + name || this.blockReceiver().newCostumeName(localize('snap')) ); };