From dc4e9a5c1c4a0d3bc7a585bf6f8878dee830d040 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Tue, 25 Feb 2014 16:18:20 -0800 Subject: Screenshts are saved as costumes of the current sprite --- objects.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 46a951f..c357f73 100644 --- a/objects.js +++ b/objects.js @@ -809,6 +809,11 @@ SpriteMorph.prototype.initBlocks = function () { category: 'sensing', spec: 'current %dates' }, + doScreenshot: { + type: 'command', + category: 'sensing', + spec: 'save a screenshot to' + }, // Operators reifyScript: { @@ -1746,6 +1751,7 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push(block('reportIsFastTracking')); blocks.push(block('doSetFastTracking')); blocks.push('-'); + blocks.push(block('doScreenshot')); blocks.push(block('reportDate')); // for debugging: /////////////// @@ -3696,6 +3702,12 @@ SpriteMorph.prototype.reactToDropOf = function (morph, hand) { morph.slideBackTo(hand.grabOrigin); }; +SpriteMorph.prototype.doScreenshot = function() { + console.log('Testing screenshot'); + var parent = this.parentThatIsA(StageMorph); + var image = parent.fullImageClassic(); +}; + // SpriteHighlightMorph ///////////////////////////////////////////////// // SpriteHighlightMorph inherits from Morph: @@ -3775,7 +3787,7 @@ StageMorph.prototype.init = function (globals) { this.blocksCache = {}; // not to be serialized (!) this.paletteCache = {}; // not to be serialized (!) this.lastAnswer = null; // last user input, do not persist - this.activeSounds = []; // do not persist + this.active = []; // do not persist this.trailsCanvas = null; this.isThreadSafe = false; @@ -4694,6 +4706,7 @@ StageMorph.prototype.userMenu = function () { menu.addItem( "pic...", function () { + //console.log(myself.fullImageClassic().toDataURL()); window.open(myself.fullImageClassic().toDataURL()); }, 'open a new window\nwith a picture of the stage' -- cgit v1.3.1 From 341d27092e3381d15f8d2c041de8dbd9ec61a29b Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Tue, 25 Feb 2014 17:01:09 -0800 Subject: Fixed incomplete code --- objects.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'objects.js') diff --git a/objects.js b/objects.js index c357f73..f7ce467 100644 --- a/objects.js +++ b/objects.js @@ -3706,6 +3706,9 @@ SpriteMorph.prototype.doScreenshot = function() { console.log('Testing screenshot'); var parent = this.parentThatIsA(StageMorph); var image = parent.fullImageClassic(); + var ide = this.parentThatIsA(IDE_Morph); + var costume = new Costume(image); + ide.currentSprite.addCostume(image); }; // SpriteHighlightMorph ///////////////////////////////////////////////// -- cgit v1.3.1 From e889dc224e68a634e1ecfc64d39f5b5432c4322e Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Tue, 25 Feb 2014 17:34:31 -0800 Subject: Fixed errors that arose from not using fullImageClassic() --- objects.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index f7ce467..1c55231 100644 --- a/objects.js +++ b/objects.js @@ -3703,12 +3703,11 @@ SpriteMorph.prototype.reactToDropOf = function (morph, hand) { }; SpriteMorph.prototype.doScreenshot = function() { - console.log('Testing screenshot'); - var parent = this.parentThatIsA(StageMorph); - var image = parent.fullImageClassic(); + var stage = this.parentThatIsA(StageMorph); + var canvas = stage.fullImageClassic(); var ide = this.parentThatIsA(IDE_Morph); - var costume = new Costume(image); - ide.currentSprite.addCostume(image); + var costume = new Costume(canvas, ""); + ide.currentSprite.addCostume(costume); }; // SpriteHighlightMorph ///////////////////////////////////////////////// -- cgit v1.3.1 From d591b743e4fade85b2b15af8a0c37d32f700cdd2 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Fri, 28 Feb 2014 16:54:00 -0800 Subject: Screenshot block now mentions that it saves the screenshot as a costume Screenshot block now accepts a string --- objects.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 1c55231..d3fbbec 100644 --- a/objects.js +++ b/objects.js @@ -812,7 +812,8 @@ SpriteMorph.prototype.initBlocks = function () { doScreenshot: { type: 'command', category: 'sensing', - spec: 'save a screenshot to' + spec: 'save screenshot as costume named %s', + defaults: ['screenshot'] }, // Operators @@ -3702,11 +3703,11 @@ SpriteMorph.prototype.reactToDropOf = function (morph, hand) { morph.slideBackTo(hand.grabOrigin); }; -SpriteMorph.prototype.doScreenshot = function() { +SpriteMorph.prototype.doScreenshot = function(data) { var stage = this.parentThatIsA(StageMorph); var canvas = stage.fullImageClassic(); var ide = this.parentThatIsA(IDE_Morph); - var costume = new Costume(canvas, ""); + var costume = new Costume(canvas, data); ide.currentSprite.addCostume(costume); }; -- cgit v1.3.1 From 0a7a186b2ca1369ea1eda45fbfef693dc75b4acd Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Fri, 28 Feb 2014 17:23:46 -0800 Subject: Screenshot counter correctly implemented --- objects.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index d3fbbec..cdefc3f 100644 --- a/objects.js +++ b/objects.js @@ -1242,6 +1242,9 @@ SpriteMorph.prototype.init = function (globals) { this.changed(); this.drawNew(); this.changed(); + + //Screenshot counter + this.screenshotCount = 0; }; // SpriteMorph duplicating (fullCopy) @@ -3707,8 +3710,12 @@ SpriteMorph.prototype.doScreenshot = function(data) { var stage = this.parentThatIsA(StageMorph); var canvas = stage.fullImageClassic(); var ide = this.parentThatIsA(IDE_Morph); - var costume = new Costume(canvas, data); + var screenshotName = data; + if(this.screenshotCount != 0) + screenshotName += ' ' + this.screenshotCount; + var costume = new Costume(canvas, screenshotName); ide.currentSprite.addCostume(costume); + this.screenshotCount++; }; // SpriteHighlightMorph ///////////////////////////////////////////////// -- cgit v1.3.1 From 93dcdee53e54616a576ea27708ccaaffbc9d181e Mon Sep 17 00:00:00 2001 From: Dibyo Majumdar Date: Fri, 28 Feb 2014 17:27:23 -0800 Subject: Random change --- objects.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'objects.js') diff --git a/objects.js b/objects.js index cdefc3f..15742cc 100644 --- a/objects.js +++ b/objects.js @@ -1,3 +1,5 @@ +// random change + /* objects.js -- cgit v1.3.1 From 04bb1414626d9989ed60df62d02fab59263990f7 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Fri, 28 Feb 2014 17:28:50 -0800 Subject: Removed dibyo's test push --- objects.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 15742cc..cdefc3f 100644 --- a/objects.js +++ b/objects.js @@ -1,5 +1,3 @@ -// random change - /* objects.js -- cgit v1.3.1 From f6afb9d08d078a98eee36ecaea493aaa759b04d6 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Tue, 4 Mar 2014 16:04:57 -0800 Subject: Final commit: -Removed an accidental change -Removed commented log statement --- objects.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index cdefc3f..41da8e3 100644 --- a/objects.js +++ b/objects.js @@ -3716,6 +3716,7 @@ SpriteMorph.prototype.doScreenshot = function(data) { var costume = new Costume(canvas, screenshotName); ide.currentSprite.addCostume(costume); this.screenshotCount++; + Canvas2Image.saveAsPNG(canvas); }; // SpriteHighlightMorph ///////////////////////////////////////////////// @@ -3797,7 +3798,7 @@ StageMorph.prototype.init = function (globals) { this.blocksCache = {}; // not to be serialized (!) this.paletteCache = {}; // not to be serialized (!) this.lastAnswer = null; // last user input, do not persist - this.active = []; // do not persist + this.activeSounds = []; // do not persist this.trailsCanvas = null; this.isThreadSafe = false; @@ -4716,7 +4717,6 @@ StageMorph.prototype.userMenu = function () { menu.addItem( "pic...", function () { - //console.log(myself.fullImageClassic().toDataURL()); window.open(myself.fullImageClassic().toDataURL()); }, 'open a new window\nwith a picture of the stage' -- cgit v1.3.1 From 6c357a5ed11afeb233edd848cf4e97c2bf7b925f Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Thu, 6 Mar 2014 13:27:11 -0800 Subject: Removed Canvas2Image error --- objects.js | 1 - 1 file changed, 1 deletion(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 41da8e3..a90d23a 100644 --- a/objects.js +++ b/objects.js @@ -3716,7 +3716,6 @@ SpriteMorph.prototype.doScreenshot = function(data) { var costume = new Costume(canvas, screenshotName); ide.currentSprite.addCostume(costume); this.screenshotCount++; - Canvas2Image.saveAsPNG(canvas); }; // SpriteHighlightMorph ///////////////////////////////////////////////// -- cgit v1.3.1 From 8a74747cd735f04f9ce7ab859e8f88642fea1ffd Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Fri, 7 Mar 2014 15:02:30 -0800 Subject: Screenshot names are now correctly tracked --- objects.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index a90d23a..2c51547 100644 --- a/objects.js +++ b/objects.js @@ -1243,8 +1243,7 @@ SpriteMorph.prototype.init = function (globals) { this.drawNew(); this.changed(); - //Screenshot counter - this.screenshotCount = 0; + this.screenshotNames = {}; // Keeps track of stage image names }; // SpriteMorph duplicating (fullCopy) @@ -3706,16 +3705,19 @@ SpriteMorph.prototype.reactToDropOf = function (morph, hand) { morph.slideBackTo(hand.grabOrigin); }; -SpriteMorph.prototype.doScreenshot = function(data) { - var stage = this.parentThatIsA(StageMorph); - var canvas = stage.fullImageClassic(); - var ide = this.parentThatIsA(IDE_Morph); - var screenshotName = data; - if(this.screenshotCount != 0) - screenshotName += ' ' + this.screenshotCount; - var costume = new Costume(canvas, screenshotName); +SpriteMorph.prototype.doScreenshot = function (data) { + if (this.screenshotNames.hasOwnProperty(data)) { + this.screenshotNames[data] += 1; + data += '(' + this.screenshotNames[data] + ')'; + } else { + this.screenshotNames[data] = 0; + } + var stage = this.parentThatIsA(StageMorph), + canvas = stage.fullImageClassic(), + ide = this.parentThatIsA(IDE_Morph), + screenshotName = data, + costume = new Costume(canvas, screenshotName); ide.currentSprite.addCostume(costume); - this.screenshotCount++; }; // SpriteHighlightMorph ///////////////////////////////////////////////// -- cgit v1.3.1 From 4888ecb9ec74b52c606e6dc7dbaf54119b553f85 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Fri, 7 Mar 2014 15:05:50 -0800 Subject: Use this.addCostume instead of IDE --- objects.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 2c51547..07b40cc 100644 --- a/objects.js +++ b/objects.js @@ -3717,7 +3717,7 @@ SpriteMorph.prototype.doScreenshot = function (data) { ide = this.parentThatIsA(IDE_Morph), screenshotName = data, costume = new Costume(canvas, screenshotName); - ide.currentSprite.addCostume(costume); + this.addCostume(costume); }; // SpriteHighlightMorph ///////////////////////////////////////////////// -- cgit v1.3.1 From 6715784dec1ee24b06f63551020ac8aabbcc6b6d Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Fri, 7 Mar 2014 15:07:41 -0800 Subject: Removed extra variables --- objects.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 07b40cc..25e94fc 100644 --- a/objects.js +++ b/objects.js @@ -3714,9 +3714,7 @@ SpriteMorph.prototype.doScreenshot = function (data) { } var stage = this.parentThatIsA(StageMorph), canvas = stage.fullImageClassic(), - ide = this.parentThatIsA(IDE_Morph), - screenshotName = data, - costume = new Costume(canvas, screenshotName); + costume = new Costume(canvas, data); this.addCostume(costume); }; -- cgit v1.3.1 From a0c076b6fa2d9ecad64a0459459f0f5a5e902e4b Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Fri, 7 Mar 2014 15:15:05 -0800 Subject: Renamed block --- objects.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 25e94fc..8c60126 100644 --- a/objects.js +++ b/objects.js @@ -812,7 +812,7 @@ SpriteMorph.prototype.initBlocks = function () { doScreenshot: { type: 'command', category: 'sensing', - spec: 'save screenshot as costume named %s', + spec: 'save stage image as costume named %s', defaults: ['screenshot'] }, -- cgit v1.3.1 From 9f00665852bb41db193634740f8a649238ec162c Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Sat, 8 Mar 2014 15:56:02 -0800 Subject: Added the screenshot block for the Stage --- objects.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 8c60126..28c652d 100644 --- a/objects.js +++ b/objects.js @@ -3807,6 +3807,8 @@ StageMorph.prototype.init = function (globals) { this.acceptsDrops = false; this.setColor(new Color(255, 255, 255)); this.fps = this.frameRate; + + this.screenshotNames = {}; // Keeps track of stage image names }; // StageMorph scaling @@ -4479,6 +4481,8 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push(block('doSetFastTracking')); blocks.push('-'); blocks.push(block('reportDate')); + blocks.push('-'); + blocks.push(block('doScreenshot')) // for debugging: /////////////// @@ -4817,6 +4821,9 @@ StageMorph.prototype.deleteVariable = SpriteMorph.prototype.deleteVariable; // StageMorph block rendering +StageMorph.prototype.doScreenshot + = SpriteMorph.prototype.doScreenshot; + StageMorph.prototype.blockForSelector = SpriteMorph.prototype.blockForSelector; -- cgit v1.3.1 From 85ebc2369b86efc5e5a6988e74f7a01d1006e9f1 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Mon, 10 Mar 2014 22:21:20 -0700 Subject: Added ability to save pen trails Added dropdown menu to choose what to save --- blocks.js | 13 +++++++++++++ objects.js | 26 +++++++++++++++++--------- 2 files changed, 30 insertions(+), 9 deletions(-) (limited to 'objects.js') diff --git a/blocks.js b/blocks.js index 480545d..04d10e8 100644 --- a/blocks.js +++ b/blocks.js @@ -665,6 +665,19 @@ SyntaxElementMorph.prototype.labelPart = function (spec) { // single-arg and specialized multi-arg slots: switch (spec) { + case '%imgsource': + part = new InputSlotMorph( + null, // text + false, // non-numeric + { + 'pen trails': ['pen trails'], + 'stage image': ['stage image'] + }, + true + ); + part.setContents(['pen trails']); + part.canBeEmpty = false; + break; case '%inputs': part = new MultiArgMorph('%s', 'with inputs'); part.isStatic = false; diff --git a/objects.js b/objects.js index 28c652d..5cb48ee 100644 --- a/objects.js +++ b/objects.js @@ -812,8 +812,8 @@ SpriteMorph.prototype.initBlocks = function () { doScreenshot: { type: 'command', category: 'sensing', - spec: 'save stage image as costume named %s', - defaults: ['screenshot'] + spec: 'save %imgsource as costume named %s', + defaults: ['pen trails', 'screenshot'] }, // Operators @@ -1755,6 +1755,7 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push(block('doSetFastTracking')); blocks.push('-'); blocks.push(block('doScreenshot')); + blocks.push('-'); blocks.push(block('reportDate')); // for debugging: /////////////// @@ -3705,16 +3706,23 @@ SpriteMorph.prototype.reactToDropOf = function (morph, hand) { morph.slideBackTo(hand.grabOrigin); }; -SpriteMorph.prototype.doScreenshot = function (data) { - if (this.screenshotNames.hasOwnProperty(data)) { +SpriteMorph.prototype.doScreenshot = function (imgSource, data) { + var canvas, + stage, + costume; + if (this.screenshotNames.hasOwnProperty(data)) { // Screenshot naming this.screenshotNames[data] += 1; data += '(' + this.screenshotNames[data] + ')'; } else { this.screenshotNames[data] = 0; } - var stage = this.parentThatIsA(StageMorph), - canvas = stage.fullImageClassic(), - costume = new Costume(canvas, data); + if (imgSource[0] === "pen trails") { + canvas = this.trailsCanvas; + } else if (imgSource[0] === "stage image") { + stage = this.parentThatIsA(StageMorph); + canvas = stage.fullImageClassic(); + } + costume = new Costume(canvas, data); this.addCostume(costume); }; @@ -4482,7 +4490,7 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push('-'); blocks.push(block('reportDate')); blocks.push('-'); - blocks.push(block('doScreenshot')) + blocks.push(block('doScreenshot')); // for debugging: /////////////// @@ -4822,7 +4830,7 @@ StageMorph.prototype.deleteVariable = SpriteMorph.prototype.deleteVariable; // StageMorph block rendering StageMorph.prototype.doScreenshot - = SpriteMorph.prototype.doScreenshot; + = SpriteMorph.prototype.doScreenshot; StageMorph.prototype.blockForSelector = SpriteMorph.prototype.blockForSelector; -- cgit v1.3.1 From 0795c1f44ca2c6a40e6c21eeb550a577fbef0e63 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Mon, 10 Mar 2014 22:42:42 -0700 Subject: Fixed error where penTrail of sprite was being used instead of penTrail of stage --- objects.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 5cb48ee..5d3237e 100644 --- a/objects.js +++ b/objects.js @@ -3708,7 +3708,7 @@ SpriteMorph.prototype.reactToDropOf = function (morph, hand) { SpriteMorph.prototype.doScreenshot = function (imgSource, data) { var canvas, - stage, + stage = this.parentThatIsA(StageMorph), costume; if (this.screenshotNames.hasOwnProperty(data)) { // Screenshot naming this.screenshotNames[data] += 1; @@ -3717,9 +3717,8 @@ SpriteMorph.prototype.doScreenshot = function (imgSource, data) { this.screenshotNames[data] = 0; } if (imgSource[0] === "pen trails") { - canvas = this.trailsCanvas; + canvas = stage.penTrails(); } else if (imgSource[0] === "stage image") { - stage = this.parentThatIsA(StageMorph); canvas = stage.fullImageClassic(); } costume = new Costume(canvas, data); @@ -4735,7 +4734,7 @@ StageMorph.prototype.userMenu = function () { if (shiftClicked) { menu.addLine(); menu.addItem( - "turn pen trails into new costume...", + " trails into new costume...", function () { var costume = new Costume( myself.trailsCanvas, -- cgit v1.3.1 From a7a1b54244c91d247511309cddfc9c4c4d895a80 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Tue, 11 Mar 2014 02:38:11 -0700 Subject: Option of switching between pen trails and stage image has been implemented Stage saves pen trails too --- objects.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 5d3237e..52abac1 100644 --- a/objects.js +++ b/objects.js @@ -3717,11 +3717,11 @@ SpriteMorph.prototype.doScreenshot = function (imgSource, data) { this.screenshotNames[data] = 0; } if (imgSource[0] === "pen trails") { - canvas = stage.penTrails(); + canvas = stage.trailsCanvas; } else if (imgSource[0] === "stage image") { canvas = stage.fullImageClassic(); } - costume = new Costume(canvas, data); + costume = new Costume(canvas, data).copy(); this.addCostume(costume); }; -- cgit v1.3.1 From 7f42be8585bdbcab6e4f2d9d6bae9a4337e43940 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Tue, 11 Mar 2014 10:30:19 -0700 Subject: pen trails is in an array --- objects.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 52abac1..0a30ab7 100644 --- a/objects.js +++ b/objects.js @@ -813,7 +813,7 @@ SpriteMorph.prototype.initBlocks = function () { type: 'command', category: 'sensing', spec: 'save %imgsource as costume named %s', - defaults: ['pen trails', 'screenshot'] + defaults: [['pen trails'], 'screenshot'] }, // Operators -- cgit v1.3.1 From e1c74e75f3581240fe528e910331f0068471f810 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Tue, 11 Mar 2014 13:20:19 -0700 Subject: Put back the accidentally deleted words Added comment explaining why copy is necessary Copy is only created for pen trails --- objects.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 0a30ab7..2f4419b 100644 --- a/objects.js +++ b/objects.js @@ -3718,10 +3718,11 @@ SpriteMorph.prototype.doScreenshot = function (imgSource, data) { } if (imgSource[0] === "pen trails") { canvas = stage.trailsCanvas; + costume = new Costume(canvas, data).copy(); // Copy is required to prevent mutation } else if (imgSource[0] === "stage image") { canvas = stage.fullImageClassic(); + costume = new Costume(canvas, data); } - costume = new Costume(canvas, data).copy(); this.addCostume(costume); }; @@ -4734,7 +4735,7 @@ StageMorph.prototype.userMenu = function () { if (shiftClicked) { menu.addLine(); menu.addItem( - " trails into new costume...", + "turn pen trails into new costume...", function () { var costume = new Costume( myself.trailsCanvas, -- cgit v1.3.1 From fa02caef5d5944496dcd32a677ba38c10a8768d9 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Wed, 12 Mar 2014 16:36:14 -0700 Subject: Implemented both ways of Screenshot naming --- objects.js | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 2f4419b..9e103be 100644 --- a/objects.js +++ b/objects.js @@ -3706,16 +3706,53 @@ SpriteMorph.prototype.reactToDropOf = function (morph, hand) { morph.slideBackTo(hand.grabOrigin); }; +SpriteMorph.prototype.newCostumeNameCached = function (data) { + if (this.screenshotNames.hasOwnProperty(data)) { // Screenshot naming + this.screenshotNames[data] += 1; + data += '(' + this.screenshotNames[data] + ')'; + } else { + this.screenshotNames[data] = 0; + } + return data; +}; + +SpriteMorph.prototype.newCostumeNameFn = function (name) { + var costume, + foundSameName = false, + foundIndex = false, + lastIndex = 0, + re; + for(i = 1; i <= this.costumes.length(); i++) { // Find a costume with the same name + costume = this.costumes.at(i); // Get the ith costume + if (costume != undefined) { + if (costume.name === name) { // Same name exists + foundSameName = true; + } + if (foundSameName) { // Scan for indexes + re = new RegExp(name + '\\(\\d+\\)'); // Reg Exp to check for digits + if (re.test(costume.name)) { // The costume name matches + lastIndex = parseInt(costume.name.match(/\d+/)[0]); + foundIndex = true; + } + } + } + } + if (foundSameName) { + if (foundIndex) { + lastIndex += 1; + return name + '(' + lastIndex + ')'; // New index with a +1 + } + return name + '(1)'; // No indexing has started so start it off with a (1) + } + return name; +}; + SpriteMorph.prototype.doScreenshot = function (imgSource, data) { var canvas, stage = this.parentThatIsA(StageMorph), costume; - if (this.screenshotNames.hasOwnProperty(data)) { // Screenshot naming - this.screenshotNames[data] += 1; - data += '(' + this.screenshotNames[data] + ')'; - } else { - this.screenshotNames[data] = 0; - } + //data = this.newCostumeNameFn(data); + data = this.newCostumeNameCached(data); // Uncomment to profile if (imgSource[0] === "pen trails") { canvas = stage.trailsCanvas; costume = new Costume(canvas, data).copy(); // Copy is required to prevent mutation -- cgit v1.3.1 From dbb5a8e0f5d2d882120c56da4aec00f4c2b569be Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Wed, 12 Mar 2014 20:04:16 -0700 Subject: Made reg-exp static --- objects.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 9e103be..91febf2 100644 --- a/objects.js +++ b/objects.js @@ -3716,22 +3716,21 @@ SpriteMorph.prototype.newCostumeNameCached = function (data) { return data; }; +var re = /\((\d+)\)$/; SpriteMorph.prototype.newCostumeNameFn = function (name) { - var costume, - foundSameName = false, + var foundSameName = false, foundIndex = false, - lastIndex = 0, - re; - for(i = 1; i <= this.costumes.length(); i++) { // Find a costume with the same name - costume = this.costumes.at(i); // Get the ith costume - if (costume != undefined) { - if (costume.name === name) { // Same name exists + lastIndex = 0; + for (i = 1; i <= this.costumes.length(); i++) { + var costume = this.costumes.at(i); + if (costume != null) { + if (costume.name === name) { foundSameName = true; } - if (foundSameName) { // Scan for indexes - re = new RegExp(name + '\\(\\d+\\)'); // Reg Exp to check for digits - if (re.test(costume.name)) { // The costume name matches - lastIndex = parseInt(costume.name.match(/\d+/)[0]); + if (foundSameName) { + var p = re.exec(costume.name); + if (p) { + lastIndex = Number(p[1]); foundIndex = true; } } @@ -3751,8 +3750,8 @@ SpriteMorph.prototype.doScreenshot = function (imgSource, data) { var canvas, stage = this.parentThatIsA(StageMorph), costume; - //data = this.newCostumeNameFn(data); - data = this.newCostumeNameCached(data); // Uncomment to profile + data = this.newCostumeNameFn(data); + //data = this.newCostumeNameCached(data); // Uncomment to profile if (imgSource[0] === "pen trails") { canvas = stage.trailsCanvas; costume = new Costume(canvas, data).copy(); // Copy is required to prevent mutation -- cgit v1.3.1 From f56dc8ecf5f2845ed40b62eec4e0e2227bebd5ba Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Mon, 21 Apr 2014 16:12:28 -0700 Subject: Fixed an error where stage could not take screenshots --- objects.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 91febf2..ea07e6e 100644 --- a/objects.js +++ b/objects.js @@ -4868,6 +4868,12 @@ StageMorph.prototype.deleteVariable = SpriteMorph.prototype.deleteVariable; StageMorph.prototype.doScreenshot = SpriteMorph.prototype.doScreenshot; +StageMorph.prototype.newCostumeNameCached + = SpriteMorph.prototype.newCostumeNameCached; + +StageMorph.prototype.newCostumeNameFn + = SpriteMorph.prototype.newCostumeNameFn; + StageMorph.prototype.blockForSelector = SpriteMorph.prototype.blockForSelector; -- cgit v1.3.1 From d3ec80f3748eeed2f6a4f7c75c85d56388171e2a Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Mon, 28 Apr 2014 01:11:23 -0700 Subject: Commented out popup --- morphic.js | 21 +++++++++++---------- objects.js | 9 ++++++++- 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'objects.js') diff --git a/morphic.js b/morphic.js index b55b180..329c3ed 100644 --- a/morphic.js +++ b/morphic.js @@ -10353,16 +10353,17 @@ WorldMorph.prototype.initEventListeners = function () { false ); - window.onbeforeunload = function (evt) { - var e = evt || window.event, - msg = "Are you sure you want to leave?"; - // For IE and Firefox - if (e) { - e.returnValue = msg; - } - // For Safari / chrome - return msg; - }; + // window.onbeforeunload = function (evt) { + // var e = evt || window.event, + // msg = "Are you sure you want to leave?"; + // // For IE and Firefox + // if (e) { + // e.returnValue = msg; + // } + // // For Safari / chrome + // return msg; + // }; + window.onbeforeunload = null; }; WorldMorph.prototype.mouseDownLeft = function () { diff --git a/objects.js b/objects.js index ea07e6e..c4e857c 100644 --- a/objects.js +++ b/objects.js @@ -4764,7 +4764,14 @@ StageMorph.prototype.userMenu = function () { menu.addItem( "pic...", function () { - window.open(myself.fullImageClassic().toDataURL()); + //window.open(); + //window.location.href = + var ref = myself.fullImageClassic().toDataURL().replace(/^data:image\/[^;]/, 'data:application/octet-stream'); + var link = document.createElement('a'); + link.download = 'download.png'; + link.href = ref; + link.click(); + console.log("here"); }, 'open a new window\nwith a picture of the stage' ); -- cgit v1.3.1 From cdecbf86aee44226f864efd26fbd0930b309a875 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Mon, 28 Apr 2014 01:11:35 -0700 Subject: Revert f56dc8e..d3ec80f This rolls back to commit f56dc8ecf5f2845ed40b62eec4e0e2227bebd5ba. --- morphic.js | 21 ++++++++++----------- objects.js | 9 +-------- 2 files changed, 11 insertions(+), 19 deletions(-) (limited to 'objects.js') diff --git a/morphic.js b/morphic.js index 329c3ed..b55b180 100644 --- a/morphic.js +++ b/morphic.js @@ -10353,17 +10353,16 @@ WorldMorph.prototype.initEventListeners = function () { false ); - // window.onbeforeunload = function (evt) { - // var e = evt || window.event, - // msg = "Are you sure you want to leave?"; - // // For IE and Firefox - // if (e) { - // e.returnValue = msg; - // } - // // For Safari / chrome - // return msg; - // }; - window.onbeforeunload = null; + window.onbeforeunload = function (evt) { + var e = evt || window.event, + msg = "Are you sure you want to leave?"; + // For IE and Firefox + if (e) { + e.returnValue = msg; + } + // For Safari / chrome + return msg; + }; }; WorldMorph.prototype.mouseDownLeft = function () { diff --git a/objects.js b/objects.js index c4e857c..ea07e6e 100644 --- a/objects.js +++ b/objects.js @@ -4764,14 +4764,7 @@ StageMorph.prototype.userMenu = function () { menu.addItem( "pic...", function () { - //window.open(); - //window.location.href = - var ref = myself.fullImageClassic().toDataURL().replace(/^data:image\/[^;]/, 'data:application/octet-stream'); - var link = document.createElement('a'); - link.download = 'download.png'; - link.href = ref; - link.click(); - console.log("here"); + window.open(myself.fullImageClassic().toDataURL()); }, 'open a new window\nwith a picture of the stage' ); -- cgit v1.3.1 From 094b5120e46478af501e46da8e58811b97da0739 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Thu, 8 May 2014 12:06:16 -0700 Subject: Moved the screenshot block to looks --- objects.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index ea07e6e..b2e0c74 100644 --- a/objects.js +++ b/objects.js @@ -387,6 +387,12 @@ SpriteMorph.prototype.initBlocks = function () { spec: 'go back %n layers', defaults: [1] }, + doScreenshot: { + type: 'command', + category: 'looks', + spec: 'save %imgsource as costume named %s', + defaults: [['pen trails'], 'screenshot'] + }, // Looks - Debugging primitives for development mode alert: { @@ -809,12 +815,6 @@ SpriteMorph.prototype.initBlocks = function () { category: 'sensing', spec: 'current %dates' }, - doScreenshot: { - type: 'command', - category: 'sensing', - spec: 'save %imgsource as costume named %s', - defaults: [['pen trails'], 'screenshot'] - }, // Operators reifyScript: { @@ -1616,6 +1616,8 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push('-'); blocks.push(block('comeToFront')); blocks.push(block('goBack')); + blocks.push('-'); + blocks.push(block('doScreenshot')); // for debugging: /////////////// @@ -1754,8 +1756,6 @@ SpriteMorph.prototype.blockTemplates = function (category) { blocks.push(block('reportIsFastTracking')); blocks.push(block('doSetFastTracking')); blocks.push('-'); - blocks.push(block('doScreenshot')); - blocks.push('-'); blocks.push(block('reportDate')); // for debugging: /////////////// @@ -4409,6 +4409,8 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push(block('changeEffect')); blocks.push(block('setEffect')); blocks.push(block('clearEffects')); + blocks.push('-'); + blocks.push(block('doScreenshot')); // for debugging: /////////////// @@ -4525,8 +4527,6 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push(block('doSetFastTracking')); blocks.push('-'); blocks.push(block('reportDate')); - blocks.push('-'); - blocks.push(block('doScreenshot')); // for debugging: /////////////// -- cgit v1.3.1 From a8baea7df983388791085c5fa2147c6d488a7d3c Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Sat, 10 May 2014 16:44:42 -0700 Subject: Localization support --- objects.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index b2e0c74..9f42f76 100644 --- a/objects.js +++ b/objects.js @@ -391,7 +391,7 @@ SpriteMorph.prototype.initBlocks = function () { type: 'command', category: 'looks', spec: 'save %imgsource as costume named %s', - defaults: [['pen trails'], 'screenshot'] + defaults: [['pen trails'], localize('screenshot')] }, // Looks - Debugging primitives for development mode -- cgit v1.3.1 From c8bb7ce225091c078819fec308fc550324505733 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Fri, 30 May 2014 09:38:54 +0400 Subject: Fixed indentation issue --- objects.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 9f42f76..36ee1ae 100644 --- a/objects.js +++ b/objects.js @@ -3707,13 +3707,13 @@ SpriteMorph.prototype.reactToDropOf = function (morph, hand) { }; SpriteMorph.prototype.newCostumeNameCached = function (data) { - if (this.screenshotNames.hasOwnProperty(data)) { // Screenshot naming - this.screenshotNames[data] += 1; - data += '(' + this.screenshotNames[data] + ')'; - } else { - this.screenshotNames[data] = 0; - } - return data; + if (this.screenshotNames.hasOwnProperty(data)) { // Screenshot naming + this.screenshotNames[data] += 1; + data += '(' + this.screenshotNames[data] + ')'; + } else { + this.screenshotNames[data] = 0; + } + return data; }; var re = /\((\d+)\)$/; -- cgit v1.3.1 From 159b4b26058fa1b630f2709b938c47902f1188c7 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Fri, 30 May 2014 09:46:16 +0400 Subject: Fixed naming issue and removed extra function --- objects.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 36ee1ae..52f3362 100644 --- a/objects.js +++ b/objects.js @@ -3706,18 +3706,8 @@ SpriteMorph.prototype.reactToDropOf = function (morph, hand) { morph.slideBackTo(hand.grabOrigin); }; -SpriteMorph.prototype.newCostumeNameCached = function (data) { - if (this.screenshotNames.hasOwnProperty(data)) { // Screenshot naming - this.screenshotNames[data] += 1; - data += '(' + this.screenshotNames[data] + ')'; - } else { - this.screenshotNames[data] = 0; - } - return data; -}; - -var re = /\((\d+)\)$/; -SpriteMorph.prototype.newCostumeNameFn = function (name) { +var re = /\((\d+)\)$/; // RegExp to match costume names +SpriteMorph.prototype.newCostumeName = function (name) { var foundSameName = false, foundIndex = false, lastIndex = 0; @@ -3741,7 +3731,7 @@ SpriteMorph.prototype.newCostumeNameFn = function (name) { lastIndex += 1; return name + '(' + lastIndex + ')'; // New index with a +1 } - return name + '(1)'; // No indexing has started so start it off with a (1) + return name + '(2)'; // No indexing has started so start it off with a (1) } return name; }; @@ -3750,7 +3740,7 @@ SpriteMorph.prototype.doScreenshot = function (imgSource, data) { var canvas, stage = this.parentThatIsA(StageMorph), costume; - data = this.newCostumeNameFn(data); + data = this.newCostumeName(data); //data = this.newCostumeNameCached(data); // Uncomment to profile if (imgSource[0] === "pen trails") { canvas = stage.trailsCanvas; -- cgit v1.3.1 From 209f05dfffa55832da56a7cb4a53d23bd97ce7c4 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Fri, 30 May 2014 09:47:22 +0400 Subject: Made updates to StageMorph functions --- objects.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 52f3362..fb1804e 100644 --- a/objects.js +++ b/objects.js @@ -4858,11 +4858,8 @@ StageMorph.prototype.deleteVariable = SpriteMorph.prototype.deleteVariable; StageMorph.prototype.doScreenshot = SpriteMorph.prototype.doScreenshot; -StageMorph.prototype.newCostumeNameCached - = SpriteMorph.prototype.newCostumeNameCached; - -StageMorph.prototype.newCostumeNameFn - = SpriteMorph.prototype.newCostumeNameFn; +StageMorph.prototype.newCostumeName + = SpriteMorph.prototype.newCostumeName; StageMorph.prototype.blockForSelector = SpriteMorph.prototype.blockForSelector; -- cgit v1.3.1 From 7daaf1252a651271f170abc0a7a0f532778aad51 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Fri, 30 May 2014 09:51:30 +0400 Subject: Do nothing when blank action passed --- objects.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index fb1804e..4b1b359 100644 --- a/objects.js +++ b/objects.js @@ -3741,7 +3741,9 @@ SpriteMorph.prototype.doScreenshot = function (imgSource, data) { stage = this.parentThatIsA(StageMorph), costume; data = this.newCostumeName(data); - //data = this.newCostumeNameCached(data); // Uncomment to profile + if (imgSource[0] === undefined) { + return; + } if (imgSource[0] === "pen trails") { canvas = stage.trailsCanvas; costume = new Costume(canvas, data).copy(); // Copy is required to prevent mutation -- cgit v1.3.1 From 36bbcdd5effc25eebb42fb260efe7eb96cdcc6bf Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Sun, 13 Jul 2014 10:01:08 +0400 Subject: Resolved conflicts and JSLinted --- objects.js | 54 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 26 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index 002b7e3..ed4c7bc 100644 --- a/objects.js +++ b/objects.js @@ -4083,32 +4083,36 @@ SpriteMorph.prototype.reactToDropOf = function (morph, hand) { var re = /\((\d+)\)$/; // RegExp to match costume names SpriteMorph.prototype.newCostumeName = function (name) { - var foundSameName = false, - foundIndex = false, - lastIndex = 0; - for (i = 1; i <= this.costumes.length(); i++) { - var costume = this.costumes.at(i); - if (costume != null) { - if (costume.name === name) { - foundSameName = true; - } - if (foundSameName) { - var p = re.exec(costume.name); - if (p) { - lastIndex = Number(p[1]); - foundIndex = true; + var foundSameName = false, + foundIndex = false, + lastIndex = 0, + i = 1, + p = null, + costume = null; + + for (i = 1; i <= this.costumes.length(); i++) { + costume = this.costumes.at(i); + if (costume !== null) { + if (costume.name === name) { + foundSameName = true; + } + if (foundSameName) { + p = re.exec(costume.name); + if (p) { + lastIndex = Number(p[1]); + foundIndex = true; + } + } } - } } - } - if (foundSameName) { - if (foundIndex) { - lastIndex += 1; - return name + '(' + lastIndex + ')'; // New index with a +1 + if (foundSameName) { + if (foundIndex) { + lastIndex += 1; + return name + '(' + lastIndex + ')'; // New index with a +1 + } + return name + '(2)'; // No indexing has started so start it off with a (1) } - return name + '(2)'; // No indexing has started so start it off with a (1) - } - return name; + return name; }; SpriteMorph.prototype.doScreenshot = function (imgSource, data) { @@ -4805,12 +4809,10 @@ StageMorph.prototype.blockTemplates = function (category) { blocks.push(block('setEffect')); blocks.push(block('clearEffects')); blocks.push('-'); -<<<<<<< HEAD blocks.push(block('doScreenshot')); -======= + blocks.push('-'); blocks.push(block('show')); blocks.push(block('hide')); ->>>>>>> master // for debugging: /////////////// -- cgit v1.3.1 From 3ca3d33642497b3b4e2a2d016f7a6824b681c5b1 Mon Sep 17 00:00:00 2001 From: Viraj Mahesh Date: Sun, 13 Jul 2014 12:37:49 +0400 Subject: Removed screenshot name cache --- objects.js | 2 -- 1 file changed, 2 deletions(-) (limited to 'objects.js') diff --git a/objects.js b/objects.js index ed4c7bc..55d30b1 100644 --- a/objects.js +++ b/objects.js @@ -4234,8 +4234,6 @@ StageMorph.prototype.init = function (globals) { this.acceptsDrops = false; this.setColor(new Color(255, 255, 255)); this.fps = this.frameRate; - - this.screenshotNames = {}; // Keeps track of stage image names }; // StageMorph scaling -- cgit v1.3.1