summaryrefslogtreecommitdiff
path: root/objects.js
diff options
context:
space:
mode:
authorViraj Mahesh <virajmahesh@gmail.com>2014-03-12 16:36:14 -0700
committerViraj Mahesh <virajmahesh@gmail.com>2014-03-12 16:36:14 -0700
commitfa02caef5d5944496dcd32a677ba38c10a8768d9 (patch)
tree7904a955b317b212ebcdd9a9dbecca87e5827646 /objects.js
parente1c74e75f3581240fe528e910331f0068471f810 (diff)
downloadsnap-byow-fa02caef5d5944496dcd32a677ba38c10a8768d9.tar.gz
snap-byow-fa02caef5d5944496dcd32a677ba38c10a8768d9.zip
Implemented both ways of Screenshot naming
Diffstat (limited to 'objects.js')
-rw-r--r--objects.js49
1 files changed, 43 insertions, 6 deletions
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