Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3578,6 +3578,10 @@ CommandBlockMorph.prototype.snap = function () {
scripts.clearDropHistory();
scripts.lastDroppedBlock = this;

// EDITED: DEBUGGING PURPOSES ONLY
scripts.blockHistory.push(this);
// console.log(scripts.blockHistory + scripts.count); // debugging purposes only

if (target === null) {
this.startLayout();
this.fixBlockColor();
Expand Down Expand Up @@ -4939,6 +4943,9 @@ ScriptsMorph.prototype.init = function (owner) {
this.lastPreservedBlocks = null;
this.lastNextBlock = null;

// edited: "undo adding block" attributes:
this.blockHistory = [];

// keyboard editing support:
this.focus = null;

Expand Down Expand Up @@ -5260,6 +5267,13 @@ ScriptsMorph.prototype.userMenu = function () {
}
menu.addItem('clean up', 'cleanUp', 'arrange scripts\nvertically');
menu.addItem('add comment', 'addComment');
// Mini Project - EDITED: ADD UNDO FOR BLOCKS BEING DROPPED
if (this.blockHistory.length > 0) {
menu.addItem(
'undo',
'undoBlockDropped',
'undo the drop\naction for the\nlast block');
}
if (this.lastDroppedBlock) {
menu.addItem(
'undrop',
Expand Down Expand Up @@ -5366,6 +5380,14 @@ ScriptsMorph.prototype.addComment = function () {
new CommentMorph().pickUp(this.world());
};

// Mini-Project - EDITED: Added function for undo-ing block dropping
ScriptsMorph.prototype.undoBlockDropped = function() {
//console.log(this.blockHistory.length); // debugging purposes
var block = this.blockHistory.pop();
//console.log(block); // debugging purposes
block.destroy();
}

ScriptsMorph.prototype.undrop = function () {
if (!this.lastDroppedBlock) {return; }
if (this.lastDroppedBlock instanceof CommandBlockMorph) {
Expand Down Expand Up @@ -5451,6 +5473,7 @@ ScriptsMorph.prototype.reactToDropOf = function (droppedMorph, hand) {
// ScriptsMorph events

ScriptsMorph.prototype.mouseClickLeft = function (pos) {
// edited: left clicking INSIDE the script box
var shiftClicked = this.world().currentKey === 16;
if (shiftClicked) {
return this.edit(pos);
Expand Down
27 changes: 22 additions & 5 deletions gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ var SoundIconMorph;
var JukeboxMorph;
var StageHandleMorph;

// EDITED: var keeping this temp instance to revert back to // for mini-project: version control attempt
var temp;

// Get the full url without "snap.html"
var baseURL = (function getPath(location) {
var origin, path, slash;
Expand Down Expand Up @@ -487,6 +490,7 @@ IDE_Morph.prototype.buildPanes = function () {
this.createSpriteEditor();
this.createCorralBar();
this.createCorral();
this.temp = this;
};

IDE_Morph.prototype.createLogo = function () {
Expand Down Expand Up @@ -1232,13 +1236,14 @@ IDE_Morph.prototype.createSpriteBar = function () {

IDE_Morph.prototype.createSpriteEditor = function () {
// assumes that the logo pane and the stage have already been created

var scripts = this.currentSprite.scripts,
myself = this;

if (this.spriteEditor) {
this.spriteEditor.destroy();
}

// EDITED : THIS IS THE SCRIPT EDITOR FRAME MORPH // for mini-project: version control attempt
if (this.currentTab === 'scripts') {
scripts.isDraggable = false;
scripts.color = this.groupColor;
Expand All @@ -1259,6 +1264,7 @@ IDE_Morph.prototype.createSpriteEditor = function () {
this.add(this.spriteEditor);
this.spriteEditor.scrollX(this.spriteEditor.padding);
this.spriteEditor.scrollY(this.spriteEditor.padding);

} else if (this.currentTab === 'costumes') {
this.spriteEditor = new WardrobeMorph(
this.currentSprite,
Expand All @@ -1270,7 +1276,7 @@ IDE_Morph.prototype.createSpriteEditor = function () {

this.spriteEditor.acceptsDrops = false;
this.spriteEditor.contents.acceptsDrops = false;
} else if (this.currentTab === 'sounds') {
} else if (this.currentTab === 'sounds') {
this.spriteEditor = new JukeboxMorph(
this.currentSprite,
this.sliderColor
Expand Down Expand Up @@ -1473,8 +1479,9 @@ IDE_Morph.prototype.fixLayout = function (situation) {
// 'selectSprite' or 'refreshPalette' or 'tabEditor'
var padding = this.padding;

// this is for changing the palette
Morph.prototype.trackChanges = false;

if (situation !== 'refreshPalette') {
// controlBar
this.controlBar.setPosition(this.logo.topRight());
Expand Down Expand Up @@ -2471,6 +2478,8 @@ IDE_Morph.prototype.projectMenu = function () {
menu.addLine();
menu.addItem('New', 'createNewProject');
menu.addItem('Open...', 'openProjectsBrowser');
// ADDED UNDO OPTION (UI) ONTO DROP DOWN SETTINGS MENU
menu.addItem('Undo', "undoLast");
menu.addItem('Save', "save");
if (shiftClicked) {
menu.addItem(
Expand Down Expand Up @@ -2745,7 +2754,7 @@ IDE_Morph.prototype.aboutSnap = function () {
}
translations = localize('Translations') + '\n' + SnapTranslator.credits();

dlg = new DialogBoxMorph();
dlg = new DiaogBoxMorph();
dlg.inform('About Snap', aboutTxt, world);
btn1 = dlg.buttons.children[0];
translatorsBtn = dlg.addButton(
Expand Down Expand Up @@ -2915,7 +2924,7 @@ IDE_Morph.prototype.newProject = function () {
};

IDE_Morph.prototype.save = function () {
if (this.source === 'examples') {
if (this.source === 'examples') { // edit: premade snap code
this.source = 'local'; // cannot save to examples
}
if (this.projectName) {
Expand All @@ -2929,6 +2938,13 @@ IDE_Morph.prototype.save = function () {
}
};

//PLEASE ADD IN THE UNDO FUNCTION INTO HERE
// IDE_Morph.prototype.undoLast = function () {
// console.log("you are calling undo");
// var myself = this;
// myself = this.temp;
// }


IDE_Morph.prototype.saveProject = function (name) {
var myself = this;
Expand Down Expand Up @@ -5601,6 +5617,7 @@ SpriteIconMorph.prototype.prepareToBeGrabbed = function () {
var ide = this.parentThatIsA(IDE_Morph),
idx;
this.mouseClickLeft(); // select me
// Edit: the encapsulated sprite icon
if (ide) {
idx = ide.sprites.asArray().indexOf(this.object);
ide.sprites.remove(idx + 1);
Expand Down
20 changes: 16 additions & 4 deletions objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,12 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'operators',
spec: '%n / %n' // '%n \u00F7 %n'
},
// week 6 assignment: added square operator
reportSquare: {
type: 'reporter',
category: 'operators',
spec: 'square %n' // '%n \u00F7 %n'
},
reportRound: {
type: 'reporter',
category: 'operators',
Expand Down Expand Up @@ -1295,10 +1301,12 @@ SpriteMorph.prototype.blockAlternatives = {
reportMouseY: ['reportMouseX'],

// operators:
reportSum: ['reportDifference', 'reportProduct', 'reportQuotient'],
reportDifference: ['reportSum', 'reportProduct', 'reportQuotient'],
reportProduct: ['reportDifference', 'reportSum', 'reportQuotient'],
reportQuotient: ['reportDifference', 'reportProduct', 'reportSum'],
// week 6 assignment: added math operator
reportSum: ['reportDifference', 'reportProduct', 'reportQuotient', 'reportSquare'],
reportDifference: ['reportSum', 'reportProduct', 'reportQuotient', 'reportSquare'],
reportProduct: ['reportDifference', 'reportSum', 'reportQuotient','reportSquare'],
reportQuotient: ['reportDifference', 'reportProduct', 'reportSum', 'reportSquare'],
reportSquare: ['reportSum','reportDifference', 'reportProduct', 'reportQuotient'],
reportLessThan: ['reportEquals', 'reportGreaterThan'],
reportEquals: ['reportLessThan', 'reportGreaterThan'],
reportGreaterThan: ['reportEquals', 'reportLessThan'],
Expand Down Expand Up @@ -1980,6 +1988,8 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push(block('reportDifference'));
blocks.push(block('reportProduct'));
blocks.push(block('reportQuotient'));
// week 6 assignment: added math operator
blocks.push(block('reportSquare'));
blocks.push('-');
blocks.push(block('reportModulus'));
blocks.push(block('reportRound'));
Expand Down Expand Up @@ -5512,6 +5522,8 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push(block('reportDifference'));
blocks.push(block('reportProduct'));
blocks.push(block('reportQuotient'));
// week 6 assignment: added math operator
blocks.push(block('reportSquare'));
blocks.push('-');
blocks.push(block('reportModulus'));
blocks.push(block('reportRound'));
Expand Down
Loading