diff --git a/HISTORY.md b/HISTORY.md index 4bea4587..4653e784 100755 --- a/HISTORY.md +++ b/HISTORY.md @@ -67,7 +67,8 @@ * Blocks, Objects, Threads: new "getImageAttribute" reporter primitive * Objects, Threads: let "getImageAttribute" deal with null costumes * Objects, Threads: new "stretch" primitive for costumes, also for flipping -* Threas: new feature: new costume from list of pixels +* Threads: new feature: new costume from list of pixels +* Objects, Threads: added "current" to costume input slot dropdown ### 2019-04-08 * Blocks, Objects, Threads: new "getSoundAttribute" reporter primitive diff --git a/src/blocks.js b/src/blocks.js index 9b76b14f..17fb161a 100644 --- a/src/blocks.js +++ b/src/blocks.js @@ -8918,6 +8918,7 @@ InputSlotMorph.prototype.costumesMenu = function () { } else { // stage dict = {Empty : ['Empty']}; } + dict.current = ['current']; rcvr.costumes.asArray().forEach(function (costume) { allNames = allNames.concat(costume.name); }); diff --git a/src/objects.js b/src/objects.js index e15c4dd0..bf617cad 100644 --- a/src/objects.js +++ b/src/objects.js @@ -3294,6 +3294,9 @@ SpriteMorph.prototype.doSwitchToCostume = function (id, noShadow) { this.wearCostume(id, noShadow); return; } + if (id instanceof Array && (id[0] === 'current')) { + return; + } var num, arr = this.costumes.asArray(), diff --git a/src/threads.js b/src/threads.js index e36b3426..ea8de89e 100644 --- a/src/threads.js +++ b/src/threads.js @@ -4338,14 +4338,7 @@ Process.prototype.doSetInstrument = function (num) { // Process image processing primitives Process.prototype.reportGetImageAttribute = function (choice, name) { - var cst = name instanceof Costume ? name - : (typeof name === 'number' ? - this.blockReceiver().costumes.at(name) - : detect( - this.blockReceiver().costumes.asArray(), - function (c) {return c.name === name.toString(); } - ) - ) || new Costume(), + var cst = this.costumeNamed(name) || new Costume(), option = this.inputOption(choice); switch (option) { @@ -4363,18 +4356,11 @@ Process.prototype.reportGetImageAttribute = function (choice, name) { }; Process.prototype.reportNewCostumeStretched = function (name, xP, yP) { + var cst; if (name instanceof List) { return this.reportNewCostume(name, xP, yP); } - - var cst = name instanceof Costume ? name - : (typeof name === 'number' ? - this.blockReceiver().costumes.at(name) - : detect( - this.blockReceiver().costumes.asArray(), - function (c) {return c.name === name.toString(); } - ) - ); + cst = this.costumeNamed(name); if (!cst) { return new Costume(); } @@ -4384,6 +4370,23 @@ Process.prototype.reportNewCostumeStretched = function (name, xP, yP) { ); }; +Process.prototype.costumeNamed = function (name) { + // private + if (name instanceof Costume) { + return name; + } + if (typeof name === 'number') { + return this.blockReceiver().costumes.at(name); + } + if (this.inputOption(name) === 'current') { + return this.blockReceiver().costume; + } + return detect( + this.blockReceiver().costumes.asArray(), + function (c) {return c.name === name.toString(); } + ); +}; + Process.prototype.reportNewCostume = function (pixels, width, height) { // private width = Math.abs(Math.floor(+width));